abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r415372 - in /incubator/abdera/java/trunk: core/src/main/java/org/apache/abdera/model/ core/src/main/java/org/apache/abdera/parser/ core/src/main/java/org/apache/abdera/util/ parser/src/main/java/org/apache/abdera/parser/stax/
Date Mon, 19 Jun 2006 16:47:08 GMT
Author: jmsnell
Date: Mon Jun 19 09:47:07 2006
New Revision: 415372

URL: http://svn.apache.org/viewvc?rev=415372&view=rev
Log:
As requested by Stephen,
  Can now pass in a reader on Parser.parse(...)
  Can now pass in a writer on Document.writeTo(...) and Element.writeTo(...)

Also, fixed a bug on Element.writeTo(...) that caused it not to output the 
complete content of the element.

Modified:
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Base.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/Parser.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractParser.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMDocument.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMElement.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMParser.java

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Base.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Base.java?rev=415372&r1=415371&r2=415372&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Base.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Base.java Mon Jun
19 09:47:07 2006
@@ -19,6 +19,7 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.io.Writer;
 
 import org.apache.abdera.factory.Factory;
 
@@ -32,6 +33,11 @@
    * Serializes the model component out to the specified stream
    */
   void writeTo(OutputStream out) throws IOException;
+  
+  /**
+   * Serializes the model component out to the specified writer
+   */
+  void writeTo(Writer writer) throws IOException;
   
   <T extends Base>T clone();
   

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/Parser.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/Parser.java?rev=415372&r1=415371&r2=415372&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/Parser.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/parser/Parser.java Mon
Jun 19 09:47:07 2006
@@ -18,6 +18,7 @@
 package org.apache.abdera.parser;
 
 import java.io.InputStream;
+import java.io.Reader;
 import java.net.URI;
 import java.net.URISyntaxException;
 
@@ -66,5 +67,31 @@
     ParserOptions options) 
       throws ParseException, URISyntaxException;
 
+  <T extends Element>Document<T> parse(
+      Reader in) 
+        throws ParseException;
+    
+  <T extends Element>Document<T> parse(
+    Reader in, 
+    URI base) 
+      throws ParseException;
+  
+  <T extends Element>Document<T> parse(
+    Reader in, 
+    URI base, 
+    ParserOptions options) 
+      throws ParseException;
+  
+  <T extends Element>Document<T> parse(
+    Reader in, 
+    String base) 
+      throws ParseException, URISyntaxException;
+  
+  <T extends Element>Document<T> parse(
+    Reader in, 
+    String base, 
+    ParserOptions options) 
+      throws ParseException, URISyntaxException;
+  
   ParserOptions getDefaultParserOptions();
 }

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractParser.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractParser.java?rev=415372&r1=415371&r2=415372&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractParser.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractParser.java
Mon Jun 19 09:47:07 2006
@@ -18,6 +18,7 @@
 package org.apache.abdera.util;
 
 import java.io.InputStream;
+import java.io.Reader;
 import java.net.URI;
 import java.net.URISyntaxException;
 
@@ -57,6 +58,36 @@
   
   public <T extends Element>Document<T> parse(
     InputStream in, 
+    String base, 
+    ParserOptions options) 
+      throws ParseException, 
+             URISyntaxException {
+    return parse(in, new URI(base), options);
+  }
+  
+  public <T extends Element>Document<T> parse(
+    Reader in) 
+      throws ParseException {
+    return parse(in, (URI)null, getDefaultParserOptions());
+  }
+
+  public <T extends Element>Document<T> parse(
+    Reader in, 
+    URI base) 
+      throws ParseException {
+    return parse(in, base, getDefaultParserOptions());
+  }
+
+  public <T extends Element>Document<T> parse(
+    Reader in, 
+    String base) 
+      throws ParseException, 
+             URISyntaxException {
+    return parse(in, new URI(base), getDefaultParserOptions());
+  }
+  
+  public <T extends Element>Document<T> parse(
+    Reader in, 
     String base, 
     ParserOptions options) 
       throws ParseException, 

