Return-Path: Delivered-To: apmail-forrest-svn-archive@www.apache.org Received: (qmail 28411 invoked from network); 21 Nov 2005 02:37:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 21 Nov 2005 02:37:49 -0000 Received: (qmail 16921 invoked by uid 500); 21 Nov 2005 02:37:48 -0000 Delivered-To: apmail-forrest-svn-archive@forrest.apache.org Received: (qmail 16845 invoked by uid 500); 21 Nov 2005 02:37:47 -0000 Mailing-List: contact svn-help@forrest.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Forrest Developers List" List-Id: Delivered-To: mailing list svn@forrest.apache.org Received: (qmail 16834 invoked by uid 99); 21 Nov 2005 02:37:47 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 20 Nov 2005 18:37:47 -0800 Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 20 Nov 2005 18:39:20 -0800 Received: (qmail 28292 invoked by uid 65534); 21 Nov 2005 02:37:26 -0000 Message-ID: <20051121023726.28289.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r345813 - /forrest/trunk/main/java/org/apache/forrest/conf/ForrestConfModule.java Date: Mon, 21 Nov 2005 02:37:26 -0000 To: svn@forrest.apache.org From: rgardler@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: rgardler Date: Sun Nov 20 18:37:20 2005 New Revision: 345813 URL: http://svn.apache.org/viewcvs?rev=345813&view=rev Log: add a new type of property file that does not need properties to be predefined in forrest.xconf, see FOR-588 for more information Modified: forrest/trunk/main/java/org/apache/forrest/conf/ForrestConfModule.java Modified: forrest/trunk/main/java/org/apache/forrest/conf/ForrestConfModule.java URL: http://svn.apache.org/viewcvs/forrest/trunk/main/java/org/apache/forrest/conf/ForrestConfModule.java?rev=345813&r1=345812&r2=345813&view=diff ============================================================================== --- forrest/trunk/main/java/org/apache/forrest/conf/ForrestConfModule.java (original) +++ forrest/trunk/main/java/org/apache/forrest/conf/ForrestConfModule.java Sun Nov 20 18:37:20 2005 @@ -16,12 +16,18 @@ */ package org.apache.forrest.conf; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.util.Enumeration; import java.util.Map; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.FactoryConfigurationError; +import javax.xml.parsers.ParserConfigurationException; + import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; @@ -31,10 +37,16 @@ import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.components.modules.input.DefaultsModule; import org.apache.cocoon.components.modules.input.InputModule; +import org.apache.cocoon.xml.XMLConsumer; import org.apache.commons.lang.SystemUtils; import org.apache.excalibur.source.Source; import org.apache.excalibur.source.SourceNotFoundException; import org.apache.excalibur.source.SourceResolver; +import org.apache.xerces.parsers.DOMParser; +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 @@ -62,7 +74,11 @@ attributeValue = this.getAttributeValues(name, modeConf, objectModel)[0].toString(); } catch (NullPointerException npe) { - throw new ConfigurationException("Unable to get attribute value for " + name); + original = "(not defined in forrest.xconf)"; + attributeValue = filteringProperties.getProperty(name); + if (attributeValue == null) { + throw new ConfigurationException("Unable to get attribute value for " + name); + } } if (debugging()) { @@ -111,9 +127,23 @@ filteringProperties.setProperty("context.home", contextHome); //NOTE: the first values set get precedence, as in AntProperties + + String forrestPropertiesStringURI; + + // get the values from properties.xml + try { + forrestPropertiesStringURI = projectHome + + SystemUtils.FILE_SEPARATOR + "forrest.properties.xml"; + + filteringProperties = loadXMLPropertiesFromURI(filteringProperties, + forrestPropertiesStringURI); + } catch (FileNotFoundException e) { + if (debugging()) + debug("Unable to find forrest.properties.xml, ignoring."); + } // get forrest.properties and load the values - String forrestPropertiesStringURI = projectHome + forrestPropertiesStringURI = projectHome + SystemUtils.FILE_SEPARATOR + "forrest.properties"; filteringProperties = loadAntPropertiesFromURI(filteringProperties, @@ -149,6 +179,61 @@ } /** + * @param propertiesStringURI + * @throws IOException + * @throws MalformedURLException + * @throws MalformedURLException + * @throws IOException + * @throws ParserConfigurationException + * @throws SAXException + * @throws SourceNotFoundException + */ + 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()); + + } finally { + if (source != null) { + m_resolver.release(source); + } + if (in != null) { + try { + in.close(); + } catch (IOException e) {} + } + } + + System.out.println("Loaded:" + propertiesStringURI + + filteringProperties.getProperty("daisy.navigation.docID")); + + return filteringProperties; + } + + /** * @param antPropertiesStringURI * @throws MalformedURLException * @throws IOException @@ -186,6 +271,10 @@ } catch (IOException e) {} } } + + + System.out.println("Loaded:" + antPropertiesStringURI + + filteringProperties.getProperty("daisy.navigation.docID")); return filteringProperties; }