From 5d847c583ec27323ea441b0210a034ed3e220cbf Mon Sep 17 00:00:00 2001 From: Peter Reilly Date: Tue, 5 Aug 2003 16:01:10 +0000 Subject: [PATCH] =?UTF-8?q?Add=20if/unless=20attributes=20to=20=20?= =?UTF-8?q?element=20of=20 + + + + + + + + + + + + + + + + \ 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