santiagopg 02/05/23 11:13:04
Modified: java/src/org/apache/xalan/xsltc/runtime/output
StreamHTMLOutput.java StreamOutput.java
StreamXMLOutput.java
TransletOutputHandlerFactory.java
Added: java/src/org/apache/xalan/xsltc/runtime/output
StreamUnknownOutput.java
Log:
Revision Changes Path
1.3 +12 -30
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamHTMLOutput.java
Index: StreamHTMLOutput.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamHTMLOutput.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- StreamHTMLOutput.java 21 May 2002 20:18:19 -0000 1.2
+++ StreamHTMLOutput.java 23 May 2002 18:13:04 -0000 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: StreamHTMLOutput.java,v 1.2 2002/05/21 20:18:19 santiagopg Exp $
+ * @(#)$Id: StreamHTMLOutput.java,v 1.3 2002/05/23 18:13:04 santiagopg Exp $
*
* The Apache Software License, Version 1.1
*
@@ -93,22 +93,18 @@
private boolean _inStyleScript = false;
private String _mediaType = "text/html";
+ public StreamHTMLOutput(StreamOutput output) {
+ super(output);
+ }
+
public StreamHTMLOutput(Writer writer, String encoding) {
- _writer = writer;
- _encoding = encoding;
- _is8859Encoded = encoding.equalsIgnoreCase("iso-8859-1");
+ super(writer, encoding);
}
public StreamHTMLOutput(OutputStream out, String encoding)
throws IOException
{
- try {
- _writer = new OutputStreamWriter(out, _encoding = encoding);
- _is8859Encoded = encoding.equalsIgnoreCase("iso-8859-1");
- }
- catch (UnsupportedEncodingException e) {
- _writer = new OutputStreamWriter(out, _encoding = "utf-8");
- }
+ super(out, encoding);
}
public void startDocument() throws TransletException {
@@ -120,24 +116,8 @@
_buffer.append("/>");
}
- try {
- int n = 0;
- final int length = _buffer.length();
- final String output = _buffer.toString();
-
- // Output buffer in chunks of OUTPUT_BUFFER_SIZE
- if (length > OUTPUT_BUFFER_SIZE) {
- do {
- _writer.write(output, n, OUTPUT_BUFFER_SIZE);
- n += OUTPUT_BUFFER_SIZE;
- } while (n + OUTPUT_BUFFER_SIZE < length);
- }
- _writer.write(output, n, length - n);
- _writer.flush();
- }
- catch (IOException e) {
- // ignore
- }
+ // Finally, output buffer to writer
+ outputBuffer();
}
public void startElement(String elementName) throws TransletException {
@@ -339,7 +319,9 @@
for (int i = 0; i < length; i++){
final char ch = base.charAt(i);
- if (ch > '\u007F') {
+ if ((ch >= '\u007F' && ch < '\u00A0') ||
+ (_is8859Encoded && ch > '\u00FF'))
+ {
_buffer.append(CHAR_ESC_START)
.append(Integer.toString((int) ch))
.append(';');
1.6 +64 -13
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamOutput.java
Index: StreamOutput.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamOutput.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- StreamOutput.java 23 May 2002 16:13:38 -0000 1.5
+++ StreamOutput.java 23 May 2002 18:13:04 -0000 1.6
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: StreamOutput.java,v 1.5 2002/05/23 16:13:38 santiagopg Exp $
+ * @(#)$Id: StreamOutput.java,v 1.6 2002/05/23 18:13:04 santiagopg Exp $
*
* The Apache Software License, Version 1.1
*
@@ -64,6 +64,10 @@
package org.apache.xalan.xsltc.runtime.output;
import java.io.Writer;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
class StreamOutput extends OutputBase {
@@ -80,33 +84,59 @@
protected static final int MAX_INDENT_LEVEL = (INDENT.length >> 1);
protected static final int MAX_INDENT = INDENT.length;
- protected static final int BUFFER_SIZE = 32 * 1024;
- protected static final int OUTPUT_BUFFER_SIZE = 4 * 1024;
+ protected static final int BUFFER_SIZE = 64 * 1024;
+ protected static final int OUTPUT_BUFFER_SIZE = 8 * 1024;
- protected Writer _writer = null;
- protected StringBuffer _buffer = new StringBuffer(BUFFER_SIZE);
+ protected Writer _writer;
+ protected StringBuffer _buffer;
- protected boolean _startTagOpen = false;
+ protected boolean _startTagOpen = false;
protected boolean _is8859Encoded = false;
- protected boolean _indent = false;
+ protected boolean _indent = false;
protected boolean _omitHeader = false;
protected String _standalone = null;
protected String _version = "1.0";
protected boolean _lineFeedNextStartTag = false;
- protected boolean _linefeedNextEndTag = false;
- protected boolean _indentNextEndTag = false;
- protected int _indentLevel = 0;
+ protected boolean _linefeedNextEndTag = false;
+ protected boolean _indentNextEndTag = false;
+ protected int _indentLevel = 0;
- protected boolean _escaping = true;
+ protected boolean _escaping = true;
protected boolean _firstElement = true;
-
- protected String _encoding;
+ protected String _encoding = "UTF-8";
protected String _doctypeSystem = null;
protected String _doctypePublic = null;
+ protected StreamOutput(StreamOutput output) {
+ _writer = output._writer;
+ _encoding = output._encoding;
+ _is8859Encoded = output._is8859Encoded;
+ _buffer = output._buffer;
+ }
+
+ protected StreamOutput(Writer writer, String encoding) {
+ _writer = writer;
+ _encoding = encoding;
+ _is8859Encoded = encoding.equalsIgnoreCase("iso-8859-1");
+ _buffer = new StringBuffer(BUFFER_SIZE);
+ }
+
+ protected StreamOutput(OutputStream out, String encoding)
+ throws IOException
+ {
+ try {
+ _writer = new OutputStreamWriter(out, _encoding = encoding);
+ _is8859Encoded = encoding.equalsIgnoreCase("iso-8859-1");
+ }
+ catch (UnsupportedEncodingException e) {
+ _writer = new OutputStreamWriter(out, _encoding = "utf-8");
+ }
+ _buffer = new StringBuffer(BUFFER_SIZE);
+ }
+
/**
* Set the output document system/public identifiers
*/
@@ -125,6 +155,27 @@
public void setStandalone(String standalone) {
_standalone = standalone;
+ }
+
+ protected void outputBuffer() {
+ try {
+ int n = 0;
+ final int length = _buffer.length();
+ final String output = _buffer.toString();
+
+ // Output buffer in chunks of OUTPUT_BUFFER_SIZE
+ if (length > OUTPUT_BUFFER_SIZE) {
+ do {
+ _writer.write(output, n, OUTPUT_BUFFER_SIZE);
+ n += OUTPUT_BUFFER_SIZE;
+ } while (n + OUTPUT_BUFFER_SIZE < length);
+ }
+ _writer.write(output, n, length - n);
+ _writer.flush();
+ }
+ catch (IOException e) {
+ // ignore
+ }
}
protected void appendDTD(String name) {
1.4 +23 -33
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamXMLOutput.java
Index: StreamXMLOutput.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamXMLOutput.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- StreamXMLOutput.java 23 May 2002 16:13:38 -0000 1.3
+++ StreamXMLOutput.java 23 May 2002 18:13:04 -0000 1.4
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: StreamXMLOutput.java,v 1.3 2002/05/23 16:13:38 santiagopg Exp $
+ * @(#)$Id: StreamXMLOutput.java,v 1.4 2002/05/23 18:13:04 santiagopg Exp $
*
* The Apache Software License, Version 1.1
*
@@ -146,22 +146,14 @@
}
public StreamXMLOutput(Writer writer, String encoding) {
- _writer = writer;
- _encoding = encoding;
- _is8859Encoded = encoding.equalsIgnoreCase("iso-8859-1");
+ super(writer, encoding);
init();
}
public StreamXMLOutput(OutputStream out, String encoding)
throws IOException
{
- try {
- _writer = new OutputStreamWriter(out, _encoding = encoding);
- _is8859Encoded = encoding.equalsIgnoreCase("iso-8859-1");
- }
- catch (UnsupportedEncodingException e) {
- _writer = new OutputStreamWriter(out, _encoding = "utf-8");
- }
+ super(out, encoding);
init();
}
@@ -211,24 +203,8 @@
closeCDATA();
}
- try {
- int n = 0;
- final int length = _buffer.length();
- final String output = _buffer.toString();
-
- // Output buffer in chunks of OUTPUT_BUFFER_SIZE
- if (length > OUTPUT_BUFFER_SIZE) {
- do {
- _writer.write(output, n, OUTPUT_BUFFER_SIZE);
- n += OUTPUT_BUFFER_SIZE;
- } while (n + OUTPUT_BUFFER_SIZE < length);
- }
- _writer.write(output, n, length - n);
- _writer.flush();
- }
- catch (IOException e) {
- // ignore
- }
+ // Finally, output buffer to writer
+ outputBuffer();
}
public void startElement(String elementName) throws TransletException {
@@ -268,6 +244,10 @@
public void endElement(String elementName) throws TransletException {
// System.out.println("endElement = " + elementName);
+ if (_cdataTagOpen) {
+ closeCDATA();
+ }
+
if (_startTagOpen) {
_startTagOpen = false;
_buffer.append("/>");
@@ -281,6 +261,7 @@
if (_indentNextEndTag) {
indent(_indentNextEndTag);
_indentNextEndTag = true;
+ _lineFeedNextStartTag = true;
}
}
_buffer.append("</").append(elementName).append('>');
@@ -351,6 +332,10 @@
_buffer.append('>');
_startTagOpen = false;
}
+ else if (_cdataTagOpen) {
+ closeCDATA();
+ }
+
_buffer.append("<!--").append(comment).append("-->");
}
@@ -362,11 +347,12 @@
_buffer.append('>');
_startTagOpen = false;
}
+ else if (_cdataTagOpen) {
+ closeCDATA();
+ }
+
_buffer.append("<?").append(target).append(' ')
.append(data).append("?>");
- if (_indent) {
- _buffer.append('\n');
- }
}
public boolean setEscaping(boolean escape) throws TransletException
@@ -499,7 +485,11 @@
// Step through characters and escape all special characters
for (int i = off; i < limit; i++) {
- if (ch[i] > '\u00ff') { // encoding??
+ final char current = ch[i];
+
+ if ((current >= '\u007F' && current < '\u00A0') ||
+ (_is8859Encoded && current > '\u00FF'))
+ {
_buffer.append(ch, offset, i - offset)
.append(CDATA_ESC_START)
.append(Integer.toString((int) ch[i]))
1.2 +8 -6
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/TransletOutputHandlerFactory.java
Index: TransletOutputHandlerFactory.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/TransletOutputHandlerFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TransletOutputHandlerFactory.java 22 May 2002 22:43:25 -0000 1.1
+++ TransletOutputHandlerFactory.java 23 May 2002 18:13:04 -0000 1.2
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: TransletOutputHandlerFactory.java,v 1.1 2002/05/22 22:43:25
santiagopg Exp $
+ * @(#)$Id: TransletOutputHandlerFactory.java,v 1.2 2002/05/23 18:13:04
santiagopg Exp $
*
* The Apache Software License, Version 1.1
*
@@ -77,7 +77,7 @@
public static final int DOM = 2;
private String _encoding = "utf-8";
- private String _method = "xml";
+ private String _method = null;
private int _outputType = STREAM;
static public TransletOutputHandlerFactory newInstance() {
@@ -95,14 +95,16 @@
}
public void setOutputMethod(String method) {
- if (method != null) {
- _method = method;
- }
+ _method = method;
}
public TransletOutputHandler getTransletOutputHandler() throws
IOException {
switch (_outputType) {
case STREAM:
+ if (_method == null) {
+ return new StreamUnknownOutput(System.out, _encoding);
+ }
+
if (_method.equalsIgnoreCase("xml")) {
return new StreamXMLOutput(System.out, _encoding);
}
@@ -110,7 +112,7 @@
return new StreamHTMLOutput(System.out, _encoding);
}
else if (_method.equalsIgnoreCase("text")) {
- return null; // TODO
+ // TODO
}
break;
case SAX:
1.1
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamUnknownOutput.java
Index: StreamUnknownOutput.java
===================================================================
/*
* @(#)$Id: StreamUnknownOutput.java,v 1.1 2002/05/23 18:13:04 santiagopg Exp
$
*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 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 [EMAIL PROTECTED]
*
* 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) 2001, Sun
* Microsystems., http://www.sun.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* @author Santiago Pericas-Geertsen
* @author G. Todd Miller
*
*/
package org.apache.xalan.xsltc.runtime.output;
import java.util.Stack;
import java.util.HashSet;
import java.util.Iterator;
import java.io.Writer;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import org.apache.xalan.xsltc.*;
import org.apache.xalan.xsltc.runtime.*;
import org.apache.xalan.xsltc.runtime.Hashtable;
public class StreamUnknownOutput extends StreamOutput {
private StreamOutput _handler;
private boolean _startDocumentCalled = false;
public StreamUnknownOutput(Writer writer, String encoding) {
super(writer, encoding);
_handler = new StreamXMLOutput(writer, encoding);
}
public StreamUnknownOutput(OutputStream out, String encoding)
throws IOException
{
super(out, encoding);
_handler = new StreamXMLOutput(out, encoding);
}
public void startDocument() throws TransletException {
_startDocumentCalled = true;
}
public void endDocument() throws TransletException {
_handler.endDocument();
}
public void startElement(String elementName) throws TransletException {
if (_firstElement) {
// If first element is HTML, create a new handler
if (elementName.equalsIgnoreCase("html")) {
_handler = new StreamHTMLOutput(_handler);
}
if (_startDocumentCalled) {
_handler.startDocument();
}
_firstElement = false;
}
_handler.startElement(elementName);
}
public void endElement(String elementName)
throws TransletException
{
_handler.endElement(elementName);
}
public void characters(String characters)
throws TransletException
{
_handler.characters(characters);
}
public void characters(char[] characters, int offset, int length)
throws TransletException
{
_handler.characters(characters, offset, length);
}
public void attribute(String name, String value)
throws TransletException
{
_handler.attribute(name, value);
}
public void comment(String comment)
throws TransletException
{
_handler.comment(comment);
}
public void processingInstruction(String target, String data)
throws TransletException
{
_handler.processingInstruction(target, data);
}
public boolean setEscaping(boolean escape)
throws TransletException
{
return _handler.setEscaping(escape);
}
public void setCdataElements(Hashtable elements) {
_handler.setCdataElements(elements);
}
public void namespace(String prefix, String uri)
throws TransletException
{
_handler.namespace(prefix, uri);
}
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);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]