abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r530895 - in /incubator/abdera/java/trunk: core/src/main/java/org/apache/abdera/model/Collection.java core/src/main/java/org/apache/abdera/util/MimeTypeHelper.java parser/src/main/java/org/apache/abdera/parser/stax/FOMCollection.java
Date Fri, 20 Apr 2007 19:22:02 GMT
Author: jmsnell
Date: Fri Apr 20 12:22:01 2007
New Revision: 530895

URL: http://svn.apache.org/viewvc?view=rev&rev=530895
Log:
The APP spec is changing the definition of the <accept> header.
Instead of <accept>entry,image/*</accept>, it's going to be multiple
elements...

  <accept>entry</accept>
  <accept>image/*</accept>
  
It's also likely that the "entry" special value will be changed to the full entry media type:

  application/atom+xml;type="entry"

Modified:
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Collection.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/MimeTypeHelper.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=530895&r1=530894&r2=530895
==============================================================================
--- 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 Apr 20 12:22:01 2007
@@ -102,12 +102,6 @@
    * @throws IRISyntaxException if the href attribute is malformed 
    */
   void setHref(String href) throws IRISyntaxException;
-
-  /**
-   * Returns the app:accept element
-   * @return The app:accept element
-   */
-  Element getAcceptElement();
   
   /**
    * Returns the listing of media-ranges allowed for this collection

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/MimeTypeHelper.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/MimeTypeHelper.java?view=diff&rev=530895&r1=530894&r2=530895
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/MimeTypeHelper.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/MimeTypeHelper.java
Fri Apr 20 12:22:01 2007
@@ -20,9 +20,11 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Comparator;
+import java.util.Enumeration;
 import java.util.List;
 
 import javax.activation.MimeType;
+import javax.activation.MimeTypeParameterList;
 import javax.activation.MimeTypeParseException;
 
 import org.apache.abdera.model.Base;
@@ -70,15 +72,30 @@
   public static boolean isMatch(MimeType a, MimeType b) {
     try {
       if (a == null || b == null) return true;
-      if (a.match(b)) return true;
+      if (a.match(b)) {
+        MimeTypeParameterList aparams = a.getParameters();
+        MimeTypeParameterList bparams = b.getParameters();
+        if (aparams.isEmpty() && bparams.isEmpty()) return true;
+        if (aparams.isEmpty() && !bparams.isEmpty()) return false;
+        if (!aparams.isEmpty() && bparams.isEmpty()) return false;
+        boolean answer = true;
+        for (Enumeration e = aparams.getNames(); e.hasMoreElements();) {
+          String aname = (String)e.nextElement();
+          String avalue = aparams.get(aname);
+          String bvalue = bparams.get(aname);
+          if (avalue.equals(bvalue)) answer = true;
+          else { answer = false; break; }
+        }
+        return answer;
+      }
       if (a.equals(WILDCARD)) return true;
       if (a.getPrimaryType().equals("*")) {
         MimeType c = new MimeType(b.getPrimaryType(), a.getSubType());
-        return c.match(b);
+        return isMatch(c,b);
       }
       if (b.getPrimaryType().equals("*")) {
         MimeType c = new MimeType(a.getPrimaryType(), b.getSubType());
-        return c.match(a);
+        return isMatch(a,c);
       }
     } catch (Exception e) {}
     return false;

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=530895&r1=530894&r2=530895
==============================================================================
--- 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 Apr 20 12:22:01 2007
@@ -17,6 +17,8 @@
 */
 package org.apache.abdera.parser.stax;
 
+import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 
 import javax.activation.MimeType;
@@ -42,8 +44,8 @@
   extends FOMExtensibleElement 
   implements Collection {
 
+  private static final String[] ENTRY = {"application/atom+xml;type=\"entry\""};
   private static final String[] EMPTY = new String[0];
-  private static final String[] ENTRY = new String[] {"entry"};
   
   private static final long serialVersionUID = -5291734055253987136L;
 
@@ -143,21 +145,25 @@
       removeAttribute(HREF);
   }
   
-  public Element getAcceptElement() {
-    return getFirstChild(ACCEPT);
-  }
-  
   public String[] getAccept(){
-    String accept = _getElementValue(ACCEPT);
-    if (accept == null) return ENTRY;
-    else accept = accept.trim();
-    if (accept.length() == 0) return EMPTY;
-    String[] list = accept.split("\\s*,\\s*(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))");
-    return MimeTypeHelper.condense(list);
+    List<String> accept = new ArrayList<String>();
+    for (Iterator i = getChildrenWithName(ACCEPT); i.hasNext();) {
+      Element e = (Element) i.next();
+      String t = e.getText();
+      if (t != null) { 
+        accept.add(t.trim());
+      }
+    }
+    if (accept.size() > 0) {
+      String[] list = accept.toArray(new String[accept.size()]);
+      return MimeTypeHelper.condense(list);
+    } else {
+      return EMPTY;
+    }
   }
 
   public void setAccept(String... mediaRanges) {
-    if (mediaRanges != null) {
+    if (mediaRanges != null || mediaRanges.length == 0) {
       mediaRanges = MimeTypeHelper.condense(mediaRanges);
       StringBuffer value = new StringBuffer();
       for (String type : mediaRanges) {
@@ -165,17 +171,16 @@
           value.append(",");
         value.append(type);
       }
-      _setElementValue(ACCEPT, value.toString());
+      addSimpleExtension(ACCEPT, value.toString());
     } else {
-      _removeChildren(ACCEPT, false);
+      _removeChildren(ACCEPT, true);
     }
   }
 
   public boolean accepts(String mediaType) {
     String[] accept = getAccept();
+    if (accept.length == 0) accept = ENTRY;
     for (String a : accept) {
-      if (mediaType.equalsIgnoreCase("entry") && 
-          a.equalsIgnoreCase("entry")) return true;
       if (MimeTypeHelper.isMatch(a, mediaType)) return true;
     }
     return false;



Mime
View raw message