You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sa...@apache.org on 2002/06/18 17:12:41 UTC
cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output StreamUnknownOutput.java
santiagopg 2002/06/18 08:12:41
Modified: java/src/org/apache/xalan/xsltc/compiler Parser.java
java/src/org/apache/xalan/xsltc/runtime/output
StreamUnknownOutput.java
Log:
Added support for XHTML in output system (c.f. embed04).
Revision Changes Path
1.48 +6 -2 xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java
Index: Parser.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Parser.java,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -r1.47 -r1.48
--- Parser.java 18 Jun 2002 13:04:12 -0000 1.47
+++ Parser.java 18 Jun 2002 15:12:41 -0000 1.48
@@ -383,7 +383,11 @@
stylesheet.setSimplified();
stylesheet.addElement(element);
stylesheet.setAttributes(element.getAttributes());
- element.addPrefixMapping(EMPTYSTRING, EMPTYSTRING);
+
+ // Map the default NS if not already defined
+ if (element.lookupNamespace(EMPTYSTRING) == null) {
+ element.addPrefixMapping(EMPTYSTRING, EMPTYSTRING);
+ }
}
stylesheet.setParser(this);
return stylesheet;
1.4 +139 -34 xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamUnknownOutput.java
Index: StreamUnknownOutput.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamUnknownOutput.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- StreamUnknownOutput.java 11 Jun 2002 20:11:18 -0000 1.3
+++ StreamUnknownOutput.java 18 Jun 2002 15:12:41 -0000 1.4
@@ -63,9 +63,7 @@
package org.apache.xalan.xsltc.runtime.output;
-import java.util.Stack;
-import java.util.HashSet;
-import java.util.Iterator;
+import java.util.ArrayList;
import java.io.Writer;
import java.io.IOException;
@@ -80,7 +78,24 @@
public class StreamUnknownOutput extends StreamOutput {
private StreamOutput _handler;
- private boolean _callStartDocument = false;
+ private boolean _callStartDocument = false;
+
+ private boolean _isHtmlOutput = false;
+ private boolean _firstTagOpen = false;
+ private boolean _firstElement = true;
+ private String _firstTagPrefix, _firstTag;
+
+ private ArrayList _attributes = null;
+ private ArrayList _namespaces = null;
+
+ static class Pair {
+ public String name, value;
+
+ public Pair(String name, String value) {
+ this.name = name;
+ this.value = value;
+ }
+ }
public StreamUnknownOutput(Writer writer, String encoding) {
super(writer, encoding);
@@ -96,68 +111,144 @@
// System.out.println("StreamUnknownOutput.<init>");
}
- public void startDocument() throws TransletException {
+ public void startDocument()
+ throws TransletException
+ {
_callStartDocument = true;
}
- public void endDocument() throws TransletException {
- if (_callStartDocument) {
+ public void endDocument()
+ throws TransletException
+ {
+ if (_firstTagOpen) {
+ initStreamOutput();
+ }
+ else if (_callStartDocument) {
_handler.startDocument();
}
_handler.endDocument();
}
- public void startElement(String elementName) throws TransletException {
+ public void startElement(String elementName)
+ throws TransletException
+ {
+// System.out.println("startElement() = " + elementName);
if (_firstElement) {
- // If first element is HTML, create a new handler
- if (elementName.equalsIgnoreCase("html")) {
- _handler = new StreamHTMLOutput(_handler);
- }
- if (_callStartDocument) {
- _handler.startDocument();
- _callStartDocument = false;
- }
_firstElement = false;
+
+ _firstTag = elementName;
+ _firstTagPrefix = BasisLibrary.getPrefix(elementName);
+ if (_firstTagPrefix == null) {
+ _firstTagPrefix = EMPTYSTRING;
+ }
+
+ _firstTagOpen = true;
+ _isHtmlOutput = BasisLibrary.getLocalName(elementName)
+ .equalsIgnoreCase("html");
+ }
+ else {
+ if (_firstTagOpen) {
+ initStreamOutput();
+ }
+ _handler.startElement(elementName);
}
- _handler.startElement(elementName);
}
public void endElement(String elementName)
throws TransletException
{
+ if (_firstTagOpen) {
+ initStreamOutput();
+ }
_handler.endElement(elementName);
}
public void characters(String characters)
throws TransletException
{
+ if (_firstTagOpen) {
+ initStreamOutput();
+ }
_handler.characters(characters);
}
public void characters(char[] characters, int offset, int length)
throws TransletException
{
+ if (_firstTagOpen) {
+ initStreamOutput();
+ }
_handler.characters(characters, offset, length);
}
public void attribute(String name, String value)
throws TransletException
{
- _handler.attribute(name, value);
+ if (_firstTagOpen) {
+ if (_attributes == null) {
+ _attributes = new ArrayList();
+ }
+ _attributes.add(new Pair(name, value));
+ }
+ else {
+ _handler.attribute(name, value);
+ }
+ }
+
+ public void namespace(String prefix, String uri)
+ throws TransletException
+ {
+// System.out.println("namespace() = " + prefix + " " + uri);
+ if (_firstTagOpen) {
+ if (_namespaces == null) {
+ _namespaces = new ArrayList();
+ }
+ _namespaces.add(new Pair(prefix, uri));
+
+ // Check if output is XHTML instead of HTML
+ if (_firstTagPrefix.equals(prefix) && !uri.equals(EMPTYSTRING)) {
+ _isHtmlOutput = false;
+ }
+ }
+ else {
+ _handler.namespace(prefix, uri);
+ }
}
public void comment(String comment)
throws TransletException
{
+ if (_firstTagOpen) {
+ initStreamOutput();
+ }
_handler.comment(comment);
}
public void processingInstruction(String target, String data)
throws TransletException
{
+ if (_firstTagOpen) {
+ initStreamOutput();
+ }
_handler.processingInstruction(target, data);
}
+ public void setDoctype(String system, String pub) {
+ _handler.setDoctype(system, pub);
+ }
+
+ public void setIndent(boolean indent) {
+ _handler.setIndent(indent);
+ }
+
+ public void omitHeader(boolean value) {
+ _handler.omitHeader(value);
+ }
+
+ public void setStandalone(String standalone) {
+ _handler.setStandalone(standalone);
+ }
+
public boolean setEscaping(boolean escape)
throws TransletException
{
@@ -168,26 +259,40 @@
_handler.setCdataElements(elements);
}
- public void namespace(String prefix, String uri)
+ private void initStreamOutput()
throws TransletException
{
- _handler.namespace(prefix, uri);
- }
+ // Create a new handler if output is HTML
+ if (_isHtmlOutput) {
+ _handler = new StreamHTMLOutput(_handler);
+ }
+ if (_callStartDocument) {
+ _handler.startDocument();
+ _callStartDocument = false;
+ }
- public void setDoctype(String system, String pub) {
- _handler.setDoctype(system, pub);
- }
+ // Output first tag
+ _handler.startElement(_firstTag);
- public void setIndent(boolean indent) {
- _handler.setIndent(indent);
- }
+ // Output namespaces of first tag
+ if (_namespaces != null) {
+ final int n = _namespaces.size();
+ for (int i = 0; i < n; i++) {
+ final Pair pair = (Pair) _namespaces.get(i);
+ _handler.namespace(pair.name, pair.value);
+ }
+ }
- public void omitHeader(boolean value) {
- _handler.omitHeader(value);
- }
+ // Output attributes of first tag
+ if (_attributes != null) {
+ final int n = _attributes.size();
+ for (int i = 0; i < n; i++) {
+ final Pair pair = (Pair) _attributes.get(i);
+ _handler.attribute(pair.name, pair.value);
+ }
+ }
- public void setStandalone(String standalone) {
- _handler.setStandalone(standalone);
+ // Close first tag
+ _firstTagOpen = false;
}
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org