You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mm...@apache.org on 2001/01/11 20:29:09 UTC
cvs commit: xml-xalan/java/compat_src/org/apache/xalan/xslt StylesheetHandler.java StylesheetRoot.java StylesheetSpec.java XSLProcessorContext.java XSLTEngineImpl.java XSLTInputSource.java XSLTProcessor.java XSLTProcessorFactory.java XSLTResultTarget.java
mmidy 01/01/11 11:29:08
Added: java/compat_src/org/apache/xalan/xpath XObject.java
XString.java
java/compat_src/org/apache/xalan/xpath/xml
FormatterToDOM.java FormatterToHTML.java
FormatterToText.java FormatterToXML.java
ProblemListener.java ProblemListenerDefault.java
TreeWalker.java XMLParserLiaison.java
java/compat_src/org/apache/xalan/xslt StylesheetHandler.java
StylesheetRoot.java StylesheetSpec.java
XSLProcessorContext.java XSLTEngineImpl.java
XSLTInputSource.java XSLTProcessor.java
XSLTProcessorFactory.java XSLTResultTarget.java
Log:
Compatibility classes for xalan1 APIs
Revision Changes Path
1.1 xml-xalan/java/compat_src/org/apache/xalan/xpath/XObject.java
Index: XObject.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" 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 name, without prior written
* permission of the Apache Software Foundation.
*
* 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 and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.xpath;
/**
* <meta name="usage" content="general"/>
* This class represents an XPath object, and is capable of
* converting the object to various types, such as a string.
* This class acts as the base class to other XPath type objects,
* such as XString, and provides polymorphic casting capabilities.
*/
public class XObject extends org.apache.xpath.objects.XObject
{
/**
* Create an XObject.
*/
public XObject()
{
super();
}
/**
* Create an XObject.
*/
public XObject(Object obj)
{
super(obj);
}
}
1.1 xml-xalan/java/compat_src/org/apache/xalan/xpath/XString.java
Index: XString.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" 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 name, without prior written
* permission of the Apache Software Foundation.
*
* 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 and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.xpath;
/**
* <meta name="usage" content="general"/>
* This class represents an XPath string object, and is capable of
* converting the string to other types, such as a number.
*/
public class XString extends org.apache.xpath.objects.XString
{
/**
* Construct a XString object.
*/
public XString(String val)
{
super(val);
}
}
1.1 xml-xalan/java/compat_src/org/apache/xalan/xpath/xml/FormatterToDOM.java
Index: FormatterToDOM.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" 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 name, without prior written
* permission of the Apache Software Foundation.
*
* 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 and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.xpath.xml;
import org.w3c.dom.*;
import org.apache.xalan.serialize.Serializer;
import org.apache.xalan.serialize.SerializerFactory;
//import org.apache.xml.serialize.BaseMarkupSerializer;
import org.apache.xalan.serialize.DOMSerializer;
import org.apache.xalan.serialize.SerializerToXML;
//import org.apache.xml.serialize.OutputFormat;
/**
* <meta name="usage" content="general"/>
* This class takes SAX events (in addition to some extra events
* that SAX doesn't handle yet) and adds the result to a document
* or document fragment.
*/
public class FormatterToDOM //extends BaseMarkupSerializer
{
DOMSerializer m_serializer;
/**
* FormatterToDOM instance constructor... it will add the DOM nodes
* to the document fragment.
*/
public FormatterToDOM(Document doc, Element elem)
{
//super(new OutputFormat());
try{
m_serializer = (new SerializerToXML()).asDOMSerializer();
}
catch (java.io.IOException ioe)
{}
}
/**
* FormatterToDOM instance constructor... it will add the DOM nodes
* to the document fragment.
*/
public FormatterToDOM(Document doc, DocumentFragment docFrag)
{
//super(new OutputFormat());
try{
m_serializer = (new SerializerToXML()).asDOMSerializer();
}
catch (java.io.IOException ioe)
{}
}
/**
* FormatterToDOM instance constructor... it will add the DOM nodes
* to the document.
*/
public FormatterToDOM(Document doc)
{
//super(new OutputFormat());
try{
m_serializer = (new SerializerToXML()).asDOMSerializer();
}
catch (java.io.IOException ioe)
{}
}
public SerializerToXML getSerializerObject()
{
return (SerializerToXML)m_serializer;
}
}
1.1 xml-xalan/java/compat_src/org/apache/xalan/xpath/xml/FormatterToHTML.java
Index: FormatterToHTML.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" 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 name, without prior written
* permission of the Apache Software Foundation.
*
* 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 and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.xpath.xml;
import java.io.Writer;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import org.apache.xalan.serialize.Serializer;
import org.apache.xalan.serialize.SerializerFactory;
import org.apache.xalan.serialize.SerializerToHTML;
//import org.apache.xml.serialize.OutputFormat;
/**
* <meta name="usage" content="general"/>
* FormatterToHTML formats SAX-style events into XML.
* Warning: this class will be replaced by the Xerces Serializer classes.
*/
public class FormatterToHTML extends SerializerToHTML
{
public FormatterToHTML()
{
super();
}
/**
* Constructor using a writer.
* @param writer The character output stream to use.
*/
public FormatterToHTML(Writer writer)
{
super ();
this.setWriter(writer);
}
/**
* Constructor using an output stream, and a simple OutputFormat.
* @param writer The character output stream to use.
*/
public FormatterToHTML(java.io.OutputStream os)
throws UnsupportedEncodingException
{
super ();
this.setOutputStream(os);
}
/**
* Constructor using a writer.
* @param writer The character output stream to use.
*/
public FormatterToHTML(FormatterToXML xmlListener)
{
super();
}
}
1.1 xml-xalan/java/compat_src/org/apache/xalan/xpath/xml/FormatterToText.java
Index: FormatterToText.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" 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 name, without prior written
* permission of the Apache Software Foundation.
*
* 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 and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.xpath.xml;
import java.io.Writer;
import org.apache.xalan.serialize.Serializer;
import org.apache.xalan.serialize.SerializerFactory;
import org.apache.xalan.serialize.SerializerToText;
//import org.apache.xml.serialize.OutputFormat;
/**
* <meta name="usage" content="general"/>
* This class takes SAX events (in addition to some extra events
* that SAX doesn't handle yet) and produces simple text only.
* Warning: this class will be replaced by the Xerces Serializer classes.
*/
public class FormatterToText //extends TextSerializer
{
private SerializerToText m_serializer;
/**
* FormatterToText instance constructor... it will add the DOM nodes
* to the document fragment.
*/
public FormatterToText(Writer pw)
{
m_serializer = new SerializerToText(); //super();
}
public SerializerToText getSerializerObject()
{
return m_serializer;
}
}
1.1 xml-xalan/java/compat_src/org/apache/xalan/xpath/xml/FormatterToXML.java
Index: FormatterToXML.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" 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 name, without prior written
* permission of the Apache Software Foundation.
*
* 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 and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.xpath.xml;
import java.io.Writer;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import org.apache.xalan.serialize.Serializer;
import org.apache.xalan.serialize.SerializerFactory;
import org.apache.xalan.serialize.SerializerToXML;
//import org.apache.xml.serialize.BaseMarkupSerializer;
import org.apache.xalan.serialize.Method;
//import org.apache.xml.serialize.OutputFormat;
/**
* <meta name="usage" content="general"/>
* FormatterToXML formats SAX-style events into XML.
* Warning: this class will be replaced by the Xerces Serializer classes.
*/
public class FormatterToXML //extends BaseMarkupSerializer
{
SerializerToXML m_serializer;
public void FormatterToXML()
{
m_serializer = new SerializerToXML();
//super( new OutputFormat( Method.XML, null, false ) );
}
/**
* Constructor using a writer.
* @param writer The character output stream to use.
*/
public FormatterToXML(Writer writer)
{
m_serializer = new SerializerToXML();
// super( format != null ? format : new OutputFormat( Method.XML, null, false ) );
//_format.setMethod( Method.XML );
m_serializer.setWriter( writer );
}
/**
* Constructor using an output stream, and a simple OutputFormat.
* @param writer The character output stream to use.
*/
public FormatterToXML(java.io.OutputStream os)
throws UnsupportedEncodingException
{
m_serializer = new SerializerToXML();
//super( format != null ? format : new OutputFormat( Method.XML, null, false ) );
//_format.setMethod( Method.XML );
m_serializer.setOutputStream( os );
}
/**
* Constructor using a writer.
* @param writer The character output stream to use.
*/
public FormatterToXML(FormatterToXML xmlListener)
{
m_serializer = new SerializerToXML();
m_serializer.CopyFrom(xmlListener.m_serializer);
//super( new OutputFormat( Method.XML, null, false ) );
}
public SerializerToXML getSerializerObject()
{
return m_serializer;
}
} //ToXMLStringVisitor
1.1 xml-xalan/java/compat_src/org/apache/xalan/xpath/xml/ProblemListener.java
Index: ProblemListener.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" 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 name, without prior written
* permission of the Apache Software Foundation.
*
* 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 and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.xpath.xml;
import org.w3c.dom.*;
/**
* <meta name="usage" content="general"/>
* This is the interface that the XSL processor calls when it
* has a problem of some kind, either an error or a warning.
* Users should ass the XSLTEngineImpl class to setProblemListener
* if they wish an object instance to be called when a problem
* event occurs.
*/
public interface ProblemListener
{
public static final short WARNING = 1;
public static final short ERROR = 2;
public static final short MESSAGE = 3;
public static final short XMLPARSER = 1;
public static final short XSLPROCESSOR = 2;
public static final short QUERYENGINE = 3;
public static final short XPATHPROCESSOR = 4;
public static final short XPATHPARSER = 5;
/**
* Function that is called when a problem event occurs.
*
* @param where Either and XMLPARSER, XSLPROCESSOR, or QUERYENGINE.
* @param classification Either ERROR or WARNING.
* @param styleNode The style tree node where the problem
* occurred. May be null.
* @param sourceNode The source tree node where the problem
* occurred. May be null.
* @param msg A string message explaining the problem.
* @param lineNo The line number where the problem occurred,
* if it is known. May be zero.
* @param charOffset The character offset where the problem,
* occurred if it is known. May be zero.
*
* @return true if the return is an ERROR, in which case
* exception will be thrown. Otherwise the processor will
* continue to process.
*/
public boolean problem(short where, short classification,
Object styleNode, Node sourceNode,
String msg, String id, int lineNo, int charOffset)
throws org.xml.sax.SAXException ;
/**
* Function that is called to issue a message.
* @param msg A string message to output.
*/
public boolean message(String msg);
}
1.1 xml-xalan/java/compat_src/org/apache/xalan/xpath/xml/ProblemListenerDefault.java
Index: ProblemListenerDefault.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" 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 name, without prior written
* permission of the Apache Software Foundation.
*
* 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 and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.xpath.xml;
import org.w3c.dom.*;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXParseException;
/**
* <meta name="usage" content="general"/>
* This is the interface that the XSL processor calls when it
* has a problem of some kind, either an error or a warning.
* Users should ass the XSLTEngineImpl class to setProblemListener
* if they wish an object instance to be called when a problem
* event occurs.
*/
public class ProblemListenerDefault implements ProblemListener
{
ErrorHandler m_errorHandler = null;
ProblemListener m_problemListener = null;
public ProblemListenerDefault()
{
m_errorHandler = new org.apache.xml.utils.DefaultErrorHandler();
}
public ProblemListenerDefault(ErrorHandler handler, ProblemListener l)
{
m_errorHandler = handler;
m_problemListener = l;
}
public void setErrorHandler (ErrorHandler handler)
{
m_errorHandler = handler;
}
public void setProblemListener (ProblemListener l)
{
m_problemListener = l;
}
public ErrorHandler getErrorHandler ()
{
return m_errorHandler;
}
public ProblemListener getProblemListener ()
{
return m_problemListener;
}
/**
* Function that is called to issue a message.
* @param msg A string message to output.
*/
public boolean message(String msg)
{
synchronized (this)
{
new java.io.PrintWriter( System.err, true ).println( msg );
}
return false; // we don't know this is an error
}
public boolean problem(short where, short classification,
Object styleNode, Node sourceNode,
String msg, String id, int lineNo, int charOffset)
throws org.xml.sax.SAXException
{
m_errorHandler.error(new SAXParseException(msg, null, id, lineNo, charOffset));
return false;
}
}
1.1 xml-xalan/java/compat_src/org/apache/xalan/xpath/xml/TreeWalker.java
Index: TreeWalker.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" 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 name, without prior written
* permission of the Apache Software Foundation.
*
* 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 and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.xpath.xml;
import org.w3c.dom.*;
import org.xml.sax.*;
import org.xml.sax.ext.LexicalHandler;
import org.apache.xml.utils.AttList;
/**
* <meta name="usage" content="advanced"/>
* This class does a pre-order walk of the DOM tree, calling the FormatterListener
* interface as it goes.
*/
public class TreeWalker extends org.apache.xml.utils.TreeWalker
{
/**
* Constructor.
* @param formatterListener The implemention of the
* FormatterListener operation (toXMLString, digest, ...)
*/
public TreeWalker(ContentHandler formatterListener)
{
super(formatterListener);
}
} //TreeWalker
1.1 xml-xalan/java/compat_src/org/apache/xalan/xpath/xml/XMLParserLiaison.java
Index: XMLParserLiaison.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" 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 name, without prior written
* permission of the Apache Software Foundation.
*
* 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 and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.xpath.xml;
import org.w3c.dom.*;
import org.apache.xpath.DOM2Helper;
/**
* <meta name="usage" content="general"/>
* This is the interface that the XSL processor calls when it
* has a problem of some kind, either an error or a warning.
* Users should ass the XSLTEngineImpl class to setProblemListener
* if they wish an object instance to be called when a problem
* event occurs.
*/
public class XMLParserLiaison extends DOM2Helper
{
}
1.1 xml-xalan/java/compat_src/org/apache/xalan/xslt/StylesheetHandler.java
Index: StylesheetHandler.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" 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 name, without prior written
* permission of the Apache Software Foundation.
*
* 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 and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.xslt;
import java.util.*;
import org.xml.sax.*;
import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.helpers.ParserAdapter;
import org.w3c.dom.*;
import java.util.Vector;
import java.io.*;
import java.net.*;
import org.apache.xalan.templates.Stylesheet;
/**
* <meta name="usage" content="advanced"/>
* Initializes and processes a stylesheet via SAX events.
* If you need to alter the code in here,
* it is not for the faint-of-heart, due to the state tracking
* that has to be done due to the SAX event model.
*/
public class StylesheetHandler extends ParserAdapter
{
/**
* Instance constructor...
* @param processor The XSLTProcessor implementation.
* @param stylesheet The root stylesheet.
*
*/
public StylesheetHandler(XSLTEngineImpl processor, Stylesheet stylesheetTree)
throws javax.xml.transform.TransformerConfigurationException, SAXException
{
super(new org.apache.xerces.parsers.SAXParser());
//try{
org.apache.xalan.processor.StylesheetHandler handler =
new org.apache.xalan.processor.StylesheetHandler(processor.getTransformerFactory());
handler.pushStylesheet(stylesheetTree);
this.setContentHandler(handler);
//}
//catch (javax.xml.transform.TransformerConfigurationException tce)
//{}
}
/**
* Instance constructor...
* @param processor The XSLTProcessor implementation.
* @param stylesheet The root stylesheet.
* @exception TransformerConfigurationException
*/
public StylesheetHandler(XSLTEngineImpl processor, StylesheetRoot stylesheetTree)
throws javax.xml.transform.TransformerConfigurationException, SAXException
{
//try{
super(new org.apache.xerces.parsers.SAXParser());
org.apache.xalan.processor.StylesheetHandler handler =
new org.apache.xalan.processor.StylesheetHandler(processor.getTransformerFactory());
handler.pushStylesheet(stylesheetTree.getObject());
this.setContentHandler(handler);
//}
//catch (javax.xml.transform.TransformerConfigurationException tce)
//{}
}
}
1.1 xml-xalan/java/compat_src/org/apache/xalan/xslt/StylesheetRoot.java
Index: StylesheetRoot.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" 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 name, without prior written
* permission of the Apache Software Foundation.
*
* 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 and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.xslt;
import org.w3c.dom.*;
import java.util.*;
import java.net.*;
import java.io.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import org.apache.xml.serialize.*;
import org.apache.xalan.serialize.*;
import org.apache.xalan.templates.ElemTemplate;
import org.apache.xalan.templates.OutputProperties;
import javax.xml.transform.OutputKeys;
import org.apache.xalan.xpath.xml.FormatterToXML;
import org.apache.xalan.xpath.xml.FormatterToHTML;
import org.apache.xalan.xpath.xml.FormatterToText;
import org.apache.xalan.xpath.xml.FormatterToDOM;
import org.apache.xalan.res.XSLTErrorResources;
/**
* <meta name="usage" content="general"/>
* Binary representation of a stylesheet -- use the {@link org.apache.xalan.xslt.XSLTProcessor} ProcessStylesheet
* method to create a StylesheetRoot and improve performance for a stylesheet performing multiple transformations.
* Also required for XSLTProcessor to function as SAX DocumentHandler.
*/
public class StylesheetRoot //extends org.apache.xalan.templates.StylesheetRoot
{
private String m_liaisonClassUsedToCreate = null;
private org.apache.xalan.templates.StylesheetRoot m_sRootObject;
/**
* Uses an XSL stylesheet document.
* @param processor The XSLTProcessor implementation.
* @param baseIdentifier The file name or URL for the XSL stylesheet.
* @exception TransformerConfigurationException thrown
*/
public StylesheetRoot(XSLTEngineImpl processor,
String baseIdentifier)
throws TransformerConfigurationException
{
m_sRootObject = new org.apache.xalan.templates.StylesheetRoot();
m_liaisonClassUsedToCreate = ((Object)processor.getXMLProcessorLiaison()).getClass().getName();
}
public StylesheetRoot()
throws TransformerConfigurationException
{
m_sRootObject = new org.apache.xalan.templates.StylesheetRoot();
}
/**
* Constructor using an org.apache.xalan.templates.StylesheetRoot.
*
* @param s an org.apache.xalan.templates.StylesheetRoot object
*/
public StylesheetRoot(org.apache.xalan.templates.StylesheetRoot s)
{
m_sRootObject = s;
}
/**
* Return the org.apache.xalan.templates.StylesheetRoot object
* associated with this stylesheet root.
*
* @return an org.apache.xalan.templates.StylesheetRoot object
*/
public org.apache.xalan.templates.StylesheetRoot getObject()
{
return m_sRootObject;
}
/**
* Transform the XML source tree and place the output in the result tree target.
* This method uses a new XSLTProcessor instance to track the running state.
* @param xmlSource The XML input source tree.
* @param outputTarget The output result tree.
* @exception SAXException
* @see org.apache.xalan.xslt.XSLTProcessor#process(XSLTInputSource, XSLTInputSource, XSLTResultTarget)
*/
public void process( XSLTInputSource xmlSource,
XSLTResultTarget outputTarget)
throws SAXException,
MalformedURLException,
FileNotFoundException,
IOException
{
XSLTProcessor iprocessor =
(null != m_liaisonClassUsedToCreate) ?
new XSLTProcessorFactory().getProcessorUsingLiaisonName(m_liaisonClassUsedToCreate)
: new XSLTProcessorFactory().getProcessor();
process(iprocessor, iprocessor.getSourceTreeFromInput(xmlSource), outputTarget);
// System.out.println("Number counters made: "+
// ((XSLTEngineImpl)iprocessor).getCountersTable().m_countersMade);
}
/**
* Transform the XML source tree and place the output in the result tree target.
* Use this version of the StylesheetRoot process() method if you have used an
* XSLTProcessor object to set a stylesheet parameter. That object is now the iprocessor parameter.
* @param iprocessor The XSLTProcessor that will track the running state.
* @param xmlSource The XML input source tree.
* @param outputTarget The output result tree.
* @exception SAXException
* @see org.apache.xalan.xslt.XSLTProcessor#process(XSLTInputSource, XSLTInputSource, XSLTResultTarget)
*/
public void process( XSLTProcessor iprocessor, XSLTInputSource xmlSource,
XSLTResultTarget outputTarget)
throws SAXException,
MalformedURLException,
FileNotFoundException,
IOException
{
process(iprocessor, iprocessor.getSourceTreeFromInput(xmlSource), outputTarget);
}
/**
* Transform the XML source tree (a DOM Node) and place the output in the result tree target.
* This is a convenience method. You can also use a DOM Node to instantiate an XSLTInputSource object,
* and call {@link #process(XSLTProcessor, XSLTInputSource, XSLTResultTarget)} or
* {@link org.apache.xalan.xslt.XSLTProcessor#process(XSLTInputSource, XSLTInputSource, XSLTResultTarget)}.
* @param iprocessor The processor that will track the running state.
* @param sourceTree The input source tree in the form of a DOM Node.
* @param outputTarget The output result tree.
* @exception SAXException
*/
public void process( XSLTProcessor iprocessor, Node sourceTree,
XSLTResultTarget outputTarget)
throws SAXException,
MalformedURLException,
FileNotFoundException,
IOException
{
XSLTEngineImpl processor = (XSLTEngineImpl)iprocessor; // TODO: Check for class cast exception
//checkInit(processor);
synchronized(processor)
{
//processor.switchLiaisonsIfNeeded(sourceTree, outputTarget.getNode());
processor.setStylesheet(this);
OutputStream ostream = null;
try
{
// Double-check the node to make sure it matches the processor liaison.
//processor.getXMLProcessorLiaison().checkNode(sourceTree);
// Needs work: We have to put the extension namespaces
// into the liaison's table. We wouldn't have to do this
// if the stylesheet handled it's own extensions, which
// I'll fix on a later date.
/* Enumeration keys = m_extensionNamespaces.keys();
while(keys.hasMoreElements())
{
Object key = keys.nextElement();
// System.out.println("Putting ext namespace: "+key);
processor.getExecContext().addExtensionNamespace ((String)key,
(ExtensionFunctionHandler)m_extensionNamespaces.get(key));
}*/
// Find the root pattern in the XSL.
ElemTemplate rootRule = m_sRootObject.getTemplateComposed(processor.getTransformer().getXPathContext(), sourceTree, null, -1, false);
//this.findTemplate(processor, sourceTree, sourceTree);
if(null == rootRule)
{
rootRule = m_sRootObject.getDefaultRootRule();
}
DocumentHandler docHandler = outputTarget.getDocumentHandler();
OutputFormat formatter = getOutputFormat();
if(null != outputTarget.getEncoding())
formatter.setEncoding(outputTarget.getEncoding());
if(null != docHandler)
{
processor.setDocumentHandler(docHandler);
}
else if(null != outputTarget.getByteStream())
{
/* if (!(processor.getXMLProcessorLiaison()..getIndent() < 0))
{
// This is to get around differences between Xalan and Xerces.
// Xalan uses -1 as default for no indenting, Xerces uses 0.
// So we just bump up the indent value here because we will
// subtract from it at output time (FormatterToXML.init());
formatter.setIndent(processor.m_parserLiaison.getIndent() + 1);
}*/
processor.setDocumentHandler(makeSAXSerializer(outputTarget.getByteStream(),
formatter));
}
else if(null != outputTarget.getCharacterStream())
{
/* if (!(processor.m_parserLiaison.getIndent() < 0))
{
formatter.setIndent(processor.m_parserLiaison.getIndent() + 1);
}*/
processor.setDocumentHandler(makeSAXSerializer(outputTarget.getCharacterStream(),
formatter));
}
else if(null != outputTarget.getFileName())
{
/*if (!(processor.m_parserLiaison.getIndent() < 0))
{
formatter.setIndent(processor.m_parserLiaison.getIndent() + 1);
}*/
ostream = new FileOutputStream(outputTarget.getFileName());
processor.setDocumentHandler( makeSAXSerializer(ostream, formatter));
}
else if(null != outputTarget.getNode())
{
ParserAdapter handler = new ParserAdapter(new org.apache.xerces.parsers.SAXParser());
// Patch from Costin Manolache
if( "org.apache.xalan.xpath.dtm.DTMLiaison".equals( processor.getXMLProcessorLiaison().getClass().getName()))
processor.error(XSLTErrorResources.ER_CANT_USE_DTM_FOR_OUTPUT); //"Can't use a DTMLiaison for an output DOM node... pass a org.apache.xalan.xpath.xdom.XercesLiaison instead!");
switch(outputTarget.getNode().getNodeType())
{
case Node.DOCUMENT_NODE:
handler.setContentHandler(new FormatterToDOM((Document)outputTarget.getNode()).getSerializerObject());
processor.setDocumentHandler(handler);
break;
case Node.DOCUMENT_FRAGMENT_NODE:
handler.setContentHandler(new FormatterToDOM(outputTarget.getNode().getOwnerDocument(), // PR:DMAN4M6PK5 Submitted by:<bk...@viae.de>
(DocumentFragment)outputTarget.getNode()).getSerializerObject());
processor.setDocumentHandler(handler);
break;
case Node.ELEMENT_NODE:
handler.setContentHandler(new FormatterToDOM(outputTarget.getNode().getOwnerDocument(), // PR:DMAN4M6PK5 Submitted by:<bk...@viae.de>
(Element)outputTarget.getNode()).getSerializerObject());
processor.setDocumentHandler(handler);
break;
default:
m_sRootObject.error(XSLTErrorResources.ER_CAN_ONLY_OUTPUT_TO_ELEMENT); //"Can only output to an Element, DocumentFragment, Document, or PrintWriter.");
}
}
else
{
ParserAdapter handler = new ParserAdapter(new org.apache.xerces.parsers.SAXParser());
outputTarget.setNode(processor.getXMLProcessorLiaison().createDocument());
handler.setContentHandler(new FormatterToDOM((Document)outputTarget.getNode()).getSerializerObject());
processor.setDocumentHandler(handler);
}
// processor.resetCurrentState(sourceTree);
// processor.m_rootDoc = sourceTree;
if(null != processor.m_diagnosticsPrintWriter)
{
processor.diag("=============================");
processor.diag("Transforming...");
processor.pushTime(sourceTree);
}
// processor.getVarStack().pushContextMarker();
// try
// {
// processor.resolveTopLevelParams();
// }
// catch(Exception e)
// {
// throw new SAXException(XSLMessages.createMessage(XSLTErrorResources.ER_PROCESS_ERROR, null), e); //"StylesheetRoot.process error", e);
// }
processor.getTransformer().getResultTreeHandler().startDocument();
// Output the action of the found root rule. All processing
// occurs from here. buildResultFromTemplate is highly recursive.
rootRule.execute(processor.getTransformer(), sourceTree, null);
processor.getTransformer().getResultTreeHandler().endDocument();
// Reset the top-level params for the next round.
// processor.m_topLevelParams = new Vector();
if(null != processor.m_diagnosticsPrintWriter)
{
processor.displayDuration("transform", sourceTree);
}
}
catch(TransformerException te)
{
throw new SAXException(te);
}
finally
{
if (null != ostream)
{
ostream.close();
}
}
}
}
/**
* Creates a compatible SAX serializer for the specified writer
* and output format. If the output format is missing, the default
* is an XML format with UTF8 encoding.
*
* @param writer The writer
* @param format The output format
* @return A compatible SAX serializer
*/
public DocumentHandler makeSAXSerializer( Writer writer, OutputFormat format )
throws IOException
{
DocumentHandler handler;
if ( format == null )
{
format = new OutputFormat( "xml", "UTF-8", false );
handler = null;
}
else
{
handler = new ParserAdapter(new org.apache.xerces.parsers.SAXParser());
OutputProperties props = m_sRootObject.getOutputComposed();
if ( format.getMethod().equalsIgnoreCase( "html" ) )
{
FormatterToHTML serializer = new FormatterToHTML(writer);
serializer.setOutputFormat(props.getProperties());
((ParserAdapter)handler).setContentHandler(serializer);
}
else if ( format.getMethod().equalsIgnoreCase( "xml" ) )
{
FormatterToXML serializer = new FormatterToXML(writer);
serializer.getSerializerObject().setOutputFormat(props.getProperties());
((ParserAdapter)handler).setContentHandler(serializer.getSerializerObject());
}
else if ( format.getMethod().equalsIgnoreCase( "text" ) )
{
FormatterToText serializer = new FormatterToText(writer);
((ParserAdapter)handler).setContentHandler(serializer.getSerializerObject());
}
else
{
handler = null;
}
}
if(null == handler)
{
String method = format.getMethod();
org.apache.xml.serialize.SerializerFactory factory = org.apache.xml.serialize.SerializerFactory.getSerializerFactory(method);
org.apache.xml.serialize.Serializer serializer = factory.makeSerializer(writer, format);
handler = serializer.asDocumentHandler();
}
return handler;
}
/**
* Creates a compatible SAX serializer for the specified output stream
* and output format. If the output format is missing, the default
* is an XML format with UTF8 encoding.
*
* @param ostream The output stream.
* @param format The output format
* @return A compatible SAX serializer
*/
public DocumentHandler makeSAXSerializer( OutputStream ostream, OutputFormat format )
throws UnsupportedEncodingException, IOException
{
DocumentHandler handler;
OutputProperties props;
if ( format == null )
{
props = new OutputProperties();
handler = null;
}
else
{
handler = new ParserAdapter(new org.apache.xerces.parsers.SAXParser());
props = m_sRootObject.getOutputComposed();
if ( format.getMethod().equalsIgnoreCase( "html" ) )
{
FormatterToHTML serializer = new FormatterToHTML(ostream);
serializer.setOutputFormat(props.getProperties());
((ParserAdapter)handler).setContentHandler(serializer);
}
else if ( format.getMethod().equalsIgnoreCase( "xml" ) )
{
FormatterToXML serializer = new FormatterToXML(ostream);
serializer.getSerializerObject().setOutputFormat(props.getProperties());
((ParserAdapter)handler).setContentHandler(serializer.getSerializerObject());
}
else if ( format.getMethod().equalsIgnoreCase( "text" ) )
{
String encoding = format.getEncoding();
if(null == encoding)
{
try
{
encoding = System.getProperty("file.encoding");
encoding = (null != encoding) ?
org.apache.xalan.serialize.Encodings.convertJava2MimeEncoding( encoding ) : "ASCII";
if(null == encoding)
{
encoding = "ASCII";
}
}
catch(SecurityException se)
{
encoding = "ASCII";
}
}
//this.m_encoding = encoding;
String javaEncoding = org.apache.xalan.serialize.Encodings.convertMime2JavaEncoding(encoding);
Writer w = new OutputStreamWriter( ostream, javaEncoding );
((ParserAdapter)handler).setContentHandler(new FormatterToText(w).getSerializerObject());
}
else if ( format.getMethod().equalsIgnoreCase( "xhtml" ) )
{
handler = new XMLSerializer(ostream, format);
//handler = Serializer.makeSAXSerializer(ostream, format);
}
else
{
handler = new XMLSerializer(ostream, format);
//handler = Serializer.makeSAXSerializer(ostream, format);
}
}
if(null == handler)
{
String method = props.getProperty(OutputKeys.METHOD);
org.apache.xml.serialize.SerializerFactory factory = org.apache.xml.serialize.SerializerFactory.getSerializerFactory(method);
org.apache.xml.serialize.Serializer serializer = factory.makeSerializer(ostream, format);
handler = serializer.asDocumentHandler();
}
return handler;
}
/**
* Creates a compatible SAX serializer for the specified output stream
* and output format. If the output format is missing, the default
* is an XML format with UTF8 encoding.
*
* @param ostream The output stream.
* @return A compatible SAX serializer
*/
public DocumentHandler getSAXSerializer( OutputStream ostream )
throws UnsupportedEncodingException, IOException
{
return makeSAXSerializer(ostream, getOutputFormat());
}
/**
* Get a new OutputFormat object according to the xsl:output attributes.
*/
public OutputFormat getOutputFormat()
{
OutputProperties outputFormat = m_sRootObject.getOutputComposed();
if (outputFormat == null)
return null;
OutputFormat formatter = new OutputFormat(outputFormat.getProperty(OutputKeys.METHOD),
outputFormat.getProperty(OutputKeys.ENCODING),
OutputProperties.getBooleanProperty(OutputKeys.INDENT, outputFormat.getProperties()));
formatter.setDoctype(outputFormat.getProperty(OutputKeys.DOCTYPE_PUBLIC),
outputFormat.getProperty(OutputKeys.DOCTYPE_SYSTEM));
formatter.setOmitXMLDeclaration(OutputProperties.getBooleanProperty(OutputKeys.OMIT_XML_DECLARATION, outputFormat.getProperties()));
formatter.setStandalone(OutputProperties.getBooleanProperty(OutputKeys.STANDALONE, outputFormat.getProperties()));
formatter.setMediaType(outputFormat.getProperty(OutputKeys.MEDIA_TYPE));
formatter.setVersion(outputFormat.getProperty(OutputKeys.VERSION));
// This is to get around differences between Xalan and Xerces.
// Xalan uses -1 as default for no indenting, Xerces uses 0.
// So we just bump up the indent value here because we will
// subtract from it at output time (FormatterToXML.init());
// if (getOutputIndent())
// formatter.setIndent(formatter.getIndent()+1);
return formatter;
}
/**
* Get the encoding string that was specified in the stylesheet.
*/
public String getOutputEncoding()
{
return m_sRootObject.getOutputComposed().getProperty(OutputKeys.ENCODING);
}
/**
* Get the media-type string that was specified in the stylesheet.
*/
public String getOutputMediaType()
{
return m_sRootObject.getOutputComposed().getProperty(OutputKeys.MEDIA_TYPE);
}
}
1.1 xml-xalan/java/compat_src/org/apache/xalan/xslt/StylesheetSpec.java
Index: StylesheetSpec.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" 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 name, without prior written
* permission of the Apache Software Foundation.
*
* 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 and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.xslt;
import javax.xml.transform.stream.StreamSource;
/**
* <meta name="usage" content="general"/>
* This class implements the representation of a stylesheet
* specification via xml-stylesheet in an XML document.
*/
public class StylesheetSpec extends StreamSource
{
String type; // CDATA #REQUIRED
String title; // CDATA #IMPLIED
String media; // CDATA #IMPLIED
String encoding; // CDATA #IMPLIED
boolean alternate; // (yes|no) "no"
/**
* Create a StylesheetSpec object.
*/
public StylesheetSpec(String href, String type, String title,
String media, boolean alternate,
String encoding)
{
this.setSystemId(href);
this.encoding = encoding;
this.type = type;
this.title = title;
this.media = media;
this.alternate = alternate;
}
/**
* Get the encoding of the stylesheet.
*/
public String getEncoding()
{
return encoding;
}
/**
* Get the type of the stylesheet, i.e. "text/xsl".
*/
public String getType()
{
return type;
}
/**
* Get the title of the element (in other words, the
* item to be presented to the user agent).
*/
public String getTitle()
{
return title;
}
/**
* Get the media attribute of the stylesheet.
*/
public String getMedia()
{
return media;
}
/**
* Get whether or not the stylesheet is specified as
* an alternate.
*/
public boolean getIsAlternate()
{
return alternate;
}
}
1.1 xml-xalan/java/compat_src/org/apache/xalan/xslt/XSLProcessorContext.java
Index: XSLProcessorContext.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" 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 name, without prior written
* permission of the Apache Software Foundation.
*
* 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 and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.xslt;
import org.w3c.dom.*;
import org.apache.xalan.templates.Stylesheet;
import org.apache.xml.utils.QName;
import org.apache.xalan.transformer.TransformerImpl;
// import org.apache.xalan.xslt.*;
/**
* <meta name="usage" content="general"/>
* Captures processor context to be
* passed to an extension element.
*
* @author Sanjiva Weerawarana (sanjiva@watson.ibm.com)
*/
public class XSLProcessorContext extends org.apache.xalan.extensions.XSLProcessorContext
{
public XSLProcessorContext (XSLTEngineImpl processor,
Stylesheet stylesheetTree,
Node sourceTree, Node sourceNode, QName mode)
{
super((TransformerImpl)(processor.getTransformer()),
stylesheetTree,
sourceTree, sourceNode, mode);
}
}
1.1 xml-xalan/java/compat_src/org/apache/xalan/xslt/XSLTEngineImpl.java
Index: XSLTEngineImpl.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" 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 name, without prior written
* permission of the Apache Software Foundation.
*
* 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 and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.xslt;
import org.apache.xpath.*;
import org.apache.xpath.compiler.XPathParser;
import org.apache.xpath.compiler.Compiler;
import org.apache.xpath.objects.XObject;
import org.apache.xpath.objects.XString;
import org.apache.xpath.objects.XNodeSet;
import org.apache.xpath.objects.XBoolean;
import org.apache.xpath.objects.XNumber;
import org.apache.xpath.objects.XNull;
import org.w3c.dom.*;
import org.w3c.dom.traversal.NodeIterator;
import org.xml.sax.ContentHandler;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import org.xml.sax.ext.*;
import org.xml.sax.helpers.ParserAdapter;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.Templates;
import javax.xml.transform.Source;
import javax.xml.transform.SourceLocator;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;
import java.util.*;
import java.net.*;
import java.io.*;
import java.lang.reflect.*;
import org.apache.xalan.templates.Stylesheet;
//import org.apache.xalan.templates.StylesheetRoot;
import org.apache.xalan.xpath.xml.XMLParserLiaison;
import org.apache.xalan.xpath.xml.ProblemListenerDefault;
import org.apache.xalan.xpath.xml.ProblemListener;
import org.apache.xalan.templates.StylesheetComposed;
import org.apache.xalan.transformer.TransformerImpl;
import org.apache.xalan.processor.StylesheetHandler;
import org.apache.xalan.processor.TransformerFactoryImpl;
//import org.apache.xalan.processor.ProcessorStylesheet;
//import org.apache.xalan.xslt.StylesheetSpec;
import org.apache.xalan.trace.*;
import org.apache.xalan.res.XSLTErrorResources;
import org.apache.xalan.res.XSLMessages;
import org.apache.xml.utils.PrefixResolverDefault;
import org.apache.xml.utils.TreeWalker;
import org.apache.xml.utils.QName;
import org.apache.xml.utils.DefaultErrorHandler;
import org.apache.xalan.stree.SourceTreeHandler;
/**
* <meta name="usage" content="advanced"/>
* The Xalan workhorse -- Collaborates with the XML parser liaison, the DOM,
* and the XPath engine, to transform a source tree of nodes into a result tree
* according to instructions and templates specified by a stylesheet tree.
* We suggest you use one of the
* static XSLTProcessorFactory getProcessor() methods to instantiate the processor
* and return an interface that greatly simplifies the process of manipulating
* XSLTEngineImpl.
*
* <p>The methods <code>process(...)</code> are the primary public entry points.
* The best way to perform transformations is to use the
* {@link XSLTProcessor#process(XSLTInputSource, XSLTInputSource, XSLTResultTarget)} method,
* but you may use any of process methods defined in XSLTEngineImpl.</p>
*
* <p>Please note that this class is not safe per instance over multiple
* threads. If you are in a multithreaded environment, you should
* keep a pool of these objects, or create a new one each time. In a
* multithreaded environment, the right way to do things is to create a
* StylesheetRoot via processStylesheet, and then reuse this object
* over multiple threads.</p>
*
* <p>If you reuse the processor instance, you should call reset() between transformations.</p>
* @see XSLTProcessorFactory
* @see XSLTProcessor
*/
public class XSLTEngineImpl implements XSLTProcessor
{
//private Processor m_processor;
private TransformerFactory m_tfactory;
private TransformerImpl m_transformerImpl;
private DOM2Helper m_liaison;
private String m_outputFileName;
private DocumentHandler m_documentHandler = null;
private ProblemListenerDefault m_problemListener;
private Hashtable m_stylesheetParams;
StylesheetRoot m_stylesheetRoot = null;
/*
* If this is true, then the diag function will
* be called.
*/
private boolean m_traceTemplateChildren = false;
/*
* If this is true, then the simple tracing of templates
* will be performed.
*/
private boolean m_traceTemplates = false;
/*
* If this is true, then diagnostics of each select
* will be performed.
*/
boolean m_traceSelects = false;
/*
* A stream to print diagnostics to.
*/
java.io.PrintWriter m_diagnosticsPrintWriter = null;
/* For diagnostics */
Hashtable m_durationsTable = new Hashtable();
/**
* A XSLMessages instance capable of producing user messages.
*/
private static XSLMessages m_XSLMessages = new XSLMessages();
/**
* Construct an XSLT processor
* @see XSLTProcessorFactory
* @see XSLTProcessor
*
protected XSLTEngineImpl(Processor p)
throws org.xml.sax.SAXException
{
//m_processor = p;
m_tfactory = TransformerFactory.newInstance();
m_transformerImpl = m_tfactory.newTransformer();
//m_transformerImpl = (TransformerImpl)t;
} */
/**
* Construct an XSLT processor that uses the default DTM (Document Table Model) liaison
* and XML parser. As a general rule, you should use XSLTProcessorFactory to create an
* instance of this class and provide access to the instance via the XSLTProcessor interface.
*
* @see XSLTProcessorFactory
* @see XSLTProcessor
*/
protected XSLTEngineImpl()
throws org.xml.sax.SAXException
{
m_tfactory = TransformerFactory.newInstance();
/*
try{
m_transformerImpl = (TransformerImpl)m_tfactory.newTransformer();
}
catch (TransformerConfigurationException tce)
{
throw new SAXException(tce);
}*/
/* try
{
String parserLiaisonClassName = Constants.LIAISON_CLASS;
Class parserLiaisonClass = Class.forName(parserLiaisonClassName);
Constructor parserLiaisonCtor = parserLiaisonClass.getConstructor(null);
m_parserLiaison
= (XMLParserLiaison)parserLiaisonCtor.newInstance(null);
m_parserLiaison.setEnvSupport(this);
}
catch(Exception e)
{
throw new XSLProcessorException(e);
}*/
}
/**
* Construct an XSLT processor that uses the the given parser liaison.
* As a general rule, you should use XSLTProcessorFactory to create an
* instance of this class and provide access to the instance via the XSLTProcessor interface.
*
* @see XSLTProcessorFactory
* @see XSLTProcessor
*/
public XSLTEngineImpl(String liaisonClassName)
throws SAXException
{
TransformerFactory m_tfactory = TransformerFactory.newInstance();
/*
try{
m_transformerImpl = (TransformerImpl)m_tfactory.newTransformer();
}
catch (TransformerConfigurationException tce)
{
throw new SAXException(tce);
}*/
// }
/* catch (ProcessorFactoryException pfe)
{
throw new TransformerException("Could not create Processor", pfe);
}
*/
try
{
DOM2Helper m_liaison = (DOM2Helper)(Class.forName(liaisonClassName).newInstance());
//getXPathContext().setDOMHelper(liaison);
}
catch (ClassNotFoundException e1)
{
throw new SAXException("XML Liaison class " + liaisonClassName +
" specified but not found", e1);
}
catch (IllegalAccessException e2)
{
throw new SAXException("XML Liaison class " + liaisonClassName +
" found but cannot be loaded", e2);
}
catch (InstantiationException e3)
{
throw new SAXException("XML Liaison class " + liaisonClassName +
" loaded but cannot be instantiated (no empty public constructor?)",
e3);
}
catch (ClassCastException e4)
{
throw new SAXException("XML Liaison class " + liaisonClassName +
" does not implement DOM2Helper", e4);
}
}
/**
* Construct an XSL processor that uses the the given parser liaison.
* As a general rule, you should use XSLTProcessorFactory to create an
* instance of this class and provide access to the instance via the XSLTProcessor interface.
*
* @param XMLParserLiaison A liaison to an XML parser.
*
* @see org.apache.xalan.xpath.xml.XMLParserLiaison
* @see XSLTProcessorFactory
* @see XSLTProcessor
*/
public XSLTEngineImpl(XMLParserLiaison parserLiaison)
throws org.xml.sax.SAXException
{
TransformerFactory m_tfactory = TransformerFactory.newInstance();
/*
try{
m_transformerImpl = (TransformerImpl)m_tfactory.newTransformer();
}
catch (TransformerConfigurationException tce)
{
throw new SAXException(tce);
}*/
// }
/* catch (ProcessorFactoryException pfe)
{
//throw new TransformException("Could not create Processor", pfe);
}*/
DOM2Helper m_liaison = (DOM2Helper)parserLiaison;
//getXPathContext().setDOMHelper(liaison);
}
/**
* Construct an XSLT processor that can call back to the XML parser, in order to handle
* included files and the like.
*
* @param XMLParserLiaison A liaison to an XML parser.
*
* @see org.apache.xalan.xpath.xml.XMLParserLiaison
* @see XSLTProcessorFactory
* @see XSLTProcessor
*/
XSLTEngineImpl(XMLParserLiaison parserLiaison, XPathFactory xpathFactory)
throws SAXException
{
m_tfactory = TransformerFactory.newInstance();
/*
try{
m_transformerImpl = (TransformerImpl)m_tfactory.newTransformer();
}
catch (TransformerConfigurationException tce)
{
throw new SAXException(tce);
}*/
// }
// catch (ProcessorFactoryException pfe)
//{
//throw new TransformException("Could not create Processor", pfe);
// }
DOM2Helper m_liaison = (DOM2Helper)parserLiaison;
//getXPathContext().setDOMHelper(liaison);
}
/**
* Reset the state. This needs to be called after a process() call
* is invoked, if the processor is to be used again.
*/
public void reset()
{
if (m_transformerImpl != null)
m_transformerImpl.reset();
}
/**
* Transform the source tree to the output in the given
* result tree target. As a general rule, we recommend you use the
* {@link XSLTProcessor#Process(XSLTInputSource, XSLTInputSource, XSLTResultTarget)} method.
* @param inputSource The input source.
* @param stylesheetSource The stylesheet source. May be null if source has a xml-stylesheet PI.
* @param outputTarget The output source tree.
* @exception XSLProcessorException thrown if the active ProblemListener and XMLParserLiaison decide
* the error condition is severe enough to halt processing.
*/
public void process( XSLTInputSource inputSource,
XSLTInputSource stylesheetSource,
XSLTResultTarget outputTarget)
throws SAXException
{
try
{
Boolean totalTimeID = new Boolean(true);
pushTime(totalTimeID);
Node sourceTree = null;
if(null != inputSource)
sourceTree = getSourceTreeFromInput(inputSource);
Templates templates = null;
if(null != stylesheetSource)
{
try{
templates = m_tfactory.newTemplates(stylesheetSource.getSourceObject());
}
catch (TransformerConfigurationException tce)
{
throw new SAXException(tce);
}
}
else if(null != sourceTree)
{
String stylesheetURI = null;
Stack hrefs = new Stack();
for(Node child=sourceTree.getFirstChild(); null != child; child=child.getNextSibling())
{
if(Node.PROCESSING_INSTRUCTION_NODE == child.getNodeType())
{
ProcessingInstruction pi = (ProcessingInstruction)child;
if(pi.getNodeName().equals("xml-stylesheet")
|| pi.getNodeName().equals("xml:stylesheet"))
{
boolean isOK = true;
StringTokenizer tokenizer = new StringTokenizer(pi.getNodeValue(), " \t=");
while(tokenizer.hasMoreTokens())
{
if(tokenizer.nextToken().equals("type"))
{
String typeVal = tokenizer.nextToken();
typeVal = typeVal.substring(1, typeVal.length()-1);
if(!typeVal.equals("text/xsl"))
{
isOK = false;
}
}
}
if(isOK)
{
tokenizer = new StringTokenizer(pi.getNodeValue(), " \t=");
while(tokenizer.hasMoreTokens())
{
if(tokenizer.nextToken().equals("href"))
{
stylesheetURI = tokenizer.nextToken();
stylesheetURI = stylesheetURI.substring(1, stylesheetURI.length()-1);
hrefs.push(stylesheetURI);
}
}
}
}
}
} // end for(int i = 0; i < nNodes; i++)
boolean isRoot = true;
Stylesheet prevStylesheet = null;
while(!hrefs.isEmpty())
{
Stylesheet stylesheet = getStylesheetFromPIURL((String)hrefs.pop(), sourceTree,
(null != inputSource)
? inputSource.getSystemId() : null,
isRoot);
if(false == isRoot)
{
prevStylesheet.setImport((StylesheetComposed)stylesheet);
}
prevStylesheet = stylesheet;
isRoot = false;
}
}
else
{
error(XSLTErrorResources.ER_NO_INPUT_STYLESHEET); //"Stylesheet input was not specified!");
}
if(null == templates)
{
error(XSLTErrorResources.ER_FAILED_PROCESS_STYLESHEET); //"Failed to process stylesheet!");
}
if(null != sourceTree)
{
TransformerImpl t;
try{
t = (TransformerImpl)templates.newTransformer();
}
catch (TransformerConfigurationException tce)
{
throw new SAXException(tce);
}
if (m_stylesheetParams != null)
{
Enumeration keys = m_stylesheetParams.keys();
while (keys.hasMoreElements())
{
String name = (String)keys.nextElement();
Object value = m_stylesheetParams.get(name);
t.setParameter(name, null, value);
}
}
try{
t.transform(inputSource.getSourceObject(),
outputTarget.getResultObject());
}
catch (TransformerException te)
{
throw new SAXException(te);
}
if(null != m_diagnosticsPrintWriter)
{
displayDuration("Total time", totalTimeID);
}
}
}
catch(MalformedURLException mue)
{
error(XSLTErrorResources.ERROR0000, new Object[] {mue.getMessage()}, mue);
// throw se;
}
catch(FileNotFoundException fnfe)
{
error(XSLTErrorResources.ERROR0000, new Object[] {fnfe.getMessage()}, fnfe);
// throw se;
}
catch(IOException ioe)
{
error(XSLTErrorResources.ERROR0000, new Object[] {ioe.getMessage()}, ioe);
// throw se;
}
catch(SAXException se)
{
error(XSLTErrorResources.ER_SAX_EXCEPTION, se); //"SAX Exception", se);
// throw se;
}
}
/**
* Bottleneck the creation of the stylesheet for derivation purposes.
*/
public StylesheetRoot createStylesheetRoot(String baseIdentifier)
throws MalformedURLException, FileNotFoundException,
IOException, SAXException
{
try{
if (baseIdentifier == null)
return new StylesheetRoot(); //this, baseIdentifier);
Source inSource = new XSLTInputSource(baseIdentifier).getSourceObject();
Templates templates = m_tfactory.newTemplates(inSource);
StylesheetRoot stylesheet = new StylesheetRoot((org.apache.xalan.templates.StylesheetRoot)templates);
return stylesheet;
}
catch (TransformerConfigurationException tce)
{
throw new SAXException(tce);
}
}
/**
* Given a URI to an XSL stylesheet,
* Compile the stylesheet into an internal representation.
* This calls reset() before processing if the stylesheet root has been set
* to non-null.
* @param xmldocURLString The URL to the input XML document.
* @return The compiled stylesheet object.
* @exception XSLProcessorException thrown if the active ProblemListener and XMLParserLiaison decide
* the error condition is severe enough to halt processing.
*/
public StylesheetRoot processStylesheet(XSLTInputSource stylesheetSource)
throws SAXException
{
try{
if(null != ((TransformerFactoryImpl)m_tfactory).newTemplatesHandler().getTemplates())
reset();
}
catch (TransformerConfigurationException tce)
{
throw new SAXException(tce);
}
String xslIdentifier = ((null == stylesheetSource) ||
(null == stylesheetSource.getSystemId()))
? "Input XSL" : stylesheetSource.getSystemId();
// In case we have a fragment identifier, go ahead and
// try and parse the XML here.
StylesheetRoot m_stylesheetRoot = null;
try
{
m_stylesheetRoot = createStylesheetRoot(stylesheetSource.getSystemId());
addTraceListenersToStylesheet();
StylesheetHandler stylesheetProcessor
= new StylesheetHandler((TransformerFactoryImpl)m_tfactory); //this, m_stylesheetRoot);
stylesheetProcessor.pushStylesheet(m_stylesheetRoot.getObject());
Source ssSource = stylesheetSource.getSourceObject();
if(ssSource instanceof DOMSource)
{
if(((DOMSource)ssSource).getNode() instanceof StylesheetRoot)
{
m_stylesheetRoot = (StylesheetRoot)((DOMSource)ssSource).getNode();
}
else
{
TreeWalker tw = new TreeWalker(stylesheetProcessor);
tw.traverse(((DOMSource)ssSource).getNode());
}
}
else
{
diag("========= Parsing "+xslIdentifier+" ==========");
pushTime(xslIdentifier);
String liaisonClassName = System.getProperty("org.apache.xalan.source.liaison");
if(null != liaisonClassName)
{
DOM2Helper liaison = (DOM2Helper)(Class.forName(liaisonClassName).newInstance());
liaison.parse(SAXSource.sourceToInputSource(ssSource));
}
if(null != m_diagnosticsPrintWriter)
displayDuration("Parse of "+xslIdentifier, xslIdentifier);
}
}
catch(Exception e)
{
error(XSLTErrorResources.ER_COULDNT_PARSE_DOC, new Object[] {xslIdentifier}, e); //"Could not parse "+xslIdentifier+" document!", e);
}
return m_stylesheetRoot;
}
/**
* Given a URI to an XSL stylesheet,
* Compile the stylesheet into an internal representation.
* This calls reset() before processing if the stylesheet root has been set
* to non-null.
* @param xmldocURLString The URL to the input XML document.
* @return The compiled stylesheet object.
* @exception XSLProcessorException thrown if the active ProblemListener and XMLParserLiaison decide
* the error condition is severe enough to halt processing.
*/
public StylesheetRoot processStylesheet(String xsldocURLString)
throws SAXException
{
try
{
XSLTInputSource input = new XSLTInputSource(getURLFromString(xsldocURLString, null).toString());
return processStylesheet(input);
}
catch(SAXException se)
{
error(XSLTErrorResources.ER_PROCESSSTYLESHEET_NOT_SUCCESSFUL, se); //"processStylesheet not succesfull!", se);
return null; // shut up compiler
}
}
/**
* Set the stylesheet for this processor. If this is set, then the
* process calls that take only the input .xml will use
* this instead of looking for a stylesheet PI. Also,
* setting the stylesheet is needed if you are going
* to use the processor as a SAX DocumentHandler.
*/
public void setStylesheet(StylesheetRoot stylesheetRoot)
{
m_stylesheetRoot = stylesheetRoot;
org.apache.xalan.templates.StylesheetRoot sr = stylesheetRoot.getObject();
if (m_transformerImpl == null)
m_transformerImpl = (TransformerImpl)sr.newTransformer();
m_transformerImpl.setStylesheet(sr);
}
/**
* Get the current stylesheet for this processor.
*/
public StylesheetRoot getStylesheet()
{
return m_stylesheetRoot;
}
/**
* <meta name="usage" content="internal"/>
* Get the filename of the output document, if it was set.
* This is for use by multiple output documents, to determine
* the base directory for the output document. It needs to
* be set by the caller.
*/
public String getOutputFileName()
{
return m_outputFileName;
}
/**
* <meta name="usage" content="internal"/>
* Set the filename of the output document.
* This is for use by multiple output documents, to determine
* the base directory for the output document. It needs to
* be set by the caller.
*/
public void setOutputFileName(String filename)
{
m_outputFileName = filename;
}
/**
* Given an input source, get the source tree.
*/
public Node getSourceTreeFromInput(XSLTInputSource inputSource)
throws org.xml.sax.SAXException
{
Node sourceTree = null;
String xmlIdentifier = ((null == inputSource) ||
(null == inputSource.getSystemId()))
? "Input XML" : inputSource.getSystemId();
Source iSource = inputSource.getSourceObject();
if(iSource instanceof DOMSource)
{
//if(getXMLProcessorLiaison() instanceof org.apache.xalan.xpath.dtm.DTMLiaison)
// error(XSLTErrorResources.ER_CANT_USE_DTM_FOR_INPUT); //"Can't use a DTMLiaison for a input DOM node... pass a org.apache.xalan.xpath.xdom.XercesLiaison instead!");
sourceTree = ((DOMSource)iSource).getNode();
}
else
{
// In case we have a fragment identifier, go ahead and
// try and parse the XML here.
try
{
diag("========= Parsing "+xmlIdentifier+" ==========");
pushTime(xmlIdentifier);
String liaisonClassName = System.getProperty("org.apache.xalan.source.liaison");
if(null != liaisonClassName)
{
DOM2Helper liaison = (DOM2Helper)(Class.forName(liaisonClassName).newInstance());
liaison.parse(SAXSource.sourceToInputSource(iSource));
if(null != m_diagnosticsPrintWriter)
displayDuration("Parse of "+xmlIdentifier, xmlIdentifier);
sourceTree = liaison.getDocument();
}
else
{
XMLReader reader = XMLReaderFactory.createXMLReader();
try
{
reader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
}
catch(SAXException se)
{
// What can we do?
// TODO: User diagnostics.
}
// Get the input content handler, which will handle the
// parse events and create the source tree.
//StylesheetHandler inputHandler = (StylesheetHandler)m_processor.getTemplatesBuilder();
//reader.setContentHandler( inputHandler );
SourceTreeHandler handler = new SourceTreeHandler();
reader.setContentHandler(handler);
reader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
// Kick off the parse. When the ContentHandler gets
// the startDocument event, it will call transformNode( node ).
reader.parse( SAXSource.sourceToInputSource(iSource));
sourceTree = handler.getRoot();
}
}
catch(Exception e)
{
// Unwrap exception
if((e instanceof SAXException) && (null != ((SAXException)e).getException()))
{
// ((SAXException)e).getException().printStackTrace();
e = ((SAXException)e).getException();
}
sourceTree = null; // shutup compiler
error(XSLTErrorResources.ER_COULDNT_PARSE_DOC, new Object[] {xmlIdentifier}, e); //"Could not parse "+xmlIdentifier+" document!", e);
}
}
return sourceTree;
}
/**
* Get Stylesheet from PI URL
*
* @param xslURLString a valid URI to an XSL stylesheet.
* @param fragbase Document fragment Node.
* @param xmlBaseIdent Base URI to resolve stylesheet URL
* @param isRoot Flag indicating if root node
*/
Stylesheet getStylesheetFromPIURL(String xslURLString, Node fragBase,
String xmlBaseIdent, boolean isRoot)
throws SAXException,
MalformedURLException,
FileNotFoundException,
IOException
{
StylesheetRoot m_stylesheetRoot = null;
Stylesheet stylesheet = null;
String[] stringHolder =
{
null};
xslURLString = xslURLString.trim();
int fragIndex = xslURLString.indexOf('#');
String fragID = null;
Document stylesheetDoc;
if(fragIndex == 0)
{
diag("Locating stylesheet from fragment identifier...");
fragID = xslURLString.substring(1);
// Try a bunch of really ugly stuff to find the fragment.
// What's the right way to do this?
// Create a XPath parser.
XPathParser parser = new XPathParser();
XPathContext xpathContext = new XPathContext();
PrefixResolverDefault nsNode = new PrefixResolverDefault(fragBase); //xpathContext.getNamespaceContext();
NodeIterator nl = null;
// Create the XPath object.
try{
XPath xpath = new XPath(fragID, null, nsNode, XPath.MATCH);
Compiler compiler = new Compiler();
// Parse the xpath
parser.initXPath(compiler, "id("+fragID+")", nsNode);
XObject xobj = xpath.execute(xpathContext, fragBase, nsNode);
nl = xobj.nodeset();
if(nl.nextNode() == null)
{
// xobj = Stylesheet.evalXPathStr(getExecContext(), "//*[@id='"+fragID+"']", fragBase, nsNode);
// Create the XPath object.
xpath = new XPath(fragID, null, nsNode, XPath.MATCH);
// Parse the xpath
parser.initXPath(compiler, "//*[@id='"+fragID+"']", nsNode);
xobj = xpath.execute(xpathContext, fragBase, nsNode);
nl = xobj.nodeset();
if(nl.nextNode() == null)
{
// xobj = Stylesheet.evalXPathStr(getExecContext(), "//*[@name='"+fragID+"']", fragBase, nsNode);
// Create the XPath object.
xpath = new XPath(fragID, null, nsNode, XPath.MATCH);
// Parse the xpath
parser.initXPath(compiler, "//*[@name='"+fragID+"']", nsNode);
xobj = xpath.execute(xpathContext, fragBase, nsNode);
nl = xobj.nodeset();
if(nl.nextNode() == null)
{
// Well, hell, maybe it's an XPath...
// xobj = Stylesheet.evalXPathStr(getExecContext(), fragID, fragBase, nsNode);
// Create the XPath object.
//((StylesheetHandler)( m_processor.getTemplatesBuilder())).getLocator()
xpath = new XPath(fragID, null, nsNode, XPath.MATCH);
// Parse the xpath
parser.initXPath(compiler, fragID, nsNode);
xobj = xpath.execute(xpathContext, fragBase, nsNode);
nl = xobj.nodeset();
}
}
}
}
catch (TransformerException te)
{
throw new SAXException(te);
}
if(nl.nextNode() == null)
{
error(XSLTErrorResources.ER_COULDNT_FIND_FRAGMENT, new Object[] {fragID}); //"Could not find fragment: "+fragID);
}
// Use previous because the previous call moved the pointer.
// or should we use getRoot??
Node frag = nl.previousNode(); //.item(0);
if(Node.ELEMENT_NODE == frag.getNodeType())
{
pushTime(frag);
if(isRoot)
{
m_stylesheetRoot = createStylesheetRoot(stringHolder[0]);
stylesheet = m_stylesheetRoot.getObject();
}
else
{
//stylesheet = new Stylesheet(m_stylesheetRoot);
// stylesheet = ((StylesheetHandler)(m_processor.getTemplatesBuilder())).getStylesheetRoot();
try{
Source source = new XSLTInputSource(fragID).getSourceObject();
Templates templates = m_tfactory.newTemplates(source);
stylesheet = (org.apache.xalan.templates.StylesheetRoot)templates;
}
catch (TransformerConfigurationException tce)
{
throw new SAXException(tce);
}
}
addTraceListenersToStylesheet();
try{
StylesheetHandler stylesheetProcessor
= new StylesheetHandler((TransformerFactoryImpl)m_tfactory);
stylesheetProcessor.pushStylesheet(stylesheet);
TreeWalker tw = new TreeWalker(stylesheetProcessor);
tw.traverse(frag);
displayDuration("Setup of "+xslURLString, frag);
}
catch (TransformerConfigurationException tce)
{
throw new SAXException(tce);
}
}
else
{
stylesheetDoc = null;
error(XSLTErrorResources.ER_NODE_NOT_ELEMENT, new Object[] {fragID}); //"Node pointed to by fragment identifier was not an element: "+fragID);
}
}
else
{
// TODO: Use Reader here??
// hmmm.. for now I'll rely on the XML parser to handle
// fragment URLs.
diag(XSLMessages.createMessage(XSLTErrorResources.WG_PARSING_AND_PREPARING, new Object[] {xslURLString})); //"========= Parsing and preparing "+xslURLString+" ==========");
pushTime(xslURLString);
if(isRoot)
{
m_stylesheetRoot = createStylesheetRoot(xslURLString);
stylesheet = m_stylesheetRoot.getObject();
}
else
{
stylesheet = new Stylesheet(m_stylesheetRoot.getObject());
}
addTraceListenersToStylesheet();
try{
org.apache.xalan.processor.StylesheetHandler stylesheetProcessor
= new StylesheetHandler((TransformerFactoryImpl)m_tfactory); //this, stylesheet);
stylesheetProcessor.pushStylesheet(stylesheet);
// new StylesheetHandler(this, stylesheet);
}
catch (TransformerConfigurationException tce)
{
throw new SAXException(tce);
}
URL xslURL = getURLFromString(xslURLString, xmlBaseIdent);
XSLTInputSource inputSource = new XSLTInputSource(xslURL.toString());
String liaisonClassName = System.getProperty("org.apache.xalan.source.liaison");
if(null != liaisonClassName)
{
try{
DOM2Helper liaison = (DOM2Helper)(Class.forName(liaisonClassName).newInstance());
liaison.parse(SAXSource.sourceToInputSource(inputSource.getSourceObject()));
}
catch (ClassNotFoundException e1)
{
throw new SAXException("XML Liaison class " + liaisonClassName +
" specified but not found", e1);
}
catch (IllegalAccessException e2)
{
throw new SAXException("XML Liaison class " + liaisonClassName +
" found but cannot be loaded", e2);
}
catch (InstantiationException e3)
{
throw new SAXException("XML Liaison class " + liaisonClassName +
" loaded but cannot be instantiated (no empty public constructor?)",
e3);
}
catch (TransformerException tce)
{
throw new SAXException(tce);
}
}
//m_parserLiaison.setDocumentHandler(stylesheetProcessor);
//m_parserLiaison.parse(inputSource);
displayDuration("Parsing and init of "+xslURLString, xslURLString);
}
return stylesheet;
}
/**
* Take a user string and try and parse XML, and also return
* the url.
* @exception XSLProcessorException thrown if the active ProblemListener and XPathContext decide
* the error condition is severe enough to halt processing.
*/
public static URL getURLFromString(String urlString, String base)
throws SAXException
{
String origURLString = urlString;
String origBase = base;
// System.out.println("getURLFromString - urlString: "+urlString+", base: "+base);
Object doc;
URL url = null;
int fileStartType = 0;
try
{
if(null != base)
{
if(base.toLowerCase().startsWith("file:/"))
{
fileStartType = 1;
}
else if(base.toLowerCase().startsWith("file:"))
{
fileStartType = 2;
}
}
boolean isAbsoluteURL;
// From http://www.ics.uci.edu/pub/ietf/uri/rfc1630.txt
// A partial form can be distinguished from an absolute form in that the
// latter must have a colon and that colon must occur before any slash
// characters. Systems not requiring partial forms should not use any
// unencoded slashes in their naming schemes. If they do, absolute URIs
// will still work, but confusion may result.
int indexOfColon = urlString.indexOf(':');
int indexOfSlash = urlString.indexOf('/');
if((indexOfColon != -1) && (indexOfSlash != -1) && (indexOfColon < indexOfSlash))
{
// The url (or filename, for that matter) is absolute.
isAbsoluteURL = true;
}
else
{
isAbsoluteURL = false;
}
if(isAbsoluteURL || (null == base) || (base.length() == 0))
{
try
{
url = new URL(urlString);
}
catch (MalformedURLException e) {}
}
// The Java URL handling doesn't seem to handle relative file names.
else if(!((urlString.charAt(0) == '.') || (fileStartType > 0)))
{
try
{
URL baseUrl = new URL(base);
url = new URL(baseUrl, urlString);
}
catch (MalformedURLException e)
{
}
}
if(null == url)
{
// Then we're going to try and make a file URL below, so strip
// off the protocol header.
if(urlString.toLowerCase().startsWith("file:/"))
{
urlString = urlString.substring(6);
}
else if(urlString.toLowerCase().startsWith("file:"))
{
urlString = urlString.substring(5);
}
}
if((null == url) && ((null == base) || (fileStartType > 0)))
{
if(1 == fileStartType)
{
if(null != base)
base = base.substring(6);
fileStartType = 1;
}
else if(2 == fileStartType)
{
if(null != base)
base = base.substring(5);
fileStartType = 2;
}
File f = new File(urlString);
if(!f.isAbsolute() && (null != base))
{
// String dir = f.isDirectory() ? f.getAbsolutePath() : f.getParent();
// System.out.println("prebuiltUrlString (1): "+base);
StringTokenizer tokenizer = new StringTokenizer(base, "\\/");
String fixedBase = null;
while(tokenizer.hasMoreTokens())
{
String token = tokenizer.nextToken();
if (null == fixedBase)
{
// Thanks to Rick Maddy for the bug fix for UNIX here.
if (base.charAt(0) == '\\' || base.charAt(0) == '/')
{
fixedBase = File.separator + token;
}
else
{
fixedBase = token;
}
}
else
{
fixedBase+= File.separator + token;
}
}
// System.out.println("rebuiltUrlString (1): "+fixedBase);
f = new File(fixedBase);
String dir = f.isDirectory() ? f.getAbsolutePath() : f.getParent();
// System.out.println("dir: "+dir);
// System.out.println("urlString: "+urlString);
// f = new File(dir, urlString);
// System.out.println("f (1): "+f.toString());
// urlString = f.getAbsolutePath();
f = new File(urlString);
boolean isAbsolute = f.isAbsolute()
|| (urlString.charAt( 0 ) == '\\')
|| (urlString.charAt( 0 ) == '/');
if(!isAbsolute)
{
// Getting more and more ugly...
if(dir.charAt( dir.length()-1 ) != File.separator.charAt(0) &&
urlString.charAt( 0 ) != File.separator.charAt(0))
{
urlString = dir + File.separator + urlString;
}
else
{
urlString = dir + urlString;
}
// System.out.println("prebuiltUrlString (2): "+urlString);
tokenizer = new StringTokenizer(urlString, "\\/");
String rebuiltUrlString = null;
while(tokenizer.hasMoreTokens())
{
String token = tokenizer.nextToken();
if (null == rebuiltUrlString)
{
// Thanks to Rick Maddy for the bug fix for UNIX here.
if (urlString.charAt(0) == '\\' || urlString.charAt(0) == '/')
{
rebuiltUrlString = File.separator + token;
}
else
{
rebuiltUrlString = token;
}
}
else
{
rebuiltUrlString+= File.separator + token;
}
}
// System.out.println("rebuiltUrlString (2): "+rebuiltUrlString);
if(null != rebuiltUrlString)
urlString = rebuiltUrlString;
}
// System.out.println("fileStartType: "+fileStartType);
if(1 == fileStartType)
{
if (urlString.charAt(0) == '/')
{
urlString = "file://"+urlString;
}
else
{
urlString = "file:/"+urlString;
}
}
else if(2 == fileStartType)
{
urlString = "file:"+urlString;
}
try
{
// System.out.println("Final before try: "+urlString);
url = new URL(urlString);
}
catch (MalformedURLException e)
{
// System.out.println("Error trying to make URL from "+urlString);
}
}
}
if(null == url)
{
// The sun java VM doesn't do this correctly, but I'll
// try it here as a second-to-last resort.
if((null != origBase) && (origBase.length() > 0))
{
try
{
URL baseURL = new URL(origBase);
// System.out.println("Trying to make URL from "+origBase+" and "+origURLString);
url = new URL(baseURL, origURLString);
// System.out.println("Success! New URL is: "+url.toString());
}
catch (MalformedURLException e)
{
// System.out.println("Error trying to make URL from "+origBase+" and "+origURLString);
}
}
if(null == url)
{
try
{
String lastPart;
if(null != origBase)
{
File baseFile = new File(origBase);
if(baseFile.isDirectory())
{
lastPart = new File(baseFile, urlString).getAbsolutePath ();
}
else
{
String parentDir = baseFile.getParent();
lastPart = new File(parentDir, urlString).getAbsolutePath ();
}
}
else
{
lastPart = new File (urlString).getAbsolutePath ();
}
// Hack
// if((lastPart.charAt(0) == '/') && (lastPart.charAt(2) == ':'))
// lastPart = lastPart.substring(1, lastPart.length() - 1);
String fullpath;
if (lastPart.charAt(0) == '\\' || lastPart.charAt(0) == '/')
{
fullpath = "file://" + lastPart;
}
else
{
fullpath = "file:" + lastPart;
}
url = new URL(fullpath);
}
catch (MalformedURLException e2)
{
throw new SAXException("Cannot create url for: " + urlString, e2 );
//XSLMessages.createXPATHMessage(XPATHErrorResources.ER_CANNOT_CREATE_URL, new Object[]{urlString}),e2); //"Cannot create url for: " + urlString, e2 );
}
}
}
}
catch(SecurityException se)
{
try
{
url = new URL("http://xml.apache.org/xslt/"+java.lang.Math.random()); // dummy
}
catch (MalformedURLException e2)
{
// I give up
}
}
// System.out.println("url: "+url.toString());
return url;
}
/**
* Add a trace listener for the purposes of debugging and diagnosis.
* @param tl Trace listener to be added.
*/
void addTraceListenersToStylesheet()
throws SAXException
{
/*try
{
TraceManager tm = m_transformerImpl.getTraceManager();
if(tm.hasTraceListeners)
{
int nListeners = tm.size();
for(int i = 0; i < nListeners; i++)
{
TraceListener tl = (TraceListener)m_traceListeners.elementAt(i);
if(null != m_stylesheetRoot)
m_stylesheetRoot.addTraceListener(tl);
}
}
}
catch(TooManyListenersException tmle)
{
throw new SAXException(XSLMessages.createMessage(XSLTErrorResources.ER_TOO_MANY_LISTENERS, null),tmle ); //"addTraceListenersToStylesheet - TooManyListenersException", tmle);
}*/
}
/**
* Warn the user of an problem.
* This is public for access by extensions.
* @exception XSLProcessorException thrown if the active ProblemListener and XMLParserLiaison decide
* the error condition is severe enough to halt processing.
*/
public void message(String msg)
throws SAXException
{
message(null, null, msg);
}
/**
* Warn the user of an problem.
* This is public for access by extensions.
* @exception XSLProcessorException thrown if the active ProblemListener and XMLParserLiaison decide
* the error condition is severe enough to halt processing.
*/
public void message(Node styleNode, Node sourceNode, String msg)
throws SAXException
{
//boolean shouldThrow = m_processor.getErrorHandler().message(msg);
//if(shouldThrow)
//{
// throw new XSLProcessorException(msg);
//}
}
/**
* <meta name="usage" content="internal"/>
* Warn the user of an problem.
* @exception XSLProcessorException thrown if the active ProblemListener and XMLParserLiaison decide
* the error condition is severe enough to halt processing.
*/
public void warn(int msg)
throws SAXException
{
warn(null, null, msg, null);
}
/**
* <meta name="usage" content="internal"/>
* Warn the user of an problem.
* @exception XSLProcessorException thrown if the active ProblemListener and XMLParserLiaison decide
* the error condition is severe enough to halt processing.
*/
public void warn(int msg, Object[] args)
throws SAXException
{
warn(null, null, msg, args);
}
/**
* <meta name="usage" content="internal"/>
* Warn the user of an problem.
* @exception XSLProcessorException thrown if the active ProblemListener and XMLParserLiaison decide
* the error condition is severe enough to halt processing.
*/
public void warn(Node styleNode, Node sourceNode, int msg)
throws SAXException
{
warn(styleNode, sourceNode, msg, null);
}
/**
* <meta name="usage" content="internal"/>
* Warn the user of an problem.
* @exception XSLProcessorException thrown if the active ProblemListener and XMLParserLiaison decide
* the error condition is severe enough to halt processing.
*/
public void warn(Node styleNode, Node sourceNode, int msg, Object args[])
throws SAXException
{
Exception e = null;
String fmsg = m_XSLMessages.createWarning(msg, args);
SourceLocator locator = null;
try{
locator = ((StylesheetHandler)(((TransformerFactoryImpl)this.m_tfactory).newTemplatesHandler())).getLocator();
}
catch (TransformerConfigurationException tce)
{
}
DefaultErrorHandler handler = (DefaultErrorHandler)m_tfactory.getErrorListener();
TransformerException te = (null == e) ? new TransformerException(fmsg, locator) :
new TransformerException(fmsg, locator, e);
if(null != handler)
{
try{
handler.warning(te);
}
catch (TransformerException te2)
{
throw new SAXException(te2);
}
}
else
throw new SAXException(te);
}
/**
* <meta name="usage" content="internal"/>
* Tell the user of an error, and probably throw an
* exception.
* @exception XSLProcessorException thrown if the active ProblemListener and XMLParserLiaison decide
* the error condition is severe enough to halt processing.
*/
public void error(String msg)
throws SAXException
{
Exception e = null;
SourceLocator locator = null;
try{
locator = ((StylesheetHandler)(((TransformerFactoryImpl)this.m_tfactory).newTemplatesHandler())).getLocator();
}
catch (TransformerConfigurationException tce)
{
}
DefaultErrorHandler handler = (DefaultErrorHandler)m_tfactory.getErrorListener();
TransformerException te = (null == e) ? new TransformerException(msg, locator) :
new TransformerException(msg, locator, e);
if(null != handler)
{
try{
handler.fatalError(te);
}
catch (TransformerException te2)
{
throw new SAXException(te2);
}
}
else
throw new SAXException(te);
}
/**
* <meta name="usage" content="internal"/>
* Tell the user of an error, and probably throw an
* exception.
* @exception XSLProcessorException thrown if the active ProblemListener and XMLParserLiaison decide
* the error condition is severe enough to halt processing.
*/
public void error(int msg)
throws SAXException
{
error(null, null, msg, null);
}
/**
* <meta name="usage" content="internal"/>
* Tell the user of an error, and probably throw an
* exception.
* @exception XSLProcessorException thrown if the active ProblemListener and XMLParserLiaison decide
* the error condition is severe enough to halt processing.
*/
public void error(int msg, Object[] args)
throws SAXException
{
error(null, null, msg, args);
}
/**
* <meta name="usage" content="internal"/>
* Tell the user of an error, and probably throw an
* exception.
* @exception XSLProcessorException thrown if the active ProblemListener and XMLParserLiaison decide
* the error condition is severe enough to halt processing.
*/
public void error(int msg, Exception e)
throws SAXException
{
error(msg, null, e);
}
/**
* <meta name="usage" content="internal"/>
* Tell the user of an error, and probably throw an
* exception.
* @exception XSLProcessorException thrown if the active ProblemListener and XMLParserLiaison decide
* the error condition is severe enough to halt processing.
*/
public void error(int msg, Object args[], Exception e)
throws SAXException
{
String fmsg = m_XSLMessages.createMessage(msg, args);
SourceLocator locator = null;
try{
locator = ((StylesheetHandler)(((TransformerFactoryImpl)this.m_tfactory).newTemplatesHandler())).getLocator();
}
catch (TransformerConfigurationException tce)
{
}
DefaultErrorHandler handler = (DefaultErrorHandler)m_tfactory.getErrorListener();
TransformerException te = (null == e) ? new TransformerException(fmsg, locator) :
new TransformerException(fmsg, locator, e);
if(null != handler)
{
try{
handler.fatalError(te);
}
catch (TransformerException te2)
{
throw new SAXException(te2);
}
}
else
throw new SAXException(te);
}
/**
* <meta name="usage" content="internal"/>
* Tell the user of an error, and probably throw an
* exception.
* @exception XSLProcessorException thrown if the active ProblemListener and XMLParserLiaison decide
* the error condition is severe enough to halt processing.
*/
public void error(Node styleNode, Node sourceNode, int msg)
throws SAXException
{
error(styleNode, sourceNode, msg, null);
}
/**
* <meta name="usage" content="internal"/>
* Tell the user of an error, and probably throw an
* exception.
* @exception XSLProcessorException thrown if the active ProblemListener and XMLParserLiaison decide
* the error condition is severe enough to halt processing.
*/
public void error(Node styleNode, Node sourceNode, int msg, Object args[])
throws SAXException
{
Exception e = null;
String fmsg = m_XSLMessages.createMessage(msg, args);
SourceLocator locator = null;
try{
locator = ((StylesheetHandler)(((TransformerFactoryImpl)this.m_tfactory).newTemplatesHandler())).getLocator();
}
catch (TransformerConfigurationException tce)
{
}
DefaultErrorHandler handler = (DefaultErrorHandler)m_tfactory.getErrorListener();
TransformerException te = (null == e) ? new TransformerException(fmsg, locator) :
new TransformerException(fmsg, locator, e);
if(null != handler)
{
try{
handler.fatalError(te);
}
catch (TransformerException te2)
{
throw new SAXException(te2);
}
}
else
throw new SAXException(te);
}
/**
* Mark the time, so that displayDuration can later
* display the elapse.
*/
void pushTime(Object key)
{
if(null != key)
{
m_durationsTable.put(key, new Long(System.currentTimeMillis()));
}
}
/**
* Returns the duration since pushTime was called,
* in milliseconds.
*/
long popDuration(Object key)
{
long millisecondsDuration = 0;
if(null != key)
{
long start = ((Long)m_durationsTable.get(key)).longValue();
long stop = System.currentTimeMillis();
millisecondsDuration = stop - start;
m_durationsTable.remove(key);
}
return millisecondsDuration;
}
/**
* Display the duration since pushTime was called.
*/
protected void displayDuration(String info, Object key)
{
long millisecondsDuration = 0;
if(null != key)
{
Date date1 = (Date)m_durationsTable.get(key);
Date date2 = new Date();
millisecondsDuration = date2.getTime() - date1.getTime();
if(null != m_diagnosticsPrintWriter)
{
m_diagnosticsPrintWriter.println(info + " took " + millisecondsDuration + " milliseconds");
}
m_durationsTable.remove(key);
}
}
/**
* If this is set, diagnostics will be
* written to the m_diagnosticsPrintWriter stream. If
* the value is null, then diagnostics will be turned
* off.
*/
public void setDiagnosticsOutput(java.io.OutputStream out)
{
setDiagnosticsOutput(new PrintWriter(out));
}
/**
* If this is set, diagnostics will be
* written to the m_diagnosticsPrintWriter stream. If
* the value is null, then diagnostics will be turned
* off.
*/
public void setDiagnosticsOutput(java.io.PrintWriter pw)
{
m_diagnosticsPrintWriter = pw;
/* if(getProblemListener() instanceof ProblemListenerDefault)
{
((ProblemListenerDefault)getProblemListener()).setDiagnosticsOutput(pw);
}*/
}
/**
* Bottleneck output of diagnostics.
*/
protected void diag(String s)
{
if(null != m_diagnosticsPrintWriter)
{
m_diagnosticsPrintWriter.println(s);
}
}
/**
* If this is set to true, simple traces of
* template calls are made.
*/
public void setTraceTemplates(boolean b)
{
m_traceTemplates = b;
}
/**
* If this is set to true, simple traces of
* template calls are made.
*/
public void setTraceSelect(boolean b)
{
m_traceSelects = b;
}
/**
* If this is set to true, debug diagnostics about
* template children as they are being constructed
* will be written to the m_diagnosticsPrintWriter
* stream. diagnoseTemplateChildren is false by
* default.
*/
public void setTraceTemplateChildren(boolean b)
{
m_traceTemplateChildren = b;
}
//
// Lexical handler interface
//
/**
* Report the start of DTD declarations, if any.
*
* <p>Any declarations are assumed to be in the internal subset
* unless otherwise indicated by a {@link #startEntity startEntity}
* event.</p>
*
* <p>Note that the start/endDTD events will appear within
* the start/endDocument events from ContentHandler and
* before the first startElement event.</p>
*
* @param name The document type name.
* @param publicId The declared public identifier for the
* external DTD subset, or null if none was declared.
* @param systemId The declared system identifier for the
* external DTD subset, or null if none was declared.
* @exception SAXException The application may raise an
* exception.
* @see #endDTD
* @see #startEntity
*/
public void startDTD (String name, String publicId, String systemId)
throws SAXException
{
if (m_transformerImpl != null && m_transformerImpl.getInputLexicalHandler() != null)
m_transformerImpl.getInputLexicalHandler().startDTD(name, publicId, systemId);
}
/**
* Report the end of DTD declarations.
*
* @exception SAXException The application may raise an exception.
* @see #startDTD
*/
public void endDTD ()
throws SAXException
{
if (m_transformerImpl != null && m_transformerImpl.getInputLexicalHandler() != null)
m_transformerImpl.getInputLexicalHandler().endDTD();
}
public void startEntity (String name)
throws SAXException
{
if (m_transformerImpl != null && m_transformerImpl.getInputLexicalHandler() != null)
m_transformerImpl.getInputLexicalHandler().startEntity (name);
}
/**
* Report the end of an entity.
*
* @param name The name of the entity that is ending.
* @exception SAXException The application may raise an exception.
* @see #startEntity
*/
public void endEntity (String name)
throws SAXException
{
if (m_transformerImpl != null && m_transformerImpl.getInputLexicalHandler() != null)
m_transformerImpl.getInputLexicalHandler().endEntity (name);
}
/**
* Report the start of a CDATA section.
*
* <p>The contents of the CDATA section will be reported through
* the regular {@link org.xml.sax.ContentHandler#characters
* characters} event.</p>
*
* @exception SAXException The application may raise an exception.
* @see #endCDATA
*/
public void startCDATA ()
throws SAXException
{
if (m_transformerImpl != null && m_transformerImpl.getInputLexicalHandler() != null)
m_transformerImpl.getInputLexicalHandler().startCDATA();
}
/**
* Report the end of a CDATA section.
*
* @exception SAXException The application may raise an exception.
* @see #startCDATA
*/
public void endCDATA ()
throws SAXException
{
if (m_transformerImpl != null && m_transformerImpl.getInputLexicalHandler() != null)
m_transformerImpl.getInputLexicalHandler().endCDATA();
}
/**
* Report an XML comment anywhere in the document.
*
* <p>This callback will be used for comments inside or outside the
* document element, including comments in the external DTD
* subset (if read).</p>
*
* @param ch An array holding the characters in the comment.
* @param start The starting position in the array.
* @param length The number of characters to use from the array.
* @exception SAXException The application may raise an exception.
*/
public void comment (char ch[], int start, int length)
throws SAXException
{
if (m_transformerImpl != null && m_transformerImpl.getInputLexicalHandler() != null)
m_transformerImpl.getInputLexicalHandler().comment (ch, start, length);
}
// DocumentHandler interface
/**
* Receive an object for locating the origin of SAX document events.
*
* <p>SAX parsers are strongly encouraged (though not absolutely
* required) to supply a locator: if it does so, it must supply
* the locator to the application by invoking this method before
* invoking any of the other methods in the DocumentHandler
* interface.</p>
*
* <p>The locator allows the application to determine the end
* position of any document-related event, even if the parser is
* not reporting an error. Typically, the application will
* use this information for reporting its own errors (such as
* character content that does not match an application's
* business rules). The information returned by the locator
* is probably not sufficient for use with a search engine.</p>
*
* <p>Note that the locator will return correct information only
* during the invocation of the events in this interface. The
* application should not attempt to use it at any other time.</p>
*
* @param locator An object that can return the location of
* any SAX document event.
* @see org.xml.sax.Locator
*/
public void setDocumentLocator (Locator locator)
{}
/**
* Receive notification of the beginning of a document.
*
* <p>The SAX parser will invoke this method only once, before any
* other methods in this interface or in DTDHandler (except for
* setDocumentLocator).</p>
*
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
*/
public void startDocument ()
throws SAXException
{
if (m_documentHandler != null)
m_documentHandler.startDocument();
else if (m_transformerImpl != null)
m_transformerImpl.getInputContentHandler().startDocument();
//m_transformerImpl.getResultTreeHandler().startDocument();
}
/**
* Receive notification of the end of a document.
*
* <p>The SAX parser will invoke this method only once, and it will
* be the last method invoked during the parse. The parser shall
* not invoke this method until it has either abandoned parsing
* (because of an unrecoverable error) or reached the end of
* input.</p>
*
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
*/
public void endDocument ()
throws SAXException
{
if (m_documentHandler != null)
m_documentHandler.endDocument();
else if (m_transformerImpl != null)
m_transformerImpl.getInputContentHandler().endDocument();
//m_transformerImpl.getResultTreeHandler().endDocument();
}
/**
* Receive notification of the beginning of an element.
*
* <p>The Parser will invoke this method at the beginning of every
* element in the XML document; there will be a corresponding
* endElement() event for every startElement() event (even when the
* element is empty). All of the element's content will be
* reported, in order, before the corresponding endElement()
* event.</p>
*
* <p>If the element name has a namespace prefix, the prefix will
* still be attached. Note that the attribute list provided will
* contain only attributes with explicit values (specified or
* defaulted): #IMPLIED attributes will be omitted.</p>
*
* @param name The element type name.
* @param atts The attributes attached to the element, if any.
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
* @see #endElement
* @see org.xml.sax.AttributeList
*/
public void startElement (String name, AttributeList atts)
throws SAXException
{
if (m_documentHandler == null)
{
m_documentHandler = new ParserAdapter(new org.apache.xerces.parsers.SAXParser());
if (m_transformerImpl != null)
{
((ParserAdapter)m_documentHandler).setContentHandler(m_transformerImpl.getInputContentHandler());
}
/* else if (m_transformerImpl != null)
{
int index = name.indexOf(":");
if (index < 0 )
m_transformerImpl.getInputContentHandler().startElement(null, name, name, (Attributes)atts);
//getResultTreeHandler().startElement(null, name, name, (Attributes)atts);
else
m_transformerImpl.getInputContentHandler().startElement(name.substring(0,index), name.substring(index+1), name, (Attributes)atts);
//m_transformerImpl.getResultTreeHandler().startElement(name.substring(0,index), name.substring(index+1), name, (Attributes)atts);
*/
}
m_documentHandler.startElement(name, atts);
}
/**
* Receive notification of the end of an element.
*
* <p>The SAX parser will invoke this method at the end of every
* element in the XML document; there will be a corresponding
* startElement() event for every endElement() event (even when the
* element is empty).</p>
*
* <p>If the element name has a namespace prefix, the prefix will
* still be attached to the name.</p>
*
* @param name The element type name
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
*/
public void endElement (String name)
throws SAXException
{
if (m_documentHandler == null)
{
m_documentHandler = new ParserAdapter(new org.apache.xerces.parsers.SAXParser());
if (m_transformerImpl != null)
{
((ParserAdapter)m_documentHandler).setContentHandler(m_transformerImpl.getInputContentHandler());
}
/* else if (m_transformerImpl != null)
{
int index = name.indexOf(":");
if (index < 0 )
m_transformerImpl.getInputContentHandler().endElement(null, name, name);
//m_transformerImpl.getResultTreeHandler().endElement(null, name, name);
else
m_transformerImpl.getInputContentHandler().endElement(name.substring(0,index), name.substring(index+1), name);
//m_transformerImpl.getResultTreeHandler().endElement(name.substring(0,index), name.substring(index+1), name);
*/
}
m_documentHandler.endElement(name);
}
/**
* Receive notification of character data.
*
* <p>The Parser will call this method to report each chunk of
* character data. SAX parsers may return all contiguous character
* data in a single chunk, or they may split it into several
* chunks; however, all of the characters in any single event
* must come from the same external entity, so that the Locator
* provides useful information.</p>
*
* <p>The application must not attempt to read from the array
* outside of the specified range.</p>
*
* <p>Note that some parsers will report whitespace using the
* ignorableWhitespace() method rather than this one (validating
* parsers must do so).</p>
*
* @param ch The characters from the XML document.
* @param start The start position in the array.
* @param length The number of characters to read from the array.
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
* @see #ignorableWhitespace
* @see org.xml.sax.Locator
*/
public void characters (char ch[], int start, int length)
throws SAXException
{
if (m_documentHandler != null)
m_documentHandler.characters(ch, start, length);
else if (m_transformerImpl != null)
m_transformerImpl.getInputContentHandler().characters(ch, start, length);
//m_transformerImpl.getResultTreeHandler().characters(ch, start, length);
}
/**
* Receive notification of ignorable whitespace in element content.
*
* <p>Validating Parsers must use this method to report each chunk
* of ignorable whitespace (see the W3C XML 1.0 recommendation,
* section 2.10): non-validating parsers may also use this method
* if they are capable of parsing and using content models.</p>
*
* <p>SAX parsers may return all contiguous whitespace in a single
* chunk, or they may split it into several chunks; however, all of
* the characters in any single event must come from the same
* external entity, so that the Locator provides useful
* information.</p>
*
* <p>The application must not attempt to read from the array
* outside of the specified range.</p>
*
* @param ch The characters from the XML document.
* @param start The start position in the array.
* @param length The number of characters to read from the array.
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
* @see #characters
*/
public void ignorableWhitespace (char ch[], int start, int length)
throws SAXException
{
if (m_documentHandler != null)
m_documentHandler.ignorableWhitespace(ch, start, length);
else if (m_transformerImpl != null)
m_transformerImpl.getInputContentHandler().ignorableWhitespace(ch, start, length);
//m_transformerImpl.getResultTreeHandler().ignorableWhitespace(ch, start, length);
}
/**
* Receive notification of a processing instruction.
*
* <p>The Parser will invoke this method once for each processing
* instruction found: note that processing instructions may occur
* before or after the main document element.</p>
*
* <p>A SAX parser should never report an XML declaration (XML 1.0,
* section 2.8) or a text declaration (XML 1.0, section 4.3.1)
* using this method.</p>
*
* @param target The processing instruction target.
* @param data The processing instruction data, or null if
* none was supplied.
* @exception org.xml.sax.SAXException Any SAX exception, possibly
* wrapping another exception.
*/
public void processingInstruction (String target, String data)
throws SAXException
{
if (m_documentHandler != null)
m_documentHandler.processingInstruction(target, data);
else if (m_transformerImpl != null)
m_transformerImpl.getInputContentHandler().processingInstruction(target, data);
//m_transformerImpl.getResultTreeHandler().processingInstruction(target, data);
}
// Implement XSLTProcessor
/**
* Set the output stream. Required when the XSLTProcessor is being used
* as a SAX DocumentHandler.
*/
public void setOutputStream(java.io.OutputStream os)
{
SourceTreeHandler handler = new SourceTreeHandler(m_transformerImpl);
handler.setResult(new StreamResult(os));
}
/**
* Convenience function to create an XString.
* @param s A valid string.
* @return An XString object.
*/
public XString createXString(String s)
{
return new XString(s);
}
/**
* Convenience function to create an XObject.
* @param o Any java object.
* @return An XObject object.
*/
public XObject createXObject(Object o)
{
return new XObject(o);
}
/**
* Convenience function to create an XNumber.
* @param d Any double number.
* @return An XNumber object.
*/
public XNumber createXNumber(double d)
{
return new XNumber(d);
}
/**
* Convenience function to create an XBoolean.
* @param b boolean value.
* @return An XBoolean object.
*/
public XBoolean createXBoolean(boolean b)
{
return new XBoolean(b);
}
/**
* Convenience function to create an XNodeSet.
* @param nl A NodeList object.
* @return An XNodeSet object.
*/
public XNodeSet createXNodeSet(NodeList nl)
{
return new XNodeSet((NodeIterator)nl);
}
/**
* Convenience function to create an XNodeSet from a node.
* @param n A DOM node.
* @return An XNodeSet object.
*/
public XNodeSet createXNodeSet(Node n)
{
return new XNodeSet(n);
}
/**
* Convenience function to create an XNull.
* @return An XNull object.
*/
public XNull createXNull()
{
return new XNull();
}
/**
* Get the XMLParserLiaison that this processor uses.
*/
public XMLParserLiaison getXMLProcessorLiaison()
{
return (XMLParserLiaison)m_liaison;
}
/**
* Get the preferred stylesheet for the XSLTInputSource XML document,
* as identified by the xml-stylesheet PI, and matching the media and
* charset criteria. See {@link http://www.w3.org/TR/xml-stylesheet/
* Associating Style Sheets with XML documents}
* Does not yet handle the LINK REL="stylesheet" syntax.
*
* @param media The media attribute to be matched. May be null, in which
* case the prefered stylesheet will be used (i.e., alternate = no).
* @param title The value of the title attribute to match. May be null.
* @param charset The value of the charset attribute to match. May be null.
* @returns StylesheetSpec extends XSLTInputSource extedns SAX InputSource; the return value
* can be passed to the processStylesheet method.
*/
public StylesheetSpec getAssociatedStylesheet(XSLTInputSource source,
String media,
String charset)
throws SAXException
{
/*InputSource[]in = m_processor.getAssociatedStylesheets(source, media, null, charset);
if (in.length >0)
return (StylesheetSpec)in[0];
else
return null; */
try{
Source s = m_tfactory.getAssociatedStylesheet(source.getSourceObject(), media, null, charset);
return (StylesheetSpec)s;
}
catch (TransformerConfigurationException tce)
{
throw new SAXException(tce);
}
}
/**
* Get a list of stylesheet specifications for the XSLTInputSource XML document,
* as identified by the xml-stylesheet PI, and matching the media and
* charset criteria. See {@link http://www.w3.org/TR/xml-stylesheet/
* Associating Style Sheets with XML documents}.
* Does not yet handle the LINK REL="stylesheet" syntax.
*
* @param media The media attribute to be matched. May be null, in which
* case the prefered stylesheet will be used (i.e., alternate = no).
* @param title The value of the title attribute to match. May be null.
* @param charset The value of the charset attribute to match. May be null.
* @returns list of StylesheetSpecs (extend XSLTInputSources extend SAX InputSources; a
* list member may be passsed to the processStylesheet method.
*/
public Vector getAssociatedStylesheets(XSLTInputSource source,
String media,
String charset)
throws SAXException
{
try{
Source s = m_tfactory.getAssociatedStylesheet(source.getSourceObject(), media, null, charset);
Vector v = new Vector();
//for (int i = 0; i< in.length; i++)
v.addElement((StylesheetSpec)s);
return v;
}
catch (TransformerConfigurationException tce)
{
throw new SAXException(tce);
}
}
/**
* Submit a top-level stylesheet parameter. This value can
* be evaluated in the stylesheet via xsl:param-variable.
* @param key The name of the param.
* @param value An XObject that will be used.
*/
public void setStylesheetParam(String key, XObject value)
{
if (m_transformerImpl != null)
m_transformerImpl.setParameter(key, null, value);
else
{
setParameter(key, value);
}
}
/**
* Set a top-level stylesheet parameter. This value can
* be evaluated via xsl:param-variable. Note that the value
* passed is an expression, and not a string. This means that
* setStylesheetParam("foo", "hello"); will look for the
* element "hello". If you want to pass a string, you'll
* need to put quotes around it:
* setStylesheetParam("foo", "'hello'"); will look for the
* @param key The name of the param.
* @param expression An expression that will be evaluated.
*/
public void setStylesheetParam(String key, String expression)
{
if (m_transformerImpl != null)
m_transformerImpl.setParameter(key, null, expression);
else
{
setParameter(key, expression);
}
}
/**
* Set a top-level stylesheet parameter. This value can
* be evaluated via xsl:param-variable. Note that the value
* passed is an expression, and not a string. This means that
* setStylesheetParam("foo", "hello"); will look for the
* element "hello". If you want to pass a string, you'll
* need to put quotes around it:
* setStylesheetParam("foo", "'hello'"); will look for the
* @param key The name of the param.
* @param expression An expression that will be evaluated.
*/
public void setParameter(String key, Object value)
{
if (m_stylesheetParams == null)
m_stylesheetParams = new Hashtable();
m_stylesheetParams.put(key, value);
}
/**
* Get the current FormatterListener (SAX DocumentHandler), or null if none has been set.
*/
public DocumentHandler getFormatterListener()
{
return m_documentHandler;
}
/**
* Set the FormatterListener (the SAX DocumentHandler).
*/
public void setFormatterListener(DocumentHandler flistener)
{
m_documentHandler = flistener;
}
/**
* Get the current SAX DocumentHandler (the same object as the FormatterListener), or null if none has been set.
*/
public DocumentHandler getDocumentHandler()
{
return m_documentHandler;
}
/**
* Set the current SAX DocumentHandler (the same
* object as the FormatterListener).
*/
public void setDocumentHandler(DocumentHandler listener)
{
if (listener instanceof ParserAdapter)
m_transformerImpl.setContentHandler(((ParserAdapter)listener).getContentHandler());
else
m_transformerImpl.setContentHandler(((XSLTEngineImpl)listener).getTransformer().getContentHandler());
m_documentHandler = listener;
}
/**
* Add a trace listener for the purposes of debugging and diagnosis.
* @param tl Trace listener to be added.
*/
public void addTraceListener(TraceListener tl)
throws TooManyListenersException
{
if (m_transformerImpl != null)
m_transformerImpl.getTraceManager().addTraceListener(tl);
}
/**
* If set to true (the default), pattern conflict warnings are not printed to the diagnostics stream.
* @param b true if conflict warnings should be suppressed.
*/
public void setQuietConflictWarnings(boolean b)
{
if (m_transformerImpl != null)
m_transformerImpl.setQuietConflictWarnings(b);
}
/**
* Remove a trace listener.
* @param tl Trace listener to be removed.
*/
public void removeTraceListener(TraceListener tl)
{
if (m_transformerImpl != null)
m_transformerImpl.getTraceManager().removeTraceListener(tl);
}
/**
* Set the problem listener property.
* The XSL class can have a single listener to be informed
* of errors and warnings. The problem listener normally controls whether an exception
* is thrown or not (or the problem listeners can throw its own RuntimeException).
* @param l A ProblemListener interface.
*/
public void setProblemListener(ProblemListener l)
{
m_problemListener = new ProblemListenerDefault((DefaultErrorHandler)m_tfactory.getErrorListener(), l);
}
/**
* Get the problem listener property.
* The XSL class can have a single listener to be informed
* of errors and warnings. The problem listener normally controls whether an exception
* is thrown or not (or the problem listener can throw its own RuntimeException).
* @return A ProblemListener interface.
*/
public ProblemListener getProblemListener()
{
return m_problemListener.getProblemListener();
}
public TransformerImpl getTransformer()
{
return m_transformerImpl;
//return (StylesheetProcessor)m_processor;
}
public TransformerFactoryImpl getTransformerFactory()
{
return (TransformerFactoryImpl)m_tfactory;
}
} // end XSLTEngineImpl class
1.1 xml-xalan/java/compat_src/org/apache/xalan/xslt/XSLTInputSource.java
Index: XSLTInputSource.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" 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 name, without prior written
* permission of the Apache Software Foundation.
*
* 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 and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.xslt;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import javax.xml.transform.Source;
import org.w3c.dom.Node;
import java.io.InputStream;
import java.io.Reader;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.dom.DOMSource;
/**
* <meta name="usage" content="general"/>
* Represents an XML source document or XSL stylesheet.
* Use XSLTInputSource objects to provide input to the XSLTProcessor process() method
* for a transformation. This class extends the SAX input source to handle
* DOM nodes as input as well as files, character streams, byte streams and SAX DocumentHandlers.
*
* @see XSLTProcessor#process(XSLTInputSource, XSLTInputSource, XSLTResultTarget)
*/
public class XSLTInputSource //extends SAXSource
{
private StreamSource streamSource = null;
private SAXSource saxSource = null;
private DOMSource domSource = null;
/**
* Zero-argument default constructor -- Before you can use the new XSLTInputSource object in a transformation,
* you must define the document source with setSystemId(), setNode(), setByteStream(), or setCharacterStream().
*
* @see #setSystemId(String)
* @see #setNode(Node)
* @see #setByteStream
* @see #setCharacterStream
* @see #setEncoding(String)
* @see #setPublicId(String)
*/
public XSLTInputSource ()
{
saxSource = new SAXSource();
}
/**
* Create a new input source with a system identifier (for a URL or file name) --
* the equivalent of creating an input source with the zero-argument
* constructor and setting the new object's SystemId property.
* If the system identifier is a URL, it must be fully resolved.
*
* @param systemId The system identifier (URI).
* @see #setSystemId(String)
* @see #setNode(Node)
* @see #setByteStream
* @see #setEncoding(String)
* @see #setCharacterStream
* @see #setPublicId(String)
*/
public XSLTInputSource (String systemId)
{
saxSource = new SAXSource();
saxSource.setSystemId(systemId);
this.setSystemId(systemId);
}
/**
* Create a new input source with a byte stream -- the equivalent of creating an input source
* with the zero-argument constructor and setting the new object's ByteStream property.
*
* @param byteStream The raw byte stream containing the document.
* @see #setByteStream
* @see #setSystemId(String)
* @see #setNode(Node)
* @see #setEncoding(String)
* @see #setCharacterStream
* @see #setPublicId(String)
*/
public XSLTInputSource (InputStream byteStream)
{
streamSource = new StreamSource();
streamSource.setInputStream(byteStream);
}
/**
* Create a new input source with a character stream -- the equivalent of creating an input source
* with the zero-argument constructor and setting the new object's CharacterStream property.
* <p>The character stream shall not include a byte order mark.</p>
*
* @param characterStream The character stream containing the document.
* @see #setCharacterStream
* @see #setByteStream
* @see #setSystemId(String)
* @see #setNode(Node)
* @see #setEncoding(String)
* @see #setPublicId(String)
*/
public XSLTInputSource (Reader characterStream)
{
streamSource = new StreamSource();
streamSource.setReader(characterStream);
}
/**
* Create a new input source with a DOM Node -- the equivalent of creating an input source
* with the zero-argument constructor and setting the new object's Node property.
*
* @param node The DOM Node containing the document.
* @see #setNode(Node)
* @see #setCharacterStream
* @see #setByteStream
* @see #setSystemId(String)
* @see #setEncoding(String)
* @see #setPublicId(String)
*/
public XSLTInputSource (Node node)
{
domSource = new DOMSource();
domSource.setNode(node);
}
/**
* Create a new XSLTInputSource source from a SAX input source.
* This operation sets the ByteStream, CharacterStream, SystemId, PublicID, and Encoding properties.
*
* @param isource The SAX input source.
* @see #setCharacterStream
* @see #setByteStream
* @see #setSystemId(String)
* @see #setEncoding(String)
* @see #setPublicId(String)
* @see #setNode(Node)
*/
public XSLTInputSource (InputSource isource)
{
saxSource = new SAXSource();
saxSource.setInputSource(isource);
//saxSource.setXMLReader(isource.getCharacterStream());
this.setEncoding(isource.getEncoding());
//this.setPublicId(isource.getPublicId());
saxSource.setSystemId(isource.getSystemId());
}
/**
* Set the DOM Node for this input source.
*
* @param characterStream The character stream containing the
* XML document or XSL stylesheet.
* @see #XSLTInputSource(Node)
* @see #getCharacterStream()
* @see java.io.Reader
*
public void setNode (Node node)
{
this.node = node;
}
/**
* Get the DOM Node for this input source.
*
* @return The DOM node containing the document, or null if none was supplied.
* @see #XSLTInputSource(Node)
* @see #setNode(Node)
*
public Node getNode ()
{
return node;
}
private Node node = null;
/**
* Set the character encoding, if known.
*
* <p>The encoding must be a string acceptable for an
* XML encoding declaration (see section 4.3.3 of the XML 1.0
* recommendation).</p>
*
* <p>This method has no effect when the application provides a
* character stream.</p>
*
* @param encoding A string describing the character encoding.
* @see #setSystemId
* @see #setByteStream
* @see #getEncoding
*/
public void setEncoding (String encoding)
{
this.encoding = encoding;
}
/**
* Get the character encoding for a byte stream or URI.
*
* @return The encoding, or null if none was supplied.
* @see #setByteStream
* @see #getSystemId
* @see #getByteStream
*/
public String getEncoding ()
{
return encoding;
}
private String encoding = null;
/**
* Set the character stream for this input source.
*
* <p>If there is a character stream specified, the SAX parser
* will ignore any byte stream and will not attempt to open
* a URI connection to the system identifier.</p>
*
* @param characterStream The character stream containing the
* XML document or other entity.
* @see #getCharacterStream
* @see java.io.Reader
*
public void setCharacterStream (Reader characterStream)
{
this.characterStream = characterStream;
}
/**
* Get the character stream for this input source.
*
* @return The character stream, or null if none was supplied.
* @see #setCharacterStream
*
public Reader getCharacterStream ()
{
return characterStream;
}
private Reader characterStream = null;
/**
* Set the base ID (URL or system ID) from where URLs
* will be resolved.
*
* @param baseID Base URL for this.
*/
public void setSystemId(String baseID) {
this.baseID = baseID;
}
/**
* Get the base ID (URL or system ID) from where URLs
* will be resolved.
*
* @return Base URL for this.
*/
public String getSystemId() {
return this.baseID;
}
private String baseID = null;
/**
* Set the byte stream to be used as input. Normally,
* a stream should be used rather than a reader, so that
* the XML parser can resolve character encoding specified
* by the XML declaration.
*
* <p>If this Source object is used to process a stylesheet, normally
* setSystemId should also be called, so that relative URL references
* can be resolved.</p>
*
* @param inputStream A valid InputStream reference to an XML stream.
*
public void setInputStream(InputStream inputStream) {
this.inputStream = inputStream;
}
/**
* Get the byte stream that was set with setByteStream.
*
* @return The byte stream that was set with setByteStream, or null
* if setByteStream or the ByteStream constructor was not called.
*
public InputStream getInputStream() {
return inputStream;
}
private InputStream inputStream = null;
*/
/**
* Get the Result object associated with this XSLTResultTarget object .
*
* @return The Result object associated with this XSLTResultTarget object
*
*/
public Source getSourceObject()
{
if (streamSource != null)
return streamSource;
else if (domSource != null)
return domSource;
else
return saxSource;
}
}
1.1 xml-xalan/java/compat_src/org/apache/xalan/xslt/XSLTProcessor.java
Index: XSLTProcessor.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" 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 name, without prior written
* permission of the Apache Software Foundation.
*
* 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 and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.xslt;
import java.util.TooManyListenersException;
import java.util.Vector;
import org.apache.xpath.objects.XObject;
import org.apache.xpath.objects.XString;
import org.apache.xpath.objects.XNodeSet;
import org.apache.xpath.objects.XBoolean;
import org.apache.xpath.objects.XNumber;
import org.apache.xpath.objects.XNull;
import org.apache.xalan.xpath.xml.XMLParserLiaison;
import org.apache.xalan.xpath.xml.ProblemListener;
import org.apache.xalan.templates.Stylesheet;
//import org.apache.xalan.templates.StylesheetRoot;
//import org.apache.xalan.xslt.StylesheetSpec;
import org.apache.xalan.trace.*;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.xml.sax.DocumentHandler;
import org.xml.sax.SAXException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import org.apache.xml.serialize.OutputFormat;
import org.xml.sax.ext.LexicalHandler;
/**
* <meta name="usage" content="general"/>
* The transformation processor -- use {@link org.apache.xalan.xslt.XSLTProcessorFactory} to instantiate an implementation of this interface.
* It's the responsibility of the implementation (XSLTEngineImpl),
* collaborating with a XMLParserLiaison, the DOM,
* and the XPath engine, to transform a source tree
* of nodes into a result tree according to instructions
* and templates specified by a stylesheet tree.
* Use the <code>process(...)</code> are the primary
* public entry points.
*
* Look at the Process class main() method for
* for an advanced usage example.
*
* <p>If you reuse the processor instance, you should call reset() between transformations.</p>
*/
public interface XSLTProcessor extends DocumentHandler, LexicalHandler
{
/**
* Use the XSL stylesheet to transform the XML input, placing the result in the result tree.
* @param xmlSource The XML input to be transformed.
* @param xslStylesheet The XSL stylesheet to be used for the transformation. May be null if XML input
* has an XSL stylesheet PI.
* @param resultTree The tree where the result of the transformation is placed.
* @exception XSLProcessorException thrown if the active ProblemListener and XMLParserLiaison decide
* the error condition is severe enough to halt processing.
*/
public void process( XSLTInputSource xmlSource,
XSLTInputSource xslStylesheet,
XSLTResultTarget resultTree)
throws SAXException;
/**
* Compile the XSL stylesheet represented by an XSLTInputSource object into an internal representation,
* and use it to set the XSLTProcessor Stylesheet property.
* This operation is required if the XSLTProcessor is to function as a
* SAX DocumentHandler.
* If the Stylesheet property has already been set to non-null, this operation
* calls reset() before a transformation is performed.
*
* @param stylesheetSource The XSL stylesheet.
* @return The compiled stylesheet object.
* @exception XSLProcessorException thrown if the active ProblemListener and XMLParserLiaison decide
* the error condition is severe enough to halt processing.
*/
public StylesheetRoot processStylesheet(XSLTInputSource stylesheetSource)
throws SAXException;
/**
* Given a URL to (or file name of) an XSL stylesheet,
* Compile the stylesheet into an internal representation, and use it to
* set the XSLTProcessor Stylesheet property.
* This operation is required if the XSLTProcessor is to function as a
* SAX DocumentHandler.
* If the Stylesheet property has already been set to non-null, this operation
* calls reset() before a transformation is performed.
*
* @param xsldocURLString The URL to the XSL stylesheet.
* @return The compiled stylesheet object.
* @exception XSLProcessorException thrown if the active ProblemListener and XMLParserLiaison decide
* the error condition is severe enough to halt processing.
*/
public StylesheetRoot processStylesheet(String xsldocURLString)
throws SAXException;
/**
* Set the output stream. Required when the XSLTProcessor is being used
* as a SAX DocumentHandler.
*/
public void setOutputStream(java.io.OutputStream os);
/**
* Reset the XSLTProcessor state. Must be used after a process() call
* if the XSLTProcessor instance is to be used again.
*/
public void reset();
/**
* Get the DOM Node from the XSLTInputSource object. Returns null if the XSLTInputSource
* object does not contain a Node (it may, for example, contain an input stream).
*/
public Node getSourceTreeFromInput(XSLTInputSource inputSource)
throws org.xml.sax.SAXException;
/**
* Use a compiled stylesheet to set the Stylesheet property for this processor.
* When this property is set, the process method uses this stylesheet rather than
* looking for a stylesheet PI if the stylesheet parameter is null. Also required
* if you are going to use the XSLTProcessor as a SAX DocumentHandler.
*/
public void setStylesheet(StylesheetRoot stylesheetRoot);
/**
* Get the current Stylesheet setting for this XSLTProcessor.
*/
public StylesheetRoot getStylesheet();
/**
* Get the XMLParserLiaison that this processor uses.
*/
public XMLParserLiaison getXMLProcessorLiaison();
/**
* Get the preferred stylesheet for the XSLTInputSource XML document,
* as identified by the xml-stylesheet PI, and matching the media and
* charset criteria. See {@link http://www.w3.org/TR/xml-stylesheet/
* Associating Style Sheets with XML documents}
* Does not yet handle the LINK REL="stylesheet" syntax.
*
* @param media The media attribute to be matched. May be null, in which
* case the prefered stylesheet will be used (i.e., alternate = no).
* @param title The value of the title attribute to match. May be null.
* @param charset The value of the charset attribute to match. May be null.
* @returns StylesheetSpec extends XSLTInputSource extedns SAX InputSource; the return value
* can be passed to the processStylesheet method.
*/
public StylesheetSpec getAssociatedStylesheet(XSLTInputSource source,
String media,
String charset)
throws SAXException;
/**
* Get a list of stylesheet specifications for the XSLTInputSource XML document,
* as identified by the xml-stylesheet PI, and matching the media and
* charset criteria. See {@link http://www.w3.org/TR/xml-stylesheet/
* Associating Style Sheets with XML documents}.
* Does not yet handle the LINK REL="stylesheet" syntax.
*
* @param media The media attribute to be matched. May be null, in which
* case the prefered stylesheet will be used (i.e., alternate = no).
* @param title The value of the title attribute to match. May be null.
* @param charset The value of the charset attribute to match. May be null.
* @returns list of StylesheetSpecs (extend XSLTInputSources extend SAX InputSources; a
* list member may be passsed to the processStylesheet method.
*/
public Vector getAssociatedStylesheets(XSLTInputSource source,
String media,
String charset)
throws SAXException;
/**
* Convenience function to create an XString.
* @param s A valid string.
* @return An XString object.
*/
public XString createXString(String s);
/**
* Convenience function to create an XObject.
* @param o Any java object.
* @return An XObject object.
*/
public XObject createXObject(Object o);
/**
* Convenience function to create an XNumber.
* @param d Any double number.
* @return An XNumber object.
*/
public XNumber createXNumber(double d);
/**
* Convenience function to create an XBoolean.
* @param b boolean value.
* @return An XBoolean object.
*/
public XBoolean createXBoolean(boolean b);
/**
* Convenience function to create an XNodeSet.
* @param nl A NodeList object.
* @return An XNodeSet object.
*/
public XNodeSet createXNodeSet(NodeList nl);
/**
* Convenience function to create an XNodeSet from a node.
* @param n A DOM node.
* @return An XNodeSet object.
*/
public XNodeSet createXNodeSet(Node n);
/**
* Convenience function to create an XNull.
* @return An XNull object.
*/
public XNull createXNull();
/**
* Submit a top-level stylesheet parameter. This value can
* be evaluated in the stylesheet via xsl:param-variable.
* @param key The name of the param.
* @param value An XObject that will be used.
*/
public void setStylesheetParam(String key, XObject value);
/**
* Set a top-level stylesheet parameter. This value can
* be evaluated via xsl:param-variable. Note that the value
* passed is an expression, and not a string. This means that
* setStylesheetParam("foo", "hello"); will look for the
* element "hello". If you want to pass a string, you'll
* need to put quotes around it:
* setStylesheetParam("foo", "'hello'"); will look for the
* @param key The name of the param.
* @param expression An expression that will be evaluated.
*/
public void setStylesheetParam(String key, String expression);
/**
* Get the current FormatterListener (SAX DocumentHandler), or null if none has been set.
*/
public DocumentHandler getFormatterListener();
/**
* Set the FormatterListener (the SAX DocumentHandler).
*/
public void setFormatterListener(DocumentHandler flistener);
/**
* Get the current SAX DocumentHandler (the same object as the FormatterListener), or null if none has been set.
*/
public DocumentHandler getDocumentHandler();
/**
* Set the current SAX DocumentHandler (the same
* object as the FormatterListener).
*/
public void setDocumentHandler(DocumentHandler listener);
/**
* Add a trace listener for the purposes of debugging and diagnosis.
* @param tl Trace listener to be added.
*/
public void addTraceListener(TraceListener tl)
throws TooManyListenersException;
/**
* If set to true, template calls are traced.
*/
public void setTraceTemplates(boolean b);
/**
* If set to true, selection events are traced.
*/
public void setTraceSelect(boolean b);
/**
* If set to true (the default is false), as template children are being constructed, debug diagnostics
* are written to the m_diagnosticsPrintWriter
* stream.
*/
public void setTraceTemplateChildren(boolean b);
/**
* If set to true (the default), pattern conflict warnings are not printed to the diagnostics stream.
* @param b true if conflict warnings should be suppressed.
*/
public void setQuietConflictWarnings(boolean b);
/**
* Remove a trace listener.
* @param tl Trace listener to be removed.
*/
public void removeTraceListener(TraceListener tl);
/**
* If set, diagnostics will be
* written to the m_diagnosticsPrintWriter stream. If
* null, diagnostics are turned off. This convenience method calls
* {@link #setDiagnosticsOutput(java.io.PrintWriter)}.
*/
public void setDiagnosticsOutput(java.io.OutputStream out);
/**
* If set, diagnostics will be
* written to the m_diagnosticsPrintWriter stream. If
* null, diagnostics are turned off.
*/
public void setDiagnosticsOutput(java.io.PrintWriter pw);
/**
* Set the problem listener property.
* The XSL class can have a single listener to be informed
* of errors and warnings. The problem listener normally controls whether an exception
* is thrown or not (or the problem listeners can throw its own RuntimeException).
* @param l A ProblemListener interface.
*/
public void setProblemListener(ProblemListener l);
/**
* Get the problem listener property.
* The XSL class can have a single listener to be informed
* of errors and warnings. The problem listener normally controls whether an exception
* is thrown or not (or the problem listener can throw its own RuntimeException).
* @return A ProblemListener interface.
*/
public ProblemListener getProblemListener();
}
1.1 xml-xalan/java/compat_src/org/apache/xalan/xslt/XSLTProcessorFactory.java
Index: XSLTProcessorFactory.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" 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 name, without prior written
* permission of the Apache Software Foundation.
*
* 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 and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.xslt;
import org.apache.xalan.xpath.xml.XMLParserLiaison;
import org.apache.xpath.XPathFactory;
//import javax.xml.transform.Processor;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.Templates;
import org.apache.xml.utils.TreeWalker;
/**
* <meta name="usage" content="general"/>
* Manufactures the processor for performing transformations. Use one of the static getProcessor methods
* to create an XSLTProcessor object.
*/
public class XSLTProcessorFactory
{
/**
* Get a new XSLTProcessor with the default high-performance DTM (Document Table Model) liaison and XML parser.
* <p><b>Note</b> If you want to process DOM Node input, use {@link #getProcessorUsingLiaisonName
* getProcessorUsingLiaisonName("org.apache.xalan.xpath.xdom.XercesLiaison")}.</p>
* @return An implentation of the XSLTProcessor interface with which you can perform transformations.
* @see org.apache.xalan.xpath.dtm.DTMLiaison
*/
public static XSLTProcessor getProcessor()
throws org.xml.sax.SAXException
{
//Processor processor = Processor.newInstance("xslt");
return new XSLTEngineImpl();
}
/**
* Get a new XSLTProcessor that will use a given XMLParserLiaison class to interact with
* a given XML parser. You can use this method, for example, if you are processing DOM Node input with
* org.apache.xalan.xpath.xdom.XercesLiaison and the Xerces XML parser.
* <p>If your input is in the form of
* a file, character stream, byte stream, or SAX DocumentHandler, you may want to use the high-performance
* DTM liaison and parser, in which case you can use the no-argument constructor.</p>
* @param parserLiaisonClassName The name of the ParserLiaison class.
* @return An implentation of the XSLTProcessor interface with which you can perform transformations.
*
* @see #getProcessor()
* @see org.apache.xalan.xpath.xml.XMLParserLiaison
* @see org.apache.xalan.xpath.dtm.DTMLiaison
*/
public static XSLTProcessor getProcessorUsingLiaisonName(String parserLiaisonClassName)
throws org.xml.sax.SAXException
{
//return new XSLTEngineImpl(parserLiaisonClassName);
//Processor processor = Processor.newInstance("xslt");
return new XSLTEngineImpl();
}
/**
* Get a new XSLTProcessor that will use the specified XMLParserLiaison to interact
* with a given XML parser. If your input is in the form of
* a file, character stream, byte stream, or SAX DocumentHandler, you may want to use the high-performance
* DTM liaison and parser, in which case you can use the no-argument getProcessor() method.
*
* @param parserLiaison the XMLParserLiaison set up to interact with a given XML parser.
* @return An implentation of the XSLTProcessor interface with which you can perform transformations.
*
* @see #getProcessor()
* @see org.apache.xalan.xpath.xml.XMLParserLiaison
* @see org.apache.xalan.xpath.dtm.DTMLiaison
*/
public static XSLTProcessor getProcessor(XMLParserLiaison parserLiaison)
{
//return new XSLTEngineImpl(parserLiaison);
try{
//Processor processor = Processor.newInstance("xslt");
return new XSLTEngineImpl();
}
/* catch (TransformerConfigurationException tce)
{
return null;
}*/
catch (org.xml.sax.SAXException e)
{
return null;
}
}
/**
* Get a new XSLTProcessor that will use the specified XMLParserLiaison and XPathFactory to interact
* with a given XML parser. If your input is in the form of
* a file, character stream, byte stream, or SAX DocumentHandler, you may want to use the high-performance
* DTM liaison and parser, in which case you can use the no-argument getProcessor() method.
*
* @param parserLiaison the XMLParserLiaison set up to interact with a given XML parser.
* @param xpathFactory A custom XPathFactory.
* @return An implentation of the XSLTProcessor interface with which you
* can perform transformations.
*
* @see #getProcessor()
* @see org.apache.xalan.xpath.xml.XMLParserLiaison
* @see org.apache.xalan.xpath.dtm.DTMLiaison
*/
public static XSLTProcessor getProcessor(XMLParserLiaison parserLiaison,
XPathFactory xpathFactory)
{
//return new XSLTEngineImpl(parserLiaison, xpathFactory);
try{
//Processor processor = Processor.newInstance("xslt");
return new XSLTEngineImpl();
}
/* catch (TransformerConfigurationException pe)
{
return null;
}*/
catch (org.xml.sax.SAXException e)
{
return null;
}
}
}
1.1 xml-xalan/java/compat_src/org/apache/xalan/xslt/XSLTResultTarget.java
Index: XSLTResultTarget.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" 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 name, without prior written
* permission of the Apache Software Foundation.
*
* 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 and was
* originally based on software copyright (c) 1999, Lotus
* Development Corporation., http://www.lotus.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.xslt;
import org.w3c.dom.Node;
import java.io.OutputStream;
import java.io.Writer;
import org.xml.sax.DocumentHandler;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.ParserAdapter;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.sax.SAXResult;
/**
* <meta name="usage" content="general"/>
* Contains the result of a transformation that you perform with the
* XSLTProcessor process() method or one of the StylesheetRoot process() methods.
* Create an instance of this class to provide the process() method a container
* for the transformation result tree.
* You can use a file name or URL, character stream, byte stream, DOM Node, or SAX DocumentHandler
* to instantiate an XSLTResultTarget object.
*
* @see XSLTProcessor#process(XSLTInputSource, XSLTInputSource, XSLTResultTarget)
* @see StylesheetRoot
*/
public class XSLTResultTarget //implements Result //extends StreamResult
{
private StreamResult sr = null;
private DOMResult saxResult = null;
private DOMResult dr = null;
/**
* Zero-argument default constructor -- Before you can use the new XSLTResultTarget object in a transformation,
* you must define the output container by setting its FileName, CharacterStrea, ByteStream, or Node property.
*
* @see #setFileName(String)
* @see #setCharacterStream(Writer)
* @see #setByteStream(OutputStream)
* @see #setNode(Node)
* @see #setDocumentHandler(DocumentHandler)
* @see #setEncoding(String)
*/
public XSLTResultTarget ()
{
sr = new StreamResult();
}
/**
* Create a new output target with a file name -- the equivalent of creating an output target
* with the zero-argument constructor and setting the new object's FileName property.
*
* @param fileName Identifies the file that will contain the transformation result (must be a valid system file name).
*
* @see #setFileName(String)
* @see #setCharacterStream(Writer)
* @see #setByteStream(OutputStream)
* @see #setNode(Node)
* @see #setDocumentHandler(DocumentHandler)
* @see #setEncoding(String)
*/
public XSLTResultTarget (String fileName) // File?
{
sr = new StreamResult();
sr.setSystemId(fileName);
}
/**
* Create a new output target with a byte stream -- the equivalent of creating an output target
* with the zero-argument constructor and setting the new object's ByteStream property.
*
* @param byteStream The raw byte stream that will contain the transformation result.
*
* @see #setByteStream(OutputStream)
* @see #setFileName(String)
* @see #setCharacterStream(Writer)
* @see #setNode(Node)
* @see #setDocumentHandler(DocumentHandler)
* @see #setEncoding(String)
*/
public XSLTResultTarget (OutputStream byteStream)
{
sr = new StreamResult();
sr.setOutputStream(byteStream);
}
/**
* Create a new output target with a character stream -- the equivalent of creating an output target
* with the zero-argument constructor and setting the new object's CharacterStream property.
*
* @param characterStream The character stream where the transformation result is written.
*
* @see #setCharacterStream(Writer)
* @see #setByteStream(OutputStream)
* @see #setFileName(String)
* @see #setNode(Node)
* @see #setDocumentHandler(DocumentHandler)
* @see #setEncoding(String)
*/
public XSLTResultTarget (Writer characterStream)
{
sr = new StreamResult();
sr.setWriter(characterStream);
}
/**
* Create a new output target with a DOM Node -- the equivalent of creating an output target
* with the zero-argument constructor and setting the new object's Node property.
*
* @param node The DOM Node that will contain the transformation result.
*
* @see #setNode(Node)
* @see #setCharacterStream(Writer)
* @see #setByteStream(OutputStream)
* @see #setFileName(String)
* @see #setDocumentHandler(DocumentHandler)
* @see #setEncoding(String)
*/
public XSLTResultTarget (Node n)
{
dr = new DOMResult();
dr.setNode(n);
}
/**
* Create a new output target with a SAX Document handler, which
* will handle result events -- the equivalent of creating an output target with the
* zero-argument constructor and setting the new object's DocyumentHandler property.
*
* @param handler The SAX Document handler to which the result is written.
*
* @see #setDocumentHandler(DocumentHandler)
* @see #setNode(Node)
* @see #setCharacterStream(Writer)
* @see #setByteStream(OutputStream)
* @see #setFileName(String)
* @see #setEncoding(String)
*/
public XSLTResultTarget(DocumentHandler handler)
{
SAXResult saxResult = new SAXResult();
if (handler instanceof ParserAdapter)
saxResult.setHandler(((ParserAdapter)handler).getContentHandler());
setDocumentHandler(handler);
}
/**
* Set the file name or URL where the transformation result will be written.
*
* @param fileName The system identifier as a string.
*
* @see #XSLTResultTarget(String)
* @see #getFileName
*
public void setFileName (String fileName) // File?
{
this.fileName = fileName;
}
/**
* Get the file name where the results are or will be written, or null if none was supplied.
*
* @return The file name or URL.
*
* @see #XSLTResultTarget(String)
* @see #setFileName(String)
*/
public String getFileName ()
{
if (sr != null)
return sr.getSystemId();
else
return null;
}
/**
* Set the character encoding, if known.
*
* @param encoding The character encoding.
*/
public void setEncoding (String encoding)
{
this.encoding = encoding;
}
/**
* Get the character encoding that was used.
*
* @return The encoding, or null if none was supplied.
*/
public String getEncoding ()
{
return encoding;
}
private String encoding;
/**
* Set a SAX DocumentHandler to process the result tree events.
* You can process events as they occur
* rather than waiting for the transformation to be completed.
*
* @param handler The SAX DocumentHandler to process result tree events.
*
* @see #XSLTResultTarget(DocumentHandler)
* @see #getDocumentHandler()
*/
public void setDocumentHandler (DocumentHandler handler)
{
this.formatterListener = handler;
}
/**
* Get the SAX DocumentHandler that processes the result tree events.
* You can use the DocumentHandler to process events as they occur
* rather than waiting for the transformation to be completed.
*
* @return The SAX DocumentHandler that processes result tree events.
*
* @see #XSLTResultTarget(DocumentHandler)
* @see #setDocumentHandler(DocumentHandler)
*/
public DocumentHandler getDocumentHandler ()
{
return formatterListener;
}
private DocumentHandler formatterListener = null;
/**
* Set the node that will contain the result DOM tree. In practice,
* the node should be a {@link org.w3c.dom.Document} node,
* a {@link org.w3c.dom.DocumentFragment} node, or a
* {@link org.w3c.dom.Element} node. In other words, a node
* that accepts children.
*
* @param node The node to which the transformation
* will be appended.
*/
public void setNode(Node node) {
if (dr == null)
dr = new DOMResult();
dr.setNode(node);
}
/**
* Get the node that will contain the result DOM tree.
* If no node was set via setNode, the node will be
* set by the transformation, and may be obtained from
* this method once the transformation is complete.
*
* @return The node to which the transformation
* will be appended.
*/
public Node getNode() {
if (dr != null)
return dr.getNode();
else
return null;
}
/**
* Set the node that will contain the result DOM tree. In practice,
* the node should be a {@link org.w3c.dom.Document} node,
* a {@link org.w3c.dom.DocumentFragment} node, or a
* {@link org.w3c.dom.Element} node. In other words, a node
* that accepts children.
*
* @param node The node to which the transformation
* will be appended.
*
public void setByteStream(OutputStream byteStrm) {
this.byteStream = byteStrm;
}
/**
* Get the node that will contain the result DOM tree.
* If no node was set via setNode, the node will be
* set by the transformation, and may be obtained from
* this method once the transformation is complete.
*
* @return The node to which the transformation
* will be appended.
*/
public OutputStream getByteStream() {
if (sr != null)
return sr.getOutputStream();
else
return null;
}
/**
* Set the system identifier for this Result.
*
* <p>If the Result is not to be written to a file, the system identifier is optional.
* The application may still want to provide one, however, for use in error messages
* and warnings, or to resolve relative output identifiers.</p>
*
* @param systemId The system identifier as a URI string.
*
public void setSystemId(String systemID)
{
systemId = systemID;
}
/**
* Get the system identifier that was set with setSystemId.
*
* @return The system identifier that was set with setSystemId,
* or null if setSystemId was not called.
*
public String getSystemId()
{
return systemId;
}
/**
* Set the writer that is to receive the result. Normally,
* a stream should be used rather than a writer, so that
* the transformer may use instructions contained in the
* transformation instructions to control the encoding. However,
* there are times when it is useful to write to a writer,
* such as when using a StringWriter.
*
* @param writer A valid Writer reference.
*
public void setWriter(Writer writer) {
this.characterStream = writer;
}
/**
* Get the character stream that was set with setWriter.
*
* @return The character stream that was set with setWriter, or null
* if setWriter or the Writer constructor was not called.
*/
public Writer getCharacterStream() {
if (sr != null)
return sr.getWriter();
else
return null;
}
//////////////////////////////////////////////////////////////////////
// Internal state.
//////////////////////////////////////////////////////////////////////
/*
private String fileName;
private OutputStream byteStream;
private Writer characterStream;
private Node node;
private String systemId;
*/
/**
* Get the Result object associated with this XSLTResultTarget object .
*
* @return The Result object associated with this XSLTResultTarget object
*
*/
public Result getResultObject()
{
if (sr != null)
return sr;
else if (dr != null)
return dr;
else
return saxResult;
}
}