abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r530211 - in /incubator/abdera/java/trunk: client/src/main/java/org/apache/abdera/protocol/client/ core/src/main/java/org/apache/abdera/model/ extensions/src/main/java/org/apache/abdera/ext/features/ parser/src/main/java/org/apache/abdera/p...
Date Thu, 19 Apr 2007 00:19:27 GMT
Author: jmsnell
Date: Wed Apr 18 17:19:26 2007
New Revision: 530211

URL: http://svn.apache.org/viewvc?view=rev&rev=530211
Log:
Some general improvements

* in the Document object, capture some of the entity headers from a request
* add the language and slug entity headers to the document element
* use the Content-Location header, if provided, as a basis for relative uri resolution
* set the slug header from the document, if provided
* add a method to ClientResponse to get the charset encoding for the request to use that in
the parse
* changes to the features extension implementation to reflect an upcoming spec update
* resolve the base language from the Document object

Removed:
    incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/features/Control.java
Modified:
    incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbstractClientResponse.java
    incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/Client.java
    incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/ClientResponse.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Document.java
    incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/features/FeaturesExtensionFactory.java
    incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/features/FeaturesHelper.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

Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbstractClientResponse.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbstractClientResponse.java?view=diff&rev=530211&r1=530210&r2=530211
==============================================================================
--- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbstractClientResponse.java
(original)
+++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbstractClientResponse.java
Wed Apr 18 17:19:26 2007
@@ -21,7 +21,11 @@
 import java.io.InputStream;
 import java.util.Date;
 
+import javax.activation.MimeType;
+import javax.activation.MimeTypeParseException;
+
 import org.apache.abdera.Abdera;
+import org.apache.abdera.i18n.iri.IRI;
 import org.apache.abdera.model.Document;
 import org.apache.abdera.model.Element;
 import org.apache.abdera.parser.ParseException;
@@ -29,6 +33,7 @@
 import org.apache.abdera.parser.ParserOptions;
 import org.apache.abdera.protocol.util.AbstractResponse;
 import org.apache.abdera.protocol.util.CacheControlUtil;
+import org.apache.abdera.util.EntityTag;
 
 public abstract class AbstractClientResponse
   extends AbstractResponse
@@ -72,7 +77,26 @@
     ParserOptions options) 
       throws ParseException {
     try {
-      return parser.parse(getInputStream(), getUri(), options);
+      String charset = getCharacterEncoding();
+      if (charset != null) options.setCharset(charset);
+      IRI cl = getContentLocation();
+      if (!cl.isAbsolute()) {
+        IRI r = new IRI(getUri());
+        cl = r.resolve(cl);
+      }
+      String base = (cl != null) ? cl.toASCIIString() : getUri();
+      Document<T> doc = parser.parse(getInputStream(), base, options);
+      EntityTag etag = getEntityTag();
+      if (etag != null) doc.setEntityTag(etag);
+      Date lm = getLastModified();
+      if (lm != null) doc.setLastModified(lm);
+      MimeType mt = getContentType();
+      if (mt != null) doc.setContentType(mt.toString());
+      String language = getContentLanguage();
+      if (language != null) doc.setLanguage(language);
+      String slug = getSlug();
+      if (slug != null) doc.setSlug(slug);
+      return doc;
     } catch (Exception e) {
       throw new ParseException(e);
     }
@@ -98,6 +122,14 @@
     String cc = getHeader("Cache-Control");
     if (cc != null)
       CacheControlUtil.parseCacheControl(cc, this);
+  }
+  
+  public String getCharacterEncoding() throws MimeTypeParseException {
+    MimeType mt = getContentType();
+    String charset = null;
+    if (mt != null)
+      charset = mt.getParameter("charset");
+    return charset;
   }
 
 }

Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/Client.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/Client.java?view=diff&rev=530211&r1=530210&r2=530211
==============================================================================
--- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/Client.java
(original)
+++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/Client.java
Wed Apr 18 17:19:26 2007
@@ -24,6 +24,7 @@
 
 import org.apache.abdera.Abdera;
 import org.apache.abdera.model.Base;
+import org.apache.abdera.model.Document;
 import org.apache.abdera.protocol.client.cache.Cache;
 import org.apache.abdera.protocol.client.cache.CacheFactory;
 import org.apache.abdera.protocol.client.cache.lru.LRUCache;
@@ -137,6 +138,12 @@
     String uri, 
     Base base, 
     RequestOptions options) {
+      if (base instanceof Document) {
+        Document d = (Document) base;
+        if (options.getSlug() == null && 
+            d.getSlug() != null) 
+          options.setSlug(d.getSlug());
+      }
       return execute("POST", uri, new BaseRequestEntity(base, options.isUseChunked()), options);
   }
     
