transformer.setOutputProperty(OutputKeys.METHOD, type); Background/rationalle: I'm looking into spliting Gumps gen.bat and gen.sh scripts into a minimal bootstrap and a normal Ant "build.xml". In order to achieve this, I need access to the functionallity that Xalan supports from the command line via the -text parameter. I've provided an implementation to seed the discussion on how this should be supported. I am by no means wedded to this approach - if others see a better way, either let me know or directly make the change. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270023 13f79535-47bb-0310-9956-ffa450edef68master
@@ -140,6 +140,13 @@ inclusion/exclusion of files works, and how to write patterns.</p> | |||||
in attribute.</td> | in attribute.</td> | ||||
<td valign="top" align="center">No</td> | <td valign="top" align="center">No</td> | ||||
</tr> | </tr> | ||||
<tr> | |||||
<td valign="top">outputtype</td> | |||||
<td valign="top">specifies the output method to be used. Only "xml" is | |||||
guaranteed to be supported by all translators. Xalan2 supports "xml", | |||||
"html", and "text"</td> | |||||
<td valign="top" align="center">No</td> | |||||
</tr> | |||||
</table> | </table> | ||||
<h3>Parameters specified as nested elements</h3> | <h3>Parameters specified as nested elements</h3> | ||||
<h4>classpath</h4> | <h4>classpath</h4> | ||||
@@ -92,6 +92,14 @@ public interface XSLTLiaison { | |||||
*/ | */ | ||||
void addParam(String name, String expression) throws Exception; | 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 | |||||
*/ | |||||
void setOutputtype(String type) throws Exception; | |||||
/** | /** | ||||
* Perform the transformation of a file into another. | * Perform the transformation of a file into another. | ||||
* @param infile the input file, probably an XML one. :-) | * @param infile the input file, probably an XML one. :-) | ||||
@@ -116,6 +116,8 @@ public class XSLTProcess extends MatchingTask { | |||||
private FileUtils fileUtils; | private FileUtils fileUtils; | ||||
private String outputtype = null; | |||||
/** | /** | ||||
* Creates a new XSLTProcess Task. | * Creates a new XSLTProcess Task. | ||||
**/ | **/ | ||||
@@ -457,6 +459,16 @@ public class XSLTProcess extends MatchingTask { | |||||
} | } | ||||
} | } | ||||
/** | |||||
* 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 | |||||
*/ | |||||
public void setOutputtype(String type) { | |||||
this.outputtype = type; | |||||
} | |||||
/** | /** | ||||
* Loads the stylesheet and set xsl:param parameters. | * Loads the stylesheet and set xsl:param parameters. | ||||
*/ | */ | ||||
@@ -59,6 +59,7 @@ import java.io.FileOutputStream; | |||||
import java.io.OutputStreamWriter; | import java.io.OutputStreamWriter; | ||||
import org.apache.tools.ant.taskdefs.XSLTLiaison; | import org.apache.tools.ant.taskdefs.XSLTLiaison; | ||||
import org.apache.tools.ant.BuildException; | |||||
import org.exolab.adaptx.xslt.XSLTProcessor; | import org.exolab.adaptx.xslt.XSLTProcessor; | ||||
import org.exolab.adaptx.xslt.XSLTReader; | import org.exolab.adaptx.xslt.XSLTReader; | ||||
@@ -93,4 +94,9 @@ public class AdaptxLiaison implements XSLTLiaison { | |||||
processor.setProperty(name, expression); | processor.setProperty(name, expression); | ||||
} | } | ||||
public void setOutputtype(String type) throws Exception { | |||||
if (!type.equals("xml")) | |||||
throw new BuildException("Unsupported output type: " + type); | |||||
} | |||||
} //-- AdaptxLiaison | } //-- AdaptxLiaison |
@@ -67,6 +67,7 @@ import javax.xml.transform.Templates; | |||||
import javax.xml.transform.stream.StreamResult; | import javax.xml.transform.stream.StreamResult; | ||||
import javax.xml.transform.stream.StreamSource; | import javax.xml.transform.stream.StreamSource; | ||||
import javax.xml.transform.OutputKeys; | |||||
/** | /** | ||||
* Concrete liaison for XSLT processor implementing TraX. (ie JAXP 1.1) | * Concrete liaison for XSLT processor implementing TraX. (ie JAXP 1.1) | ||||
@@ -160,4 +161,8 @@ public class TraXLiaison implements XSLTLiaison { | |||||
public void addParam(String name, String value){ | public void addParam(String name, String value){ | ||||
transformer.setParameter(name, value); | transformer.setParameter(name, value); | ||||
} | } | ||||
public void setOutputtype(String type) throws Exception { | |||||
transformer.setOutputProperty(OutputKeys.METHOD, type); | |||||
} | |||||
} //-- TraXLiaison | } //-- TraXLiaison |
@@ -54,6 +54,7 @@ | |||||
package org.apache.tools.ant.taskdefs.optional; | package org.apache.tools.ant.taskdefs.optional; | ||||
import org.apache.tools.ant.BuildException; | |||||
import org.apache.tools.ant.taskdefs.XSLTLiaison; | import org.apache.tools.ant.taskdefs.XSLTLiaison; | ||||
import org.apache.xalan.xslt.XSLTProcessorFactory; | import org.apache.xalan.xslt.XSLTProcessorFactory; | ||||
@@ -127,4 +128,9 @@ public class XalanLiaison implements XSLTLiaison { | |||||
public void addParam(String name, String value){ | public void addParam(String name, String value){ | ||||
processor.setStylesheetParam(name, value); | processor.setStylesheetParam(name, value); | ||||
} | } | ||||
public void setOutputtype(String type) throws Exception { | |||||
if (!type.equals("xml")) | |||||
throw new BuildException("Unsupported output type: " + type); | |||||
} | |||||
} //-- XalanLiaison | } //-- XalanLiaison |
@@ -58,6 +58,7 @@ import com.kvisco.xsl.XSLProcessor; | |||||
import com.kvisco.xsl.XSLReader; | import com.kvisco.xsl.XSLReader; | ||||
import com.kvisco.xsl.XSLStylesheet; | import com.kvisco.xsl.XSLStylesheet; | ||||
import org.apache.tools.ant.taskdefs.XSLTLiaison; | import org.apache.tools.ant.taskdefs.XSLTLiaison; | ||||
import org.apache.tools.ant.BuildException; | |||||
import java.io.File; | import java.io.File; | ||||
import java.io.FileOutputStream; | import java.io.FileOutputStream; | ||||
@@ -103,4 +104,9 @@ public class XslpLiaison implements XSLTLiaison { | |||||
processor.setProperty(name, expression); | processor.setProperty(name, expression); | ||||
} | } | ||||
public void setOutputtype(String type) throws Exception { | |||||
if (!type.equals("xml")) | |||||
throw new BuildException("Unsupported output type: " + type); | |||||
} | |||||
} //-- XSLPLiaison | } //-- XSLPLiaison |