Modified: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMDocument.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMDocument.java?rev=415372&r1=415371&r2=415372&view=diff
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMDocument.java
(original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMDocument.java
Mon Jun 19 09:47:07 2006
@@ -24,7 +24,9 @@
 import java.util.Date;
 
 import javax.activation.MimeType;
+import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.abdera.factory.Factory;
 import org.apache.abdera.model.Document;
@@ -33,6 +35,7 @@
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMOutputFormat;
 import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
 import org.apache.axiom.om.impl.llom.OMDocumentImpl;
 
 
@@ -100,16 +103,34 @@
   }
 
   public void writeTo(OutputStream out) throws IOException {
+    try {    
+      OMOutputFormat outputFormat = new OMOutputFormat();
+      outputFormat.setCharSetEncoding(this.getCharsetEncoding());
+      MTOMXMLStreamWriter omwriter = new MTOMXMLStreamWriter(out, outputFormat);
+      internalSerialize(omwriter, true);
+      omwriter.flush();
+    } catch (XMLStreamException e) {
+      throw new FOMException(e);
+    }
+  }
+
+  public void writeTo(java.io.Writer writer) throws IOException {
     try {
       setComplete(true);      
       OMOutputFormat outputFormat = new OMOutputFormat();
       outputFormat.setCharSetEncoding(this.getCharsetEncoding());
-      serializeAndConsume(out, outputFormat);
+      XMLStreamWriter streamwriter = 
+        XMLOutputFactory.newInstance().createXMLStreamWriter(
+          writer);
+      MTOMXMLStreamWriter omwriter = new MTOMXMLStreamWriter(streamwriter);
+      omwriter.setOutputFormat(outputFormat);
+      this.internalSerializeAndConsume(omwriter);
+      omwriter.flush();
     } catch (XMLStreamException e) {
       throw new FOMException(e);
     }
   }
-
+  
   public MimeType getContentType() {
     return contentType;
   }
@@ -145,4 +166,5 @@
   public Factory getFactory() {
     return (Factory) this.factory;
   }
+  
 }

Modified: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMElement.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMElement.java?rev=415372&r1=415371&r2=415372&view=diff
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMElement.java
(original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMElement.java
Mon Jun 19 09:47:07 2006
@@ -27,7 +27,9 @@
 import java.util.List;
 
 import javax.xml.namespace.QName;
+import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.abdera.factory.Factory;
 import org.apache.abdera.model.Base;
@@ -51,6 +53,7 @@
 import org.apache.axiom.om.OMProcessingInstruction;
 import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
 import org.apache.axiom.om.impl.llom.OMElementImpl;
 
 
@@ -291,12 +294,31 @@
     try {
       OMOutputFormat outputFormat = new OMOutputFormat();
       outputFormat.setCharSetEncoding(getDocument().getCharset());
-      serializeAndConsume(out, outputFormat);
+      MTOMXMLStreamWriter omwriter = 
+        new MTOMXMLStreamWriter(out, outputFormat);
+      internalSerialize(omwriter, true);
+      omwriter.flush();
     } catch (XMLStreamException e) {
       throw new FOMException(e);
     }
   }
 
