Clover coverage report - QedeqKernelSe Coverage Report
Coverage timestamp: Do Mai 10 2007 03:16:40 CEST
file stats: LOC: 299   Methods: 22
NCLOC: 108   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
QedeqConfig.java 10% 18,4% 22,7% 17,5%
coverage coverage
 1    /* $Id: QedeqConfig.java,v 1.2 2007/05/10 00:37:53 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.util.List;
 23   
 24   
 25    /**
 26    * This class gives a type save access to properties of the application.
 27    *
 28    * FIXME mime 20070328: for directory files are different methods used:
 29    * 1. look relative to getStartDirectory
 30    * 2. try absolute path
 31    * Only one way should be used for all.
 32    *
 33    *
 34    * @version $Revision: 1.2 $
 35    * @author Michael Meyling
 36    */
 37    public final class QedeqConfig {
 38   
 39    /** Default location for newly created QEDEQ modules. */
 40    private static final String DEFAULT_LOCAL_MODULES_DIRECTORY
 41    = "local";
 42   
 43    /** Default location for locally buffered module files. */
 44    private static final String DEFAULT_LOCAL_BUFFER
 45    = "buffer";
 46   
 47    /** Default location for generated module and document files. */
 48    private static final String DEFAULT_GENERATED
 49    = "generated";
 50   
 51    /** Default log file path. */
 52    private static final String DEFAULT_LOG_FILE
 53    = "log/log.txt";
 54   
 55    /** This class organizes the access to the config parameters. */
 56    private final ConfigAccess configAccess;
 57   
 58    /**
 59    * Constructor.
 60    *
 61    * @param configDirectory Directory location of config file.
 62    * @param configFileName Name of config file.
 63    * @param description Config file description
 64    * @throws IOException Config file couldn't be loaded.
 65    */
 66  3 public QedeqConfig(final File configDirectory, final String configFileName,
 67    final String description) throws IOException {
 68  3 configAccess = new ConfigAccess(configDirectory, configFileName, description);
 69    }
 70   
 71    /**
 72    * Store properties in config file.
 73    *
 74    * @throws IOException
 75    */
 76  3 public final void store() throws IOException {
 77  3 configAccess.store();
 78    }
 79   
 80    /**
 81    * Get local file directory to save generated files in.
 82    *
 83    * @return Generation directory.
 84    */
 85  0 public final String getGenerationDirectory() {
 86  0 final String location = configAccess.getString("generationLocation");
 87  0 if (location == null) {
 88  0 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 configAccess.setString("generationLocation", location);
 100    }
 101   
 102    /**
 103    * Get local file directory for module buffering.
 104    *
 105    * @return Buffer directory.
 106    */
 107  0 public final String getBufferDirectory() {
 108  0 final String location = configAccess.getString("bufferLocation");
 109  0 if (location == null) {
 110  0 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 configAccess.setString("bufferLocation", location);
 124    }
 125   
 126    /**
 127    * Get local file location for log file.
 128    *
 129    * @return Log file path.
 130    */
 131  0 public final String getLogFilePath() {
 132  0 final String location = configAccess.getString("logLocation");
 133  0 if (location == null) {
 134  0 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  0 public final String[] getModuleHistory() {
 145  0 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  0 public final void saveModuleHistory(final List modules) {
 154  0 configAccess.removeProperties(("moduleHistory."));
 155  0 for (int i = 0; i < modules.size(); i++) {
 156  0 configAccess.setString("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  6 public final String[] getPreviouslyCheckedModules() {
 167  6 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  3 public final void setLoadedModules(final String[] moduleAddresses) {
 176  3 configAccess.removeProperties("checkedModule.");
 177  3 for (int i = 0; i < moduleAddresses.length; i++) {
 178  9 configAccess.setString("checkedModule." + (i + 1), moduleAddresses[i]);
 179    }
 180    }
 181   
 182    /**
 183    * Get start directory of this application.
 184    *
 185    * TODO mime 20070326: ok?
 186    *
 187    * @return Start directory.
 188    */
 189  0 public final File getStartDirectory() {
 190  0 return new File(".");
 191    }
 192   
 193    /**
 194    * Get autostart html mode.
 195    *
 196    * @return list of modules.
 197    */
 198  0 public final boolean isAutoStartHtmlBrowser() {
 199  0 return "true".equals(
 200    configAccess.getString("autoStartHtmlBrowser", "true"));
 201    }
 202   
 203   
 204    /**
 205    * Set auto start HTML browser.
 206    *
 207    * @param mode Auto start?
 208    */
 209  0 public final void setAutoStartHtmlBrowser(final boolean mode) {
 210  0 configAccess.setString("autoStartHtmlBrowser", (mode ? "true" : "false"));
 211    }
 212   
 213   
 214    /**
 215    * Get direct response mode.
 216    *
 217    * @return Direct response mode.
 218    */
 219  0 public final boolean isDirectResponse() {
 220  0 return "true".equals(
 221    configAccess.getString("directResponse", "true"));
 222    }
 223   
 224   
 225    /**
 226    * Set direct response mode.
 227    *
 228    * @param mode enable direct response?
 229    */
 230  0 public final void setDirectResponse(final boolean mode) {
 231  0 configAccess.setString("directResponse", (mode ? "true" : "false"));
 232    }
 233   
 234    /**
 235    * Get auto reload of last session successfully loaded modules.
 236    *
 237    * @return auto reload enabled?
 238    */
 239  3 public boolean isAutoReloadLastSessionChecked() {
 240  3 return "true".equals(
 241    configAccess.getString("sessionAutoReload", "true"));
 242    }
 243   
 244   
 245    /**
 246    * Set auto reload checked modules of last session mode.
 247    *
 248    * @param mode enable auto reload?
 249    */
 250  0 public final void setAutoReloadLastSessionChecked(final boolean mode) {
 251  0 configAccess.setString("sessionAutoReload", (mode ? "true" : "false"));
 252    }
 253   
 254   
 255    /**
 256    * Should old html code be generated?
 257    *
 258    * @return old html code?
 259    */
 260  0 public final boolean isOldHtml() {
 261  0 return "true".equals(configAccess.getString("oldHtml", "true"));
 262    }
 263   
 264    /**
 265    * Set old html code generation flag.
 266    *
 267    * @param mode set old html code generation?
 268    */
 269  0 public final void setOldHtml(final boolean mode) {
 270  0 configAccess.setString("oldHtml", (mode ? "true" : "false"));
 271    }
 272   
 273   
 274    /**
 275    * Get directory for newly created QEDEQ module files.
 276    *
 277    * @return Directory for newly created QEDEQ modules.
 278    */
 279  0 public final String getLocalModulesDirectory() {
 280  0 final String location = configAccess.getString("localModulesDirectory");
 281  0 if (location == null) {
 282  0 return QedeqConfig.DEFAULT_LOCAL_MODULES_DIRECTORY;
 283    }
 284  0 return location;
 285    }
 286   
 287   
 288    /**
 289    * Set directory for newly created module files.
 290    * After changing this location the buffer should eventually be cleared.
 291    *
 292    * @param location Buffer directory.
 293    */
 294  0 public final void setLocalModulesDirectory(final String location) {
 295  0 configAccess.setString("localModulesDirectory", location);
 296    }
 297   
 298   
 299    }