abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r598014 - in /incubator/abdera/java/trunk: core/src/main/java/org/apache/abdera/util/ core/src/main/java/org/apache/abdera/writer/ parser/src/main/java/org/apache/abdera/parser/stax/
Date Sun, 25 Nov 2007 17:13:28 GMT
Author: jmsnell
Date: Sun Nov 25 09:13:28 2007
New Revision: 598014

URL: http://svn.apache.org/viewvc?rev=598014&view=rev
Log:
Additional improvements to StreamWriter to avoid having to use the QName class at all (along
with other minor improvements)

Modified:
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractStreamWriter.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/StreamWriter.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/StaxStreamWriter.java

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractStreamWriter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractStreamWriter.java?rev=598014&r1=598013&r2=598014&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractStreamWriter.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractStreamWriter.java
Sun Nov 25 09:13:28 2007
@@ -23,6 +23,7 @@
 import java.nio.channels.Channels;
 import java.nio.channels.WritableByteChannel;
 import java.util.Date;
+import java.util.Formatter;
 import java.util.Locale;
 
 import javax.activation.DataHandler;
@@ -33,6 +34,7 @@
 import org.apache.abdera.model.AtomDate;
 import org.apache.abdera.model.Content;
 import org.apache.abdera.model.Text;
+import org.apache.abdera.model.Text.Type;
 import org.apache.abdera.writer.StreamWriter;
 import org.apache.commons.codec.binary.Base64;
 
@@ -465,6 +467,10 @@
   public StreamWriter writeAuthor(String name, String email, String uri) {
     return writePerson(Constants.AUTHOR,name,email,uri);
   }
