conor 2003/09/10 08:18:41 Modified: src/main/org/apache/tools/ant/taskdefs XSLTProcess.java src/main/org/apache/tools/ant/taskdefs/optional TraXLiaison.java Added: src/main/org/apache/tools/ant/taskdefs XSLTLiaison2.java Log: Refactor TraxLiasion initialization to remove dependency from core Ant to optional packages. PR: 11103 Revision Changes Path 1.75 +28 -38 ant/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java Index: XSLTProcess.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java,v retrieving revision 1.74 retrieving revision 1.75 diff -u -w -u -r1.74 -r1.75 --- XSLTProcess.java 6 Sep 2003 13:51:47 -0000 1.74 +++ XSLTProcess.java 10 Sep 2003 15:18:40 -0000 1.75 @@ -62,7 +62,6 @@ import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.DynamicConfigurator; import org.apache.tools.ant.Project; -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.types.XMLCatalog; @@ -559,6 +558,29 @@ } /** + * Get the factory instance configured for this processor + * + * @return the factory instance in use + */ + public Factory getFactory() { + return factory; + } + + /** + * Get the XML catalog containing entity definitions + * + * @return the XML catalog for the task. + */ + public XMLCatalog getXMLCatalog() { + return xmlCatalog; + } + + public Enumeration getOutputProperties() { + return outputProperties.elements(); + } + + + /** * Get the Liason implementation to use in processing. * * @return an instance of the XSLTLiason interface. @@ -793,45 +815,13 @@ liaison.addParam(p.getName(), p.getExpression()); } } - if (liaison instanceof TraXLiaison) { - configureTraXLiaison((TraXLiaison) liaison); + if (liaison instanceof XSLTLiaison2) { + ((XSLTLiaison2) liaison).configure(this); } } catch (Exception ex) { - log("Failed to transform using stylesheet " + stylesheet, Project.MSG_INFO); + log("Failed to transform using stylesheet " + stylesheet, + Project.MSG_INFO); throw new BuildException(ex); - } - } - - /** - * Specific configuration for the TRaX liaison. Support for - * all others 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) { - if (factory != null) { - liaison.setFactory(factory.getName()); - - // configure factory attributes - for (Enumeration attrs = factory.getAttributes(); - attrs.hasMoreElements();) { - Factory.Attribute attr = - (Factory.Attribute) attrs.nextElement(); - liaison.setAttribute(attr.getName(), attr.getValue()); - } - } - - // 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()); } } 1.1 ant/src/main/org/apache/tools/ant/taskdefs/XSLTLiaison2.java Index: XSLTLiaison2.java =================================================================== /* * The Apache Software License, Version 1.1 * * Copyright (c) 2000-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 [EMAIL PROTECTED] * * 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 * <http://www.apache.org/>. */ package org.apache.tools.ant.taskdefs; /** * Extended Proxy interface for XSLT processors. * * @author Conro MacNeill * @see XSLTProcess * @since Ant 1.6 */ public interface XSLTLiaison2 extends XSLTLiaison { /** * Configure the liasion from the XSLTProcess task */ void configure(XSLTProcess xsltTask); } 1.29 +42 -3 ant/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java Index: TraXLiaison.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java,v retrieving revision 1.28 retrieving revision 1.29 diff -u -w -u -r1.28 -r1.29 --- TraXLiaison.java 18 Jul 2003 12:45:57 -0000 1.28 +++ TraXLiaison.java 10 Sep 2003 15:18:41 -0000 1.29 @@ -63,6 +63,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.Vector; +import java.util.Enumeration; import javax.xml.parsers.SAXParserFactory; import javax.xml.transform.ErrorListener; import javax.xml.transform.Source; @@ -77,9 +78,11 @@ import javax.xml.transform.stream.StreamSource; import javax.xml.transform.TransformerConfigurationException; import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.taskdefs.XSLTLiaison; +import org.apache.tools.ant.taskdefs.XSLTLiaison2; +import org.apache.tools.ant.taskdefs.XSLTProcess; import org.apache.tools.ant.taskdefs.XSLTLogger; import org.apache.tools.ant.taskdefs.XSLTLoggerAware; +import org.apache.tools.ant.types.XMLCatalog; import org.apache.tools.ant.util.JAXPUtils; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; @@ -93,7 +96,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Bailliez</a> * @since Ant 1.3 */ -public class TraXLiaison implements XSLTLiaison, ErrorListener, XSLTLoggerAware { +public class TraXLiaison implements XSLTLiaison2, ErrorListener, XSLTLoggerAware { /** * the name of the factory implementation class to use @@ -430,4 +433,40 @@ return JAXPUtils.getSystemId(file); } -} //-- TraXLiaison + + /** + * Specific configuration for the TRaX liaison. + * @param xsltTask the XSLTProcess task instance from which this liasion + * is to be configured. + */ + public void configure(XSLTProcess xsltTask) { + XSLTProcess.Factory factory = xsltTask.getFactory(); + if (factory != null) { + setFactory(factory.getName()); + + // configure factory attributes + for (Enumeration attrs = factory.getAttributes(); + attrs.hasMoreElements();) { + XSLTProcess.Factory.Attribute attr = + (XSLTProcess.Factory.Attribute) attrs.nextElement(); + setAttribute(attr.getName(), attr.getValue()); + } + } + + XMLCatalog xmlCatalog = xsltTask.getXMLCatalog(); + // use XMLCatalog as the entity resolver and URI resolver + if (xmlCatalog != null) { + setEntityResolver(xmlCatalog); + setURIResolver(xmlCatalog); + } + + + // configure output properties + for (Enumeration props = xsltTask.getOutputProperties(); + props.hasMoreElements();) { + XSLTProcess.OutputProperty prop + = (XSLTProcess.OutputProperty) props.nextElement(); + setOutputProperty(prop.getName(), prop.getValue()); + } + } +}
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]