abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dand...@apache.org
Subject svn commit: r671525 - in /incubator/abdera/java/trunk: adapters/jcr/src/main/java/org/apache/abdera/protocol/server/adapters/jcr/ server/src/main/java/org/apache/abdera/protocol/server/filters/ server/src/test/java/org/apache/abdera/protocol/server/tes...
Date Wed, 25 Jun 2008 12:19:32 GMT
Author: dandiep
Date: Wed Jun 25 05:19:32 2008
New Revision: 671525

URL: http://svn.apache.org/viewvc?rev=671525&view=rev
Log:
Make the OpenSearch filter available to everyone. Add the ability for JcrCollectionAdapter
to handle non text content.

Added:
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/filters/OpenSearchFilter.java
  (contents, props changed)
      - copied, changed from r671453, incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/custom/OpenSearchFilter.java
Removed:
    incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/custom/OpenSearchFilter.java
Modified:
    incubator/abdera/java/trunk/adapters/jcr/src/main/java/org/apache/abdera/protocol/server/adapters/jcr/JcrCollectionAdapter.java
    incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/custom/CustomProvider.java

Modified: incubator/abdera/java/trunk/adapters/jcr/src/main/java/org/apache/abdera/protocol/server/adapters/jcr/JcrCollectionAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/adapters/jcr/src/main/java/org/apache/abdera/protocol/server/adapters/jcr/JcrCollectionAdapter.java?rev=671525&r1=671524&r2=671525&view=diff
==============================================================================
--- incubator/abdera/java/trunk/adapters/jcr/src/main/java/org/apache/abdera/protocol/server/adapters/jcr/JcrCollectionAdapter.java
(original)
+++ incubator/abdera/java/trunk/adapters/jcr/src/main/java/org/apache/abdera/protocol/server/adapters/jcr/JcrCollectionAdapter.java
Wed Jun 25 05:19:32 2008
@@ -17,6 +17,8 @@
 */
 package org.apache.abdera.protocol.server.adapters.jcr;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Calendar;
@@ -37,11 +39,14 @@
 import javax.jcr.Value;
 import javax.jcr.Workspace;
 
+import org.apache.abdera.Abdera;
+import org.apache.abdera.factory.Factory;
 import org.apache.abdera.i18n.iri.IRI;
 import org.apache.abdera.i18n.text.Sanitizer;
 import org.apache.abdera.model.Content;
 import org.apache.abdera.model.Person;
 import org.apache.abdera.model.Text;
+import org.apache.abdera.model.Content.Type;
 import org.apache.abdera.protocol.server.RequestContext;
 import org.apache.abdera.protocol.server.ResponseContext;
 import org.apache.abdera.protocol.server.RequestContext.Scope;
@@ -319,7 +324,18 @@
     }
 
     if (content != null) {
-      entry.setProperty(CONTENT, content.getText());
+      switch(content.getContentType()) {
+      case TEXT:
+	entry.setProperty(CONTENT, content.getText());
+	entry.setProperty(CONTENT_TYPE, Type.TEXT.toString());
+	break;
+      case XHTML:
+	entry.setProperty(CONTENT, asString(content));
+	entry.setProperty(CONTENT_TYPE, Type.XHTML.toString());
+	break;
+      default:
+	throw new ResponseContextException("Invalid content element type.", 500);
+      }
     }
 
     if (summary != null) {
@@ -329,7 +345,17 @@
     return entry;
   }
 
-  private Session getSession(RequestContext request) {
+  private String asString(Content content2) throws ResponseContextException {
+    ByteArrayOutputStream bos = new ByteArrayOutputStream();
+    try {
+      content2.getFirstChild().writeTo(bos);
+    } catch (IOException e) {
+      throw new ResponseContextException(500, e);
+    }
+    return new String(bos.toByteArray());
+  }
+
+  protected Session getSession(RequestContext request) {
     return (Session)request.getAttribute(Scope.REQUEST, SESSION_KEY);
   }
 
@@ -420,7 +446,22 @@
 
   @Override
   public Object getContent(Node entry, RequestContext request) throws ResponseContextException
{
-    return getStringOrNull(entry, CONTENT);
+    
+    String typeStr = getStringOrNull(entry, CONTENT_TYPE);
+    Factory factory = Abdera.getInstance().getFactory();
+    String textContent = getStringOrNull(entry, CONTENT);
+    Type type = Type.valueOf(typeStr);
+    Content content = factory.newContent(type);
+    switch (type) {
+      case TEXT:
+        content.setValue(textContent);
+        return content;
+      case XHTML:
+        content.setWrappedValue(textContent);
+        return content;
+      default:	
+    }
+    return null;
   }
 
   @Override

Copied: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/filters/OpenSearchFilter.java
(from r671453, incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/custom/OpenSearchFilter.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/filters/OpenSearchFilter.java?p2=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/filters/OpenSearchFilter.java&p1=incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/custom/OpenSearchFilter.java&r1=671453&r2=671525&rev=671525&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/custom/OpenSearchFilter.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/filters/OpenSearchFilter.java
Wed Jun 25 05:19:32 2008
@@ -15,7 +15,7 @@
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
-package org.apache.abdera.protocol.server.test.custom;
+package org.apache.abdera.protocol.server.filters;
 
 import java.io.IOException;
 import java.util.HashMap;
@@ -137,20 +137,20 @@
           StreamWriter sw) 
             throws IOException {
           sw.startDocument()
-            .startElement("OpenSearchDescription", OSDNS)
-              .startElement("ShortName", OSDNS)
+            .startElement("OpenSearchDescription", OSDNS, "")
+              .startElement("ShortName", OSDNS, "")
                 .writeElementText(getShortName())
               .endElement()
-              .startElement("Description", OSDNS)
+              .startElement("Description", OSDNS, "")
                 .writeElementText(getDescription())
               .endElement()
-              .startElement("Tags", OSDNS)
+              .startElement("Tags", OSDNS, "")
                 .writeElementText(combineTags())
               .endElement()
-              .startElement("Contact", OSDNS)
+              .startElement("Contact", OSDNS, "")
                 .writeElementText(getContact())
               .endElement()
-              .startElement("Url", OSDNS)
+              .startElement("Url", OSDNS, "")
                 .writeAttribute("type", "application/atom+xml")
                 .writeAttribute("template",getTemplate())
               .endElement()

Propchange: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/filters/OpenSearchFilter.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Modified: incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/custom/CustomProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/custom/CustomProvider.java?rev=671525&r1=671524&r2=671525&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/custom/CustomProvider.java
(original)
+++ incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/custom/CustomProvider.java
Wed Jun 25 05:19:32 2008
@@ -24,6 +24,7 @@
 import org.apache.abdera.protocol.server.ResponseContext;
 import org.apache.abdera.protocol.server.TargetType;
 import org.apache.abdera.protocol.server.context.RequestContextWrapper;
+import org.apache.abdera.protocol.server.filters.OpenSearchFilter;
 import org.apache.abdera.protocol.server.impl.AbstractWorkspaceProvider;
 import org.apache.abdera.protocol.server.impl.RegexTargetResolver;
 import org.apache.abdera.protocol.server.impl.SimpleWorkspaceInfo;



Mime
View raw message