diff --git a/ccm-core/src/com/arsdigita/bebop/Page.java b/ccm-core/src/com/arsdigita/bebop/Page.java index afee4e79b..40780144f 100755 --- a/ccm-core/src/com/arsdigita/bebop/Page.java +++ b/ccm-core/src/com/arsdigita/bebop/Page.java @@ -30,6 +30,7 @@ import com.arsdigita.developersupport.DeveloperSupport; import com.arsdigita.kernel.Kernel; import com.arsdigita.profiler.Profiler; import com.arsdigita.util.Assert; +import com.arsdigita.util.SystemInformation; import com.arsdigita.xml.Document; import com.arsdigita.xml.Element; import java.util.ArrayList; @@ -42,7 +43,6 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; import javax.servlet.ServletException; @@ -175,11 +175,7 @@ public class Page extends BlockStylable implements Container { * URL and use the HttpSession for the rest of the page state. */ private boolean m_useHttpSession = false; - /** - * HasMap for page generator information. - */ - private HashMap m_pageGenerator = new HashMap(); - + /** * Returns * true if this page should export state through the @@ -566,7 +562,7 @@ public class Page extends BlockStylable implements Container { exportAttributes(page); /* Generator information */ - exportPageGenerator(page); + exportSystemInformation(page); Element title = page.newChildElement("bebop:title", BEBOP_XML_NS); title.setText(getTitle(ps).getLabel(ps)); @@ -892,28 +888,6 @@ public class Page extends BlockStylable implements Container { } } - final protected void addPageGeneratorInformation(String key, String value) { - if (key != null && !key.isEmpty()) { - m_pageGenerator.put(key, value); - } - } - - final protected String getPageGeneratorInformation(String key) { - if (key != null && !key.isEmpty()) { - return m_pageGenerator.get(key); - } else { - return null; - } - } - - final protected String removePageGeneratorInformation(String key) { - if (key != null && !key.isEmpty()) { - return m_pageGenerator.remove(key); - } else { - return null; - } - } - /** * Export page generator information if set. The m_pageGenerator is a * HashMap containing the information as key value. In general this should @@ -923,11 +897,12 @@ public class Page extends BlockStylable implements Container { * * @pre m_pageGenerator != null && !m_pageGenerator.isEmpty() */ - final protected void exportPageGenerator(Element page) { - if (m_pageGenerator != null && !m_pageGenerator.isEmpty()) { - Element gen = page.newChildElement("bebop:pageGenerator", BEBOP_XML_NS); + final protected void exportSystemInformation(Element page) { + SystemInformation sysInfo = SystemInformation.getInstance(); + if (!sysInfo.isEmpty()) { + Element gen = page.newChildElement("bebop:systemInformation", BEBOP_XML_NS); - Iterator> keyValues = ((Set>) m_pageGenerator.entrySet()).iterator(); + Iterator> keyValues = sysInfo.iterator(); while (keyValues.hasNext()) { Map.Entry entry = keyValues.next(); gen.addAttribute(entry.getKey(), entry.getValue()); diff --git a/ccm-core/src/com/arsdigita/core/Initializer.java b/ccm-core/src/com/arsdigita/core/Initializer.java index 926d09538..ef83bc872 100755 --- a/ccm-core/src/com/arsdigita/core/Initializer.java +++ b/ccm-core/src/com/arsdigita/core/Initializer.java @@ -45,6 +45,7 @@ import com.arsdigita.toolbox.CharsetEncodingProvider; import com.arsdigita.ui.admin.Admin; import com.arsdigita.ui.login.Login; import com.arsdigita.ui.permissions.Permissions; +import com.arsdigita.util.SystemInformation; import com.arsdigita.util.URLRewriter; import com.arsdigita.web.ApplicationType; import com.arsdigita.web.Host; @@ -188,8 +189,8 @@ public class Initializer extends CompoundInitializer { } }); - - + // Set system informations + loadSystemInformation(); // register the document converters Converter converter = new PDFConverter(); @@ -228,4 +229,14 @@ 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", "2.1.0"); + sysInfo.put("appname", "ScientificCMS"); + sysInfo.put("apphomepage", "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 new file mode 100644 index 000000000..6199cf39a --- /dev/null +++ b/ccm-core/src/com/arsdigita/util/SystemInformation.java @@ -0,0 +1,100 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.arsdigita.util; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +/** + * + * @author Sören Bernstein (quasimodo) + */ +public class SystemInformation implements Lockable { + + private Map systemInformation = new HashMap(); + private boolean locked = false; + /** + * The one and only instance of this class + */ + private static final SystemInformation INSTANCE = new SystemInformation(); + + private SystemInformation() { + // Nothing + } + + /** + * @return The instance of this class. + */ + public static SystemInformation getInstance() { + return SystemInformation.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(String key, 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 + * @return value for key + * @throws IllegalArgumentException if key is null or empty + */ + final public String get(String key) throws IllegalArgumentException { + if (key == null || key.isEmpty()) { + throw new IllegalArgumentException("Parameter key must not be null or empty."); + } + return systemInformation.get(key); + } + + /** + * Get iterator of this map. + * + * @return iterator of map + */ + final public Iterator> iterator() { + return ((Set>) systemInformation.entrySet()).iterator(); + } + + /** + * + * @return + */ + final public boolean isEmpty() { + return systemInformation.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; + } +}