You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2008/12/31 21:45:52 UTC

svn commit: r730472 - /xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/

Author: mrglavas
Date: Wed Dec 31 12:45:51 2008
New Revision: 730472

URL: http://svn.apache.org/viewvc?rev=730472&view=rev
Log:
Implementation of writeAsEncodedUnicode().

Modified:
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/AttributeImpl.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/CharactersImpl.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/CommentImpl.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/DTDImpl.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/EndDocumentImpl.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/EndElementImpl.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/EntityDeclarationImpl.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/EntityReferenceImpl.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/NotationDeclarationImpl.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/ProcessingInstructionImpl.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/StartDocumentImpl.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/StartElementImpl.java
    xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/XMLEventImpl.java

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/AttributeImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/AttributeImpl.java?rev=730472&r1=730471&r2=730472&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/AttributeImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/AttributeImpl.java Wed Dec 31 12:45:51 2008
@@ -17,8 +17,12 @@
 
 package org.apache.xerces.stax.events;
 
+import java.io.IOException;
+import java.io.Writer;
+
 import javax.xml.namespace.QName;
 import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.events.Attribute;
 
 /**
@@ -77,5 +81,23 @@
     public final boolean isSpecified() {
         return fIsSpecified;
     }
-
+    
+    public final void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
+        try {
+            // Write name
+            String prefix = fName.getPrefix();
+            if (prefix != null && prefix.length() > 0) {
+                writer.write(prefix);
+                writer.write(':');
+            }
+            writer.write(fName.getLocalPart());
+            // Write value
+            writer.write("=\"");
+            writer.write(fValue);
+            writer.write('"');
+        }
+        catch (IOException ioe) {
+            throw new XMLStreamException(ioe);
+        }
+    }
 }

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/CharactersImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/CharactersImpl.java?rev=730472&r1=730471&r2=730472&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/CharactersImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/CharactersImpl.java Wed Dec 31 12:45:51 2008
@@ -17,7 +17,11 @@
 
 package org.apache.xerces.stax.events;
 
+import java.io.IOException;
+import java.io.Writer;
+
 import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.events.Characters;
 
 import org.apache.xerces.util.XMLChar;
@@ -41,7 +45,7 @@
      */
     public CharactersImpl(final String data, final int eventType, final Location location) {
         super(eventType, location);
-        fData = data;
+        fData = (data != null) ? data : "";
     }
 
     /**
@@ -81,4 +85,12 @@
         return SPACE == getEventType();
     }
     
+    public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
+        try {
+            writer.write(fData);
+        }
+        catch (IOException ioe) {
+            throw new XMLStreamException(ioe);
+        }
+    }
 }

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/CommentImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/CommentImpl.java?rev=730472&r1=730471&r2=730472&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/CommentImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/CommentImpl.java Wed Dec 31 12:45:51 2008
@@ -17,7 +17,11 @@
 
 package org.apache.xerces.stax.events;
 
+import java.io.IOException;
+import java.io.Writer;
+
 import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.events.Comment;
 
 /**
@@ -40,7 +44,7 @@
      */
     public CommentImpl(final String text, final Location location) {
         super(COMMENT, location);
-        fText = text;
+        fText = (text != null) ? text : "";
     }
 
     /**
@@ -49,4 +53,15 @@
     public String getText() {
         return fText; 
     }
+    
+    public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
+        try {
+            writer.write("<!--");
+            writer.write(fText);
+            writer.write("-->");
+        }
+        catch (IOException ioe) {
+            throw new XMLStreamException(ioe);
+        }
+    }
 }

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/DTDImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/DTDImpl.java?rev=730472&r1=730471&r2=730472&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/DTDImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/DTDImpl.java Wed Dec 31 12:45:51 2008
@@ -17,10 +17,13 @@
 
 package org.apache.xerces.stax.events;
 
+import java.io.IOException;
+import java.io.Writer;
 import java.util.Collections;
 import java.util.List;
 
 import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.events.DTD;
 
 /**
@@ -39,7 +42,7 @@
      */
     public DTDImpl(final String dtd, final Location location) {
         super(DTD, location);
-        fDTD = dtd;
+        fDTD = (dtd != null) ? dtd : null;
     }
     
     /**
@@ -69,4 +72,13 @@
     public List getEntities() {
         return Collections.EMPTY_LIST;
     }
+    
+    public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
+        try {
+            writer.write(fDTD);
+        }
+        catch (IOException ioe) {
+            throw new XMLStreamException(ioe);
+        }
+    }
 }

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/EndDocumentImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/EndDocumentImpl.java?rev=730472&r1=730471&r2=730472&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/EndDocumentImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/EndDocumentImpl.java Wed Dec 31 12:45:51 2008
@@ -17,7 +17,10 @@
 
 package org.apache.xerces.stax.events;
 
+import java.io.Writer;
+
 import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.events.EndDocument;
 
 /**
@@ -37,4 +40,5 @@
         super(END_DOCUMENT, location);
     }
 
+    public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {}
 }

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/EndElementImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/EndElementImpl.java?rev=730472&r1=730471&r2=730472&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/EndElementImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/EndElementImpl.java Wed Dec 31 12:45:51 2008
@@ -17,8 +17,12 @@
 
 package org.apache.xerces.stax.events;
 
+import java.io.IOException;
+import java.io.Writer;
+
 import javax.xml.namespace.QName;
 import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.events.EndElement;
 
 /**
@@ -36,5 +40,22 @@
     public EndElementImpl(final QName name, final Location location) {
         super(name, false, location);
     }
-    
+
+    public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
+        try {
+            // Write end tags.
+            writer.write("</");
+            QName name = getName();
+            String prefix = name.getPrefix();
+            if (prefix != null && prefix.length() > 0) {
+                writer.write(prefix);
+                writer.write(':');
+            }
+            writer.write(name.getLocalPart());
+            writer.write('>');
+        }
+        catch (IOException ioe) {
+            throw new XMLStreamException(ioe);
+        }
+    }
 }

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/EntityDeclarationImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/EntityDeclarationImpl.java?rev=730472&r1=730471&r2=730472&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/EntityDeclarationImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/EntityDeclarationImpl.java Wed Dec 31 12:45:51 2008
@@ -17,7 +17,11 @@
 
 package org.apache.xerces.stax.events;
 
+import java.io.IOException;
+import java.io.Writer;
+
 import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.events.EntityDeclaration;
 
 /**
@@ -91,5 +95,31 @@
         // TODO Auto-generated method stub
         return null;
     }
-
+    
+    public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
+        try {
+            writer.write("<!ENTITY ");
+            writer.write(fName);
+            if (fPublicId != null) {
+                writer.write(" PUBLIC \"");
+                writer.write(fPublicId);
+                writer.write("\" \"");
+                writer.write(fSystemId);
+                writer.write('"');
+            }
+            else {
+                writer.write(" SYSTEM \"");
+                writer.write(fSystemId);
+                writer.write('"');
+            }
+            if (fNotationName != null) {
+                writer.write(" NDATA ");
+                writer.write(fNotationName);
+            }
+            writer.write('>');
+        }
+        catch (IOException ioe) {
+            throw new XMLStreamException(ioe);
+        }
+    }
 }

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/EntityReferenceImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/EntityReferenceImpl.java?rev=730472&r1=730471&r2=730472&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/EntityReferenceImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/EntityReferenceImpl.java Wed Dec 31 12:45:51 2008
@@ -17,7 +17,11 @@
 
 package org.apache.xerces.stax.events;
 
+import java.io.IOException;
+import java.io.Writer;
+
 import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.events.EntityDeclaration;
 import javax.xml.stream.events.EntityReference;
 
@@ -47,7 +51,7 @@
      * @param location
      */
     public EntityReferenceImpl(final EntityDeclaration decl, final Location location) {
-        this(decl != null ? decl.getName() : null, decl, location);
+        this(decl != null ? decl.getName() : "", decl, location);
     }
     
     /**
@@ -58,7 +62,7 @@
      */
     public EntityReferenceImpl(final String name, final EntityDeclaration decl, final Location location) {
         super(ENTITY_REFERENCE, location);
-        fName = name;
+        fName = (name != null) ? name : "";
         fDecl = decl;
     }
 