+  
+  public StreamWriter writeAuthor(String name) {
+    return writeAuthor(name, null, null);
+  }
 
   public StreamWriter startAuthor() {
     return startElement(Constants.AUTHOR);
@@ -477,6 +483,10 @@
   public StreamWriter writeContributor(String name, String email, String uri) {
     return writePerson(Constants.CONTRIBUTOR,name,email,uri);
   }
+  
+  public StreamWriter writeContributor(String name) {
+    return writeContributor(name,null,null);
+  }
 
   public StreamWriter startContributor() {
     return startElement(Constants.CONTRIBUTOR);
@@ -850,4 +860,266 @@
     return writeLanguage(new Lang(locale));
   }
 
+  public StreamWriter writeIRIElement(String name, IRI iri) {
+    return 
+      startElement(name).
+      writeElementText(iri.toString()).
+      endElement();
+  }
+
+  public StreamWriter writeIRIElement(String name, String namespace, IRI iri) {
+    return 
+      startElement(name,namespace).
+      writeElementText(iri.toString()).
+      endElement();
+  }
+
+  public StreamWriter writeIRIElement(
+    String name, 
+    String namespace,
+    String prefix, 
+    IRI iri) {
+      return 
+        startElement(name,namespace,prefix).
+        writeElementText(iri.toString()).
+        endElement();
+  }
+
+  public StreamWriter writeIRIElement(
+    String name, 
+    String namespace,
+    String prefix, 
+    String iri) {
+      return 
+        startElement(name,namespace,prefix).
+        writeElementText(iri).
+        endElement();
+  }
+
+  public StreamWriter writeIRIElement(
+    String name, 
+    String namespace, 
+    String iri) {
+      return 
+      startElement(name,namespace).
+      writeElementText(iri).
+      endElement();
+  }
+
+  public StreamWriter writeIRIElement(
+    String name, 
+    String iri) {
+      return 
+        startElement(name).
+        writeElementText(iri).
+        endElement();
+  }
+
+  public StreamWriter writeDate(
+    String name, 
+    Date date) {
+      return
+        startElement(name).
+        writeElementText(date).
+        endElement();
+  }
+
+  public StreamWriter writeDate(
+    String name, 
+    String namespace, 
+    Date date) {
+      return
+        startElement(name,namespace).
+        writeElementText(date).
+        endElement();
+  }
+
+  public StreamWriter writeDate(
+    String name, 
+    String namespace, 
+    String prefix,
+    Date date) {
+      return
+        startElement(name,namespace,prefix).
+        writeElementText(date).
+        endElement();
+  }
+
+  public StreamWriter writeDate(
+    String name, 
+    String date) {
+      return
+        startElement(name).
+        writeElementText(date).
+        endElement();
+  }
+  
+  public StreamWriter writeDate(
+    String name,
+    String namespace,
+    String date) {
+      return
+        startElement(name,namespace).
+        writeElementText(date).
+        endElement();
+  }
+
+  public StreamWriter writeDate(
+    String name,
+    String namespace,
+    String prefix,
+    String date) {
+      return
+        startElement(name,namespace,prefix).
+        writeElementText(date).
+        endElement();
+  }
+
+  public StreamWriter startText(
+    String name, 
+    String namespace, 
+    String prefix,
+    Type type) {
+      return 
+        startElement(name,namespace,prefix).
+        writeAttribute("type",type!=null?type.name().toLowerCase():"text");
+  }
+
+  public StreamWriter startText(
+    String name, 
+    String namespace, 
+    Type type) {
+      return 
+        startElement(name,namespace).
+        writeAttribute("type",type!=null?type.name().toLowerCase():"text");
+  }
+
+  public StreamWriter startText(
+    String name, 
+    Type type) {
+      return 
+        startElement(name).
+        writeAttribute("type",type!=null?type.name().toLowerCase():"text");
+  }
+
+  public StreamWriter writeText(
+    String name, 
+    String namespace, 
+    String prefix,
+    Type type, 
+    String value) {
+      return 
+        startText(name,namespace,prefix,type).
+        writeElementText(value).
+        endElement();
+  }
+
+  public StreamWriter writeText(
+    String name, 
+    String namespace, 
+    Type type,
+    String value) {
+      return 
+        startText(name,namespace,type).
+        writeElementText(value).
+        endElement();
+  }
+
+  public StreamWriter writeText(
+    String name, 
+    Type type, 
+    String value) {
+      return 
+        startText(name,type).
+        writeElementText(value).
+        endElement();
+  }
+
+  public StreamWriter startPerson(
+    String name, 
+    String namespace, 
+    String prefix) {
+      return startElement(name,namespace,prefix);
+  }
+
+  public StreamWriter startPerson(
+    String name, 
+    String namespace) {
+      return startElement(name,namespace);
+  }
+
+  public StreamWriter startPerson(String name) {
+    return startElement(name);
+  }
+
+  public StreamWriter writePerson(
+    String localname, 
+    String namespace,
+    String prefix, 
+    String name, 
+    String email, 
+    String uri) {
+      return 
+        startPerson(localname,namespace,prefix).
+        writePersonName(name).
+        writePersonEmail(email).
+        writePersonUri(uri).
+        endPerson();
+  }
+
+  public StreamWriter writePerson(
+    String localname, 
+    String namespace,
+    String name, 
+    String email, 
+    String uri) {
+      return 
+        startPerson(localname,namespace).
+        writePersonName(name).
+        writePersonEmail(email).
+        writePersonUri(uri).
+        endPerson();
+  }
+
+  public StreamWriter writePerson(
+    String localname, 
+    String name, 
+    String email,
+    String uri) {
+      return 
+        startPerson(localname).
+        writePersonName(name).
+        writePersonEmail(email).
+        writePersonUri(uri).
+        endPerson();
+  }
+
+  public Appendable append(
+    char c) 
+      throws IOException {
+    return writeElementText(
+      String.valueOf(c));
+  }
+
+  public Appendable append(
+    CharSequence csq, 
+    int start, 
+    int end)
+      throws IOException {
+    return append(
+      csq.subSequence(
+        start, end));
+  }
+
+  public Appendable append(
+    CharSequence csq) 
+      throws IOException {
+    return writeElementText(
+      csq.toString());
+  }  
+  
+  public StreamWriter writeElementText(String format, Object... args) {
+    new Formatter(this).format(format,args); 
+    return this;
+  }
 }

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/StreamWriter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/StreamWriter.java?rev=598014&r1=598013&r2=598014&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/StreamWriter.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/StreamWriter.java
Sun Nov 25 09:13:28 2007
@@ -17,6 +17,7 @@
  */
 package org.apache.abdera.writer;
 
+import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Date;
@@ -39,7 +40,9 @@
  * The StreamWriter is NOT synchronized and is NOT threadsafe
  */
 public interface StreamWriter 
