abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r555825 - in /incubator/abdera/java/trunk: contrib/rss/src/main/java/org/apache/abdera/contrib/rss/ core/src/main/java/org/apache/abdera/factory/ core/src/main/java/org/apache/abdera/util/ examples/src/main/java/org/apache/abdera/examples/e...
Date Fri, 13 Jul 2007 00:47:00 GMT
Author: jmsnell
Date: Thu Jul 12 17:46:59 2007
New Revision: 555825

URL: http://svn.apache.org/viewvc?view=rev&rev=555825
Log:
Add the ability for ExtensionFactory instances to specify a mime type for extensions.

Modified:
    incubator/abdera/java/trunk/contrib/rss/src/main/java/org/apache/abdera/contrib/rss/RssConstants.java
    incubator/abdera/java/trunk/contrib/rss/src/main/java/org/apache/abdera/contrib/rss/RssExtensionFactory.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/ExtensionFactory.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/ExtensionFactoryMap.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/Factory.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/MimeTypeHelper.java
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/extension/FooExtensionFactory.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/media/MediaExtensionFactory.java
    incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/opensearch/OpenSearchExtensionFactory.java
    incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/thread/ThreadExtensionFactory.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMFactory.java

Modified: incubator/abdera/java/trunk/contrib/rss/src/main/java/org/apache/abdera/contrib/rss/RssConstants.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/contrib/rss/src/main/java/org/apache/abdera/contrib/rss/RssConstants.java?view=diff&rev=555825&r1=555824&r2=555825
==============================================================================
--- incubator/abdera/java/trunk/contrib/rss/src/main/java/org/apache/abdera/contrib/rss/RssConstants.java
(original)
+++ incubator/abdera/java/trunk/contrib/rss/src/main/java/org/apache/abdera/contrib/rss/RssConstants.java
Thu Jul 12 17:46:59 2007
@@ -21,6 +21,8 @@
 
 public interface RssConstants {
 
+  public static final String RSS_MEDIATYPE = "application/rss+xml";
+  
   public static final String ENC_NS = "http://purl.org/rss/1.0/modules/content/";
   public static final String RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
   public static final String RSS1_NS = "http://purl.org/rss/1.0/";

Modified: incubator/abdera/java/trunk/contrib/rss/src/main/java/org/apache/abdera/contrib/rss/RssExtensionFactory.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/contrib/rss/src/main/java/org/apache/abdera/contrib/rss/RssExtensionFactory.java?view=diff&rev=555825&r1=555824&r2=555825
==============================================================================
--- incubator/abdera/java/trunk/contrib/rss/src/main/java/org/apache/abdera/contrib/rss/RssExtensionFactory.java
(original)
+++ incubator/abdera/java/trunk/contrib/rss/src/main/java/org/apache/abdera/contrib/rss/RssExtensionFactory.java
Thu Jul 12 17:46:59 2007
@@ -23,6 +23,8 @@
 import javax.xml.namespace.QName;
 
 import org.apache.abdera.factory.ExtensionFactory;
+import org.apache.abdera.model.Base;
+import org.apache.abdera.model.Document;
 import org.apache.abdera.model.Element;
 
 public class RssExtensionFactory 
@@ -117,6 +119,12 @@
 
   public boolean handlesNamespace(String namespace) {
     return (namespace.equals("") || namespace.equals(ENC_NS));
+  }
+
+  public <T extends Base> String getMimeType(T base) {
+    Element element = base instanceof Element ? (Element)base : ((Document)base).getRoot();
+    if (element instanceof RssFeed) return RssConstants.RSS_MEDIATYPE;
+    return null;
   }
 
 }

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/ExtensionFactory.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/ExtensionFactory.java?view=diff&rev=555825&r1=555824&r2=555825
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/ExtensionFactory.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/ExtensionFactory.java
Thu Jul 12 17:46:59 2007
@@ -19,6 +19,7 @@
 
 import java.util.List;
 
+import org.apache.abdera.model.Base;
 import org.apache.abdera.model.Element;
 
 /**
@@ -63,4 +64,9 @@
    * the parameter itself if a wrapper could not be retrieved
    */
   <T extends  Element>T getElementWrapper(Element internal);
+  
+  /**
+   * Retrieve the mime type for the element
+   */
+  <T extends Base>String getMimeType(T base);
 }

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/ExtensionFactoryMap.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/ExtensionFactoryMap.java?view=diff&rev=555825&r1=555824&r2=555825
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/ExtensionFactoryMap.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/ExtensionFactoryMap.java
Thu Jul 12 17:46:59 2007
@@ -26,6 +26,7 @@
 import javax.xml.namespace.QName;
 
 import org.apache.abdera.model.Base;