@@ -75,5 +79,15 @@
     public String getName() {
         return fName;
     }
-
+    
+    public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
+        try {
+            writer.write('&');
+            writer.write(fName);
+            writer.write(';');
+        }
+        catch (IOException ioe) {
+            throw new XMLStreamException(ioe);
+        }
+    }
 }

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/NotationDeclarationImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/NotationDeclarationImpl.java?rev=730472&r1=730471&r2=730472&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/NotationDeclarationImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/NotationDeclarationImpl.java Wed Dec 31 12:45:51 2008
@@ -17,7 +17,11 @@
 
 package org.apache.xerces.stax.events;
 
+import java.io.IOException;
+import java.io.Writer;
+
 import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.events.NotationDeclaration;
 
 /**
@@ -66,6 +70,30 @@
     public String getSystemId() {
         return fSystemId;
     }
-
-
+    
+    public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
+        try {
+            writer.write("<!NOTATION ");
+            if (fPublicId != null) {
+                writer.write("PUBLIC \"");
+                writer.write(fPublicId);
+                writer.write('\"');
+                if (fSystemId != null) {
+                    writer.write(" \"");
+                    writer.write(fSystemId);
+                    writer.write('\"');
+                }
+            }
+            else {
+                writer.write("SYSTEM \"");
+                writer.write(fSystemId);
+                writer.write('\"');
+            }
+            writer.write(fName);
+            writer.write('>');
+        }
+        catch (IOException ioe) {
+            throw new XMLStreamException(ioe);
+        }
+    }
 }

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/ProcessingInstructionImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/ProcessingInstructionImpl.java?rev=730472&r1=730471&r2=730472&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/ProcessingInstructionImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/ProcessingInstructionImpl.java Wed Dec 31 12:45:51 2008
@@ -17,9 +17,11 @@
 
 package org.apache.xerces.stax.events;
 
+import java.io.IOException;
+import java.io.Writer;
+
 import javax.xml.stream.Location;
 import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamWriter;
 import javax.xml.stream.events.ProcessingInstruction;
 
 /**
@@ -40,7 +42,7 @@
      */
     public ProcessingInstructionImpl(final String target, final String data, final Location location) {
         super(PROCESSING_INSTRUCTION, location);
-        fTarget = target;
+        fTarget = target != null ? target : "";
         fData = data;
     }
 