-  extends NamedItem {
+  extends NamedItem, 
+          Appendable, 
+          Closeable {
 
   StreamWriter flush();
   
@@ -144,8 +147,32 @@
    * @param iri The value
    */
   StreamWriter writeIRIElement(QName qname, String iri);
+  
+  /**
+   * Write an IRI element
+   * @param name The element localname
+   * @param namespace The element namespace
+   * @param prefix the element prefix
+   * @param iri the IRI to write
+   */
+  StreamWriter writeIRIElement(String name, String namespace, String prefix, String iri);
 
   /**
+   * Write an IRI element
+   * @param name The element localname
+   * @param namespace The element namespace
+   * @param iri the IRI to write
+   */
+  StreamWriter writeIRIElement(String name, String namespace, String iri);
+  
+  /**
+   * Write an IRI element
+   * @param name The element localname
+   * @param iri the IRI to write
+   */
+  StreamWriter writeIRIElement(String name, String iri);
+  
+  /**
    * Write an atom:id element
    * @param iri The value
    */
@@ -170,6 +197,30 @@
   StreamWriter writeIRIElement(QName qname, IRI iri);
   
   /**
+   * Write an IRI element
+   * @param name The element localname
+   * @param namespace The element namespace
+   * @param prefix the element prefix
+   * @param iri the IRI to write
+   */
+  StreamWriter writeIRIElement(String name, String namespace, String prefix, IRI iri);
+
+  /**
+   * Write an IRI element
+   * @param name The element localname
+   * @param namespace The element namespace
+   * @param iri the IRI to write
+   */
+  StreamWriter writeIRIElement(String name, String namespace, IRI iri);
+  
+  /**
+   * Write an IRI element
+   * @param name The element localname
+   * @param iri the IRI to write
+   */
+  StreamWriter writeIRIElement(String name, IRI iri);
+  
+  /**
    * Write an atom:id element with a new IRI value
    * @param iri The value
    */
@@ -199,6 +250,30 @@
    * @param date The date value
    */
   StreamWriter writeDate(QName qname, Date date);
+  
+  /**
+   * Write a Date element
+   * @param name The element localname
+   * @param namespace The element namespace
+   * @param prefix The element prefix
+   * @param date The date value
+   */
+  StreamWriter writeDate(String name, String namespace, String prefix, Date date);
+  
+  /**
+   * Write a Date element
+   * @param name The element localname
+   * @param namespace The element namespace
+   * @param date The date value
+   */
+  StreamWriter writeDate(String name, String namespace, Date date);
+
+  /**
+   * Write a Date element
+   * @param name The element localname
+   * @param date The date value
+   */
+  StreamWriter writeDate(String name, Date date);
 
   /**
    * Write an atom:updated element
@@ -226,6 +301,30 @@
   StreamWriter writeDate(QName qname, String date);
   
   /**
+   * Write a Date element
+   * @param name The element localname
+   * @param namespace The element namespace
+   * @param prefix The element prefix
+   * @param date The date value
+   */
+  StreamWriter writeDate(String name, String namespace, String prefix, String date);
+  
+  /**
+   * Write a Date element
+   * @param name The element localname
+   * @param namespace The element namespace
+   * @param date The date value
+   */
+  StreamWriter writeDate(String name, String namespace, String date);
+
+  /**
+   * Write a Date element
+   * @param name The element localname
+   * @param date The date value
+   */
+  StreamWriter writeDate(String name, String date);
+  
+  /**
    * End the person element
    */
   StreamWriter endPerson();
@@ -365,6 +464,33 @@
    * @param value The text value
    */
   StreamWriter writeText(QName qname, Text.Type type, String value);
+
+  /**
+   * Write a Text element
+   * @param name The element name
+   * @param type The text type
+   * @param value The text value
+   */
+  StreamWriter writeText(String name, Text.Type type, String value);
+
+  /**
+   * Write a Text element
+   * @param name The element name
+   * @param namespace The element namespace
+   * @param type The text type
+   * @param value The text value
+   */
+  StreamWriter writeText(String name, String namespace, Text.Type type, String value);
+  
+  /**
+   * Write a Text element
+   * @param name The element name
+   * @param namespace The element namespace
+   * @param prefix The element prefix
+   * @param type The text type
+   * @param value The text value
+   */
+  StreamWriter writeText(String name, String namespace, String prefix, Text.Type type, String
value);
   
   /**
    * Start a Text element
@@ -372,6 +498,33 @@
    * @param type The text type
    */
   StreamWriter startText(QName qname, Text.Type type);
+
+  /**
+   * Start a Text element
+   * @param name The element name
+   * @param type The text type
+   * @param value The text value
+   */
+  StreamWriter startText(String name, Text.Type type);
+
+  /**
+   * Start a Text element
+   * @param name The element name
+   * @param namespace The element namespace
+   * @param type The text type
+   * @param value The text value
+   */
+  StreamWriter startText(String name, String namespace, Text.Type type);
+  
+  /**
+   * Start a Text element
+   * @param name The element name
+   * @param namespace The element namespace
+   * @param prefix The element prefix
+   * @param type The text type
+   * @param value The text value
+   */
+  StreamWriter startText(String name, String namespace, String prefix, Text.Type type); 

   
   /**
    * End the atom:content element
@@ -454,6 +607,13 @@
   StreamWriter startElement(String name, String namespace, String prefix);
   
   /**
+   * Write element text using Formatter
+   * @param format
+   * @param params
+   */
+  StreamWriter writeElementText(String format, Object... params);
+  
+  /**
    * Write element text
    * @param value The text value
    */  
@@ -562,10 +722,61 @@
   StreamWriter writePerson(QName qname, String name, String email, String uri);
 
   /**
+   * Write a person element
+   * @param localhost the element name
+   * @param name The person name
+   * @param email The person email
+   * @param uri The person uri
+   */
+  StreamWriter writePerson(String localname, String name, String email, String uri);
+
+  /**
+   * Write a person element
+   * @param localhost the element name
+   * @param namespace the element namespace
+   * @param name The person name
+   * @param email The person email
+   * @param uri The person uri
+   */
+  StreamWriter writePerson(String localname, String namespace, String name, String email,
String uri);
+
+  /**
+   * Write a person element
+   * @param localhost the element name
+   * @param namespace the element namespace
+   * @param prefix the element prefix
+   * @param name The person name
+   * @param email The person email
+   * @param uri The person uri
+   */
+  StreamWriter writePerson(String localname, String namespace, String prefix, String name,
String email, String uri);
+  
+  /**
    * Start a person element
    * @param qname The element qname
    */  
   StreamWriter startPerson(QName qname);
+
+  /**
+   * Start a person element
+   * @param name The element name
+   */  
+  StreamWriter startPerson(String name);
+  
+  /**
+   * Start a person element
+   * @param name The element name
+   * @param namespace The element namespace
+   */  
+  StreamWriter startPerson(String name, String namespace);
+
+  /**
+   * Start a person element
+   * @param name The element name
+   * @param namespace The element namespace
+   * @param prefix The element prefix
+   */  
+  StreamWriter startPerson(String name, String namespace, String prefix);
   
   /**
    * Write a person name
@@ -594,6 +805,12 @@
   StreamWriter writeAuthor(String name, String email, String uri);
   
   /**
+   * Write an atom:author element
+   * @param name The person name
+   */
+  StreamWriter writeAuthor(String name);
+  
+  /**
    * Start an atom:author element
    */
   StreamWriter startAuthor();
@@ -610,6 +827,12 @@
    * @param uri The person uri
    */
   StreamWriter writeContributor(String name, String email, String uri);
+
+  /**
+   * Write an atom:contributor element
+   * @param name The person name
+   */
+  StreamWriter writeContributor(String name);
   
   /**
    * Start an atom:contributor element

Modified: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/StaxStreamWriter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/StaxStreamWriter.java?rev=598014&r1=598013&r2=598014&view=diff
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/StaxStreamWriter.java
(original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/StaxStreamWriter.java
Sun Nov 25 09:13:28 2007
@@ -17,6 +17,7 @@
  */
 package org.apache.abdera.parser.stax;
 
+import java.io.IOException;
 import java.io.OutputStream;
 import java.io.Writer;
 import java.util.Arrays;
@@ -302,5 +303,13 @@
       throw new RuntimeException(e);
     }
     return this;
+  }
+
+  public void close() throws IOException {
+    try {
+      writer.close();
+    } catch (XMLStreamException e) {
+      throw new RuntimeException(e);
+    }
   }
 }



Mime
View raw message