+import org.apache.abdera.model.Document;
 import org.apache.abdera.model.Element;
 
 public class ExtensionFactoryMap 
@@ -92,5 +93,17 @@
   public void addFactory(ExtensionFactory factory) {
     if (!factories.contains(factory))
       factories.add(factory);
+  }
+
+  public <T extends Base> String getMimeType(T base) {
+    Element element = base instanceof Element ? (Element)base : ((Document)base).getRoot();
+    String namespace = element.getQName().getNamespaceURI();
+    synchronized(factories) {
+      for (ExtensionFactory factory : factories) {
+        if (factory.handlesNamespace(namespace)) 
+          return factory.getMimeType(base);
+      }
+    }
+    return null;
   }
 }

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/Factory.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/Factory.java?view=diff&rev=555825&r1=555824&r2=555825
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/Factory.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/Factory.java
Thu Jul 12 17:46:59 2007
@@ -553,7 +553,7 @@
    * Create a new Element with the given QName.
    * @return A newly created element
    */
-  Element newElement(QName qname);
+  <T extends Element>T newElement(QName qname);
 
   /**
    * Create a new Element with the given QName as a child of the given Base.
@@ -561,14 +561,14 @@
    * @param parent The element or document to which the new element should be added as a
child
    * @return A newly created element
    */
-  Element newElement(QName qname, Base parent);
+  <T extends Element>T newElement(QName qname, Base parent);
 
   /**
    * Create a new extension element with the given QName.
    * @param qname The XML QName of the element to create
    * @return A newly created element
    */
-  Element newExtensionElement(QName qname);
+  <T extends Element>T newExtensionElement(QName qname);
 
   /**
    * Create a new extension element with the given QName as a child of the given Base.
@@ -576,7 +576,7 @@
    * @param parent The element or document to which the new element should be added as a
child
    * @return A newly created element
    */
-  Element newExtensionElement(QName qname, Base parent);
+  <T extends Element>T newExtensionElement(QName qname, Base parent);
 
   /**
    * Create a new Control element.  The app:control element is introduced by
@@ -645,4 +645,9 @@
    * Get the Abdera instance for this factory
    */
   Abdera getAbdera();
+  
+  /**
+   * Get the mime type for the specified extension element / document
+   */
+  <T extends Base>String getMimeType(T base);
 }

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=555825&r1=555824&r2=555825
==============================================================================
--- 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
Thu Jul 12 17:46:59 2007
@@ -210,10 +210,10 @@
           type = Constants.APP_MEDIA_TYPE;
         else if (el instanceof Categories)
           type = Constants.CAT_MEDIA_TYPE;
-        else 
-          type = Constants.XML_MEDIA_TYPE;
       }
     }    
+    if (type == null)
+      type = base.getFactory().getMimeType(base);
     return (type != null) ? type : Constants.XML_MEDIA_TYPE;
   }
   

Modified: incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/extension/FooExtensionFactory.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/extension/FooExtensionFactory.java?view=diff&rev=555825&r1=555824&r2=555825
==============================================================================
--- incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/extension/FooExtensionFactory.java
(original)
+++ incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/extension/FooExtensionFactory.java
Thu Jul 12 17:46:59 2007
@@ -22,6 +22,7 @@
 import javax.xml.namespace.QName;
 
 import org.apache.abdera.factory.ExtensionFactory;
+import org.apache.abdera.model.Base;
 import org.apache.abdera.model.Element;
 
 public class FooExtensionFactory 
@@ -45,6 +46,10 @@
 
   public boolean handlesNamespace(String namespace) {
     return NS.equals(namespace);
+  }
+
+  public <T extends Base> String getMimeType(T base) {
+    return null;
   }
 
 }

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=555825&r1=555824&r2=555825
==============================================================================
--- 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
Thu Jul 12 17:46:59 2007
@@ -23,6 +23,7 @@
 import javax.xml.namespace.QName;
 
 import org.apache.abdera.factory.ExtensionFactory;
+import org.apache.abdera.model.Base;
 import org.apache.abdera.model.Element;
 
 public final class FeaturesExtensionFactory 
@@ -44,6 +45,10 @@
     if (FeaturesHelper.FEATURE.equals(qname)) 
       return (T)new Feature(internal);
     else return (T)internal;
+  }
+
+  public <T extends Base> String getMimeType(T base) {
+    return null;
   }
 
 

Modified: incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/media/MediaExtensionFactory.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/media/MediaExtensionFactory.java?view=diff&rev=555825&r1=555824&r2=555825
==============================================================================
--- incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/media/MediaExtensionFactory.java
(original)
+++ incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/media/MediaExtensionFactory.java
Thu Jul 12 17:46:59 2007
@@ -22,6 +22,7 @@
 import javax.xml.namespace.QName;
 
 import org.apache.abdera.factory.ExtensionFactory;
