Load systeminformation from easy to change source.

git-svn-id: https://svn.libreccm.org/ccm/trunk@2673 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2014-06-06 11:59:22 +00:00
parent b37c376eb6
commit f6ae155a06
3 changed files with 45 additions and 105 deletions

View File

@ -188,9 +188,6 @@ public class Initializer extends CompoundInitializer {
} }
}); });
// Set system informations
// loadSystemInformation();
// register the document converters // register the document converters
Converter converter = new PDFConverter(); Converter converter = new PDFConverter();
ConverterRegistry.registerConverter(converter, ConverterRegistry.registerConverter(converter,
@ -228,14 +225,4 @@ public class Initializer extends CompoundInitializer {
s_log.info("Core init(DomainInitEvent) done"); s_log.info("Core init(DomainInitEvent) done");
} }
// private void loadSystemInformation() {
// SystemInformation sysInfo = SystemInformation.getInstance();
//
// // Hardcoded for now
// sysInfo.put("version", "v2.3.x-SNAPSHOT");
// sysInfo.put("appname", "ScientificCMS");
// sysInfo.put("apphomepage", "http://www.scientificcms.org");
// sysInfo.lock();
// }
} }

View File

@ -1,14 +1,24 @@
/* /*
* To change this template, choose Tools | Templates * Copyright (c) 2014 Jens Pelzetter
* and open the template in the editor. *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/ */
package com.arsdigita.util; package com.arsdigita.util;
import com.arsdigita.runtime.AbstractConfig;
import com.arsdigita.util.parameter.Parameter;
import com.arsdigita.util.parameter.StringParameter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
@ -16,32 +26,46 @@ import java.util.Properties;
/** /**
* Provides the system name of the CCM Spin off (eg aplaws or ScientificCMS) and the version number. * Provides the system name of the CCM Spin off (eg aplaws or ScientificCMS) and the version number.
* It's primary use is to provide the theme engine with that information for display. It is * It's primary use is to provide the theme engine with that information for display. The data
* currently stored as a (configurable) property, but should be retrieved from the build system in * displayed is stored in the /WEB-INF/systeminformation.properties, which is usually provided by
* the future. * the bundle. The ccm-sci-bundle for example provides this file, which can be found in
* {@code ccm-sci-bundle/web/WEB-INF} directory. At the moment it is necessary to update this
* (these) file(s) manually.
*
* A {@code systeminformations.properties} should contain at least these three properties:
* <dl>
* <dt>version</dt>
* <dd>The version of the specific CCM distribution.</dd>
* <dt>appname</dt>
* <dd>The name of the CCM distribution, for example <strong>ScientificCMS</strong>
* <dt>apphomepage</dt>
* <dd>
The URL of the website of the CCM distribution, for example
* {@code http://www.scientificcms.org}
* </dd>
* </dl>
*
* *
* @author Sören Bernstein <quasi@quasiweb.de>
* @author Jens Pelzetter * @author Jens Pelzetter
* @version $Id$
*/ */
public class SystemInformation { //extends AbstractConfig { //implements Lockable { public class SystemInformation {
// private Parameter sysInfoParam = new StringParameter(
// "ccm.systeminformation",
// Parameter.REQUIRED,
// "version::2.x.y; appname::LibreCCM; apphomepage::http://www.libreccm.org;");
/**
* Map containing all informations provided by the {@code systeminformation.properties} file.
*/
private final Map<String, String> sysInfo = new HashMap<String, String>(); private final Map<String, String> sysInfo = new HashMap<String, String>();
//private boolean locked = false;
/** /**
* The one and only instance of this class * The one and only instance of this class
*/ */
private final static SystemInformation INSTANCE = new SystemInformation(); private final static SystemInformation INSTANCE = new SystemInformation();
/**
* The constructor takes care of loading the data from the properties file and placing them into
* {@code HashMap}.
*/
public SystemInformation() { public SystemInformation() {
//register(sysInfoParam);
//loadInfo();
final Properties properties = new Properties(); final Properties properties = new Properties();
try { try {
properties.load(ResourceManager.getInstance().getResourceAsStream("/WEB-INF/systeminformation.properties")); properties.load(ResourceManager.getInstance().getResourceAsStream("/WEB-INF/systeminformation.properties"));
@ -58,35 +82,10 @@ public class SystemInformation { //extends AbstractConfig { //implements Lockabl
* @return The instance of this class. * @return The instance of this class.
*/ */
public static SystemInformation getInstance() { public static SystemInformation getInstance() {
// if (INSTANCE == null) {
// INSTANCE = new SystemInformation();
// INSTANCE.load();
// }
return INSTANCE; return INSTANCE;
} }
// /** /*
// * Put system information into the map. If this instance is locked, this method throw an
// * {@link AssertionError}.
// *
// * @param key Key for the Map. Also used as attribute name during output.
// * @param value Value
// *
// * @throws IllegalArgumentException if key or value is null or empty
// */
// final public void put(final String key, final String value) throws IllegalArgumentException {
// if (key == null || key.isEmpty()) {
// throw new IllegalArgumentException("Parameter key must not be null or empty.");
// }
// if (value == null || value.isEmpty()) {
// throw new IllegalArgumentException("Parameter value must not be null or empty.");
// }
// // Test if instance is not locked
// Assert.isUnlocked(this);
// systemInformation.put(key, value);
// }
/**
* Get system informations by key. * Get system informations by key.
* *
* @param key Key for the map * @param key Key for the map
@ -96,10 +95,6 @@ public class SystemInformation { //extends AbstractConfig { //implements Lockabl
* @throws IllegalArgumentException if key is null or empty * @throws IllegalArgumentException if key is null or empty
*/ */
final public String get(final String key) throws IllegalArgumentException { final public String get(final String key) throws IllegalArgumentException {
// if (sysInfo == null) {
// loadMap();
// }
if (key == null || key.isEmpty()) { if (key == null || key.isEmpty()) {
throw new IllegalArgumentException("Parameter key must not be null or empty."); throw new IllegalArgumentException("Parameter key must not be null or empty.");
} }
@ -112,10 +107,6 @@ public class SystemInformation { //extends AbstractConfig { //implements Lockabl
* @return iterator of map * @return iterator of map
*/ */
final public Iterator<Map.Entry<String, String>> iterator() { final public Iterator<Map.Entry<String, String>> iterator() {
// if (sysInfo == null) {
// loadMap();
// }
return sysInfo.entrySet().iterator(); return sysInfo.entrySet().iterator();
} }
@ -124,43 +115,7 @@ public class SystemInformation { //extends AbstractConfig { //implements Lockabl
* @return * @return
*/ */
final public boolean isEmpty() { final public boolean isEmpty() {
// if (sysInfo == null) {
// loadMap();
// }
return sysInfo.isEmpty(); return sysInfo.isEmpty();
} }
/**
* Lock this instance to prevent further changes.
*/
// final public void lock() {
// locked = true;
// }
//
// /**
// * Test, if this instance is locked.
// *
// * @return locked
// */
// final public boolean isLocked() {
// return locked;
// }
// private void loadMap() {
// sysInfo = new HashMap<String, String>();
//
// final String[] tokens = ((String) get(sysInfoParam)).split(";");
// for (String token : tokens) {
// processToken(token);
// }
// }
//
// private void processToken(final String token) {
// final String[] parts = token.split("::");
// if (2 == parts.length) {
// sysInfo.put(parts[0].trim(), parts[1].trim());
// }
// }
} }

View File

@ -1,5 +1,3 @@
version = 2.3.x version = 2.3.x
appname = ScientificCMS appname = ScientificCMS
apphomepage = http://www.scientificcms.org apphomepage = http://www.scientificcms.org
ccm.test = "Loaded from property file"