|
From: <th...@us...> - 2004-01-06 10:25:01
|
Update of /cvsroot/jaxme/JaxMe/src/runtime/de/ispsoft/jaxme
In directory sc8-pr-cvs1:/tmp/cvs-serv20967/src/runtime/de/ispsoft/jaxme
Modified Files:
XMLSerializer.java
Added Files:
XMLSerializerNoNS.java
Log Message:
handling of writing and receiving documents without namespace and map them into namespace aware docs
(tamino workaround)
--- NEW FILE: XMLSerializerNoNS.java ---
package de.ispsoft.jaxme;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import java.io.IOException;
import java.io.Writer;
import java.util.Iterator;
import java.util.Map;
import org.apache.log4j.Category;
/** <p>A simple serializer for XML documents. This serializer
* overrides the common XMLSerializer to prevent the output of namespaces.
* All namespaces are cut of.</p>
*
* @author <a href="mailto:jo...@is...">Jochen Wiedmann</a>
* @author <a href="mailto:Bur...@gm...">Burkhard Vogel</a>
* @author <a href="mailto:hae...@gm...">Thomas Haenel</a>
*/
public class XMLSerializerNoNS extends XMLSerializer {
private static final Category cat = Category.getInstance(XMLSerializerNoNS.class.getName());
/** Creates a new XmlSerializer */
public XMLSerializerNoNS() {
super();
}
/** Creates a new XMLSerializer using the given Writer.
*
* @param pWriter A Writer for which setWriter is being called.
* @see #setWriter
*/
public XMLSerializerNoNS(Writer pWriter) {
super(pWriter);
}
/** Creates a new XMLSerializer using the given Writer and
* indentation.
*
* @param pWriter A Writer for which setWriter is being called.
* @param pIndent The indent level to use for elements.
*/
public XMLSerializerNoNS(Writer pWriter, int pIndent) {
super(pWriter, pIndent);
}
/** <p>Terminates an element.</p>
*
* @param namespaceURI The namespace URI, if any, or null
* @param localName The local name, without prefix, or null
* @param qName The qualified name, including a prefix, or null
* @throws SAXException Thrown in case of an IOException.
*/
public void endElement(String namespaceURI, String localName, String qName)
throws SAXException {
if (baseIndent != 0) curIndent -= baseIndent;
if (w != null) {
try {
if (state == STATE_IN_START_ELEMENT) {
w.write("/>");
state = STATE_OUTSIDE;
} else {
if (state == STATE_OUTSIDE) {
indentMe();
}
w.write("</");
w.write(localName);
w.write('>');
}
state = STATE_OUTSIDE;
} catch (java.io.IOException e) {
throw new SAXException(e);
}
}
}
/** Starts a new element.
*
* @param namespaceURI The namespace URI, if any, or null
* @param localName The local name, without prefix, or null
* @param qName The qualified name, including a prefix, or null
* @param attr The element attributes
* @throws SAXException Thrown in case of an IOException.
*/
public void startElement(String namespaceURI, String localName,
String qName, Attributes attr) throws SAXException {
cat.debug("startElement ->");
cat.debug("namespaceURI: " + namespaceURI);
cat.debug("localName: " + localName);
cat.debug("qName: " + qName);
try {
stopTerminator();
if (curIndent > 0) {
indentMe();
}
curIndent += baseIndent;
if (w != null) {
w.write('<');
w.write(localName);
if (attr != null) {
for (int i = attr.getLength(); i > 0;) {
w.write(' ');
String name = attr.getQName(--i);
cat.debug("name: " + name);
if (delayedPrefixes != null) {
delayedPrefixes.remove(name);
}
if(name != null && name.startsWith("xmlns")) {
continue;
} else {
w.write(name);
w.write("=\"");
writeCData(attr.getValue(i));
w.write('"');
}
}
}
if (delayedPrefixes != null && delayedPrefixes.size() > 0) {
for (Iterator iter = delayedPrefixes.entrySet().iterator();
iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
if(entry.getKey().toString().startsWith("xmlns")) {
continue;
} else {
w.write(' ');
w.write((String) entry.getKey());
w.write("=\"");
w.write((String) entry.getValue());
w.write('"');
}
}
delayedPrefixes.clear();
}
}
state = STATE_IN_START_ELEMENT;
} catch (IOException e) {
throw new SAXException(e);
}
}
}
Index: XMLSerializer.java
===================================================================
RCS file: /cvsroot/jaxme/JaxMe/src/runtime/de/ispsoft/jaxme/XMLSerializer.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- XMLSerializer.java 8 Oct 2003 10:58:41 -0000 1.5
+++ XMLSerializer.java 6 Jan 2004 10:24:58 -0000 1.6
@@ -12,19 +12,19 @@
* @author <a href="mailto:Bur...@gm...">Burkhard Vogel</a>
*/
public class XMLSerializer implements org.xml.sax.ContentHandler {
- private int baseIndent;
- private int curIndent;
- private String lineFeed;
- private Writer w;
- private Locator l;
- private java.util.Map delayedPrefixes;
+ protected int baseIndent;
+ protected int curIndent;
+ protected String lineFeed;
+ protected Writer w;
+ protected Locator l;
+ protected java.util.Map delayedPrefixes;
- private static final int STATE_OUTSIDE = 0;
- private static final int STATE_IN_START_ELEMENT = 1;
- private static final int STATE_IN_ELEMENT = 2;
- private int state;
+ protected static final int STATE_OUTSIDE = 0;
+ protected static final int STATE_IN_START_ELEMENT = 1;
+ protected static final int STATE_IN_ELEMENT = 2;
+ protected int state;
- private static final String BLANKS_64;
+ protected static final String BLANKS_64;
static {
StringBuffer s = new StringBuffer();
for (int i = 0; i < 64; i++) {
@@ -220,7 +220,7 @@
characters(ch, start, length);
}
- private void stopTerminator() throws java.io.IOException {
+ protected void stopTerminator() throws java.io.IOException {
if (state == STATE_IN_START_ELEMENT) {
if (w != null) {
w.write('>');
@@ -297,7 +297,7 @@
}
}
- private void indentMe() throws java.io.IOException {
+ protected void indentMe() throws java.io.IOException {
if (w != null) {
if (lineFeed != null) {
w.write(lineFeed);
@@ -312,7 +312,7 @@
}
}
- private void writeCData(String v) throws java.io.IOException {
+ protected void writeCData(String v) throws java.io.IOException {
int len = v.length();
for (int j = 0; j < len; j++) {
char c = v.charAt(j);
@@ -419,7 +419,7 @@
}
}
- private int emptyElementStyle = EMPTY_ELEMENT_STYLE_XML;
+ protected int emptyElementStyle = EMPTY_ELEMENT_STYLE_XML;
/** <p>Returns how empty elements will be serialized.</p>
*
* @see #setEmptyElementStyle
|