+import org.apache.abdera.model.Base;
 import org.apache.abdera.model.Element;
 
 public final class MediaExtensionFactory implements ExtensionFactory {
@@ -53,6 +54,10 @@
 
   public boolean handlesNamespace(String namespace) {
     return namespace.equals(MediaConstants.MEDIA_NS);
+  }
+
+  public <T extends Base> String getMimeType(T base) {
+    return null;
   }
 
 }

Modified: incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/opensearch/OpenSearchExtensionFactory.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/opensearch/OpenSearchExtensionFactory.java?view=diff&rev=555825&r1=555824&r2=555825
==============================================================================
--- incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/opensearch/OpenSearchExtensionFactory.java
(original)
+++ incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/opensearch/OpenSearchExtensionFactory.java
Thu Jul 12 17:46:59 2007
@@ -22,6 +22,7 @@
 import javax.xml.namespace.QName;
 
 import org.apache.abdera.factory.ExtensionFactory;
+import org.apache.abdera.model.Base;
 import org.apache.abdera.model.Element;
 
 public final class OpenSearchExtensionFactory 
@@ -55,6 +56,10 @@
   public boolean handlesNamespace(String namespace) {
     return OpenSearchConstants.OPENSEARCH_NS.equals(namespace) ||
            OpenSearchConstants.OPENSEARCH_V10_NS.equals(namespace);
+  }
+
+  public <T extends Base> String getMimeType(T base) {
+    return null;
   }
 
 }

Modified: incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/thread/ThreadExtensionFactory.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/thread/ThreadExtensionFactory.java?view=diff&rev=555825&r1=555824&r2=555825
==============================================================================
--- incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/thread/ThreadExtensionFactory.java
(original)
+++ incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/thread/ThreadExtensionFactory.java
Thu Jul 12 17:46:59 2007
@@ -23,6 +23,7 @@
 import javax.xml.namespace.QName;
 
 import org.apache.abdera.factory.ExtensionFactory;
+import org.apache.abdera.model.Base;
 import org.apache.abdera.model.Element;
 
 public final class ThreadExtensionFactory 
@@ -46,6 +47,10 @@
     else if (ThreadConstants.THRTOTAL.equals(qname))
       return (T)new Total(internal);
     else return (T)internal;
+  }
+
+  public <T extends Base> String getMimeType(T base) {
+    return null;
   }
 
 

Modified: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMFactory.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMFactory.java?view=diff&rev=555825&r1=555824&r2=555825
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMFactory.java
(original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMFactory.java
Thu Jul 12 17:46:59 2007
@@ -393,44 +393,45 @@
     return new FOMText(type, qname, (OMContainer)parent,this);
   }
   
-  public Element newElement(QName qname) {
+  public <T extends Element>T newElement(QName qname) {
     return newElement(qname, null);
   }
   
-  public Element newElement(
+  public <T extends Element>T newElement(
     QName qname, 
     Base parent) {
       return newExtensionElement(qname, parent);
   }
   
-  public Element newExtensionElement(QName qname) {
+  public <T extends Element>T newExtensionElement(QName qname) {
     return newExtensionElement(qname, (OMContainer)null);
   }
   
-  public Element newExtensionElement(
+  public <T extends Element>T newExtensionElement(
     QName qname, 
     Base parent) {
     return newExtensionElement(qname, (OMContainer)parent);
   }
   
-  private Element newExtensionElement(
+  @SuppressWarnings("unchecked")
+  private <T extends Element>T newExtensionElement(
     QName qname, 
     OMContainer parent) {
       String ns = qname.getNamespaceURI();
       Element el = newExtensionElement(qname, parent, null);
-      return (ATOM_NS.equals(ns) || APP_NS.equals(ns)) ?
-        el : factoriesMap.getElementWrapper(el);
+      return (T)((ATOM_NS.equals(ns) || APP_NS.equals(ns)) ?
+        el : factoriesMap.getElementWrapper(el));
   }
   
   @SuppressWarnings("unchecked")
-  private Element newExtensionElement(
+  private <T extends Element>T newExtensionElement(
     QName qname,
     OMContainer parent,
     OMXMLParserWrapper parserWrapper) {
     Element element = (parserWrapper == null) ?
       new FOMExtensibleElement(qname, parent, this) :
       new FOMExtensibleElement(qname, parent, this, parserWrapper);
-    return element;
+    return (T) element;
   }
   
   public Control newControl() {
@@ -817,5 +818,9 @@
 
   public Abdera getAbdera() {
     return abdera;
+  }
+
+  public <T extends Base> String getMimeType(T base) {
+    return factoriesMap.getMimeType(base);
   }
 }



Mime
View raw message