+  public void writeTo(java.io.Writer writer) throws IOException {
+    try { 
+      OMOutputFormat outputFormat = new OMOutputFormat();
+      outputFormat.setCharSetEncoding(getDocument().getCharset());
+      XMLStreamWriter streamwriter = 
+        XMLOutputFactory.newInstance().createXMLStreamWriter(
+          writer);
+      MTOMXMLStreamWriter omwriter = new MTOMXMLStreamWriter(streamwriter);
+      omwriter.setOutputFormat(outputFormat);
+      this.internalSerialize(omwriter, true);
+      omwriter.flush();
+    } catch (XMLStreamException e) {
+      throw new FOMException(e);
+    }
+  }
+  
   @SuppressWarnings("unchecked")
   public <T extends Element>Document<T> getDocument() {
     Document<T> document = null;
@@ -472,8 +494,6 @@
   
   @SuppressWarnings("unchecked")
   public <T extends Base>T clone() {
-    // TODO: axiom 1.0 now has a clone method, but it doesn't seem
-    // to want to work with this.  we need to investigate
     OMElement el = _create(this);
     _copyElement(this, el);
     return (T) el;

Modified: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMParser.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMParser.java?rev=415372&r1=415371&r2=415372&view=diff
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMParser.java
(original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMParser.java
Mon Jun 19 09:47:07 2006
@@ -18,8 +18,12 @@
 package org.apache.abdera.parser.stax;
 
 import java.io.InputStream;
+import java.io.Reader;
 import java.net.URI;
 
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
 import org.apache.abdera.factory.Factory;
 import org.apache.abdera.model.Document;
 import org.apache.abdera.model.Element;
@@ -29,11 +33,32 @@
 import org.apache.abdera.util.AbstractParser;
 import org.apache.axiom.om.OMDocument;
 
-
 public class FOMParser 
   extends AbstractParser 
   implements Parser {
 
+  private FOMFactory getFomFactory(ParserOptions options) {
+    FOMFactory factory = 
+      (options != null && options.getFactory() != null) ? 
+        (FOMFactory)options.getFactory() : null;
+    if (factory == null)
+      factory = (Factory.INSTANCE instanceof FOMFactory) ? 
+        (FOMFactory)Factory.INSTANCE : new FOMFactory();
+    return factory;
+  }
+  
+  private <T extends Element>Document<T> getDocument(
+    FOMBuilder builder, 
+    URI base, 
+    ParserOptions options) {
+      Document<T> document = builder.getFomDocument();
+      document.setBaseUri(base);
+      if (options.getCharset() != null) {
+        ((OMDocument)document).setCharsetEncoding(options.getCharset());
+      }
+      return document;
+  }
+  
   public <T extends Element>Document<T> parse(
     InputStream in, 
     URI base, 
@@ -41,16 +66,9 @@
       throws ParseException {
     Document<T> document = null;
     try {
-      FOMFactory factory = (options != null && options.getFactory() != null) ? (FOMFactory)options.getFactory()
: null;
-      if (factory == null)
-        factory = (Factory.INSTANCE instanceof FOMFactory) ? (FOMFactory)Factory.INSTANCE
: new FOMFactory();
-      
+      FOMFactory factory = getFomFactory(options);
       FOMBuilder builder = new FOMBuilder(factory, in, options);
-      document = builder.getFomDocument();
-      document.setBaseUri(base);
-      if (options.getCharset() != null) {
-        ((OMDocument)document).setCharsetEncoding(options.getCharset());
-      }
+      document = getDocument(builder, base, options);
     } catch (Exception e) {
       if (!(e instanceof ParseException))
         e = new ParseException(e);
@@ -59,6 +77,26 @@
     return document;
   }
 
+  public <T extends Element> Document<T> parse(
+    Reader in, 
+    URI base, 
+    ParserOptions options) 
+      throws ParseException {
+    Document<T> document = null;
+    try {
+      FOMFactory factory = getFomFactory(options);
+      XMLStreamReader xmlreader = 
+        XMLInputFactory.newInstance().createXMLStreamReader(in);
+      FOMBuilder builder = new FOMBuilder(factory, xmlreader, options);
+      document = getDocument(builder, base, options);
+    } catch (Exception e) {
+      if (!(e instanceof ParseException))
+        e = new ParseException(e);
+      throw (ParseException)e;
+    }
+    return document;
+  }
+  
   @Override
   public ParserOptions getDefaultParserOptions() {
     return new FOMParserOptions();



Mime
View raw message