You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by gv...@apache.org on 2006/02/11 20:20:54 UTC
svn commit: r377018 - in
/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config:
ClayConfigParser.java ClayTemplateParser.java ClayXmlParser.java
beans/ComponentConfigBean.java
Author: gvanmatre
Date: Sat Feb 11 11:20:52 2006
New Revision: 377018
URL: http://svn.apache.org/viewcvs?rev=377018&view=rev
Log:
Changed the way Clay uses the digester to allow external entities to be included into a single XML configuration file - related to bug# 38482.
Modified:
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/ClayConfigParser.java
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/ClayTemplateParser.java
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/ClayXmlParser.java
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java
Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/ClayConfigParser.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/ClayConfigParser.java?rev=377018&r1=377017&r2=377018&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/ClayConfigParser.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/ClayConfigParser.java Sat Feb 11 11:20:52 2006
@@ -19,7 +19,7 @@
package org.apache.shale.clay.config;
import java.io.IOException;
-import java.io.InputStream;
+import java.net.URL;
import org.apache.shale.clay.config.beans.ConfigBean;
import org.xml.sax.SAXException;
@@ -52,9 +52,9 @@
public ConfigBean getConfig();
/**
- * <p>Loads the <code>inputStream</code> identified by the <code>watchDogName</code>
+ * <p>Loads the <code>url</code> identified by the <code>watchDogName</code>
* into the {@link ConfigBean} object pool.</p>
*/
- public void loadConfigFile(InputStream inputStream, String watchDogName)
+ public void loadConfigFile(URL url, String watchDogName)
throws IOException, SAXException;
}
Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/ClayTemplateParser.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/ClayTemplateParser.java?rev=377018&r1=377017&r2=377018&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/ClayTemplateParser.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/ClayTemplateParser.java Sat Feb 11 11:20:52 2006
@@ -19,6 +19,7 @@
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
import java.util.Iterator;
import java.util.List;
@@ -78,13 +79,13 @@
}
/**
- * <p>Loads the <code>inputStream</code> identified by the <code>templateName</code>
+ * <p>Loads the <code>templateURL</code> identified by the <code>templateName</code>
* into a graph of {@link ComponentBean}'s.</p>
*/
- public void loadConfigFile(InputStream inputStream, String templateName) throws IOException,
+ public void loadConfigFile(URL templateURL, String templateName) throws IOException,
SAXException {
- ((ComponentConfigBean) config).addChild(generateElement(inputStream, templateName));
+ ((ComponentConfigBean) config).addChild(generateElement(templateURL, templateName));
}
@@ -95,7 +96,7 @@
* within target view.
* </p>
*/
- public ComponentBean generateElement(InputStream inputStream, String templateName) throws IOException {
+ protected ComponentBean generateElement(URL templateURL, String templateName) throws IOException {
if (log.isInfoEnabled())
log.info(messages.getMessage("loading.template", new Object[] {templateName}));
@@ -105,7 +106,17 @@
root.setComponentType("javax.faces.NamingContainer");
// generate the document
- StringBuffer buffer = loadTemplate(inputStream, templateName);
+
+ InputStream inputStream = null;
+ StringBuffer buffer = null;
+
+ try {
+ inputStream = templateURL.openStream();
+ buffer = loadTemplate(inputStream, templateName);
+ } finally {
+ if (inputStream != null)
+ inputStream.close();
+ }
List roots = new Parser().parse(buffer);
Iterator ri = roots.iterator();
@@ -122,7 +133,9 @@
}
}
+ roots.clear();
roots = null;
+ buffer.setLength(0);
buffer = null;
ri = null;
Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/ClayXmlParser.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/ClayXmlParser.java?rev=377018&r1=377017&r2=377018&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/ClayXmlParser.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/ClayXmlParser.java Sat Feb 11 11:20:52 2006
@@ -133,10 +133,10 @@
}
/**
- * <p>Loads a configuration file from an <code>inputStream</code>. The
+ * <p>Loads a configuration file from a <code>url</code>. The
* input stream is identifed by the <code>watchDogName</code>.</p>
*/
- public void loadConfigFile(InputStream inputStream, String watchDogName) throws IOException, SAXException {
+ public void loadConfigFile(URL configURL, String watchDogName) throws IOException, SAXException {
if (digester == null) {
@@ -160,8 +160,18 @@
digester.push(config);
}
- InputSource inputSource = new InputSource(inputStream);
- digester.parse(inputSource);
+ InputStream in = null;
+ InputSource inputSource = null;
+ try {
+ in = configURL.openStream();
+ inputSource = new InputSource(configURL.toExternalForm());
+ inputSource.setByteStream(in);
+ digester.parse(inputSource);
+ } finally {
+ if (in != null) {
+ in.close();
+ }
+ }
inputSource = null;
}
Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java?rev=377018&r1=377017&r2=377018&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java Sat Feb 11 11:20:52 2006
@@ -1125,13 +1125,11 @@
new Object[] { configDefs[i].getConfigUrl()
.getPath() }));
- InputStream in = null;
try {
configDefs[i].setLastModified(connections[i]
.getLastModified());
- in = connections[i].getInputStream();
- parser.loadConfigFile(in, getName());
+ parser.loadConfigFile(connections[i].getURL(), getName());
} catch (IOException e) {
log.error(messages.getMessage("parser.load.error",
@@ -1141,14 +1139,7 @@
log.error(messages.getMessage("parser.load.error",
new Object[] { configDefs[i].getConfigUrl()
.getPath() }), e);
- } finally {
- if (in != null) {
- try {
- in.close();
- } catch (IOException e) {
- }
- }
- }
+ }
}
resolveInheritance();
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org