Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Sa Dez 22 2007 01:35:21 CET
file stats: LOC: 297   Methods: 22
NCLOC: 109   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
QedeqConfig.java 75% 82,1% 86,4% 81,8%
coverage coverage
 1    /* $Id: QedeqConfig.java,v 1.4 2007/12/21 23:33:46 m31 Exp $
 2    *
 3    * This file is part of the project "Hilbert II" - http://www.qedeq.org
 4    *
 5    * Copyright 2000-2007, Michael Meyling <mime@qedeq.org>.
 6    *
 7    * "Hilbert II" is free software; you can redistribute
 8    * it and/or modify it under the terms of the GNU General Public
 9    * License as published by the Free Software Foundation; either
 10    * version 2 of the License, or (at your option) any later version.
 11    *
 12    * This program is distributed in the hope that it will be useful,
 13    * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 15    * GNU General Public License for more details.
 16    */
 17   
 18    package org.qedeq.kernel.config;
 19   
 20    import java.io.File;
 21    import java.io.IOException;
 22    import java.net.URL;
 23    import java.util.List;
 24   
 25   
 26    /**
 27    * This class gives a type save access to properties of the application.
 28    *
 29    * @version $Revision: 1.4 $
 30    * @author Michael Meyling
 31    */
 32    public class QedeqConfig {
 33   
 34    /** Default location for newly created QEDEQ modules. */
 35    private static final String DEFAULT_LOCAL_MODULES_DIRECTORY
 36    = "local";
 37   
 38    /** Default location for locally buffered module files. */
 39    private static final String DEFAULT_LOCAL_BUFFER
 40    = "buffer";
 41   
 42    /** Default location for generated module and document files. */
 43    private static final String DEFAULT_GENERATED
 44    = "generated";
 45   
 46    /** Default log file path. */
 47    private static final String DEFAULT_LOG_FILE
 48    = "log/log.txt";
 49   
 50    /** This class organizes the access to the config parameters. */
 51    private final ConfigAccess configAccess;
 52   
 53    /** Basis directory of application for all variable data. Basis for all relative paths. */
 54    private final File basisDirectory;
 55   
 56    /**
 57    * Constructor.
 58    *
 59    * @param configFile Config file.
 60    * @param description Config file description.
 61    * @param basisDirectory Basis directory of application for all variable data. Basis for all
 62    * relative paths
 63    * @throws IOException Config file couldn't be loaded.
 64    */
 65  28 public QedeqConfig(final File configFile, final String description, final File basisDirectory)
 66    throws IOException {
 67  28 configAccess = new ConfigAccess(configFile, description);
 68  28 this.basisDirectory = basisDirectory;
 69    }
 70   
 71    /**
 72    * Store properties in config file.
 73    *
 74    * @throws IOException
 75    */
 76  28 public final void store() throws IOException {
 77  28 configAccess.store();
 78    }
 79   
 80    /**
 81    * Get local file directory to save generated files in.
 82    *
 83    * @return Generation directory.
 84    */
 85  11 public final String getGenerationDirectory() {
 86  11 final String location = getKeyValue("generationLocation");
 87  11 if (location == null) {
 88  11 return QedeqConfig.DEFAULT_GENERATED;
 89    }
 90  0 return location;
 91    }
 92   
 93    /**
 94    * Set local file directory for generated files.
 95    *
 96    * @param location generation directory.
 97    */
 98  0 public final void setGenerationDirectory(final String location) {
 99  0 setKeyValue("generationLocation", location);
 100    }
 101   
 102    /**
 103    * Get local file directory for module buffering.
 104    *
 105    * @return Buffer directory.
 106    */
 107  464 public final String getBufferDirectory() {
 108  464 final String location = getKeyValue("bufferLocation");
 109  464 if (location == null) {
 110  464 return QedeqConfig.DEFAULT_LOCAL_BUFFER;
 111    }
 112  0 return location;
 113    }
 114   
 115   
 116    /**
 117    * Set local file directory for module buffering.
 118    * After changing this location the buffer should eventually be cleared.
 119    *
 120    * @param location buffer directory.
 121    */
 122  0 public final void setBufferDirectory(final String location) {
 123  0 setKeyValue("bufferLocation", location);
 124    }
 125   
 126    /**
 127    * Get local file location for log file.
 128    *
 129    * @return Log file path.
 130    */
 131  8 public final String getLogFile() {
 132  8 final String location = getKeyValue("logLocation");
 133  8 if (location == null) {
 134  8 return QedeqConfig.DEFAULT_LOG_FILE;
 135    }
 136  0 return location;
 137    }
 138   
 139    /**
 140    * Get history of modules, which were tried to load.
 141    *
 142    * @return list of modules.
 143    */
 144  4 public final String[] getModuleHistory() {
 145  4 return configAccess.getStringProperties("moduleHistory.");
 146    }
 147   
 148    /**
 149    * Save history of modules, which were tried to load.
 150    *
 151    * @param modules list of modules.
 152    */
 153  5 public final void saveModuleHistory(final List modules) {
 154  5 configAccess.removeProperties(("moduleHistory."));
 155  5 for (int i = 0; i < modules.size(); i++) {
 156  39 setKeyValue("moduleHistory." + (i + 101),
 157    modules.get(i).toString());
 158    }
 159    }
 160   
 161    /**
 162    * Get list of previously checked modules.
 163    *
 164    * @return list of modules.
 165    */
 166  56 public final String[] getPreviouslyCheckedModules() {
 167  56 return configAccess.getStringProperties("checkedModule.");
 168    }
 169   
 170    /**
 171    * Set successfully list of successfully loaded QEDEQ modules.
 172    *
 173    * @param moduleAddresses This modules were successfully checked.
 174    */
 175  28 public final void setLoadedModules(final URL[] moduleAddresses) {
 176  28 configAccess.removeProperties("checkedModule.");
 177  28 for (int i = 0; i < moduleAddresses.length; i++) {
 178  342 setKeyValue("checkedModule." + (i + 1), moduleAddresses[i].toExternalForm());
 179    }
 180    }
 181   
 182    /**
 183    * Get basis directory of this application.
 184    *
 185    * @return Basis directory of application for all variable data. Basis for all relative paths.
 186    */
 187  478 public final File getBasisDirectory() {
 188  478 return basisDirectory;
 189    }
 190   
 191    /**
 192    * Get file path starting from basis directory of this application.
 193    *
 194    * @param path Go to this path starting from basis directory.
 195    * @return File path resolved against basis application directory.
 196    */
 197  463 public final File getRelativeToBasis(final String path) {
 198  463 return new File(getBasisDirectory(), path);
 199    }
 200   
 201    /**
 202    * Get auto reload of last session successfully loaded modules.
 203    *
 204    * @return auto reload enabled?
 205    */
 206  58 public boolean isAutoReloadLastSessionChecked() {
 207  58 return "true".equals(
 208    getKeyValue("sessionAutoReload", "true"));
 209    }
 210   
 211   
 212    /**
 213    * Set auto reload checked modules of last session mode.
 214    *
 215    * @param mode enable auto reload?
 216    */
 217  2 public final void setAutoReloadLastSessionChecked(final boolean mode) {
 218  2 setKeyValue("sessionAutoReload", (mode ? "true" : "false"));
 219    }
 220   
 221   
 222    /**
 223    * Should old html code be generated?
 224    *
 225    * @return old html code?
 226    */
 227  2 public final boolean isOldHtml() {
 228  2 return "true".equals(getKeyValue("oldHtml", "true"));
 229    }
 230   
 231    /**
 232    * Set old html code generation flag.
 233    *
 234    * @param mode set old html code generation?
 235    */
 236  2 public final void setOldHtml(final boolean mode) {
 237  2 setKeyValue("oldHtml", (mode ? "true" : "false"));
 238    }
 239   
 240   
 241    /**
 242    * Get directory for newly created QEDEQ module files.
 243    *
 244    * @return Directory for newly created QEDEQ modules.
 245    */
 246  2 public final String getLocalModulesDirectory() {
 247  2 final String location = getKeyValue("localModulesDirectory");
 248  2 if (location == null) {
 249  2 return QedeqConfig.DEFAULT_LOCAL_MODULES_DIRECTORY;
 250    }
 251  0 return location;
 252    }
 253   
 254   
 255    /**
 256    * Set directory for newly created module files.
 257    * After changing this location the buffer should eventually be cleared.
 258    *
 259    * @param location Buffer directory.
 260    */
 261  0 public final void setLocalModulesDirectory(final String location) {
 262  0 setKeyValue("localModulesDirectory", location);
 263    }
 264   
 265    /**
 266    * Get value for given key.
 267    *
 268    * @param key Get value for this key.
 269    * @return Value, maybe <code>null</code>.
 270    */
 271  489 protected String getKeyValue(final String key) {
 272  489 return configAccess.getString(key);
 273    }
 274   
 275    /**
 276    * Get value for given key.
 277    *
 278    * @param key Get value for this key.
 279    * @param defaultValue Default value..
 280    * @return Value. If value for key is originally <code>null</code> <code>defaultValue</code>
 281    * is returned..
 282    */
 283  470 protected String getKeyValue(final String key, final String defaultValue) {
 284  470 return configAccess.getString(key, defaultValue);
 285    }
 286   
 287    /**
 288    * Set value for given key.
 289    *
 290    * @param key For this key.
 291    * @param value Set this value.
 292    */
 293  393 protected void setKeyValue(final String key, final String value) {
 294  393 configAccess.setString(key, value);
 295    }
 296   
 297    }