Hello.
I'm looking over the code and found that the Kernel class contains a copy
of the org.apache.xindice.xml.TextWriter class; the comment along with the
copy says:
"TextWriter takes a Document, DocumentFragment, or Element and streams it
as text to an output source (or a String) -- Stolen from
org.apache.xindice.xml"
I do not believe that it's being used; could anyone tell me the reasoning
why the copy is there? Attached is a patch to simply remove the
Kernel.TextWriter class from Kernel.
Fernando Padilla
? bin/xindice
? bin/xindiceadmin
? java/classes
? java/lib/xindice.jar
? java/src/org/apache/xindice/client/corba/db
Index: java/src/org/apache/xindice/server/Kernel.java
===================================================================
RCS file:
/home/cvspublic/xml-xindice/java/src/org/apache/xindice/server/Kernel.java,v
retrieving revision 1.2
diff -u -r1.2 Kernel.java
--- java/src/org/apache/xindice/server/Kernel.java 26 Feb 2002 07:10:09
-0000 1.2
+++ java/src/org/apache/xindice/server/Kernel.java 1 May 2002 03:07:34
-0000
@@ -526,153 +526,5 @@
this.lastrun = System.currentTimeMillis();
}
}
-
-
- /**
- * TextWriter takes a Document, DocumentFragment, or Element and streams it
- * as text to an output source (or a String) -- Stolen from
org.apache.xindice.xml
- */
-
- public final class TextWriter {
- private Node node = null;
-
- public TextWriter(Node node) throws DOMException {
- this.node = node;
- }
-
- private void writeNode(Writer writer, Node node) throws IOException {
- short type = node.getNodeType();
- switch ( type ) {
-
- case Node.DOCUMENT_NODE: {
- writer.write("<?xml version=\"1.0\"?>\n");
- writeChildren(writer, node);
- break;
- }
-
- case Node.DOCUMENT_FRAGMENT_NODE: {
- writeChildren(writer, node);
- break;
- }
-
- case Node.ELEMENT_NODE: {
- Element e = (Element)node;
- String n = e.getTagName();
-
- writer.write('<');
- writer.write(n);
-
- NamedNodeMap a = e.getAttributes();
- int size = a.getLength();
- for ( int i = 0; i < size; i++ ) {
- Attr att = (Attr)a.item(i);
- writer.write(' ');
- writeNode(writer, att);
- }
-
- if ( e.hasChildNodes() ) {
- writer.write('>');
- writeChildren(writer, node);
- writer.write("</");
- writer.write(n);
- writer.write('>');
- }
- else
- writer.write(" />");
- break;
- }
-
- case Node.ATTRIBUTE_NODE:
- Attr a = (Attr)node;
- writer.write(a.getName());
- writer.write("=\"");
- writeEscapedText(writer, a.getValue());
- writer.write("\"");
- break;
-
-
- case Node.PROCESSING_INSTRUCTION_NODE: {
- ProcessingInstruction pi = (ProcessingInstruction)node;
- writer.write("<?");
- writer.write(pi.getTarget());
- writer.write(" ");
- writer.write(pi.getData());
- writer.write("?>\n");
- break;
- }
-
- case Node.TEXT_NODE: {
- writeEscapedText(writer, node.getNodeValue());
- break;
- }
-
- case Node.CDATA_SECTION_NODE: {
- writer.write("<![CDATA[");
- writer.write(node.getNodeValue());
- writer.write("]]>");
- break;
- }
-
- case Node.COMMENT_NODE: {
- writer.write("<!--");
- writer.write(node.getNodeValue());
- writer.write("-->");
- break;
- }
- }
- }
-
- private void writeChildren(Writer writer, Node node) throws IOException {
- NodeList l = node.getChildNodes();
- int size = l.getLength();
- for ( int i = 0; i < size; i++ )
- writeNode(writer, l.item(i));
- }
-
- private void writeEscapedText(Writer writer, String text) throws
IOException {
- char[] value = text.toCharArray();
- String outval = null;
- int start = 0;
- int len = 0;
- for ( int i = 0; i < value.length; i++ ) {
- switch ( value[i] ) {
- case '&' : outval = "&"; break;
- case '\'' : outval = "'"; break;
- case '\"' : outval = """; break;
- case '<' : outval = "<"; break;
- case '>' : outval = ">"; break;
- default : len++; break;
- }
-
- if ( outval != null ) {
- if ( len > 0 )
- writer.write(value, start, len);
- writer.write(outval);
- start = i+1;
- len = 0;
- outval = null;
- }
- }
- if ( len > 0 )
- writer.write(value, start, len);
- }
-
- /**
- * write writes the node to the OutputStream as text.
- *
- * @param output The OutputStream to write to
- */
- public void write(OutputStream output) throws IOException {
- try {
- OutputStreamWriter o = new OutputStreamWriter(output);
- BufferedWriter buf = new BufferedWriter(o, 4096);
- writeNode(buf, node);
- buf.flush();
- }
- catch ( Exception e ) {
- org.apache.xindice.Debug.printStackTrace(e);
- }
- }
- }
}