@@ -58,11 +60,18 @@
         return fData;
     }
 
-    /**
-     * @see org.apache.xerces.stax.events.XMLEventImpl#writeToStreamWriter(javax.xml.stream.XMLStreamWriter)
-     */
-    public void writeToStreamWriter(XMLStreamWriter writer) throws XMLStreamException {
-        
+    public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
+        try {
+            writer.write("<?");
+            writer.write(fTarget);
+            if (fData != null && fData.length() > 0) {
+                writer.write(' ');
+                writer.write(fData);
+            }
+            writer.write("?>");
+        }
+        catch (IOException ioe) {
+            throw new XMLStreamException(ioe);
+        }
     }
-
 }

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/StartDocumentImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/StartDocumentImpl.java?rev=730472&r1=730471&r2=730472&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/StartDocumentImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/StartDocumentImpl.java Wed Dec 31 12:45:51 2008
@@ -17,7 +17,11 @@
 
 package org.apache.xerces.stax.events;
 
+import java.io.IOException;
+import java.io.Writer;
+
 import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.events.StartDocument;
 
 /**
@@ -88,5 +92,26 @@
     public String getVersion() {
         return fVersion;
     }
- 
+    
+    public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
+        try {
+            writer.write("<?xml version=\"");
+            writer.write(fVersion != null && fVersion.length() > 0 ? fVersion : "1.0");
+            writer.write('"');
+            if (encodingSet()) {
+                writer.write(" encoding=\"");
+                writer.write(fCharEncoding);
+                writer.write('"');
+            }
+            if (standaloneSet()) {
+                writer.write(" standalone=\"");
+                writer.write(fIsStandalone ? "yes" : "no");
+                writer.write('"');
+            }
+            writer.write("?>");
+        }
+        catch (IOException ioe) {
+            throw new XMLStreamException(ioe);
+        }
+    }
 }

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/StartElementImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/StartElementImpl.java?rev=730472&r1=730471&r2=730472&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/StartElementImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/StartElementImpl.java Wed Dec 31 12:45:51 2008
@@ -17,6 +17,8 @@
 
 package org.apache.xerces.stax.events;
 
+import java.io.IOException;
+import java.io.Writer;
 import java.util.Comparator;
 import java.util.Iterator;
 import java.util.Map;
@@ -25,7 +27,9 @@
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
 import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.events.Attribute;
+import javax.xml.stream.events.Namespace;
 import javax.xml.stream.events.StartElement;
 
 /**
@@ -88,5 +92,36 @@
     public void addAttribute(final Attribute attribute) {
         fAttributes.put(attribute.getName(), attribute);
     }
-        
+    
+    public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
+        try {
+            // Write start tag.
+            writer.write("<");
+            QName name = getName();
+            String prefix = name.getPrefix();
+            if (prefix != null && prefix.length() > 0) {
+                writer.write(prefix);
+                writer.write(':');
+            }
+            writer.write(name.getLocalPart());
+            // Write namespace declarations.
+            Iterator nsIter = getNamespaces();
+            while (nsIter.hasNext()) {
+                Namespace ns = (Namespace) nsIter.next();
+                writer.write(' ');
+                ns.writeAsEncodedUnicode(writer);
+            }
+            // Write attributes
+            Iterator attrIter = getAttributes();
+            while (attrIter.hasNext()) {
+                Attribute attr = (Attribute) attrIter.next();
+                writer.write(' ');
+                attr.writeAsEncodedUnicode(writer);
+            }
+            writer.write('>');
+        }
+        catch (IOException ioe) {
+            throw new XMLStreamException(ioe);
+        }
+    }
 }

Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/XMLEventImpl.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/XMLEventImpl.java?rev=730472&r1=730471&r2=730472&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/XMLEventImpl.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/stax/events/XMLEventImpl.java Wed Dec 31 12:45:51 2008
@@ -18,7 +18,6 @@
 package org.apache.xerces.stax.events;
 
 import java.io.StringWriter;
-import java.io.Writer;
 
 import javax.xml.namespace.QName;
 import javax.xml.stream.Location;
@@ -170,13 +169,6 @@
     public final QName getSchemaType() {
         return null;
     }
-
-    /**
-     * @see javax.xml.stream.events.XMLEvent#writeAsEncodedUnicode(java.io.Writer)
-     */
-    public void writeAsEncodedUnicode(final Writer writer) throws XMLStreamException {
-        // TODO Auto-generated method stub
-    }
     
     public final String toString() {
         final StringWriter writer = new StringWriter();



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org