sboag 00/10/02 16:42:34
Modified: java/src/org/apache/xalan/processor ProcessorLRE.java
ProcessorTemplateElem.java
java/src/org/apache/xalan/templates
OutputFormatExtended.java StylesheetRoot.java
java/src/org/apache/xalan/transformer ResultTreeHandler.java
TransformerImpl.java
Log:
Fixes for Literal Result Element as Stylesheet, and for general HTML handling
and defaults.
Revision Changes Path
1.4 +28 -1
xml-xalan/java/src/org/apache/xalan/processor/ProcessorLRE.java
Index: ProcessorLRE.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/processor/ProcessorLRE.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ProcessorLRE.java 2000/08/08 00:27:21 1.3
+++ ProcessorLRE.java 2000/10/02 23:42:33 1.4
@@ -60,6 +60,9 @@
import org.apache.xalan.templates.ElemTemplateElement;
import org.apache.xalan.templates.Stylesheet;
import org.apache.xalan.templates.ElemExtensionCall;
+import org.apache.xalan.templates.ElemTemplate;
+import org.apache.xpath.XPath;
+import org.apache.xalan.templates.StylesheetRoot;
import org.xml.sax.SAXException;
import org.xml.sax.Attributes;
@@ -79,11 +82,35 @@
String rawName, Attributes attributes)
throws SAXException
{
+ ElemTemplateElement p = handler.getElemTemplateElement();
+ if(null == p)
+ {
+ // Literal Result Template as stylesheet.
+ Stylesheet stylesheet = new StylesheetRoot();
+ // stylesheet.setDOMBackPointer(handler.getOriginatingNode());
+ stylesheet.setLocaterInfo(new org.xml.sax.helpers.LocatorImpl());
+ stylesheet.setPrefixes(handler.getNamespaceSupport());
+
+ handler.pushStylesheet(stylesheet);
+
+ setPropertiesFromAttributes(handler, "stylesheet", attributes,
stylesheet);
+
+ handler.pushElemTemplateElement(stylesheet);
+
+ ElemTemplate template = new ElemTemplate();
+ appendAndPush(handler, template);
+
+ XPath rootMatch = new XPath("/", stylesheet, stylesheet, XPath.MATCH);
+ template.setMatch(rootMatch);
+ // template.setDOMBackPointer(handler.getOriginatingNode());
+ stylesheet.setTemplate(template);
+ p = handler.getElemTemplateElement();
+ }
+
XSLTElementDef def = getElemDef();
Class classObject = def.getClassObject();
boolean isExtension = false;
- ElemTemplateElement p = handler.getElemTemplateElement();
while(null != p)
{
// System.out.println("Checking: "+p);
1.3 +2 -0
xml-xalan/java/src/org/apache/xalan/processor/ProcessorTemplateElem.java
Index: ProcessorTemplateElem.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/processor/ProcessorTemplateElem.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ProcessorTemplateElem.java 2000/08/08 00:27:22 1.2
+++ ProcessorTemplateElem.java 2000/10/02 23:42:33 1.3
@@ -87,6 +87,8 @@
String rawName, Attributes attributes)
throws SAXException
{
+ ElemTemplateElement parent = handler.getElemTemplateElement();
+
XSLTElementDef def = getElemDef();
Class classObject = def.getClassObject();
1.6 +105 -97
xml-xalan/java/src/org/apache/xalan/templates/OutputFormatExtended.java
Index: OutputFormatExtended.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/OutputFormatExtended.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- OutputFormatExtended.java 2000/10/02 02:43:07 1.5
+++ OutputFormatExtended.java 2000/10/02 23:42:33 1.6
@@ -79,8 +79,6 @@
public boolean methodHasBeenSet() { return m_methodHasBeenSet; }
private boolean m_versionHasBeenSet = false;
public boolean versionHasBeenSet() { return m_versionHasBeenSet; }
- private boolean m_indentingHasBeenSet = false;
- public boolean indentingHasBeenSet() { return m_indentingHasBeenSet; }
private boolean m_indentHasBeenSet = false;
public boolean indentHasBeenSet() { return m_indentHasBeenSet; }
private boolean m_encodingHasBeenSet = false;
@@ -109,65 +107,85 @@
m_shouldRecordHasBeenSet = true;
setPreserveSpace(true);
}
-
- /**
- * Constructs a new output format with the default values for
- * the specified method and encoding. If <tt>indent</tt>
- * is true, the document will be pretty printed with the default
- * indentation level and default line wrapping.
- *
- * @param method The specified output method
- * @param encoding The specified encoding
- * @param indenting True for pretty printing
- * @see #setEncoding
- * @see #setIndenting
- * @see #setMethod
- */
- public OutputFormatExtended( String method, String encoding, boolean
indenting )
- {
- // super(method, encoding, indenting);
- if(null != method)
- super.setMethod(method);
- if(null != encoding)
- super.setEncoding(encoding);
- super.setIndent(indenting);
- m_shouldRecordHasBeenSet = true;
+
+ void copyFrom(OutputFormatExtended of)
+ {
+ setPreserveSpace(true);
+ if(of.methodHasBeenSet())
+ setMethod(of.getMethod());
+ else
+ super.setMethod(of.getMethod());
+ if(of.cdataElementsHasBeenSet())
+ setCDataElements(of.getCDataElements());
+ else
+ super.setCDataElements(of.getCDataElements());
+ if(of.doctypePublicHasBeenSet())
+ setDoctypePublicId(of.getDoctypePublicId());
+ else
+ super.setDoctypePublicId(of.getDoctypePublicId());
+
+ if(of.doctypeSystemHasBeenSet())
+ setDoctypeSystemId(of.getDoctypeSystemId());
+ else
+ super.setDoctypeSystemId(of.getDoctypeSystemId());
+ if(of.encodingHasBeenSet())
+ setEncoding(of.getEncoding());
+ else
+ super.setEncoding(of.getEncoding());
+ boolean indent = of.getIndent();
+ if(of.indentHasBeenSet())
+ {
+ setIndent(indent);
+ setPreserveSpace(!indent);
+ }
+ else
+ {
+ super.setIndent(indent);
+ super.setPreserveSpace(!indent);
+ }
+ if(of.mediaTypeHasBeenSet())
+ setMediaType(of.getMediaType());
+ else
+ super.setMediaType(of.getMediaType());
+ if(of.nonEscapingElementsHasBeenSet())
+ setNonEscapingElements(of.getNonEscapingElements());
+ else
+ super.setNonEscapingElements(of.getNonEscapingElements());
+ if(of.omitXmlDeclarationHasBeenSet())
+ setOmitXMLDeclaration(of.getOmitXMLDeclaration());
+ else
+ super.setOmitXMLDeclaration(of.getOmitXMLDeclaration());
+ if(of.standaloneHasBeenSet())
+ setStandalone(of.getStandalone());
+ else
+ super.setStandalone(of.getStandalone());
+ if(of.versionHasBeenSet())
+ setVersion(of.getVersion());
+ else
+ super.setVersion(of.getVersion());
+ }
+
+ void copyFrom(OutputFormat of)
+ {
+ setPreserveSpace(true);
+ setCDataElements(of.getCDataElements());
+ setDoctypePublicId(of.getDoctypePublicId());
+ // setDoctype(of.getDoctypePublic(), of.getDoctypeSystem());
+ setEncoding(of.getEncoding());
+ // System.out.println("getOutputFormat - of.getIndent(): "+
of.getIndent());
+ // setIndent(of.getIndent());
+ setIndent(of.getIndent());
+ // setLineSeparator(of.getLineSeparator());
+ // setLineWidth(of.getLineWidth());
+ setMediaType(of.getMediaType());
+ setMethod(of.getMethod());
+ setNonEscapingElements(of.getNonEscapingElements());
+ setOmitXMLDeclaration(of.getOmitXMLDeclaration());
+ setPreserveSpace(of.getPreserveSpace());
+ setStandalone(of.getStandalone());
+ setVersion(of.getVersion());
}
- /*
- * Constructs a new output format with the proper method,
- * document type identifiers and media type for the specified
- * document.
- *
- * @param doc The document to output
- * @see #whichMethod
- */
- // public OutputFormatExtended( Document doc )
- // {
- // super(doc);
- // super();
- // m_shouldRecordHasBeenSet = true;
- // }
-
- /**
- * Constructs a new output format with the proper method,
- * document type identifiers and media type for the specified
- * document, and with the specified encoding. If <tt>indent</tt>
- * is true, the document will be pretty printed with the default
- * indentation level and default line wrapping.
- *
- * @param doc The document to output
- * @param encoding The specified encoding
- * @param indenting True for pretty printing
- * @see #setEncoding
- * @see #setIndenting
- * @see #whichMethod
- */
- // public OutputFormatExtended( Document doc, String encoding, boolean
indenting )
- // {
- // super(doc, encoding, indenting);
- // m_shouldRecordHasBeenSet = true;
- // }
/**
* The doctype-public attribute.
@@ -235,9 +253,21 @@
*/
public void setMethod( String method )
{
+ // System.out.println("Setting the method to: "+method);
if(m_shouldRecordHasBeenSet)
m_methodHasBeenSet = true;
- super.setMethod(method);;
+ super.setMethod(method);
+
+ if((null != method) && method.equalsIgnoreCase("html"))
+ {
+ // System.out.println("m_indentHasBeenSet: "+m_indentHasBeenSet);
+ if(!this.m_indentHasBeenSet)
+ {
+ // System.out.println("Setting indent to true");
+ setIndent(true);
+ this.m_indentHasBeenSet = false;
+ }
+ }
}
/**
@@ -253,6 +283,17 @@
// TODO: Work with Assaf on this.
String meth = method.getLocalPart();
super.setMethod(meth);;
+ if((null != method) && (method.getNamespaceURI() == null)
+ && method.getLocalName().equalsIgnoreCase("html"))
+ {
+ // System.out.println("m_indentHasBeenSet: "+m_indentHasBeenSet);
+ if(!this.m_indentHasBeenSet)
+ {
+ // System.out.println("Setting indent to true");
+ setIndent(true);
+ this.m_indentHasBeenSet = false;
+ }
+ }
}
/**
@@ -288,45 +329,12 @@
*/
public void setIndent( boolean indent )
{
- // System.out.println("setIndent( "+indent+" )");
- // setPreserveSpace(false);
- setIndent(indent);
- }
-
- /**
- * Sets the indentation amount. The document will not be
- * indented if the indentation is set to zero.
- * Calling [EMAIL PROTECTED] #setIndenting} will reset this
- * value to zero (off) or the default (on).
- *
- * @param indent The indentation, or zero
- */
- public void setIndent( int indent )
- {
- // System.out.println("setIndent( int indent )");
if(m_shouldRecordHasBeenSet)
m_indentHasBeenSet = true;
- // For the moment, there doesn't seem to be a way
- // to set the indenting amount.
- // super.setIndent(indent);
- }
-
- /**
- * Sets the indentation on and off. When set on, the default
- * indentation level and default line wrapping is used
- * (see [EMAIL PROTECTED] #DEFAULT_INDENT} and [EMAIL PROTECTED]
#DEFAULT_LINE_WIDTH}).
- * To specify a different indentation level or line wrapping,
- * use [EMAIL PROTECTED] #setIndent} and [EMAIL PROTECTED] #setLineWidth}.
- *
- * @param on True if indentation should be on
- */
- public void setIndenting( boolean on )
- {
- // System.out.println("setIndenting( "+on+" ), m_shouldRecordHasBeenSet:
"+m_shouldRecordHasBeenSet);
- if(m_shouldRecordHasBeenSet)
- m_indentingHasBeenSet = true;
- setPreserveSpace(!on);
- super.setIndent(on);
+
+ // System.out.println("setIndent( "+indent+" )");
+ setPreserveSpace(!indent);
+ super.setIndent(indent);
}
/**
1.9 +11 -50
xml-xalan/java/src/org/apache/xalan/templates/StylesheetRoot.java
Index: StylesheetRoot.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/StylesheetRoot.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- StylesheetRoot.java 2000/10/02 02:43:07 1.8
+++ StylesheetRoot.java 2000/10/02 23:42:33 1.9
@@ -149,24 +149,15 @@
*/
public OutputFormat getOutputFormat()
{
- OutputFormat cloned = new OutputFormatExtended();
- cloned.setPreserveSpace(true);
- cloned.setCDataElements(m_outputFormatComposed.getCDataElements());
- cloned.setDoctypePublicId(m_outputFormatComposed.getDoctypePublicId());
- // cloned.setDoctype(m_outputFormatComposed.getDoctypePublic(),
m_outputFormatComposed.getDoctypeSystem());
- cloned.setEncoding(m_outputFormatComposed.getEncoding());
- // System.out.println("getOutputFormat -
m_outputFormatComposed.getIndent(): "+ m_outputFormatComposed.getIndent());
- // cloned.setIndent(m_outputFormatComposed.getIndent());
- cloned.setIndent(m_outputFormatComposed.getIndent());
- // cloned.setLineSeparator(m_outputFormatComposed.getLineSeparator());
- // cloned.setLineWidth(m_outputFormatComposed.getLineWidth());
- cloned.setMediaType(m_outputFormatComposed.getMediaType());
- cloned.setMethod(m_outputFormatComposed.getMethod());
-
cloned.setNonEscapingElements(m_outputFormatComposed.getNonEscapingElements());
-
cloned.setOmitXMLDeclaration(m_outputFormatComposed.getOmitXMLDeclaration());
- cloned.setPreserveSpace(m_outputFormatComposed.getPreserveSpace());
- cloned.setStandalone(m_outputFormatComposed.getStandalone());
- cloned.setVersion(m_outputFormatComposed.getVersion());
+ OutputFormatExtended cloned = new OutputFormatExtended();
+ if(m_outputFormatComposed instanceof OutputFormatExtended)
+ {
+ cloned.copyFrom((OutputFormatExtended)m_outputFormatComposed);
+ }
+ else
+ {
+ cloned.copyFrom(m_outputFormatComposed);
+ }
return cloned;
}
@@ -241,7 +232,7 @@
public void recomposeOutput()
{
// System.out.println("Recomposing output...");
- m_outputFormatComposed = new OutputFormat();
+ m_outputFormatComposed = new OutputFormatExtended();
m_outputFormatComposed.setPreserveSpace(true);
recomposeOutput(this);
}
@@ -276,37 +267,7 @@
OutputFormatExtended of = getOutput();
if(null != of)
{
- // System.out.println("Composing output - of.indentHasBeenSet(): "
- // + of.indentHasBeenSet()+",
of.indentingHasBeenSet(): "
- // + of.indentingHasBeenSet());
- if(of.cdataElementsHasBeenSet())
- m_outputFormatComposed.setCDataElements(of.getCDataElements());
- if(of.doctypePublicHasBeenSet())
- m_outputFormatComposed.setDoctypePublicId(of.getDoctypePublicId());
- if(of.doctypeSystemHasBeenSet())
- m_outputFormatComposed.setDoctypePublicId(of.getDoctypeSystemId());
- if(of.encodingHasBeenSet())
- m_outputFormatComposed.setEncoding(of.getEncoding());
- if(of.indentHasBeenSet())
- m_outputFormatComposed.setIndent(of.getIndent());
- if(of.indentingHasBeenSet())
- {
- boolean indent = of.getIndent();
- m_outputFormatComposed.setIndent(indent);
- m_outputFormatComposed.setPreserveSpace(!indent);
- }
- if(of.mediaTypeHasBeenSet())
- m_outputFormatComposed.setMediaType(of.getMediaType());
- if(of.methodHasBeenSet())
- m_outputFormatComposed.setMethod(of.getMethod());
- if(of.nonEscapingElementsHasBeenSet())
-
m_outputFormatComposed.setNonEscapingElements(of.getNonEscapingElements());
- if(of.omitXmlDeclarationHasBeenSet())
-
m_outputFormatComposed.setOmitXMLDeclaration(of.getOmitXMLDeclaration());
- if(of.standaloneHasBeenSet())
- m_outputFormatComposed.setStandalone(of.getStandalone());
- if(of.versionHasBeenSet())
- m_outputFormatComposed.setVersion(of.getVersion());
+ ((OutputFormatExtended)m_outputFormatComposed).copyFrom(of);
}
}
1.12 +33 -8
xml-xalan/java/src/org/apache/xalan/transformer/ResultTreeHandler.java
Index: ResultTreeHandler.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/ResultTreeHandler.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ResultTreeHandler.java 2000/10/02 02:43:08 1.11
+++ ResultTreeHandler.java 2000/10/02 23:42:34 1.12
@@ -59,6 +59,8 @@
import org.w3c.dom.*;
import java.util.Stack;
import java.util.Enumeration;
+import java.io.Writer;
+import java.io.OutputStream;
import org.xml.sax.ContentHandler;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.Locator;
@@ -76,6 +78,7 @@
import org.apache.xalan.templates.Stylesheet;
import org.apache.xalan.templates.StylesheetRoot;
import org.apache.xalan.templates.ElemTemplateElement;
+import org.apache.xalan.templates.OutputFormatExtended;
import serialize.SerializerFactory;
import serialize.OutputFormat;
import serialize.Method;
@@ -84,6 +87,7 @@
import org.apache.xpath.XPathContext;
import org.apache.xpath.DOMHelper;
import serialize.SerializerHandler;
+import serialize.Serializer;
/**
* This class is a layer between the direct calls to the result
@@ -310,20 +314,41 @@
public void flushPending()
throws SAXException
{
- if(m_pendingStartDoc && (null != m_pendingElementName))
+ // The stylesheet is set at a rather late stage, so I do
+ // this here, though it would probably be better done elsewhere.
+ if((null == m_stylesheetRoot) && (null != m_transformer))
+ m_stylesheetRoot = m_transformer.getStylesheet();
+
+ if(!m_foundStartDoc && (null != m_pendingElementName))
{
- if(null != m_stylesheetRoot && !m_stylesheetRoot.isOutputMethodSet())
+ if(null != m_stylesheetRoot && !m_stylesheetRoot.isOutputMethodSet())
{
if(m_pendingElementName.equalsIgnoreCase("html")
&& (null == m_nsSupport.getURI("")))
{
- // System.out.println("Setting the method automatically to HTML");
-
- /* TBD: I don't think this works yet? */
- // SerializerFactory factory =
SerializerFactory.getSerializerFactory(Method.HTML);
OutputFormat oformat = m_stylesheetRoot.getOutputFormat();
oformat.setMethod(Method.HTML);
- // m_flistener =
factory.makeSerializer(oformat).asContentHandler();
+ try
+ {
+ Serializer oldSerializer = m_transformer.getSerializer();
+ Serializer serializer = SerializerFactory.getSerializer(oformat);
+ Writer writer = oldSerializer.getWriter();
+ if(null != writer)
+ serializer.setWriter(writer);
+ else
+ {
+ OutputStream os = serializer.getOutputStream();
+ serializer.setOutputStream(os);
+ }
+ m_transformer.setSerializer(serializer);
+ ContentHandler ch = serializer.asContentHandler();
+ m_transformer.setContentHandler(ch);
+ m_contentHandler = ch;
+ }
+ catch(java.io.IOException e)
+ {
+ throw new SAXException(e);
+ }
}
}
}
@@ -1013,7 +1038,7 @@
* The root of a linked set of stylesheets.
*/
private StylesheetRoot m_stylesheetRoot = null;
-
+
/**
* This is used whenever a unique namespace is needed.
*/
1.22 +16 -3
xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java
Index: TransformerImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- TransformerImpl.java 2000/10/02 02:43:08 1.21
+++ TransformerImpl.java 2000/10/02 23:42:34 1.22
@@ -482,7 +482,8 @@
/**
* Create a ContentHandler from a Result object.
*/
- public ContentHandler createResultContentHandler(Result outputTarget,
OutputFormat format)
+ public ContentHandler createResultContentHandler(Result outputTarget,
+ OutputFormat format)
throws TransformException
{
ContentHandler handler;
@@ -511,14 +512,13 @@
try
{
- // System.out.println("createResultContentHandler --
format.getIndenting: "
- // +format.getIndenting());
Serializer serializer = SerializerFactory.getSerializer(format);
if(null != outputTarget.getCharacterStream())
serializer.setWriter(outputTarget.getCharacterStream());
else
serializer.setOutputStream(outputTarget.getByteStream());
handler = serializer.asContentHandler();
+ this.setSerializer(serializer);
}
catch(UnsupportedEncodingException uee)
{
@@ -668,6 +668,19 @@
m_outputFormat;
return format;
}
+
+ private Serializer m_serializer;
+
+ public Serializer getSerializer()
+ {
+ return m_serializer;
+ }
+
+ public void setSerializer(Serializer s)
+ {
+ m_serializer = s;;
+ }
+
/**
* Set a parameter for the templates.