abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r415728 - in /incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util: AbderaResult.java AbderaSource.java
Date Tue, 20 Jun 2006 16:50:39 GMT
Author: jmsnell
Date: Tue Jun 20 09:50:39 2006
New Revision: 415728

URL: http://svn.apache.org/viewvc?rev=415728&view=rev
Log:
Adding the javax.xml.transform Source and Result implementations

Added:
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaResult.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaSource.java

Added: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaResult.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaResult.java?rev=415728&view=auto
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaResult.java
(added)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaResult.java
Tue Jun 20 09:50:39 2006
@@ -0,0 +1,68 @@
+package org.apache.abdera.util;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.io.Writer;
+
+import javax.xml.transform.Result;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.abdera.model.Document;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.parser.Parser;
+
+/**
+ * Provides a simple (and likely somewhat inefficient) implementation of 
+ * javax.xml.transform.Result that allows Abdera objects to be used with
+ * the javax.xml.transform API's
+ * 
+ * Only use this once per transform!!!
+ */
+public class AbderaResult 
+  extends StreamResult 
+  implements Result {
+
+  private PipedOutputStream pipeout = null;
+  private PipedInputStream pipein = null;
+  private Document doc = null;
+  
+  @SuppressWarnings("unchecked")
+  public <T extends Element>Document<T> getDocument() {
+    if (doc == null) {
+      if (pipein == null) return null;
+      doc = Parser.INSTANCE.parse(pipein);
+    } 
+    return doc;
+  }
+  
+  @Override
+  public OutputStream getOutputStream() {
+    if (pipein == null && pipeout == null) { 
+      try {
+        pipeout = new PipedOutputStream();
+        pipein = new PipedInputStream(pipeout);
+      } catch (IOException e) {}
+    }
+    return pipeout;
+  }
+
+  @Override
+  public Writer getWriter() {
+    return null;
+  }
+
+  @Override
+  public void setOutputStream(OutputStream out) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public void setWriter(Writer out) {
+    throw new UnsupportedOperationException();
+  }
+
+  
+  
+}

Added: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaSource.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaSource.java?rev=415728&view=auto
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaSource.java
(added)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaSource.java
Tue Jun 20 09:50:39 2006
@@ -0,0 +1,57 @@
+package org.apache.abdera.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.io.Reader;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.abdera.model.Base;
+
+/**
+ * Provides a simple (and likely somewhat inefficient) implementation of 
+ * javax.xml.transform.Source that allows Abdera objects to be used with
+ * the javax.xml.transform API's
+ */
+public class AbderaSource 
+  extends StreamSource 
+  implements Source {
+
+  private Base base = null;
+  
+  public AbderaSource(Base base) {
+    this.base = base;
+  }
+  
+  @Override
+  public InputStream getInputStream() {
+    try {
+      PipedOutputStream pipeout = new PipedOutputStream();
+      PipedInputStream pipein = new PipedInputStream(pipeout);
+      base.writeTo(pipeout);
+      pipeout.flush();
+      pipeout.close();
+      return pipein;
+    } catch (IOException e) {}
+    return null;
+  }
+
+  @Override
+  public Reader getReader() {
+    return null;
+  }
+
+  @Override
+  public void setInputStream(InputStream in) {
+    throw new UnsupportedOperationException();
+  }
+
+  @Override
+  public void setReader(Reader reader) {
+    throw new UnsupportedOperationException();
+  }
+
+}



Mime
View raw message