From f6ae155a068507c95dfb18ab2baf9d5f38c0d5a3 Mon Sep 17 00:00:00 2001 From: jensp Date: Fri, 6 Jun 2014 11:59:22 +0000 Subject: [PATCH] Load systeminformation from easy to change source. git-svn-id: https://svn.libreccm.org/ccm/trunk@2673 8810af33-2d31-482b-a856-94f89814c4df --- .../src/com/arsdigita/core/Initializer.java | 13 -- .../com/arsdigita/util/SystemInformation.java | 135 ++++++------------ .../web/WEB-INF/systeminformation.properties | 2 - 3 files changed, 45 insertions(+), 105 deletions(-) diff --git a/ccm-core/src/com/arsdigita/core/Initializer.java b/ccm-core/src/com/arsdigita/core/Initializer.java index 23b2df921..b9bd1d6b3 100755 --- a/ccm-core/src/com/arsdigita/core/Initializer.java +++ b/ccm-core/src/com/arsdigita/core/Initializer.java @@ -188,9 +188,6 @@ public class Initializer extends CompoundInitializer { } }); - // Set system informations -// loadSystemInformation(); - // register the document converters Converter converter = new PDFConverter(); ConverterRegistry.registerConverter(converter, @@ -228,14 +225,4 @@ public class Initializer extends CompoundInitializer { 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(); -// } - } diff --git a/ccm-core/src/com/arsdigita/util/SystemInformation.java b/ccm-core/src/com/arsdigita/util/SystemInformation.java index e46203303..7d625624d 100644 --- a/ccm-core/src/com/arsdigita/util/SystemInformation.java +++ b/ccm-core/src/com/arsdigita/util/SystemInformation.java @@ -1,14 +1,24 @@ /* - * To change this template, choose Tools | Templates - * and open the template in the editor. + * Copyright (c) 2014 Jens Pelzetter + * + * 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; -import com.arsdigita.runtime.AbstractConfig; -import com.arsdigita.util.parameter.Parameter; -import com.arsdigita.util.parameter.StringParameter; import java.io.IOException; -import java.io.InputStream; import java.util.HashMap; import java.util.Iterator; 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. - * It's primary use is to provide the theme engine with that information for display. It is - * currently stored as a (configurable) property, but should be retrieved from the build system in - * the future. + * It's primary use is to provide the theme engine with that information for display. The data + * displayed is stored in the /WEB-INF/systeminformation.properties, which is usually provided by + * 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: + *
+ *
version
+ *
The version of the specific CCM distribution.
+ *
appname
+ *
The name of the CCM distribution, for example ScientificCMS + *
apphomepage
+ *
+ The URL of the website of the CCM distribution, for example + * {@code http://www.scientificcms.org} + *
+ *
+ * * - * @author Sören Bernstein * @author Jens Pelzetter + * @version $Id$ */ -public class SystemInformation { //extends AbstractConfig { //implements Lockable { - -// private Parameter sysInfoParam = new StringParameter( -// "ccm.systeminformation", -// Parameter.REQUIRED, -// "version::2.x.y; appname::LibreCCM; apphomepage::http://www.libreccm.org;"); +public class SystemInformation { + /** + * Map containing all informations provided by the {@code systeminformation.properties} file. + */ private final Map sysInfo = new HashMap(); - //private boolean locked = false; /** * The one and only instance of this class */ 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() { - //register(sysInfoParam); - //loadInfo(); - final Properties properties = new Properties(); try { 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. */ public static SystemInformation getInstance() { -// if (INSTANCE == null) { -// INSTANCE = new SystemInformation(); -// INSTANCE.load(); -// } - 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. * * @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 */ final public String get(final String key) throws IllegalArgumentException { -// if (sysInfo == null) { -// loadMap(); -// } - if (key == null || key.isEmpty()) { 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 */ final public Iterator> iterator() { -// if (sysInfo == null) { -// loadMap(); -// } - return sysInfo.entrySet().iterator(); } @@ -124,43 +115,7 @@ public class SystemInformation { //extends AbstractConfig { //implements Lockabl * @return */ final public boolean isEmpty() { -// if (sysInfo == null) { -// loadMap(); -// } - 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(); -// -// 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()); -// } -// } - } diff --git a/ccm-sci-bundle/web/WEB-INF/systeminformation.properties b/ccm-sci-bundle/web/WEB-INF/systeminformation.properties index 9c74a7a54..84165fa6b 100644 --- a/ccm-sci-bundle/web/WEB-INF/systeminformation.properties +++ b/ccm-sci-bundle/web/WEB-INF/systeminformation.properties @@ -1,5 +1,3 @@ version = 2.3.x appname = ScientificCMS apphomepage = http://www.scientificcms.org - -ccm.test = "Loaded from property file"