@@ -158,6 +165,12 @@
       String uri, 
       Base base, 
       RequestOptions options) {
+    if (base instanceof Document) {
+      Document d = (Document) base;
+      if (options.getSlug() == null && 
+          d.getSlug() != null) 
+        options.setSlug(d.getSlug());
+    }
     return execute("PUT", uri, new BaseRequestEntity(base, options.isUseChunked()), options);
   }
       

Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/ClientResponse.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/ClientResponse.java?view=diff&rev=530211&r1=530210&r2=530211
==============================================================================
--- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/ClientResponse.java
(original)
+++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/ClientResponse.java
Wed Apr 18 17:19:26 2007
@@ -21,6 +21,8 @@
 import java.io.InputStream;
 import java.util.Date;
 
+import javax.activation.MimeTypeParseException;
+
 import org.apache.abdera.model.Document;
 import org.apache.abdera.model.Element;
 import org.apache.abdera.parser.ParseException;
@@ -79,5 +81,11 @@
    * Return the server-specified date returned in the response
    */
   Date getServerDate();
+  
+  /**
+   * Return the character set encoding specified in the ContentType header, if ant
+   * @throws MimeTypeParseException 
+   */
+  String getCharacterEncoding() throws MimeTypeParseException;
   
 }

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Document.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Document.java?view=diff&rev=530211&r1=530210&r2=530211
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Document.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/model/Document.java Wed
Apr 18 17:19:26 2007
@@ -25,6 +25,8 @@
 
 import org.apache.abdera.i18n.iri.IRI;
 import org.apache.abdera.i18n.iri.IRISyntaxException;
+import org.apache.abdera.i18n.lang.InvalidLangTagSyntax;
+import org.apache.abdera.i18n.lang.Lang;
 import org.apache.abdera.util.EntityTag;
 
 /**
@@ -130,4 +132,30 @@
    * Set the entity tag for this document
    */
   void setEntityTag(String tag);
+  
+  /**
+   * Get the language
+   */
+  String getLanguage();
+  
+  /**
+   * Returns the value of the xml:lang attribute as a Lang object
+   */
+  Lang getLanguageTag() throws InvalidLangTagSyntax;
+  
+  /**
+   * set the base language
+   */
+  void setLanguage(String lang);
+  
+  /**
+   * Get the slug for this document
+   */
+  String getSlug();
+  
+  /**
+   * Set the slug for this document
+   */
+  void setSlug(String slug);
+  
 }

Modified: incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/features/FeaturesExtensionFactory.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/features/FeaturesExtensionFactory.java?view=diff&rev=530211&r1=530210&r2=530211
==============================================================================
--- incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/features/FeaturesExtensionFactory.java
(original)
+++ incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/features/FeaturesExtensionFactory.java
Wed Apr 18 17:19:26 2007
@@ -43,8 +43,6 @@
     QName qname = internal.getQName();
     if (FeaturesHelper.FEATURE.equals(qname)) 
       return (T)new Feature(internal);
-    else if (FeaturesHelper.CONTROL.equals(qname))
-      return (T)new Control(internal);
     else return (T)internal;
   }
 

Modified: incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/features/FeaturesHelper.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/features/FeaturesHelper.java?view=diff&rev=530211&r1=530210&r2=530211
==============================================================================
--- incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/features/FeaturesHelper.java
(original)
+++ incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/features/FeaturesHelper.java
Wed Apr 18 17:19:26 2007
@@ -21,6 +21,7 @@
 
 import javax.xml.namespace.QName;
 
+import org.apache.abdera.ext.thread.ThreadConstants;
 import org.apache.abdera.factory.Factory;
 import org.apache.abdera.i18n.iri.IRI;
 import org.apache.abdera.i18n.iri.IRISyntaxException;
@@ -35,7 +36,6 @@
 
   public static final String FNS = "http://purl.org/atompub/features/1.0";
   public static final QName FEATURE = new QName(FNS, "feature","f");
-  public static final QName CONTROL = new QName(FNS, "control","f");
   
   public static final String FEATURE_DRAFTS = "http://purl.org/atom/app#drafts";
   public static final String FEATURE_PRESERVE_ENTRY = "http://purl.org/atom/app#preserve-entry";
@@ -59,10 +59,12 @@
   public static final String FEATURE_PRESERVE_UPDATED = "http://purl.org/atom/app#preserve-updated";
   public static final String FEATURE_PRESERVE_EXTENSIONS = "http://purl.org/atom/app#preserve-extensions";
   public static final String FEATURE_PRESERVE_LINKS = "http://purl.org/atom/app#preserve-links";
