Coverage Report - org.crosswire.jsword.util.WebWarning
 
Classes in this File Line Coverage Branch Coverage Complexity
WebWarning
0%
0/25
N/A
1.25
 
 1  
 /**
 2  
  * Distribution License:
 3  
  * JSword is free software; you can redistribute it and/or modify it under
 4  
  * the terms of the GNU Lesser General Public License, version 2.1 or later
 5  
  * as published by the Free Software Foundation. This program is distributed
 6  
  * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 7  
  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 8  
  * See the GNU Lesser General Public License for more details.
 9  
  *
 10  
  * The License is available on the internet at:
 11  
  *      http://www.gnu.org/copyleft/lgpl.html
 12  
  * or by writing to:
 13  
  *      Free Software Foundation, Inc.
 14  
  *      59 Temple Place - Suite 330
 15  
  *      Boston, MA 02111-1307, USA
 16  
  *
 17  
  * © CrossWire Bible Society, 2007 - 2016
 18  
  *
 19  
  */
 20  
 package org.crosswire.jsword.util;
 21  
 
 22  
 import java.io.IOException;
 23  
 import java.net.URI;
 24  
 
 25  
 import org.crosswire.common.util.CWProject;
 26  
 import org.crosswire.common.util.FileUtil;
 27  
 import org.crosswire.common.util.NetUtil;
 28  
 import org.crosswire.common.util.PropertyMap;
 29  
 import org.crosswire.common.util.ResourceUtil;
 30  
 import org.crosswire.jsword.JSMsg;
 31  
 import org.slf4j.Logger;
 32  
 import org.slf4j.LoggerFactory;
 33  
 
 34  
 /**
 35  
  * Provide a configurable warning that the Internet is going to be accessed.
 36  
  * This is important in places where Internet activity may be monitored and
 37  
  * Christians may be persecuted.
 38  
  * 
 39  
  * @see gnu.lgpl.License The GNU Lesser General Public License for details.
 40  
  * @author DM Smith
 41  
  */
 42  
 public final class WebWarning {
 43  
     /**
 44  
      * This is a utility class, thus it's constructor is private.
 45  
      */
 46  0
     private WebWarning() {
 47  
         try {
 48  0
             PropertyMap props = ResourceUtil.getProperties(getClass().getName());
 49  0
             shown = Boolean.valueOf(props.get(SHOWN_KEY, Boolean.valueOf(DEFAULT_SHOWN).toString())).booleanValue();
 50  0
         } catch (IOException e) {
 51  0
             shown = DEFAULT_SHOWN;
 52  0
         }
 53  0
     }
 54  
 
 55  
     /**
 56  
      * All access to WebWarning is through this single instance.
 57  
      * 
 58  
      * @return the singleton instance
 59  
      */
 60  
     public static WebWarning instance() {
 61  0
         return instance;
 62  
     }
 63  
 
 64  
     /**
 65  
      * @param newShown
 66  
      *            Whether this WebWarning should be shown.
 67  
      */
 68  
     public void setShown(boolean newShown) {
 69  
         try {
 70  0
             shown = newShown;
 71  0
             PropertyMap props = new PropertyMap();
 72  0
             props.put(SHOWN_KEY, Boolean.valueOf(shown).toString());
 73  0
             URI outputURI = CWProject.instance().getWritableURI(getClass().getName(), FileUtil.EXTENSION_PROPERTIES);
 74  0
             NetUtil.storeProperties(props, outputURI, "JSword WebWarning");
 75  0
         } catch (IOException ex) {
 76  0
             log.error("Failed to save JSword WebWarning", ex);
 77  0
         }
 78  0
     }
 79  
 
 80  
     /**
 81  
      * @return Whether this WebWarning should be shown.
 82  
      */
 83  
     public boolean isShown() {
 84  0
         return shown;
 85  
     }
 86  
 
 87  
     /**
 88  
      * From configuration set the state.
 89  
      * 
 90  
      * @param newShown
 91  
      *            Whether this WebWarning should be shown.
 92  
      */
 93  
     public static void setWarningShown(boolean newShown) {
 94  0
         WebWarning.instance().setShown(newShown);
 95  0
     }
 96  
 
 97  
     /**
 98  
      * @return Whether this WebWarning should be shown.
 99  
      */
 100  
     public static boolean isWarningShown() {
 101  0
         return WebWarning.instance().isShown();
 102  
     }
 103  
 
 104  
     /**
 105  
      * @return a warning that the Internet is about to be accessed
 106  
      */
 107  
     public String getWarning() {
 108  
         // TRANSLATOR: Warn the user that the program is about to access the Internet.
 109  
         // In some countries, this warning may be too bland. It might be better to warn the user that this might
 110  
         // put them at risk of persecution.
 111  0
         return JSMsg.gettext("You are about to access the Internet. Are you sure you want to do this?");
 112  
     }
 113  
 
 114  
     /**
 115  
      * @return indicate that the warning will be shown again
 116  
      */
 117  
     public String getShownWarningLabel() {
 118  
         // TRANSLATOR: This labels a checkbox, which is checked by default.
 119  
         // Unchecking it allows the user to not see the message again but the Internet will be accessed.
 120  0
         return JSMsg.gettext("Show this warning every time the Internet is accessed.");
 121  
     }
 122  
 
 123  0
     private static WebWarning instance = new WebWarning();
 124  
 
 125  
     private static final String SHOWN_KEY = "shown";
 126  
     private static final boolean DEFAULT_SHOWN = true;
 127  
     private boolean shown;
 128  
 
 129  
     /**
 130  
      * The log stream
 131  
      */
 132  0
     private static final Logger log = LoggerFactory.getLogger(WebWarning.class);
 133  
 }