ASF Bugzilla – Attachment 21044 Details for
Bug 42558
[Patch] lenya.properties.xml per publication
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch for aggregate-fallback, requires older patch (which is already applied).
properties_patch.txt (text/plain), 11.31 KB, created by
Markus Angst
on 2007-10-25 09:38:40 UTC
(
hide
)
Description:
Patch for aggregate-fallback, requires older patch (which is already applied).
Filename:
MIME Type:
Creator:
Markus Angst
Created:
2007-10-25 09:38:40 UTC
Size:
11.31 KB
patch
obsolete
>Index: C:/lenya/lenya-2.0-dev/src/modules-core/properties/java/src/org/apache/lenya/cms/cocoon/components/modules/input/PropertiesModule.java >=================================================================== >--- C:/lenya/lenya-2.0-dev/src/modules-core/properties/java/src/org/apache/lenya/cms/cocoon/components/modules/input/PropertiesModule.java (revision 587551) >+++ C:/lenya/lenya-2.0-dev/src/modules-core/properties/java/src/org/apache/lenya/cms/cocoon/components/modules/input/PropertiesModule.java (working copy) >@@ -19,7 +19,7 @@ > import java.io.IOException; > import java.net.MalformedURLException; > import java.util.Enumeration; >-import java.util.HashSet; >+import java.util.HashMap; > import java.util.Iterator; > import java.util.Map; > import java.util.SortedSet; >@@ -42,7 +42,8 @@ > import org.apache.excalibur.source.Source; > import org.apache.excalibur.source.SourceResolver; > import org.apache.forrest.conf.AntProperties; >-import org.apache.lenya.cms.publication.Publication; >+import org.apache.lenya.cms.cocoon.source.AggregatingSource; >+import org.apache.lenya.cms.publication.Publication; > import org.apache.lenya.cms.publication.PublicationUtil; > import org.apache.lenya.cms.module.ModuleManager; > import org.w3c.dom.Document; >@@ -58,7 +59,7 @@ > public class PropertiesModule extends DefaultsModule implements InputModule, > Initializable, ThreadSafe, Serviceable { > >- private HashSet pubInit; >+ private HashMap pubProperties; > > private AntProperties filteringProperties; > >@@ -80,8 +81,11 @@ > throws ConfigurationException { > String attributeValue; > >- loadPublicationPropertiesIfNotDone(objectModel); >- attributeValue = filteringProperties.getProperty(name); >+ AntProperties pubProp = loadPublicationPropertiesIfNotDone(objectModel); >+ attributeValue = pubProp.getProperty(name); >+ if (attributeValue == null) { >+ attributeValue = filteringProperties.getProperty(name); >+ } > if (attributeValue == null) { > String error = "Unable to get attribute value for " > + name >@@ -95,7 +99,6 @@ > + "our mailing list."; > throw new ConfigurationException(error); > } >- > if (debugging()) { > debug(" - Requested:" + name); > debug(" - Given:" + attributeValue); >@@ -100,7 +103,6 @@ > debug(" - Requested:" + name); > debug(" - Given:" + attributeValue); > } >- > return attributeValue; > } > >@@ -106,9 +108,12 @@ > > public Object[] getAttributeValues(String name, Configuration modeConf, > Map objectModel) throws ConfigurationException { >- loadPublicationPropertiesIfNotDone(objectModel); >+ >+ AntProperties pubProp = loadPublicationPropertiesIfNotDone(objectModel); > Object[] attributeValues = super.getAttributeValues(name, modeConf, > objectModel); >+ // FIXME >+ // what exactly are we doing here? > for (int i = 0; i < attributeValues.length; i++) { > attributeValues[i] = filteringProperties.filter(attributeValues[i] > .toString()); >@@ -113,7 +118,12 @@ > attributeValues[i] = filteringProperties.filter(attributeValues[i] > .toString()); > } >- >+ // depending on the answer to the question above, this has to be >+ // done also... >+ // for (int i = 0; i < attributeValues.length; i++) { >+ // attributeValues[i] = pubProp.filter(attributeValues[i] >+ // .toString()); >+ // } > return attributeValues; > } > >@@ -119,9 +129,15 @@ > > public Iterator getAttributeNames(Configuration modeConf, Map objectModel) > throws ConfigurationException { >- loadPublicationPropertiesIfNotDone(objectModel); > SortedSet matchset = new TreeSet(); >- Enumeration enumeration = filteringProperties.keys(); >+ >+ AntProperties pubProp = loadPublicationPropertiesIfNotDone(objectModel); >+ Enumeration enumeration = pubProp.keys(); >+ while (enumeration.hasMoreElements()) { >+ String key = (String) enumeration.nextElement(); >+ matchset.add(key); >+ } >+ enumeration = filteringProperties.keys(); > while (enumeration.hasMoreElements()) { > String key = (String) enumeration.nextElement(); > matchset.add(key); >@@ -133,8 +149,8 @@ > } > > public void initialize() throws Exception { >- >- pubInit = new HashSet(); >+ >+ pubProperties = new HashMap(); > > // add all homes important to Lenya to the properties > setHomes(); >@@ -144,7 +160,8 @@ > // NOTE: the first values set get precedence, as in AntProperties > // > // Order of precedence: >- // 1. Publication (lazy loaded in loadPublicationPropertiesIfNotDone()) >+ // 1. Publication (lazy loaded in loadPublicationPropertiesIfNotDone(); >+ // aggregate-fallback enabled) > // 2. Lenya local > // 3. Modules (all modules, not only the ones referenced in the publication) > // 4. Lenya >@@ -156,7 +173,7 @@ > lenyaPropertiesStringURI = lenyaHome + SystemUtils.FILE_SEPARATOR > + PROPERTY_NAME_LOCAL; > filteringProperties = loadXMLPropertiesFromURI(filteringProperties, >- lenyaPropertiesStringURI, false); >+ lenyaPropertiesStringURI); > > // get the values from all modules > String[] module2src = moduleManager.getModuleIds(); >@@ -167,7 +184,7 @@ > lenyaPropertiesStringURI = value + SystemUtils.FILE_SEPARATOR > + PROPERTY_NAME; > filteringProperties = loadXMLPropertiesFromURI( >- filteringProperties, lenyaPropertiesStringURI, false); >+ filteringProperties, lenyaPropertiesStringURI); > } > } > // get the values from lenya.properties.xml this are the default >@@ -175,7 +192,7 @@ > lenyaPropertiesStringURI = lenyaHome + SystemUtils.FILE_SEPARATOR > + PROPERTY_NAME; > filteringProperties = loadXMLPropertiesFromURI(filteringProperties, >- lenyaPropertiesStringURI, false); >+ lenyaPropertiesStringURI); > } finally { > if (debugging()) > debug("Loaded project lenya.properties.xml:" + filteringProperties); >@@ -225,23 +242,24 @@ > * @throws ParserConfigurationException > * @throws SAXException > */ >- private AntProperties loadXMLPropertiesFromURI(AntProperties precedingProperties, >- String propertiesStringURI, boolean overwrite) >+ private AntProperties loadXMLPropertiesFromURI(AntProperties properties, >+ String propertiesStringURI) > throws MalformedURLException, IOException, > ParserConfigurationException, SAXException { >- >+ > Source source = null; > try { >- > source = m_resolver.resolveURI(propertiesStringURI); >- > if (source.exists()) { >- > DocumentBuilderFactory factory = DocumentBuilderFactory > .newInstance(); > DocumentBuilder builder = factory.newDocumentBuilder(); >- Document document = builder.parse(source.getURI()); >- >+ Document document = null; >+ if (source instanceof AggregatingSource) { >+ document = builder.parse(source.getInputStream()); >+ } else { >+ document = builder.parse(source.getURI()); >+ } > NodeList nl = document.getElementsByTagName("property"); > if (nl != null && nl.getLength() > 0) { > for (int i = 0; i < nl.getLength(); i++) { >@@ -246,22 +264,13 @@ > if (nl != null && nl.getLength() > 0) { > for (int i = 0; i < nl.getLength(); i++) { > Element el = (Element) nl.item(i); >- if (overwrite == true) { >- overwriteProperty(filteringProperties, el.getAttribute("name"), >- el.getAttribute("value")); >- } else { >- filteringProperties.setProperty(el.getAttribute("name"), >- el.getAttribute("value")); >- } >+ properties.setProperty(el.getAttribute("name"), >+ el.getAttribute("value")); > } > } >- > if (debugging()) >- debug("Loaded:" + propertiesStringURI >- + filteringProperties.toString()); >- >+ debug("Loaded: " + propertiesStringURI + properties.toString()); > } >- > } finally { > if (source != null) { > m_resolver.release(source); >@@ -267,8 +276,7 @@ > m_resolver.release(source); > } > } >- >- return filteringProperties; >+ return properties; > } > > /** >@@ -274,31 +282,37 @@ > /** > * Get the properties from the requested publication > */ >- private void loadPublicationPropertiesIfNotDone(Map objectModel) >+ private AntProperties loadPublicationPropertiesIfNotDone(Map objectModel) > throws ConfigurationException { >- Publication pub; >- String pubId; >- >+ String pubId = getPubId(objectModel); >+ AntProperties pubProp = new AntProperties(); >+ >+ if (pubProperties.containsKey(pubId)) { >+ return (AntProperties)pubProperties.get(pubId); >+ } > try { >- pub = PublicationUtil.getPublication(serviceManager, objectModel); >+ pubProp = loadXMLPropertiesFromURI(pubProp, >+ "aggregate-fallback://" + PROPERTY_NAME); >+ pubProperties.put(pubId, pubProp); >+ } catch (IOException e) { >+ getLogger().warn("Could not load properties from pub \"" + pubId + "\".\n" + e); > } catch (Exception e) { > throw new ConfigurationException(e.getMessage()); > } >- pubId = pub.getId(); >- if (pubInit.contains(pubId)) { >- return; >- } >+ return pubProp; >+ } >+ >+ private String getPubId(Map objectModel) throws ConfigurationException { >+ Publication pub; >+ > try { >- filteringProperties = loadXMLPropertiesFromURI(filteringProperties, >- PROPERTY_NAME, true); >- } catch (IOException e) { >- getLogger().warn("Could not load properties from pub \""+pubId+"\".\n"+e); >+ pub = PublicationUtil.getPublication(serviceManager, objectModel); >+ return pub.getId(); > } catch (Exception e) { > throw new ConfigurationException(e.getMessage()); > } >- pubInit.add(pubId); > } >- >+ > public void service(ServiceManager manager) throws ServiceException { > this.serviceManager = manager; > m_resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 42558
:
20301
|
20569
| 21044