You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by je...@apache.org on 2003/11/23 11:13:11 UTC
cvs commit: cocoon-2.1/tools/src/anttasks XConfToolTask.java
jeremy 2003/11/23 02:13:11
Modified: tools/src/anttasks XConfToolTask.java
Log:
addition of variable expansion to root tag's attributes, mostly Upayavira's work ....
Revision Changes Path
1.10 +32 -24 cocoon-2.1/tools/src/anttasks/XConfToolTask.java
Index: XConfToolTask.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/tools/src/anttasks/XConfToolTask.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- XConfToolTask.java 17 Nov 2003 15:40:33 -0000 1.9
+++ XConfToolTask.java 23 Nov 2003 10:13:11 -0000 1.10
@@ -52,7 +52,6 @@
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
-import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.MatchingTask;
import org.apache.tools.ant.types.XMLCatalog;
import org.apache.xpath.XPathAPI;
@@ -68,18 +67,13 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
-import javax.xml.transform.Source;
-import javax.xml.transform.Result;
import javax.xml.transform.TransformerException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileWriter;
import java.io.IOException;
import java.net.UnknownHostException;
@@ -219,7 +213,10 @@
} catch (ParserConfigurationException e) {
throw new BuildException("ParserConfigurationException: "+e);
} catch (UnknownHostException e) {
- throw new BuildException("UnknownHostException. Probable cause: The parser is " +
"trying to resolve a dtd from the internet and no connection exists.\n" +
"You can either connect to the internet during the build, or patch \n" +
"XConfToolTask.java to ignore DTD declarations when your parser is in use.");
+ throw new BuildException("UnknownHostException. Probable cause: The parser is " +
+ "trying to resolve a dtd from the internet and no connection exists.\n" +
+ "You can either connect to the internet during the build, or patch \n" +
+ "XConfToolTask.java to ignore DTD declarations when your parser is in use.");
} catch (IOException ioe) {
throw new BuildException("IOException: "+ioe);
}
@@ -249,8 +246,13 @@
return false;
}
+ String replacePropertiesStr = elem.getAttribute("replace-properties");
+
+ boolean replaceProperties = !("no".equalsIgnoreCase(replacePropertiesStr) ||
+ "false".equalsIgnoreCase(replacePropertiesStr));
+
// Get 'root' node were 'component' will be inserted into
- String xpath = elem.getAttribute("xpath");
+ String xpath = getAttribute(elem, "xpath", replaceProperties);
NodeList nodes = XPathAPI.selectNodeList(configuration, xpath);
@@ -263,15 +265,15 @@
Node root = nodes.item(0);
// Test that 'root' node satisfies 'component' insertion criteria
- String testPath = component.getDocumentElement().getAttribute("unless-path");
+ String testPath = getAttribute(elem, "unless-path", replaceProperties);
if (testPath == null || testPath.length()==0) {
// only look for old "unless" attr if unless-path is not present
- testPath = component.getDocumentElement().getAttribute("unless");
+ testPath = getAttribute(elem, "unless", replaceProperties);
}
// Is if-path needed?
- String ifProp = component.getDocumentElement().getAttribute("if-prop");
+ String ifProp = getAttribute(elem, "if-prop", replaceProperties);
boolean ifValue = Boolean.valueOf(project.getProperty(ifProp)).booleanValue();
-
+
if (ifProp != null && (ifProp.length()>0) && !ifValue ) {
log("Skipping: " + file, Project.MSG_DEBUG);
return false;
@@ -281,7 +283,7 @@
return false;
} else {
// Test if component wants us to remove a list of nodes first
- xpath = component.getDocumentElement().getAttribute("remove");
+ xpath = getAttribute(elem, "remove", replaceProperties);
Node remove = null;
@@ -297,8 +299,8 @@
}
// Test for an attribute that needs to be added to an element
- String name = component.getDocumentElement().getAttribute("add-attribute");
- String value = component.getDocumentElement().getAttribute("value");
+ String name = getAttribute(elem, "add-attribute", replaceProperties);
+ String value = getAttribute(elem, "value", replaceProperties);
if ((name!=null) && (name.length()>0)) {
if (value==null) {
@@ -311,7 +313,7 @@
}
// Test if 'component' provides desired insertion point
- xpath = component.getDocumentElement().getAttribute("insert-before");
+ xpath = getAttribute(elem, "insert-before", replaceProperties);
Node before = null;
if ((xpath!=null) && (xpath.length()>0)) {
@@ -324,7 +326,7 @@
}
before = nodes.item(0);
} else {
- xpath = component.getDocumentElement().getAttribute("insert-after");
+ xpath = getAttribute(elem, "insert-after", replaceProperties);
if ((xpath!=null) && (xpath.length()>0)) {
nodes = XPathAPI.selectNodeList(root, xpath);
if (nodes.getLength()!=1) {
@@ -341,11 +343,6 @@
log("Processing: "+file);
NodeList componentNodes = component.getDocumentElement().getChildNodes();
- String replacePropertiesStr = component.getDocumentElement().getAttribute("replace-properties");
-
- boolean replaceProperties = "yes".equalsIgnoreCase(replacePropertiesStr) ||
- "true".equalsIgnoreCase(replacePropertiesStr);
-
if (this.addComments) {
root.appendChild(configuration.createComment("..... Start configuration from '"+basename+"' "));
root.appendChild(configuration.createTextNode(NL));
@@ -371,8 +368,19 @@
}
}
+ private String getAttribute(Element elem, String attrName, boolean replaceProperties) {
+ String attr = elem.getAttribute(attrName);
+ if (attr == null) {
+ return null;
+ } else if (replaceProperties) {
+ return getProject().replaceProperties(attr);
+ } else {
+ return attr;
+ }
+ }
+
private void replaceProperties(Node n) throws DOMException {
-
+
NamedNodeMap attrs = n.getAttributes();
if (attrs!=null) {
for (int i = 0; i< attrs.getLength(); i++) {