xml-commons-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mrgla...@apache.org
Subject svn commit: r670394 - /xml/commons/trunk/java/external/src/javax/xml/transform/stax/StAXSource.java
Date Sun, 22 Jun 2008 18:50:37 GMT
Author: mrglavas
Date: Sun Jun 22 11:50:36 2008
New Revision: 670394

URL: http://svn.apache.org/viewvc?rev=670394&view=rev
Log:
Completing the implementation of StAXSource.

Modified:
    xml/commons/trunk/java/external/src/javax/xml/transform/stax/StAXSource.java

Modified: xml/commons/trunk/java/external/src/javax/xml/transform/stax/StAXSource.java
URL: http://svn.apache.org/viewvc/xml/commons/trunk/java/external/src/javax/xml/transform/stax/StAXSource.java?rev=670394&r1=670393&r2=670394&view=diff
==============================================================================
--- xml/commons/trunk/java/external/src/javax/xml/transform/stax/StAXSource.java (original)
+++ xml/commons/trunk/java/external/src/javax/xml/transform/stax/StAXSource.java Sun Jun 22
11:50:36 2008
@@ -19,16 +19,63 @@
 
 package javax.xml.transform.stax;
 
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.events.XMLEvent;
 import javax.xml.transform.Source;
 
 public class StAXSource implements Source {
+    
+    public static final String FEATURE = "http://javax.xml.transform.stax.StAXSource/feature";
+    
+    private final XMLStreamReader xmlStreamReader;
+    private final XMLEventReader xmlEventReader;
+    private final String systemId;
+    
+    public StAXSource(XMLStreamReader xmlStreamReader) {
+        if (xmlStreamReader == null) {
+            throw new IllegalArgumentException("XMLStreamReader cannot be null.");
+        }
+        final int event = xmlStreamReader.getEventType();
+        if (event != XMLStreamConstants.START_DOCUMENT && 
+            event != XMLStreamConstants.START_ELEMENT) {
+            throw new IllegalStateException("The state of the XMLStreamReader must be START_DOCUMENT
or START_ELEMENT");
+        }
+        this.xmlStreamReader = xmlStreamReader;
+        this.xmlEventReader = null;
+        this.systemId = xmlStreamReader.getLocation().getSystemId();
+    }
+    
+    public StAXSource(XMLEventReader xmlEventReader)
+        throws XMLStreamException {
+        if (xmlEventReader == null) {
+            throw new IllegalArgumentException("XMLEventReader cannot be null.");
+        }
+        final XMLEvent event = xmlEventReader.peek();
+        if (!event.isStartDocument() && 
+            !event.isStartElement()) {
+            throw new IllegalStateException("The state of the XMLEventReader must be START_DOCUMENT
or START_ELEMENT");
+        }
+        this.xmlStreamReader = null;
+        this.xmlEventReader = xmlEventReader;
+        this.systemId = event.getLocation().getSystemId();
+    }
+    
+    public XMLStreamReader getXMLStreamReader() {
+        return xmlStreamReader;
+    }
+    
+    public XMLEventReader getXMLEventReader() {
+        return xmlEventReader;
+    }
 
     public String getSystemId() {
-        // TODO Auto-generated method stub
-        return null;
+        return systemId;
     }
 
     public void setSystemId(String systemId) {
-        // TODO Auto-generated method stub
+        throw new UnsupportedOperationException("Setting systemId is not supported.");
     }
 }



Mime
View raw message