diff --git a/docs/manual/CoreTasks/style.html b/docs/manual/CoreTasks/style.html index de184d734..a8f11b832 100644 --- a/docs/manual/CoreTasks/style.html +++ b/docs/manual/CoreTasks/style.html @@ -187,9 +187,20 @@ element is used to perform Entity and URI resolution.

expression Text value to be placed into the param.
- Was originally intended to be an XSL expression. + Was originally intended to be an XSL expression. Yes + + if + The param will only passed if this property is set. + No + + + unless + The param will only passed unless this property is set. + No + +

outputproperty ('trax' processors only)

@@ -230,7 +241,7 @@ Used to specify factory settings. transformer factory to use. For example org.apache.xalan.processor.TransformerFactoryImpl or org.apache.xalan.xsltc.trax.TransformerFactoryImpl - or net.sf.saxon.TransformerFactoryImpl... + or net.sf.saxon.TransformerFactoryImpl... No. Defaults to the JAXP lookup mechanism. @@ -318,7 +329,7 @@ And in Saxon 7.x:

Using factory settings

<xslt in="doc.xml" out="build/doc/output.xml"
       style="style/apache.xsl">
-  <factory name="org.apache.xalan.processor.TransformerFactoryImpl">  
+  <factory name="org.apache.xalan.processor.TransformerFactoryImpl">
     <attribute name="http://xml.apache.org/xalan/features/optimize" value="true"/>
   </factory>
 </xslt>
@@ -329,4 +340,3 @@ Reserved.

- diff --git a/src/etc/testcases/taskdefs/style/build.xml b/src/etc/testcases/taskdefs/style/build.xml new file mode 100644 index 000000000..dde2b9b1d --- /dev/null +++ b/src/etc/testcases/taskdefs/style/build.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/etc/testcases/taskdefs/style/data.xml b/src/etc/testcases/taskdefs/style/data.xml new file mode 100644 index 000000000..b86e0c064 --- /dev/null +++ b/src/etc/testcases/taskdefs/style/data.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/etc/testcases/taskdefs/style/printParams.xsl b/src/etc/testcases/taskdefs/style/printParams.xsl new file mode 100644 index 000000000..1d8728e42 --- /dev/null +++ b/src/etc/testcases/taskdefs/style/printParams.xsl @@ -0,0 +1,20 @@ + + + + + +set default value +empty default value +undefined default value + + + +set='' +empty='' +undefined='' + + + \ No newline at end of file diff --git a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java index 6a0a2eb0f..b06dfd20c 100644 --- a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java +++ b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java @@ -615,6 +615,19 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { /** The parameter's value */ private String expression = null; + private String ifProperty; + private String unlessProperty; + private Project project; + + /** + * Set the current project + * + * @param project the current project + */ + public void setProject(Project project) { + this.project = project; + } + /** * Set the parameter name. * @@ -658,6 +671,39 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { } return expression; } + + /** + * Set whether this param should be used. It will be + * used if the property has been set, otherwise it won't. + * @param ifProperty name of property + */ + public void setIf(String ifProperty) { + this.ifProperty = ifProperty; + } + + /** + * Set whether this param should NOT be used. It + * will not be used if the property has been set, orthwise it + * will be used. + * @param unlessProperty name of property + */ + public void setUnless(String unlessProperty) { + this.unlessProperty = unlessProperty; + } + /** + * Ensures that the param passes the conditions placed + * on it with if and unless properties. + */ + public boolean shouldUse() { + if (ifProperty != null && project.getProperty(ifProperty) == null) { + return false; + } else if (unlessProperty != null + && project.getProperty(unlessProperty) != null) { + return false; + } + + return true; + } } // Param @@ -743,7 +789,9 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { liaison.setStylesheet(stylesheet); for (Enumeration e = params.elements(); e.hasMoreElements();) { Param p = (Param) e.nextElement(); - liaison.addParam(p.getName(), p.getExpression()); + if (p.shouldUse()) { + liaison.addParam(p.getName(), p.getExpression()); + } } if (liaison instanceof TraXLiaison) { configureTraXLiaison((TraXLiaison) liaison); diff --git a/src/testcases/org/apache/tools/ant/taskdefs/StyleTest.java b/src/testcases/org/apache/tools/ant/taskdefs/StyleTest.java new file mode 100644 index 000000000..75a5c16f7 --- /dev/null +++ b/src/testcases/org/apache/tools/ant/taskdefs/StyleTest.java @@ -0,0 +1,154 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001-2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "Ant" and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ +package org.apache.tools.ant.taskdefs; + + +import org.apache.tools.ant.BuildFileTest; +import org.apache.tools.ant.util.FileUtils; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; + + +/** + * TestCases für