Author: thorsten
Date: Thu Aug 3 09:44:38 2006
New Revision: 428447
URL: http://svn.apache.org/viewvc?rev=428447&view=rev
Log:
Adding a new configuration system module.
This new property system is based on the new forrest property system. It let
you define properties e.g. in modules or pubs that can be locally
overriden without patching the module/pub.
You can add lenya.properties.xml to your module to define the default
properties for the module. This overrides the default lenya properties in
src/webapp/lenya.properties.xml. However the module config can be overriden by
defining
local.lenya.properties.xml in src/webapp/.
Try the following:
See the default property "the lenya community" in the heading of
http://localhost:8888/default/authoring/index.html.
cd src/webapp/src/webapp/lenya.properties.xml
src/webapp/src/webapp/local.lenya.properties.xml
change pubs.default.author in the new file, restart/rebuild lenya and request
http://localhost:8888/default/authoring/index.html
See your new prop and smile.
Added:
lenya/trunk/src/modules-core/properties/
lenya/trunk/src/modules-core/properties/config/
lenya/trunk/src/modules-core/properties/config/cocoon-xconf/
lenya/trunk/src/modules-core/properties/config/cocoon-xconf/properties-input-module.xconf
(with props)
lenya/trunk/src/modules-core/properties/java/
lenya/trunk/src/modules-core/properties/java/src/
lenya/trunk/src/modules-core/properties/java/src/org/
lenya/trunk/src/modules-core/properties/java/src/org/apache/
lenya/trunk/src/modules-core/properties/java/src/org/apache/lenya/
lenya/trunk/src/modules-core/properties/java/src/org/apache/lenya/cms/
lenya/trunk/src/modules-core/properties/java/src/org/apache/lenya/cms/cocoon/
lenya/trunk/src/modules-core/properties/java/src/org/apache/lenya/cms/cocoon/components/
lenya/trunk/src/modules-core/properties/java/src/org/apache/lenya/cms/cocoon/components/modules/
lenya/trunk/src/modules-core/properties/java/src/org/apache/lenya/cms/cocoon/components/modules/input/
lenya/trunk/src/modules-core/properties/java/src/org/apache/lenya/cms/cocoon/components/modules/input/PropertiesModule.java
- copied, changed from r428442,
forrest/trunk/main/java/org/apache/forrest/conf/ForrestConfModule.java
lenya/trunk/src/modules-core/properties/module.xml (with props)
lenya/trunk/src/webapp/lenya.properties.xml (with props)
Modified:
lenya/trunk/src/pubs/default/sitemap.xmap
lenya/trunk/src/pubs/default/xslt/page2xhtml.xsl
lenya/trunk/src/webapp/ (props changed)
Added:
lenya/trunk/src/modules-core/properties/config/cocoon-xconf/properties-input-module.xconf
URL:
http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/properties/config/cocoon-xconf/properties-input-module.xconf?rev=428447&view=auto
==============================================================================
---
lenya/trunk/src/modules-core/properties/config/cocoon-xconf/properties-input-module.xconf
(added)
+++
lenya/trunk/src/modules-core/properties/config/cocoon-xconf/properties-input-module.xconf
Thu Aug 3 09:44:38 2006
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<!--
+ Copyright 1999-2005 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!-- $Id: usecases-workflow-deactivate.xconf 348547 2005-11-23 20:13:01Z chestnut
$ -->
+<!--
+ This file defines the publication specific use-cases
+-->
+
+ <xconf xpath="/cocoon/input-modules" unless="/cocoon/input-modules/[EMAIL PROTECTED]
= 'properties']">
+ <component-instance logger="core.modules.input.properties"
name="properties"
+
class="org.apache.lenya.cms.cocoon.components.modules.input.PropertiesModule"/>
+ </xconf>
Propchange:
lenya/trunk/src/modules-core/properties/config/cocoon-xconf/properties-input-module.xconf
------------------------------------------------------------------------------
svn:eol-style = native
Copied:
lenya/trunk/src/modules-core/properties/java/src/org/apache/lenya/cms/cocoon/components/modules/input/PropertiesModule.java
(from r428442,
forrest/trunk/main/java/org/apache/forrest/conf/ForrestConfModule.java)
URL:
http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/properties/java/src/org/apache/lenya/cms/cocoon/components/modules/input/PropertiesModule.java?p2=lenya/trunk/src/modules-core/properties/java/src/org/apache/lenya/cms/cocoon/components/modules/input/PropertiesModule.java&p1=forrest/trunk/main/java/org/apache/forrest/conf/ForrestConfModule.java&r1=428442&r2=428447&rev=428447&view=diff
==============================================================================
--- forrest/trunk/main/java/org/apache/forrest/conf/ForrestConfModule.java
(original)
+++
lenya/trunk/src/modules-core/properties/java/src/org/apache/lenya/cms/cocoon/components/modules/input/PropertiesModule.java
Thu Aug 3 09:44:38 2006
@@ -14,15 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.forrest.conf;
+package org.apache.lenya.cms.cocoon.components.modules.input;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.util.Enumeration;
+import java.util.Iterator;
import java.util.Map;
-import java.util.StringTokenizer;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -41,185 +41,134 @@
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceNotFoundException;
import org.apache.excalibur.source.SourceResolver;
+import org.apache.forrest.conf.AntProperties;
+import org.apache.lenya.cms.module.ModuleManager;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
/**
- * Input module for accessing the base properties used in Forrest. The main
- * values are the locations of the <b>source </b> directories and of the
- * <b>forrest </b> directories. The values are gotten using the
ForrestConfUtils
- * class.
+ * Input module for accessing the base properties used in Lenya. The main
values
+ * are the locations of the <b>source </b> directories and of the <b>Lenya </b>
+ * directories.
*/
-public class ForrestConfModule extends DefaultsModule implements InputModule,
Initializable,
- ThreadSafe, Serviceable {
+public class PropertiesModule extends DefaultsModule implements InputModule,
+ Initializable, ThreadSafe, Serviceable {
private AntProperties filteringProperties;
- private String forrestHome, projectHome, contextHome;
-
private SourceResolver m_resolver;
- private final static String defaultHome = "context:/";
+ private ModuleManager moduleManager;
+
+ private final static String lenyaHome = "context:/";
+
+ private final static String DEFAULT_HOME_PROP = "lenya.home";
+
+ private final static String PROPERTY_NAME = "lenya.properties.xml";
- public Object getAttribute(String name, Configuration modeConf, Map objectModel)
- throws ConfigurationException {
- String original;
+ private final static String PROPERTY_NAME_LOCAL = "local." + PROPERTY_NAME;
+
+ public Object getAttribute(String name, Configuration modeConf,
+ Map objectModel) throws ConfigurationException {
String attributeValue;
- try {
- original = super.getAttributeValues(name, modeConf,
objectModel)[0].toString();
- attributeValue = this.getAttributeValues(name, modeConf,
objectModel)[0].toString();
- } catch (NullPointerException npe) {
- original = "(not defined in forrest.xconf)";
- attributeValue = filteringProperties.getProperty(name);
- if (attributeValue == null) {
- String error = "Unable to get attribute value for "
+ attributeValue = filteringProperties.getProperty(name);
+ if (attributeValue == null) {
+ String error = "Unable to get attribute value for "
+ name
+ "\n"
+ "Please make sure you defined "
+ name
- + " in forrest.properties.xml either in $PROJECT_HOME "
- + "or in the default.forrest.properties.xml of the plugin "
- + "that is requesting this property."
+ + " in lenya.properties.xml either in $LENYA_HOME or in the
module that is requesting this property"
+ "\n"
- + "If you see this message, most of the time you spotted a plugin bug "
+ + "If you see this message, most of the time you spotted a
module bug "
+ "(forget to define the default property). Please report it to
our mailing list.";
throw new ConfigurationException(
error);
- }
}
if (debugging()) {
debug(" - Requested:" + name);
- debug(" - Unfiltered:" + original);
debug(" - Given:" + attributeValue);
}
return attributeValue;
}
- public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel)
- throws ConfigurationException {
- Object[] attributeValues = super.getAttributeValues(name, modeConf,
objectModel);
+ public Object[] getAttributeValues(String name, Configuration modeConf,
+ Map objectModel) throws ConfigurationException {
+ Object[] attributeValues = super.getAttributeValues(name, modeConf,
+ objectModel);
for (int i = 0; i < attributeValues.length; i++) {
- attributeValues[i] =
filteringProperties.filter(attributeValues[i].toString());
+ attributeValues[i] = filteringProperties.filter(attributeValues[i]
+ .toString());
}
return attributeValues;
}
- private final String getSystemProperty(String propertyName) {
-
- // if the property is not set, default to the webapp context
- String propertyValue = System.getProperty(propertyName, defaultHome);
-
- if (debugging())
- debug("system property " + propertyName + "=" + propertyValue);
-
- return propertyValue;
- }
-
public void initialize() throws Exception {
- // add all homes important to forrest to the properties
+ // add all homes important to Lenya to the properties
setHomes();
// NOTE: the first values set get precedence, as in AntProperties
+ String lenyaPropertiesStringURI = "";
- String forrestPropertiesStringURI;
-
- // get the values from local.forrest.properties.xml
+ // get the values from local.lenya.properties.xml
try {
- forrestPropertiesStringURI = projectHome +
SystemUtils.FILE_SEPARATOR
- + "local.forrest.properties.xml";
+ lenyaPropertiesStringURI = lenyaHome + SystemUtils.FILE_SEPARATOR
+ + PROPERTY_NAME_LOCAL;
filteringProperties = loadXMLPropertiesFromURI(filteringProperties,
- forrestPropertiesStringURI);
+ lenyaPropertiesStringURI);
} catch (FileNotFoundException e) {
if (debugging())
- debug("Unable to find local.forrest.properties.xml,
ignoring.");
+ debug("Unable to find local.lenya.properties.xml, ignoring.");
}
- // get the values from forrest.properties.xml
- try {
- forrestPropertiesStringURI = projectHome +
SystemUtils.FILE_SEPARATOR
- + "forrest.properties.xml";
+ Map module2src = moduleManager.getModuleList();
+ Iterator iterator = module2src.keySet().iterator();
+ while (iterator.hasNext()) {
+ Object key = iterator.next();
+ Object value = module2src.get(key);
- filteringProperties = loadXMLPropertiesFromURI(filteringProperties,
- forrestPropertiesStringURI);
- } catch (FileNotFoundException e) {
- if (debugging())
- debug("Unable to find forrest.properties.xml, ignoring.");
+ if (value != null) {
+ lenyaPropertiesStringURI = value
+ + SystemUtils.FILE_SEPARATOR + PROPERTY_NAME;
+ filteringProperties = loadXMLPropertiesFromURI(
+ filteringProperties, lenyaPropertiesStringURI);
+ }
}
-
- // get the values from default.forrest.properties.xml
+ // get the values from lenya.properties.xml this are the default lenya
+ // values
try {
- forrestPropertiesStringURI = contextHome +
SystemUtils.FILE_SEPARATOR
- + "default.forrest.properties.xml";
+ lenyaPropertiesStringURI = lenyaHome + SystemUtils.FILE_SEPARATOR
+ + PROPERTY_NAME;
filteringProperties = loadXMLPropertiesFromURI(filteringProperties,
- forrestPropertiesStringURI);
+ lenyaPropertiesStringURI);
} catch (FileNotFoundException e) {
if (debugging())
- debug("Unable to find default.forrest.properties.xml,
ignoring.");
- }
-
- // get forrest.properties and load the values
- forrestPropertiesStringURI = projectHome + SystemUtils.FILE_SEPARATOR
- + "forrest.properties";
-
- filteringProperties = loadAntPropertiesFromURI(filteringProperties,
- forrestPropertiesStringURI);
-
- // get default-forrest.properties and load the values
- String defaultForrestPropertiesStringURI = contextHome +
SystemUtils.FILE_SEPARATOR
- + "default-forrest.properties";
-
- filteringProperties = loadAntPropertiesFromURI(filteringProperties,
- defaultForrestPropertiesStringURI);
-
- // Load plugin default properties
- String strPluginList =
filteringProperties.getProperty("project.required.plugins");
- if (strPluginList != null) {
- StringTokenizer st = new StringTokenizer(strPluginList, ",");
- while (st.hasMoreTokens()) {
- forrestPropertiesStringURI =
ForrestConfUtils.getPluginDir(st.nextToken().trim());
- try {
- forrestPropertiesStringURI = forrestPropertiesStringURI
- + SystemUtils.FILE_SEPARATOR +
"default.plugin.properties.xml";
- filteringProperties =
loadXMLPropertiesFromURI(filteringProperties,
- forrestPropertiesStringURI);
- } catch (FileNotFoundException e) {
- if (debugging())
- debug("Unable to load " + forrestPropertiesStringURI + ",
ignoring. "
- + e.getMessage());
- }
- }
+ debug("Unable to find lenya.properties.xml, ignoring.");
}
loadSystemProperties(filteringProperties);
- ForrestConfUtils.aliasSkinProperties(filteringProperties);
if (debugging())
- debug("Loaded project forrest.properties:" + filteringProperties);
+ debug("Loaded project lenya.properties.xml:" +
filteringProperties);
}
/**
- * Sets all forrest related home locations such as - forrestHome -
- * projectHome - contextHome
+ * Sets all Lenya related home locations such as - LenyaHome - projectHome
-
+ * contextHome
*
* @throws Exception
*/
private void setHomes() throws Exception {
- forrestHome = ForrestConfUtils.getForrestHome();
- projectHome = ForrestConfUtils.getProjectHome();
- contextHome = ForrestConfUtils.getContextHome();
filteringProperties = new AntProperties();
-
- filteringProperties.setProperty("forrest.home", forrestHome);
- filteringProperties.setProperty("project.home", projectHome);
- filteringProperties.setProperty("context.home", contextHome);
+ filteringProperties.setProperty(DEFAULT_HOME_PROP, lenyaHome);
}
/**
@@ -248,73 +197,39 @@
* @throws SAXException
* @throws SourceNotFoundException
*/
- private AntProperties loadXMLPropertiesFromURI(AntProperties
precedingProperties,
- String propertiesStringURI) throws MalformedURLException,
IOException,
+ private AntProperties loadXMLPropertiesFromURI(
+ AntProperties precedingProperties, String propertiesStringURI)
+ throws MalformedURLException, IOException,
ParserConfigurationException, SAXException {
Source source = null;
InputStream in = null;
try {
- if (debugging())
- debug("Searching for forrest.properties.xml in" +
source.getURI());
source = m_resolver.resolveURI(propertiesStringURI);
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document document = builder.parse(source.getURI());
-
- NodeList nl = document.getElementsByTagName("property");
- if (nl != null && nl.getLength() > 0) {
- for (int i = 0; i < nl.getLength(); i++) {
- Element el = (Element) nl.item(i);
- filteringProperties.setProperty(el.getAttribute("name"), el
- .getAttribute("value"));
- }
- }
-
- if (debugging())
- debug("Loaded:" + propertiesStringURI +
filteringProperties.toString());
+ if (source.exists()) {
- } finally {
- if (source != null) {
- m_resolver.release(source);
- }
- if (in != null) {
- try {
- in.close();
- } catch (IOException e) {
+ DocumentBuilderFactory factory = DocumentBuilderFactory
+ .newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document document = builder.parse(source.getURI());
+
+ NodeList nl = document.getElementsByTagName("property");
+ if (nl != null && nl.getLength() > 0) {
+ for (int i = 0; i < nl.getLength(); i++) {
+ Element el = (Element) nl.item(i);
+ filteringProperties.setProperty(
+ el.getAttribute("name"), el
+ .getAttribute("value"));
+ }
}
- }
- }
- return filteringProperties;
- }
+ if (debugging())
+ debug("Loaded:" + propertiesStringURI
+ + filteringProperties.toString());
- /**
- * @param antPropertiesStringURI
- * @throws MalformedURLException
- * @throws IOException
- * @throws SourceNotFoundException
- */
- private AntProperties loadAntPropertiesFromURI(AntProperties
precedingProperties,
- String antPropertiesStringURI) throws MalformedURLException,
IOException,
- SourceNotFoundException {
-
- Source source = null;
- InputStream in = null;
- try {
-
- source = m_resolver.resolveURI(antPropertiesStringURI);
-
- if (debugging())
- debug("Searching for forrest.properties in" + source.getURI());
- in = source.getInputStream();
- filteringProperties = new AntProperties(precedingProperties);
- filteringProperties.load(in);
-
- if (debugging())
- debug("Loaded:" + antPropertiesStringURI +
filteringProperties.toString());
+ }
} finally {
if (source != null) {
@@ -333,6 +248,7 @@
public void service(ServiceManager manager) throws ServiceException {
m_resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
+ moduleManager = (ModuleManager) manager.lookup(ModuleManager.ROLE);
}
/**
Added: lenya/trunk/src/modules-core/properties/module.xml
URL:
http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/properties/module.xml?rev=428447&view=auto
==============================================================================
--- lenya/trunk/src/modules-core/properties/module.xml (added)
+++ lenya/trunk/src/modules-core/properties/module.xml Thu Aug 3 09:44:38 2006
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 1999-2005 The Apache Software Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!-- $Id: publication.xml 374687 2006-02-03 15:24:55Z michi $ -->
+
+<module xmlns="http://apache.org/lenya/module/1.0">
+ <id>org.apache.lenya.modules.properties</id>
+ <published>false</published>
+ <package>org.apache.lenya.modules</package>
+ <version>0.1-dev</version>
+ <name>Property system implementation</name>
+ <lenya-version>@lenya.version@</lenya-version>
+ <description>Property system implementation</description>
+</module>
Propchange: lenya/trunk/src/modules-core/properties/module.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified: lenya/trunk/src/pubs/default/sitemap.xmap
URL:
http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/sitemap.xmap?rev=428447&r1=428446&r2=428447&view=diff
==============================================================================
--- lenya/trunk/src/pubs/default/sitemap.xmap (original)
+++ lenya/trunk/src/pubs/default/sitemap.xmap Thu Aug 3 09:44:38 2006
@@ -152,6 +152,8 @@
<map:parameter name="title" value="{dublincore:title}"/>
<map:parameter name="lastPublishedUser"
value="{workflow:lastUser.publish}"/>
<map:parameter name="lastPublishedDate"
value="{workflow:lastDate.publish}"/>
+ <!--Following is a show off to explain lenya.properties.xml -->
+ <map:parameter name="author"
value="{properties:pubs.default.author}"/>
</map:transform>
</map:when>
<map:otherwise>
@@ -167,6 +169,8 @@
<map:parameter name="title" value="{dublincore:title}"/>
<map:parameter name="lastPublishedUser"
value="{workflow:lastUser.publish}"/>
<map:parameter name="lastPublishedDate"
value="{workflow:lastDate.publish}"/>
+ <!--Following is a show off to explain lenya.properties.xml -->
+ <map:parameter name="author"
value="{properties:pubs.default.author}"/>
</map:transform>
</map:otherwise>
</map:select>
Modified: lenya/trunk/src/pubs/default/xslt/page2xhtml.xsl
URL:
http://svn.apache.org/viewvc/lenya/trunk/src/pubs/default/xslt/page2xhtml.xsl?rev=428447&r1=428446&r2=428447&view=diff
==============================================================================
--- lenya/trunk/src/pubs/default/xslt/page2xhtml.xsl (original)
+++ lenya/trunk/src/pubs/default/xslt/page2xhtml.xsl Thu Aug 3 09:44:38 2006
@@ -45,6 +45,9 @@
<xsl:param name="lastPublishedUser"/>
<xsl:param name="lastPublishedDate"/>
+
+<!--Following is a show off to explain lenya.properties.xml -->
+<xsl:param name="author"/>
<xsl:template match="cmsbody">
<html>
@@ -75,10 +78,10 @@
<td id="publication-title">
<xsl:choose>
<xsl:when test="$language = 'de'">
- Willkommen zur Default Publikation!
+ Willkommen zur Default Publikation von <xsl:value-of
select="$author"/>!
</xsl:when>
<xsl:otherwise>
- Welcome to the Default Publication!
+ Welcome to the Default Publication from <xsl:value-of
select="$author"/>!
</xsl:otherwise>
</xsl:choose>
</td>
Propchange: lenya/trunk/src/webapp/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Aug 3 09:44:38 2006
@@ -0,0 +1 @@
+local.lenya.properties.xml
Added: lenya/trunk/src/webapp/lenya.properties.xml
URL:
http://svn.apache.org/viewvc/lenya/trunk/src/webapp/lenya.properties.xml?rev=428447&view=auto
==============================================================================
--- lenya/trunk/src/webapp/lenya.properties.xml (added)
+++ lenya/trunk/src/webapp/lenya.properties.xml Thu Aug 3 09:44:38 2006
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<properties>
+ <property name="pubs.default.author" value="the lenya community"/>
+</properties>
Propchange: lenya/trunk/src/webapp/lenya.properties.xml
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]