Browse Source

Have to fix fix from bug 39407, because a nested resource and a nested resource

collection are ambiguous; all resources are resource collections.  Added
addConfiguredStyle(Resources) for maximum ease of use; user can specify a
nested resource e.g. <file> or <url>, or any resource collection known to
evaluate to a single result e.g. <fileset file="foo" /> OR
<style refid="somesingleelementcollection" /> is supported OOTB.  Docs to come.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@447990 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 19 years ago
parent
commit
427c2d293d
3 changed files with 31 additions and 12 deletions
  1. +10
    -5
      src/etc/testcases/taskdefs/style/build.xml
  2. +19
    -6
      src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
  3. +2
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java

+ 10
- 5
src/etc/testcases/taskdefs/style/build.xml View File

@@ -109,15 +109,18 @@
</target>

<target name="testWithStyleAttrAndResource">
<property name="value" value="myvalue"/>
<!-- also testing style as resources, with refid -->
<file id="xslFile" file="printParams.xsl"/>
<xslt in="data.xml" out="${out.dir}/out.xml" style="printParams.xsl">
<file file="printParams.xsl"/>
<style refid="xslFile" />
</xslt>
</target>

<target name="testWithFileResource">
<xslt in="data.xml" out="${out.dir}/out.xml">
<file file="printParams.xsl"/>
<style>
<file file="printParams.xsl"/>
</style>
<param name="set" expression="value"/>
</xslt>
</target>
@@ -125,7 +128,9 @@
<target name="testWithUrlResource">
<makeurl file="printParams.xsl" property="printParams.xsl.url"/>
<xslt in="data.xml" out="${out.dir}/out.xml">
<url url="${printParams.xsl.url}"/>
<style>
<url url="${printParams.xsl.url}"/>
</style>
<param name="set" expression="value"/>
</xslt>
</target>
@@ -180,4 +185,4 @@
/> <!-- without 'filenameparameter' to check, that the xsl:param is NOT set -->
</target>

</project>
</project>

+ 19
- 6
src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java View File

@@ -34,6 +34,7 @@ import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.ResourceCollection;
import org.apache.tools.ant.types.XMLCatalog;
import org.apache.tools.ant.types.resources.FileResource;
import org.apache.tools.ant.types.resources.Resources;
import org.apache.tools.ant.types.resources.Union;
import org.apache.tools.ant.util.FileNameMapper;
import org.apache.tools.ant.util.FileUtils;
@@ -222,13 +223,25 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
}

/**
* Adds the XSLT stylesheet as a resource
* @param xslResource the stylesheet as a
* {@link org.apache.tools.ant.types.Resource}
* Add a nested &lt;style&gt; element.
* @param rc the configured Resources object represented as &lt;style&gt;.
* @since Ant 1.7
*/
public void addConfigured(Resource xslResource) {
this.xslResource = xslResource;
public void addConfiguredStyle(Resources rc) {
if (rc.size() != 1) {
throw new BuildException("The style element must be specified"
+ " with exactly one nested resource.");
}
setXslResource((Resource) rc.iterator().next());
}

/**
* API method to set the XSL Resource.
* @param xslResource Resource to set as the stylesheet.
* @since Ant 1.7
*/
public void setXslResource(Resource xslResource) {
this.xslResource = xslResource;
}

/**
@@ -1204,4 +1217,4 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
}
}

}
}

+ 2
- 1
src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java View File

@@ -229,7 +229,8 @@ public class AggregateTransformer {
XSLTProcess xsltTask = new XSLTProcess();
xsltTask.bindToOwner(task);

xsltTask.addConfigured(getStylesheet());
xsltTask.setXslResource(getStylesheet());

// acrobatic cast.
xsltTask.setIn(((XMLResultAggregator) task).getDestinationFile());
File outputFile = null;


Loading…
Cancel
Save