+  public static final String FEATURE_PRESERVE_RIGHTS = "http://purl.org/atom/app#preserve-rights";
   public static final String FEATURE_SLUG = "http://purl.org/atom/app#slug";
   public static final String FEATURE_MULTIPLE_CATEGORIES= "http://purl.org/atom/app#multiple-categories";
   public static final String FEATURE_CONTRIBUTORS = "http://purl.org/atom/app#contributors";
   public static final String FEATURE_MULTIPLE_AUTHORS = "http://purl.org/atom/app#multiple-authors";
+  public static final String FEATURE_FEED_THREAD = ThreadConstants.THR_NS;
   
   private FeaturesHelper() {}
   
@@ -81,20 +83,6 @@
   }
   
   /**
-   * Returns the specified control element or null
-   */
-  public static Control getControl(
-    Collection collection,
-    String control) {
-      List<Element> list = collection.getExtensions(CONTROL);
-      for (Element el : list) {
-        if (el.getAttributeValue("ref").equals(control))
-          return (Control)el;
-      }
-      return null;
-  }
-  
-  /**
    * Returns true if the collection contains the specified feature element
    */
   public static boolean supportsFeature(
@@ -113,24 +101,6 @@
       return check(list,features) == features.length;
   }
   
-  /**
-   * Returns true if the collection contains the specified control element
-   */
-  public static boolean supportsControl(
-    Collection collection,
-    String control) { 
-      return supportsControl(collection, new String[] {control});
-  }
-  
-  /**
-   * Returns true if the collection contains the specified control element(s)
-   */
-  public static boolean supportsControl(
-    Collection collection, 
-    String... controls) {
-      List<Element> list = collection.getExtensions(CONTROL);
-      return check(list, controls) == controls.length;
-  }
   
   private static int check(List<Element> exts, String... refvals) {
     int c = 0;
@@ -175,32 +145,4 @@
     return el;
   }
   
-  /**
-   * Add the specified control to the collection
-   * @param collection The collection
-   * @param feature The IRI of the control to add 
-   * @param required True if the control is required
-   * @param href An IRI pointing to a human readable resource describing the control
-   * @param label A human readable label for the control
-   */
-  public static Control addControl(
-    Collection collection,
-    String control,
-    boolean required,
-    String href,
-    String label) 
-      throws IRISyntaxException {
-    if (supportsControl(collection, control)) 
-      throw new IllegalArgumentException("Control already supported");
-    Factory factory = collection.getFactory();
-    Control el = 
-      (Control)factory.newExtensionElement(
-        FeaturesHelper.CONTROL, collection);
-    collection.declareNS(FNS, "f");
-    el.setAttributeValue("ref", (new IRI(control)).toString());
-    if (required) el.setAttributeValue("required", "yes");
-    if (href != null) el.setAttributeValue("href", (new IRI(href)).toString());
-    if (label != null) el.setAttributeValue("label", label);
-    return el;
-  }
 }

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?view=diff&rev=530211&r1=530210&r2=530211
==============================================================================
--- 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
Wed Apr 18 17:19:26 2007
@@ -34,6 +34,8 @@
 import org.apache.abdera.util.EntityTag;
 import org.apache.abdera.i18n.iri.IRI;
 import org.apache.abdera.i18n.iri.IRISyntaxException;
+import org.apache.abdera.i18n.lang.InvalidLangTagSyntax;
+import org.apache.abdera.i18n.lang.Lang;
 import org.apache.axiom.om.OMComment;
 import org.apache.axiom.om.OMDocType;
 import org.apache.axiom.om.OMDocument;
@@ -57,6 +59,8 @@
   protected MimeType contentType = null;
   protected Date lastModified = null;
   protected EntityTag etag = null;
+  protected String language = null;
+  protected String slug = null;
 
   public FOMDocument() {
     super();
@@ -235,4 +239,24 @@
     this.etag = new EntityTag(tag);
   }
   
+  public String getLanguage() {
+    return language;
+  }
+  
+  public Lang getLanguageTag() throws InvalidLangTagSyntax {
+    String lang = getLanguage();
+    return (lang != null) ? new Lang(lang) : null;
+  }
+  
+  public void setLanguage(String lang) {
+    this.language = lang;
+  }
+  
+  public String getSlug() {
+    return slug;
+  }
+  
+  public void setSlug(String slug) {
+    this.slug = slug;
+  }
 }

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?view=diff&rev=530211&r1=530210&r2=530211
==============================================================================
--- 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
Wed Apr 18 17:19:26 2007
@@ -218,7 +218,9 @@
     Base parent = this.getParentElement();
     return (lang != null) ? lang :
       (parent != null && parent instanceof Element) ? 
-        ((Element)parent).getLanguage() : null;
+        ((Element)parent).getLanguage() : 
+      (parent != null && parent instanceof Document) ? 
+        ((Document)parent).getLanguage(): null;
   }
 
   public void setLanguage(String language) {



Mime
View raw message