abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r564623 - in /incubator/abdera/java/trunk: core/src/main/java/org/apache/abdera/model/Collection.java parser/src/main/java/org/apache/abdera/parser/stax/FOMCollection.java
Date Fri, 10 Aug 2007 15:41:16 GMT
Author: jmsnell
Date: Fri Aug 10 08:41:15 2007
New Revision: 564623

URL: http://svn.apache.org/viewvc?view=rev&rev=564623
Log:
Fixing a bug in Collection as reported by David Calavera on the users list.

> the source code:
>     Collection users = workspace.addCollection("Users", USERS_URL);
>     users.setAccept(new String[]{"multipart/form-data", "entry"});
> 
> the output:
> 
>     <collection href="/api/v1/users">
>       <atom:title type="text">Users</atom:title>
>       <accept>multipart/form-data</accept>
>     </collection>

Update the code so that a mime type parse exception is not ignored and that the "entry"
token is automatically converted to the full Atom entry media type.

Modified:
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Collection.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMCollection.java

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Collection.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Collection.java?view=diff&rev=564623&r1=564622&r2=564623
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Collection.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Collection.java
Fri Aug 10 08:41:15 2007
@@ -20,6 +20,7 @@
 import java.util.List;
 
 import javax.activation.MimeType;
+import javax.activation.MimeTypeParseException;
 
 import org.apache.abdera.i18n.iri.IRI;
 
@@ -112,8 +113,9 @@
    * Set the listing of media-ranges allowed for this collection.  The special
    * value "entry" is used to indicate Atom Entry Documents.
    * @param mediaRanges a listing of media-ranges 
+   * @throws MimeTypeParseException 
    */
-  void setAccept(String... mediaRanges);
+  void setAccept(String... mediaRanges) throws MimeTypeParseException;
   
   /**
    * Returns true if the collection accepts the given media-type

Modified: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMCollection.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMCollection.java?view=diff&rev=564623&r1=564622&r2=564623
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMCollection.java
(original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMCollection.java
Fri Aug 10 08:41:15 2007
@@ -22,6 +22,7 @@
 import java.util.List;
 
 import javax.activation.MimeType;
+import javax.activation.MimeTypeParseException;
 import javax.xml.namespace.QName;
 
 import org.apache.abdera.model.Categories;
@@ -55,7 +56,8 @@
   public FOMCollection(
     String title, 
     String href, 
-    String[] accepts) {
+    String[] accepts) 
+      throws MimeTypeParseException {
     this();
     setTitle(title);
     setHref(href);
@@ -162,11 +164,11 @@
     }
   }
 
-  public void setAccept(String mediaRange) {
+  public void setAccept(String mediaRange) throws MimeTypeParseException {
     setAccept(new String[] {mediaRange});
   }
   
-  public void setAccept(String... mediaRanges) {
+  public void setAccept(String... mediaRanges) throws MimeTypeParseException {
     if (mediaRanges != null && mediaRanges.length > 0) {
       _removeChildren(ACCEPT, true);
       _removeChildren(PRE_RFC_ACCEPT, true);
@@ -175,9 +177,11 @@
       } else {
         mediaRanges = MimeTypeHelper.condense(mediaRanges);
         for (String type : mediaRanges) {
-          try {
+          if (type.equalsIgnoreCase("entry")) {
+            addSimpleExtension(ACCEPT,"application/atom+xml;type=entry");
+          } else {
             addSimpleExtension(ACCEPT, new MimeType(type).toString());
-          } catch (Exception e) {}
+          }
         }
       }
     } else {
@@ -207,11 +211,15 @@
   }
   
   public void setAcceptsEntry() {
-    setAccept("application/atom+xml;type=entry");
+    try {
+      setAccept("application/atom+xml;type=entry");
+    } catch (MimeTypeParseException m) {}
   }
   
   public void setAcceptsNothing() {
-    setAccept("");
+    try {
+      setAccept("");
+    } catch (MimeTypeParseException m) {}
   }
   
   public boolean acceptsEntry() {



Mime
View raw message