sbailliez 2002/06/29 08:31:07
Modified: src/main/org/apache/tools/ant/taskdefs/optional Tag:
ANT_15_BRANCH TraXLiaison.java XalanLiaison.java
XslpLiaison.java
src/main/org/apache/tools/ant/taskdefs Tag: ANT_15_BRANCH
XSLTLiaison.java XSLTProcess.java
Log:
Add a way to specify output properties in a generic way.
This avoid to use a specifc 'outputtype', so it has been removed from the
liaison interface.
output properties are 'trax' only, others are no more supported.
fixed some spelling mistakes and remove the reflection about the xmlcatalog
(I cannot understand why it was there, but if there is any problem it should
surface quickly)
Revision Changes Path
No revision
No revision
1.17.2.2 +17 -7
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java
Index: TraXLiaison.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java,v
retrieving revision 1.17.2.1
retrieving revision 1.17.2.2
diff -u -r1.17.2.1 -r1.17.2.2
--- TraXLiaison.java 24 May 2002 15:47:57 -0000 1.17.2.1
+++ TraXLiaison.java 29 Jun 2002 15:31:06 -0000 1.17.2.2
@@ -78,7 +78,6 @@
import javax.xml.transform.ErrorListener;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
-import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
import javax.xml.transform.URIResolver;
@@ -119,6 +118,21 @@
tfactory.setErrorListener(this);
}
+
+ /**
+ * Set the output property for the current transformer.
+ * Note that the stylesheet must be set prior to calling
+ * this method.
+ * @param name the output property name.
+ * @param value the output property value.
+ */
+ public void setOutputProperty(String name, String value){
+ if (transformer == null){
+ throw new IllegalStateException("stylesheet must be set prior to
setting the output properties");
+ }
+ transformer.setOutputProperty(name, value);
+ }
+
//------------------- IMPORTANT
// 1) Don't use the StreamSource(File) ctor. It won't work with
// xalan prior to 2.2 because of systemid bugs.
@@ -214,10 +228,6 @@
transformer.setParameter(name, value);
}
- public void setOutputtype(String type) throws Exception {
- transformer.setOutputProperty(OutputKeys.METHOD, type);
- }
-
public void setLogger(XSLTLogger l) {
logger = l;
}
@@ -269,13 +279,13 @@
/** Set the class to resolve entities during the transformation
*/
- public void setEntityResolver(EntityResolver aResolver) throws Exception
{
+ public void setEntityResolver(EntityResolver aResolver) {
entityResolver = aResolver;
}
/** Set the class to resolve URIs during the transformation
*/
- public void setURIResolver(URIResolver aResolver) throws Exception {
+ public void setURIResolver(URIResolver aResolver) {
uriResolver = aResolver;
}
1.11.2.1 +0 -5
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/XalanLiaison.java
Index: XalanLiaison.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/XalanLiaison.java,v
retrieving revision 1.11
retrieving revision 1.11.2.1
diff -u -r1.11 -r1.11.2.1
--- XalanLiaison.java 12 Apr 2002 12:58:02 -0000 1.11
+++ XalanLiaison.java 29 Jun 2002 15:31:06 -0000 1.11.2.1
@@ -130,9 +130,4 @@
processor.setStylesheetParam(name, value);
}
- public void setOutputtype(String type) throws Exception {
- if (!type.equals("xml")) {
- throw new BuildException("Unsupported output type: " + type);
- }
- }
} //-- XalanLiaison
1.13.2.1 +0 -6
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/XslpLiaison.java
Index: XslpLiaison.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/XslpLiaison.java,v
retrieving revision 1.13
retrieving revision 1.13.2.1
diff -u -r1.13 -r1.13.2.1
--- XslpLiaison.java 14 Apr 2002 11:16:16 -0000 1.13
+++ XslpLiaison.java 29 Jun 2002 15:31:06 -0000 1.13.2.1
@@ -103,10 +103,4 @@
processor.setProperty(name, expression);
}
- public void setOutputtype(String type) throws Exception {
- if (!type.equals("xml")) {
- throw new BuildException("Unsupported output type: " + type);
- }
- }
-
} //-- XSLPLiaison
No revision
No revision
1.12.2.1 +0 -9
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/XSLTLiaison.java
Index: XSLTLiaison.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/XSLTLiaison.java,v
retrieving revision 1.12
retrieving revision 1.12.2.1
diff -u -r1.12 -r1.12.2.1
--- XSLTLiaison.java 12 Apr 2002 12:36:09 -0000 1.12
+++ XSLTLiaison.java 29 Jun 2002 15:31:07 -0000 1.12.2.1
@@ -93,15 +93,6 @@
void addParam(String name, String expression) throws Exception;
/**
- * set the output type to use for the transformation. Only "xml" (the
- * default) is guaranteed to work for all parsers. Xalan2 also
- * supports "html" and "text".
- * @param type the output method to use
- * @since Ant 1.5
- */
- void setOutputtype(String type) throws Exception;
-
- /**
* Perform the transformation of a file into another.
* @param infile the input file, probably an XML one. :-)
* @param outfile the output file resulting from the transformation
1.43.2.6 +86 -40
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
Index: XSLTProcess.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java,v
retrieving revision 1.43.2.5
retrieving revision 1.43.2.6
diff -u -r1.43.2.5 -r1.43.2.6
--- XSLTProcess.java 24 Jun 2002 02:28:08 -0000 1.43.2.5
+++ XSLTProcess.java 29 Jun 2002 15:31:07 -0000 1.43.2.6
@@ -62,6 +62,7 @@
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.AntClassLoader;
+import org.apache.tools.ant.taskdefs.optional.TraXLiaison;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;
import org.apache.tools.ant.util.FileUtils;
@@ -127,7 +128,7 @@
private FileUtils fileUtils;
/** XSL output method to be used */
- private String outputtype = null;
+ private Vector outputProperties = new Vector();
/** for resolving entities such as dtds */
private XMLCatalog xmlCatalog = new XMLCatalog();
@@ -137,11 +138,11 @@
"org.apache.tools.ant.taskdefs.optional.TraXLiaison";
/** Name of the now-deprecated XSLP Liason class */
- private static final String XSLP_LIASON_CLASS =
+ private static final String XSLP_LIAISON_CLASS =
"org.apache.tools.ant.taskdefs.optional.XslpLiaison";
/** Name of the Xalan liason class */
- private static final String XALAN_LIASON_CLASS =
+ private static final String XALAN_LIAISON_CLASS =
"org.apache.tools.ant.taskdefs.optional.XalanLiaison";
/**
@@ -371,10 +372,10 @@
} else if (proc.equals("xslp")) {
log("DEPRECATED - xslp processor is deprecated. Use trax or "
+ "xalan instead.");
- final Class clazz = loadClass(XSLP_LIASON_CLASS);
+ final Class clazz = loadClass(XSLP_LIAISON_CLASS);
liaison = (XSLTLiaison) clazz.newInstance();
} else if (proc.equals("xalan")) {
- final Class clazz = loadClass(XALAN_LIASON_CLASS);
+ final Class clazz = loadClass(XALAN_LIAISON_CLASS);
liaison = (XSLTLiaison) clazz.newInstance();
} else {
liaison = (XSLTLiaison) loadClass(proc).newInstance();
@@ -631,17 +632,64 @@
}
return expression;
}
+ } // Param
+
+
+ /**
+ * Create an instance of an output property to be configured.
+ * @return the newly created output property.
+ * @since Ant 1.5
+ */
+ public OutputProperty createOutputProperty() {
+ OutputProperty p = new OutputProperty();
+ outputProperties.addElement(p);
+ return p;
}
-
+
+
/**
- * Set the output type to use for the transformation;
- * optional, default="xml".
- * Only "xml" is guaranteed to work for all parsers.
- * Xalan2 also supports "html" and "text".
- * @param type the output method to use
+ * Specify how the result tree should be output as specified
+ * in the <a href="http://www.w3.org/TR/xslt#output">
+ * specification</a>.
+ * @since Ant 1.5
*/
- public void setOutputtype(String type) {
- this.outputtype = type;
+ public static class OutputProperty {
+ /** output property name */
+ private String name;
+
+ /** output property value */
+ private String value;
+
+ /**
+ * @return the output property name.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * set the name for this property
+ * @param name A non-null String that specifies an
+ * output property name, which may be namespace qualified.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @return the output property value.
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * set the value for this property
+ * @param value The non-null string value of the output property.
+ */
+ public void setValue(String value) {
+ this.value = value;
+ }
}
/**
@@ -649,7 +697,6 @@
*/
public void init() throws BuildException {
super.init();
-
xmlCatalog.setProject(project);
}
@@ -668,39 +715,38 @@
try {
log("Loading stylesheet " + stylesheet, Project.MSG_INFO);
liaison.setStylesheet(stylesheet);
- if (outputtype != null) {
- liaison.setOutputtype(outputtype);
- }
for (Enumeration e = params.elements(); e.hasMoreElements();) {
Param p = (Param) e.nextElement();
liaison.addParam(p.getName(), p.getExpression());
}
+ if (liaison instanceof TraXLiaison) {
+ configureTraXLiaison((TraXLiaison)liaison);
+ }
} catch (Exception ex) {
- log("Failed to read stylesheet " + stylesheet, Project.MSG_INFO);
+ log("Failed to transform using stylesheet " + stylesheet,
Project.MSG_INFO);
throw new BuildException(ex);
}
+ }
- try {
- // if liaison is a TraxLiason, use XMLCatalog as the entity
- // resolver and URI resolver
- if (liaison.getClass().getName().equals(TRAX_LIAISON_CLASS) &&
- xmlCatalog != null) {
- log("Configuring TraxLiaison: setting entity resolver " +
- "and setting URI resolver", Project.MSG_DEBUG);
- Method resolver = liaison.getClass()
- .getDeclaredMethod("setEntityResolver",
- new Class[] {EntityResolver.class});
- resolver.invoke(liaison, new Object[] {xmlCatalog});
-
- resolver = liaison.getClass()
- .getDeclaredMethod("setURIResolver",
- new Class[]
{loadClass("javax.xml.transform.URIResolver")});
- resolver.invoke(liaison, new Object[] {xmlCatalog});
- }
- } catch (Exception e) {
- throw new BuildException("Failed to configure XMLCatalog for "
- + "TraxLiaison", e);
+ /**
+ * Specific configuration for the TRaX liaison... support for
+ * all other has been dropped so this liaison will soon look
+ * like the exact copy of JAXP interface..
+ * @param liaison the TRaXLiaison to configure.
+ */
+ protected void configureTraXLiaison(TraXLiaison liaison){
+ // use XMLCatalog as the entity resolver and URI resolver
+ if (xmlCatalog != null) {
+ liaison.setEntityResolver(xmlCatalog);
+ liaison.setURIResolver(xmlCatalog);
+ }
+
+ // configure output properties
+ for (Enumeration props = outputProperties.elements();
+ props.hasMoreElements();) {
+ OutputProperty prop = (OutputProperty)props.nextElement();
+ liaison.setOutputProperty(prop.getName(), prop.getValue());
}
}
-
+
} //-- XSLTProcess
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>