abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1239246 - in /abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext: ./ json/ serializer/
Date Wed, 01 Feb 2012 18:26:47 GMT
Author: jmsnell
Date: Wed Feb  1 18:26:46 2012
New Revision: 1239246

URL: http://svn.apache.org/viewvc?rev=1239246&view=rev
Log:
moving a bit more to the separate server project... now that we have the activity streams conversion, we really should just drop the older json conversion code since the json activity streams stuff is so much better and the conversion is bi-directional

Added:
    abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/
    abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/
    abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONFilter.java   (with props)
    abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONServlet.java   (with props)
    abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONStream.java   (with props)
    abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONUtil.java   (with props)
    abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONWriter.java   (with props)
    abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/serializer/
    abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/serializer/ObjectResponseContext.java   (with props)

Added: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONFilter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONFilter.java?rev=1239246&view=auto
==============================================================================
--- abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONFilter.java (added)
+++ abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONFilter.java Wed Feb  1 18:26:46 2012
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.ext.json;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.common.misc.Chain;
+import org.apache.abdera2.common.misc.Task;
+import org.apache.abdera2.common.protocol.RequestContext;
+import org.apache.abdera2.common.protocol.ResponseContext;
+import org.apache.abdera2.common.protocol.ProviderHelper;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.protocol.server.AtompubResponseContext;
+import org.apache.abdera2.protocol.server.context.ResponseContextWrapper;
+import org.apache.abdera2.writer.Writer;
+
+/**
+ * Filter implementation that will convert an Atom document returned by the server into a JSON document if the request
+ * specifies a higher preference value for JSON or explicitly requests JSON by including a format=json querystring
+ * parameter
+ */
+public class JSONFilter implements Task<RequestContext,ResponseContext> {
+
+    public ResponseContext apply(RequestContext request, Chain<RequestContext,ResponseContext> chain) {
+        AtompubResponseContext resp = (AtompubResponseContext) chain.next(request);
+        String format = request.getParameter("format");
+        return ((resp.getContentType() != null && jsonPreferred(request, resp.getContentType().toString())) || (format != null && format
+            .equalsIgnoreCase("json")) ? new JsonResponseContext(resp, Abdera.getInstance()) : resp);
+    }
+
+    private boolean jsonPreferred(RequestContext request, String type) {
+        return ProviderHelper.isPreferred(request, "application/json", type);
+    }
+
+    private static class JsonResponseContext extends ResponseContextWrapper {
+
+        private final Abdera abdera;
+
+        public JsonResponseContext(AtompubResponseContext response, Abdera abdera) {
+            super(response);
+            setContentType("application/json");
+            this.abdera = abdera;
+        }
+
+        public void writeTo(OutputStream out, Writer writer) throws IOException {
+            try {
+                toJson(out, writer);
+            } catch (Exception se) {
+                if (se instanceof RuntimeException)
+                    throw (RuntimeException)se;
+                throw new RuntimeException(se);
+            }
+        }
+
+        public void writeTo(OutputStream out) throws IOException {
+            try {
+                toJson(out, null);
+            } catch (Exception se) {
+                if (se instanceof RuntimeException)
+                    throw (RuntimeException)se;
+                throw new RuntimeException(se);
+            }
+        }
+
+        private void toJson(OutputStream aout, Writer writer) throws Exception {
+            Document<Element> doc = null;
+            try {
+                ByteArrayOutputStream out = new ByteArrayOutputStream();
+                if (writer == null)
+                    super.writeTo(out);
+                else
+                    super.writeTo(out, writer);
+                ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+                doc = abdera.getParser().parse(in);
+            } catch (Exception e) {
+            }
+            if (doc != null) {
+                doc.writeTo("json", aout);
+            } else {
+                throw new RuntimeException("There was an error serializing the entry to JSON");
+            }
+        }
+    }
+}

Propchange: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONFilter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONServlet.java
URL: http://svn.apache.org/viewvc/abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONServlet.java?rev=1239246&view=auto
==============================================================================
--- abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONServlet.java (added)
+++ abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONServlet.java Wed Feb  1 18:26:46 2012
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.ext.json;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URLDecoder;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.protocol.client.AbderaClient;
+import org.apache.abdera2.protocol.client.RequestHelper;
+import org.apache.abdera2.protocol.client.RequestOptions;
+
+/**
+ * Servlet that will do an HTTP GET to retrieve an Atom document then convert that into a JSON doc. The URL pattern is
+ * simple: http://.../servlet/path/{url}
+ */
+public class JSONServlet extends HttpServlet {
+
+    private static final long serialVersionUID = 1414392196430276024L;
+
+    private Abdera getAbdera() {
+        ServletContext sc = getServletContext();
+        Abdera abdera = null;
+        synchronized (sc) {
+            abdera = (Abdera)sc.getAttribute(Abdera.class.getName());
+            if (abdera == null) {
+                abdera = Abdera.getInstance();
+                sc.setAttribute(Abdera.class.getName(), abdera);
+            }
+        }
+        return abdera;
+    }
+
+    @Override
+    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+        String url = request.getPathInfo();
+        if (url != null && url.length() > 1)
+            url = URLDecoder.decode(url, "UTF-8");
+        else {
+            response.sendError(400);
+            return;
+        }
+        url = url.substring(1);
+
+        Abdera abdera = getAbdera();
+        AbderaClient client = new AbderaClient(abdera);
+        RequestOptions.Builder options = 
+          RequestHelper.createAtomDefaultRequestOptions();
+        if (request.getHeader("If-Match") != null)
+            options.ifMatch(request.getHeader("If-Match"));
+        if (request.getHeader("If-None-Match") != null)
+            options.ifNoneMatch(request.getHeader("If-None-Match"));
+        if (request.getHeader("If-Modified-Since") != null)
+            options.ifNoneMatch(request.getHeader("If-Modified-Since"));
+        if (request.getHeader("If-Unmodified-Since") != null)
+            options.ifNoneMatch(request.getHeader("If-Unmodified-Since"));
+        try {
+          Document<?> doc = client.get(url,options.get());
+          response.setContentType("application/json");
+          response.setCharacterEncoding("UTF-8");
+          if (doc.getEntityTag() != null)
+            response.setHeader("ETag", doc.getEntityTag().toString());
+          if (doc.getLanguage() != null)
+            response.setHeader("Content-Language", doc.getLanguage());
+          if (doc.getLastModified() != null)
+            response.setDateHeader("Last-Modified", doc.getLastModified().getMillis());
+          OutputStream out = response.getOutputStream();
+          doc.writeTo("json", out);
+        } catch (Exception e) {
+          response.sendError(500);
+          return;
+        }
+        client.shutdown();
+    }
+
+}

Propchange: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONServlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONStream.java
URL: http://svn.apache.org/viewvc/abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONStream.java?rev=1239246&view=auto
==============================================================================
--- abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONStream.java (added)
+++ abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONStream.java Wed Feb  1 18:26:46 2012
@@ -0,0 +1,218 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.ext.json;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.Stack;
+
+import javax.activation.MimeType;
+
+import org.apache.abdera2.common.iri.IRI;
+import org.apache.abdera2.common.date.DateTimes;
+import org.apache.abdera2.common.http.EntityTag;
+import org.joda.time.DateTime;
+
+public class JSONStream {
+
+    private final Writer writer;
+    private int depth = 0;
+    private Stack<Boolean> sepstack = new Stack<Boolean>();
+
+    private void pushStack() {
+        sepstack.push(true);
+    }
+
+    private boolean isStart() {
+        boolean b = sepstack.peek();
+        if (b) {
+            sepstack.set(sepstack.size() - 1, false);
+        }
+        return b;
+    }
+
+    private void popStack() {
+        sepstack.pop();
+    }
+
+    public JSONStream(Writer writer) {
+        this.writer = writer;
+    }
+
+    private void inc() {
+        depth++;
+    }
+
+    private void dec() {
+        depth--;
+    }
+
+    private void writeIndent() throws IOException {
+        for (int n = 0; n < depth; n++) {
+            writer.write(' ');
+        }
+    }
+
+    private void writeNewLine() throws IOException {
+        writer.write('\n');
+    }
+
+    public void startObject() throws IOException {
+        writer.write('{');
+        inc();
+        pushStack();
+    }
+
+    public void endObject() throws IOException {
+        popStack();
+        dec();
+        writeNewLine();
+        writeIndent();
+        writer.write('}');
+    }
+
+    public void startArray() throws IOException {
+        writer.write('[');
+        inc();
+    }
+
+    public void endArray() throws IOException {
+        dec();
+        writeNewLine();
+        writeIndent();
+        writer.write(']');
+    }
+
+    public void writeSeparator() throws IOException {
+        writer.write(',');
+    }
+
+    private void writeColon() throws IOException {
+        writer.write(':');
+    }
+
+    public void writeQuoted(String value) throws IOException {
+        if (value != null) {
+            writer.write('"');
+            writer.write(escape(value));
+            writer.write('"');
+        }
+    }
+
+    public void writeField(String name) throws IOException {
+        if (!isStart()) {
+            writeSeparator();
+        }
+        writeNewLine();
+        writeIndent();
+        writeQuoted(name);
+        writeColon();
+    }
+
+    public void writeField(String name, DateTime value) throws IOException {
+        if (value != null) {
+            writeField(name, DateTimes.format(value));
+        }
+    }
+
+    public void writeField(String name, IRI value) throws IOException {
+        if (value != null) {
+            writeField(name, value.toASCIIString());
+        }
+    }
+
+    public void writeField(String name, MimeType value) throws IOException {
+        if (value != null) {
+            writeField(name, value.toString());
+        }
+    }
+
+    public void writeField(String name, EntityTag value) throws IOException {
+        if (value != null) {
+            writeField(name, value.toString());
+        }
+    }
+
+    public void writeField(String name, String value) throws IOException {
+        if (value != null) {
+            writeField(name);
+            writeQuoted(value);
+        }
+    }
+
+    public void writeField(String name, Number value) throws IOException {
+        if (value != null) {
+            writeField(name);
+            writer.write(value.toString());
+        }
+    }
+
+    public void writeField(String name, Boolean value) throws IOException {
+        if (value != null) {
+            writeField(name);
+            writer.write(value.toString());
+        }
+    }
+
+    private static String escape(String value) {
+        if (value == null)
+            return null;
+        StringBuffer buf = new StringBuffer();
+        char[] chars = value.toCharArray();
+        char b = 0;
+        String t = null;
+        for (char c : chars) {
+            switch (c) {
+                case '\\':
+                case '"':
+                    buf.append('\\');
+                    buf.append(c);
+                    break;
+                case '/':
+                    if (b == '<')
+                        buf.append('\\');
+                    buf.append(c);
+                    break;
+                case '\b':
+                    buf.append("\\b");
+                    break;
+                case '\t':
+                    buf.append("\\t");
+                    break;
+                case '\n':
+                    buf.append("\\n");
+                    break;
+                case '\f':
+                    buf.append("\\f");
+                    break;
+                case '\r':
+                    buf.append("\\r");
+                    break;
+                default:
+                    if (c < ' ' || c > 127) {
+                        t = "000" + Integer.toHexString(c);
+                        buf.append("\\u" + t.substring(t.length() - 4));
+                    } else {
+                        buf.append(c);
+                    }
+            }
+            b = c;
+        }
+        return buf.toString();
+    }
+}

Propchange: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONStream.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONUtil.java
URL: http://svn.apache.org/viewvc/abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONUtil.java?rev=1239246&view=auto
==============================================================================
--- abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONUtil.java (added)
+++ abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONUtil.java Wed Feb  1 18:26:46 2012
@@ -0,0 +1,586 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.ext.json;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.ext.bidi.BidiHelper;
+import org.apache.abdera2.ext.bidi.BidiHelper.Direction;
+import org.apache.abdera2.ext.history.FeedPagingHelper;
+import org.apache.abdera2.ext.html.HtmlHelper;
+import org.apache.abdera2.ext.thread.InReplyTo;
+import org.apache.abdera2.ext.thread.ThreadHelper;
+import org.apache.abdera2.common.iri.IRI;
+import org.apache.abdera2.model.Base;
+import org.apache.abdera2.model.Categories;
+import org.apache.abdera2.model.Category;
+import org.apache.abdera2.model.Collection;
+import org.apache.abdera2.model.Content;
+import org.apache.abdera2.model.Control;
+import org.apache.abdera2.model.Div;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.model.ExtensibleElement;
+import org.apache.abdera2.model.Feed;
+import org.apache.abdera2.model.Generator;
+import org.apache.abdera2.model.Link;
+import org.apache.abdera2.model.Person;
+import org.apache.abdera2.model.Service;
+import org.apache.abdera2.model.Source;
+import org.apache.abdera2.model.Text;
+import org.apache.abdera2.model.TextValue;
+import org.apache.abdera2.model.Workspace;
+import org.apache.abdera2.xpath.XPath;
+
+import com.google.common.collect.Iterables;
+
+public class JSONUtil {
+
+    public static void toJson(Base base, Writer writer) throws IOException {
+        JSONStream jstream = new JSONStream(writer);
+        if (base instanceof Document) {
+            toJson((Document<?>)base, jstream);
+        } else if (base instanceof Element) {
+            toJson((Element)base, jstream);
+        }
+    }
+
+    private static boolean isSameAsParentBase(Element element) {
+        IRI parentbase = null;
+        if (element.getParentElement() != null) {
+            parentbase =
+                element instanceof Document ? ((Document<?>)element).getBaseUri() : ((Element)element)
+                    .getResolvedBaseUri();
+        }
+        IRI base = element.getResolvedBaseUri();
+
+        if (parentbase == null && base != null) {
+            return false;
+        }
+        if (parentbase == null && base == null) {
+            return true;
+        }
+        return parentbase.equals(element.getResolvedBaseUri());
+    }
+
+    private static void toJson(Element element, JSONStream jstream) throws IOException {
+
+        if (element instanceof Text) {
+            Text text = (Text)element;
+            Text.Type texttype = text.getTextType();
+            if (texttype.equals(Text.Type.TEXT) && !needToWriteLanguageFields(text)) {
+                jstream.writeQuoted(text.getValue());
+            } else {
+                jstream.startObject();
+                jstream.writeField("attributes");
+                jstream.startObject();
+                jstream.writeField("type", texttype.name().toLowerCase());
+                writeLanguageFields(element, jstream);
+                if (!isSameAsParentBase(element)) {
+                    jstream.writeField("xml:base", element.getResolvedBaseUri());
+                }
+                jstream.endObject();
+                jstream.writeField("children");
+                switch (text.getTextType()) {
+                    case TEXT:
+                        jstream.startArray();
+                        jstream.writeQuoted(text.getValue());
+                        jstream.endArray();
+                        break;
+                    case HTML:
+                        if (text.getValue() != null) {
+                            Div div = HtmlHelper.parse(text.getValue());
+                            writeElementValue(div, jstream);
+                        } else {
+                            jstream.writeQuoted("");
+                        }
+                        break;
+                    case XHTML:
+                        if (text.getValueElement() != null) {
+                            writeElementValue(text.getValueElement(), jstream);
+                        } else {
+                            jstream.writeQuoted("");
+                        }
+                        break;
+                }
+                jstream.endObject();
+            }
+        } else if (element instanceof Content) {
+            Content content = (Content)element;
+            Content.Type contenttype = content.getContentType();
+            if (contenttype.equals(Content.Type.TEXT) && !needToWriteLanguageFields(content)) {
+                jstream.writeQuoted(content.getValue());
+            } else {
+                jstream.startObject();
+                jstream.writeField("attributes");
+                jstream.startObject();
+                switch (content.getContentType()) {
+                    case TEXT:
+                    case HTML:
+                    case XHTML:
+                        jstream.writeField("type", contenttype.name().toLowerCase());
+                        break;
+                    case MEDIA:
+                    case XML:
+                        jstream.writeField("type", content.getMimeType());
+                }
+                writeLanguageFields(element, jstream);
+                if (!isSameAsParentBase(element))
+                    jstream.writeField("xml:base", element.getResolvedBaseUri());
+                writeLanguageFields(content, jstream);
+                jstream.writeField("src", content.getResolvedSrc());
+                jstream.endObject();
+                jstream.writeField("children");
+                switch (content.getContentType()) {
+                    case TEXT:
+                        jstream.startArray();
+                        jstream.writeQuoted(content.getValue());
+                        jstream.endArray();
+                        break;
+                    case HTML:
+                        Div div = HtmlHelper.parse(content.getValue());
+                        writeElementValue(div, jstream);
+                        break;
+                    case XHTML:
+                        writeElementValue(content.getValueElement(), jstream);
+                        break;
+                    case MEDIA:
+                    case XML:
+                        jstream.startArray();
+                        jstream.writeQuoted(content.getValue());
+                        jstream.endArray();
+                }
+                jstream.endObject();
+            }
+        } else {
+            if (element instanceof Categories) {
+                jstream.startObject();
+                writeLanguageFields(element, jstream);
+                if (!isSameAsParentBase(element))
+                    jstream.writeField("xml:base", element.getResolvedBaseUri());
+                Categories categories = (Categories)element;
+                jstream.writeField("fixed", categories.isFixed() ? "true" : "false");
+                jstream.writeField("scheme", categories.getScheme());
+                writeList("categories", categories.getCategories(), jstream);
+                writeExtensions((ExtensibleElement)element, jstream);
+                jstream.endObject();
+            } else if (element instanceof Category) {
+                jstream.startObject();
+                writeLanguageFields(element, jstream);
+                if (!isSameAsParentBase(element))
+                    jstream.writeField("xml:base", element.getResolvedBaseUri());
+                Category category = (Category)element;
+                jstream.writeField("term", category.getTerm());
+                jstream.writeField("scheme", category.getScheme());
+                jstream.writeField("label", category.getLabel());
+                writeExtensions((ExtensibleElement)element, jstream);
+                jstream.endObject();
+            } else if (element instanceof Collection) {
+                jstream.startObject();
+                writeLanguageFields(element, jstream);
+                if (!isSameAsParentBase(element))
+                    jstream.writeField("xml:base", element.getResolvedBaseUri());
+                Collection collection = (Collection)element;
+                jstream.writeField("href", collection.getResolvedHref());
+                writeElement("title", collection.getTitleElement(), jstream);
+                String[] accepts = collection.getAccept();
+                if (accepts != null && accepts.length > 0) {
+                    jstream.writeField("accept");
+                    jstream.startArray();
+                    for (int n = 0; n < accepts.length; n++) {
+                        jstream.writeQuoted(accepts[n]);
+                        if (n < accepts.length - 1)
+                            jstream.writeSeparator();
+                    }
+                    jstream.endArray();
+                }
+                List<Categories> cats = collection.getCategories();
+                if (cats.size() > 0)
+                    writeList("categories", collection.getCategories(), jstream);
+                writeExtensions((ExtensibleElement)element, jstream);
+                jstream.endObject();
+            } else if (element instanceof Control) {
+                jstream.startObject();
+                writeLanguageFields(element, jstream);
+                if (!isSameAsParentBase(element)) {
+                    jstream.writeField("xml:base", element.getResolvedBaseUri());
+                }
+                Control control = (Control)element;
+                jstream.writeField("draft", control.isDraft() ? "true" : "false");
+                writeExtensions((ExtensibleElement)element, jstream);
+                jstream.endObject();
+            } else if (element instanceof Entry) {
+                jstream.startObject();
+                writeLanguageFields(element, jstream);
+                if (!isSameAsParentBase(element)){
+                    jstream.writeField("xml:base", element.getResolvedBaseUri());
+                }
+                Entry entry = (Entry)element;
+                jstream.writeField("id", entry.getId());
+                writeElement("title", entry.getTitleElement(), jstream);
+                writeElement("summary", entry.getSummaryElement(), jstream);
+                writeElement("rights", entry.getRightsElement(), jstream);
+                writeElement("content", entry.getContentElement(), jstream);
+                jstream.writeField("updated", entry.getUpdated());
+                jstream.writeField("published", entry.getPublished());
+                jstream.writeField("edited", entry.getEdited());
+                writeElement("source", entry.getSource(), jstream);
+                writeList("authors", entry.getAuthors(), jstream);
+                writeList("contributors", entry.getContributors(), jstream);
+                writeList("links", entry.getLinks(), jstream);
+                writeList("categories", entry.getCategories(), jstream);
+                writeList("inreplyto", ThreadHelper.getInReplyTos(entry), jstream);
+                writeElement("control", entry.getControl(), jstream);
+                writeExtensions((ExtensibleElement)element, jstream);
+                jstream.endObject();
+            } else if (element instanceof Generator) {
+                jstream.startObject();
+                writeLanguageFields(element, jstream);
+                if (!isSameAsParentBase(element)) {
+                    jstream.writeField("xml:base", element.getResolvedBaseUri());
+                }
+                Generator generator = (Generator)element;
+                jstream.writeField("version", generator.getVersion());
+                jstream.writeField("uri", generator.getResolvedUri());
+                jstream.writeField("value", generator.getText());
+                jstream.endObject();
+            } else if (element instanceof Link) {
+                jstream.startObject();
+                writeLanguageFields(element, jstream);
+                if (!isSameAsParentBase(element)) {
+                    jstream.writeField("xml:base", element.getResolvedBaseUri());
+                }
+                Link link = (Link)element;
+                jstream.writeField("href", link.getResolvedHref());
+                jstream.writeField("rel", link.getRel());
+                jstream.writeField("title", link.getTitle());
+                jstream.writeField("type", link.getMimeType());
+                jstream.writeField("hreflang", link.getHrefLang());
+                if (link.getLength() > -1) {
+                    jstream.writeField("length", link.getLength());
+                }
+                writeExtensions((ExtensibleElement)element, jstream);
+                jstream.endObject();
+            } else if (element instanceof Person) {
+                jstream.startObject();
+                writeLanguageFields(element, jstream);
+                if (!isSameAsParentBase(element))
+                    jstream.writeField("xml:base", element.getResolvedBaseUri());
+                Person person = (Person)element;
+                jstream.writeField("name", person.getName());
+                if (person.getEmail() != null)
+                    jstream.writeField("email", person.getEmail());
+                if (person.getUri() != null)
+                    jstream.writeField("uri", person.getUriElement().getResolvedValue());
+                writeExtensions((ExtensibleElement)element, jstream);
+                jstream.endObject();
+            } else if (element instanceof Service) {
+                jstream.startObject();
+                writeLanguageFields(element, jstream);
+                if (!isSameAsParentBase(element))
+                    jstream.writeField("xml:base", element.getResolvedBaseUri());
+                Service service = (Service)element;
+                writeList("workspaces", service.getWorkspaces(), jstream);
+                writeExtensions((ExtensibleElement)element, jstream);
+                jstream.endObject();
+            } else if (element instanceof Source) {
+                jstream.startObject();
+                writeLanguageFields(element, jstream);
+                if (!isSameAsParentBase(element))
+                    jstream.writeField("xml:base", element.getResolvedBaseUri());
+                Source source = (Source)element;
+                jstream.writeField("id", source.getId());
+                writeElement("title", source.getTitleElement(), jstream);
+                writeElement("subtitle", source.getSubtitleElement(), jstream);
+                writeElement("rights", source.getRightsElement(), jstream);
+                jstream.writeField("updated", source.getUpdated());
+                writeElement("generator", source.getGenerator(), jstream);
+                if (source.getIconElement() != null)
+                    jstream.writeField("icon", source.getIconElement().getResolvedValue());
+                if (source.getLogoElement() != null)
+                    jstream.writeField("logo", source.getLogoElement().getResolvedValue());
+                writeList("authors", source.getAuthors(), jstream);
+                writeList("contributors", source.getContributors(), jstream);
+                writeList("links", source.getLinks(), jstream);
+                writeList("categories", source.getCategories(), jstream);
+                if (FeedPagingHelper.isComplete(source))
+                    jstream.writeField("complete", true);
+                if (FeedPagingHelper.isArchive(source))
+                    jstream.writeField("archive", true);
+                if (source instanceof Feed) {
+                    writeList("entries", ((Feed)source).getEntries(), jstream);
+                }
+                writeExtensions((ExtensibleElement)element, jstream);
+                jstream.endObject();
+            } else if (element instanceof Workspace) {
+                jstream.startObject();
+                writeLanguageFields(element, jstream);
+                if (!isSameAsParentBase(element))
+                    jstream.writeField("xml:base", element.getResolvedBaseUri());
+                Workspace workspace = (Workspace)element;
+                writeElement("title", workspace.getTitleElement(), jstream);
+                writeList("collections", workspace.getCollections(), jstream);
+                writeExtensions((ExtensibleElement)element, jstream);
+                jstream.endObject();
+            } else if (element instanceof InReplyTo) {
+                jstream.startObject();
+                writeLanguageFields(element, jstream);
+                if (!isSameAsParentBase(element))
+                    jstream.writeField("xml:base", element.getResolvedBaseUri());
+                InReplyTo irt = (InReplyTo)element;
+                jstream.writeField("ref", irt.getRef());
+                jstream.writeField("href", irt.getResolvedHref());
+                jstream.writeField("type", irt.getMimeType());
+                jstream.writeField("source", irt.getResolvedSource());
+                jstream.endObject();
+            } else {
+                writeElement(element, null, jstream);
+            }
+        }
+    }
+
+    private static void writeElementValue(Element element, JSONStream jstream) throws IOException {
+        writeElementChildren(element, jstream);
+    }
+
+    private static String getName(QName qname) {
+        String prefix = qname.getPrefix();
+        String name = qname.getLocalPart();
+        return (prefix != null && !"".equals(prefix)) ? prefix + ":" + name : name;
+    }
+
+    private static void writeElement(Element child, QName parentqname, JSONStream jstream) throws IOException {
+        QName childqname = child.getQName();
+        String prefix = childqname.getPrefix();
+        jstream.startObject();
+        jstream.writeField("name", getName(childqname));
+        jstream.writeField("attributes");
+        List<QName> attributes = child.getAttributes();
+        jstream.startObject();
+        if (!isSameNamespace(childqname, parentqname)) {
+            if (prefix != null && !"".equals(prefix))
+                jstream.writeField("xmlns:" + prefix);
+            else
+                jstream.writeField("xmlns");
+            jstream.writeQuoted(childqname.getNamespaceURI());
+        }
+        if (!isSameAsParentBase(child))
+            jstream.writeField("xml:base", child.getResolvedBaseUri());
+        writeLanguageFields(child, jstream);
+        for (QName attr : attributes) {
+            String name = getName(attr);
+            jstream.writeField(name);
+            if ("".equals(attr.getPrefix()) || "xml".equals(attr.getPrefix())) {
+                String val = child.getAttributeValue(attr);
+                if (val != null && ("href".equalsIgnoreCase(name) || "src".equalsIgnoreCase(name) || "action"
+                    .equalsIgnoreCase(name))) {
+                    IRI base = child.getResolvedBaseUri();
+                    if (base != null)
+                        val = base.resolve(val).toASCIIString();
+                }
+                jstream.writeQuoted(val);
+            } else {
+                jstream.startObject();
+                jstream.writeField("attributes");
+                jstream.startObject();
+                jstream.writeField("xmlns:" + attr.getPrefix());
+                jstream.writeQuoted(attr.getNamespaceURI());
+                jstream.endObject();
+                jstream.writeField("value");
+                jstream.writeQuoted(child.getAttributeValue(attr));
+                jstream.endObject();
+            }
+        }
+        jstream.endObject();
+        jstream.writeField("children");
+        writeElementChildren((Element)child, jstream);
+        jstream.endObject();
+    }
+
+    private static void writeElementChildren(Element element, JSONStream jstream) throws IOException {
+        jstream.startArray();
+        Object[] children = getChildren(element);
+        QName parentqname = element.getQName();
+        for (int n = 0; n < children.length; n++) {
+            Object child = children[n];
+            if (child instanceof Element) {
+                writeElement((Element)child, parentqname, jstream);
+                if (n < children.length - 1)
+                    jstream.writeSeparator();
+            } else if (child instanceof TextValue) {
+                TextValue textvalue = (TextValue)child;
+                String value = textvalue.getText();
+                if (!element.getMustPreserveWhitespace()) {
+                    if (!value.matches("\\s*")) {
+                        jstream.writeQuoted(value.trim());
+                        if (n < children.length - 1)
+                            jstream.writeSeparator();
+                    }
+                } else {
+                    jstream.writeQuoted(value);
+                    if (n < children.length - 1)
+                        jstream.writeSeparator();
+                }
+            }
+        }
+        jstream.endArray();
+    }
+
+    private static void writeExtensions(ExtensibleElement element, JSONStream jstream) throws IOException {
+        writeExtensions(element, jstream, true);
+    }
+
+    private static void writeExtensions(ExtensibleElement element, JSONStream jstream, boolean startsep)
+        throws IOException {
+        List<QName> attributes = element.getExtensionAttributes();
+        writeList("extensions", element.getExtensions(), jstream);
+        if (attributes.size() > 0) {
+            jstream.writeField("attributes");
+
+            jstream.startObject();
+            for (int n = 0; n < attributes.size(); n++) {
+                QName qname = attributes.get(n);
+                jstream.writeField(getName(qname));
+                if ("".equals(qname.getPrefix()) || "xml".equals(qname.getPrefix())) {
+                    jstream.writeQuoted(element.getAttributeValue(qname));
+                } else {
+                    jstream.startObject();
+                    jstream.writeField("attributes");
+                    jstream.startObject();
+                    jstream.writeField("xmlns:" + qname.getPrefix());
+                    jstream.writeQuoted(qname.getNamespaceURI());
+                    jstream.endObject();
+                    jstream.writeField("value");
+                    jstream.writeQuoted(element.getAttributeValue(qname));
+                    jstream.endObject();
+                }
+            }
+            jstream.endObject();
+        }
+    }
+
+    private static boolean needToWriteLanguageFields(Element element) {
+        return needToWriteLang(element) || needToWriteDir(element);
+    }
+
+    private static boolean needToWriteLang(Element element) {
+        String parentlang = null;
+        if (element.getParentElement() != null) {
+            Base parent = element.getParentElement();
+            parentlang =
+                parent instanceof Document ? ((Document<?>)parent).getLanguage() : ((Element)parent).getLanguage();
+        }
+        String lang = element.getLanguage();
+        return (parentlang == null && lang != null) || (lang != null && parentlang != null && !parentlang
+            .equalsIgnoreCase(lang));
+    }
+
+    private static boolean needToWriteDir(Element element) {
+        Direction parentdir = Direction.UNSPECIFIED;
+        Direction dir = BidiHelper.getDirection(element);
+        if (element.getParentElement() != null) {
+            Base parent = element.getParentElement();
+            if (parent instanceof Element)
+                parentdir = BidiHelper.getDirection((Element)parent);
+        }
+        return dir != Direction.UNSPECIFIED && !dir.equals(parentdir);
+    }
+
+    private static void writeLanguageFields(Element element, JSONStream jstream) throws IOException {
+        if (needToWriteLang(element)) {
+            String lang = element.getLanguage();
+            jstream.writeField("lang", lang);
+        }
+        if (needToWriteDir(element)) {
+            Direction dir = BidiHelper.getDirection(element);
+            jstream.writeField("dir", dir.name().toLowerCase());
+        }
+    }
+
+    private static void writeElement(String name, Element element, JSONStream jstream) throws IOException {
+        if (element != null) {
+            jstream.writeField(name);
+            toJson(element, jstream);
+        }
+    }
+
+    private static boolean is_empty(Iterable<?> list) {
+      return Iterables.isEmpty(list);
+    }
+    
+    private static boolean writeList(String name, Iterable<?> list, JSONStream jstream) throws IOException {
+        if (is_empty(list))
+            return false;
+        jstream.writeField(name);
+        jstream.startArray();
+        boolean start = true;
+        for (Object obj : list) {
+            Element el = (Element)obj;
+            if (!(el instanceof InReplyTo) && !(el instanceof Control)) {
+                if (!start) jstream.writeSeparator();
+                else start = false;
+                toJson(el, jstream);
+            }
+        }
+        jstream.endArray();
+        return true;
+    }
+
+    private static void toJson(Document<?> document, JSONStream jstream) throws IOException {
+        jstream.startObject();
+        jstream.writeField("base", document.getBaseUri());
+        jstream.writeField("content-type", document.getContentType());
+        jstream.writeField("etag", document.getEntityTag());
+        jstream.writeField("language", document.getLanguage());
+        jstream.writeField("slug", document.getSlug());
+        jstream.writeField("last-modified", document.getLastModified());
+
+        Element root = document.getRoot();
+        if (root != null) {
+            String rootname = root.getQName().getLocalPart();
+            writeElement(rootname, document.getRoot(), jstream);
+        }
+        jstream.endObject();
+    }
+
+    private static Object[] getChildren(Element element) {
+        Abdera abdera = element.getFactory().getAbdera();
+        XPath xpath = abdera.getXPath();
+        List<?> nodes = xpath.selectNodes("node()", element);
+        return nodes.toArray(new Object[nodes.size()]);
+    }
+
+    private static boolean isSameNamespace(QName q1, QName q2) {
+        if (q1 == null && q2 != null)
+            return false;
+        if (q1 != null && q2 == null)
+            return false;
+        String p1 = q1 == null ? "" : q1.getPrefix() != null ? q1.getPrefix() : "";
+        String p2 = q2 == null ? "" : q2.getPrefix() != null ? q2.getPrefix() : "";
+        String n1 = q1 == null ? "" : q1.getNamespaceURI() != null ? q1.getNamespaceURI() : "";
+        String n2 = q2 == null ? "" : q2.getNamespaceURI() != null ? q2.getNamespaceURI() : "";
+        return n1.equals(n2) && p1.equals(p2);
+    }
+
+}

Propchange: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONUtil.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONWriter.java
URL: http://svn.apache.org/viewvc/abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONWriter.java?rev=1239246&view=auto
==============================================================================
--- abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONWriter.java (added)
+++ abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONWriter.java Wed Feb  1 18:26:46 2012
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.abdera2.ext.json;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.common.anno.Name;
+import org.apache.abdera2.model.Base;
+import org.apache.abdera2.writer.AbstractWriter;
+import org.apache.abdera2.writer.WriterOptions;
+
+@Name("json")
+public class JSONWriter extends AbstractWriter {
+
+    public JSONWriter(Abdera abdera) {
+        super(
+          "application/json", 
+          "application/javascript", 
+          "application/ecmascript", 
+          "text/javascript", 
+          "text/ecmascript");
+    }
+
+    @Override
+    protected WriterOptions.Builder initDefaultWriterOptions() {
+        return WriterOptions.make();
+    }
+
+    public Object write(Base base, WriterOptions options) throws IOException {
+        try {
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+            writeTo(base, out, options);
+            return new String(out.toByteArray(), options.getCharset());
+        } catch (IOException i) {
+            throw i;
+        } catch (Exception e) {
+            throw new IOException(e.getMessage());
+        }
+    }
+
+    public void writeTo(Base base, OutputStream out, WriterOptions options) throws IOException {
+        writeTo(base, new OutputStreamWriter(out, options.getCharset()), options);
+    }
+
+    public void writeTo(Base base, java.io.Writer out, WriterOptions options) throws IOException {
+        try {
+            JSONUtil.toJson(base, out);
+            out.flush();
+            if (options.getAutoClose())
+                out.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new IOException(e.getMessage());
+        }
+    }
+
+}

Propchange: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/json/JSONWriter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/serializer/ObjectResponseContext.java
URL: http://svn.apache.org/viewvc/abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/serializer/ObjectResponseContext.java?rev=1239246&view=auto
==============================================================================
--- abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/serializer/ObjectResponseContext.java (added)
+++ abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/serializer/ObjectResponseContext.java Wed Feb  1 18:26:46 2012
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.ext.serializer;
+
+import java.io.IOException;
+import java.lang.reflect.AccessibleObject;
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.common.misc.ExceptionHelper;
+import org.apache.abdera2.common.misc.MoreFunctions;
+import org.apache.abdera2.ext.serializer.annotation.EntityTag;
+import org.apache.abdera2.ext.serializer.annotation.LastModified;
+import org.apache.abdera2.ext.serializer.annotation.MediaType;
+import org.apache.abdera2.protocol.server.context.StreamWriterResponseContext;
+import org.apache.abdera2.writer.StreamWriter;
+import org.joda.time.DateTime;
+
+public class ObjectResponseContext extends StreamWriterResponseContext {
+
+    private final Object object;
+    private final ObjectContext objectContext;
+    private final Conventions conventions;
+    private final Class<? extends SerializationContext> context;
+
+    public ObjectResponseContext(Object object, Abdera abdera, String encoding, String sw) {
+        this(object, null, null, abdera, encoding, sw);
+    }
+
+    public ObjectResponseContext(Object object,
+                                 Class<? extends SerializationContext> context,
+                                 Conventions conventions,
+                                 Abdera abdera,
+                                 String encoding,
+                                 String sw) {
+        super(abdera, encoding, sw);
+        this.object = object;
+        this.objectContext = new ObjectContext(object);
+        this.conventions = conventions != null ? conventions : new DefaultConventions();
+        this.context = context != null ? context : ConventionSerializationContext.class;
+        init();
+    }
+
+    public ObjectResponseContext(Object object, Abdera abdera, String encoding) {
+        this(object, null, null, abdera, encoding, null);
+    }
+
+    public ObjectResponseContext(Object object,
+                                 Class<? extends SerializationContext> context,
+                                 Conventions conventions,
+                                 Abdera abdera,
+                                 String encoding) {
+        this(object, context, conventions, abdera, encoding, null);
+    }
+
+    public ObjectResponseContext(Object object, Abdera abdera) {
+        this(object, null, null, abdera, null, null);
+    }
+
+    public ObjectResponseContext(Object object,
+                                 Class<? extends SerializationContext> context,
+                                 Conventions conventions,
+                                 Abdera abdera) {
+        this(object, context, null, abdera, null, null);
+    }
+
+    private void init() {
+        setContentType(getObjectContentType());
+        setEntityTag(getObjectEntityTag());
+        setLastModified(getObjectLastModified());
+    }
+
+    private DateTime getObjectLastModified() {
+        DateTime date = null;
+        AccessibleObject accessor = objectContext.getAccessor(LastModified.class, conventions);
+        if (accessor != null) {
+            Object value = BaseSerializer.eval(accessor, object);
+            date = getDate(value);
+        }
+        return date;
+    }
+
+    private DateTime getDate(Object value) {
+        return new DateTime(value);
+    }
+
+    private String getObjectEntityTag() {
+        String etag = null;
+        AccessibleObject accessor = objectContext.getAccessor(EntityTag.class, conventions);
+        if (accessor != null) {
+            Object value = BaseSerializer.eval(accessor, object);
+            etag = value != null ? BaseSerializer.toString(value) : null;
+        }
+        return etag;
+    }
+
+    private String getObjectContentType() {
+        String ctype = null;
+        AccessibleObject accessor = objectContext.getAccessor(MediaType.class, conventions);
+        if (accessor != null) {
+            Object value = BaseSerializer.eval(accessor, object);
+            ctype = value != null ? BaseSerializer.toString(value) : null;
+        }
+        if (ctype == null) {
+            MediaType content_type = objectContext.getAnnotation(MediaType.class);
+            if (content_type != null && !content_type.value().equals(BaseSerializer.DEFAULT)) {
+                ctype = content_type.value();
+            }
+        }
+        return ctype;
+    }
+
+    @Override
+    protected void writeTo(StreamWriter sw) throws IOException {
+        SerializationContext context = 
+          newSerializationContext(getAbdera(), conventions, sw);
+        sw.startDocument();
+        context.serialize(object, objectContext);
+        sw.endDocument();
+    }
+
+    private SerializationContext newSerializationContext(
+      Abdera abdera, 
+      Conventions conventions, 
+      StreamWriter sw) {
+        try {
+          return MoreFunctions
+            .createInstance(
+              context,
+              Abdera.class,
+              Conventions.class,
+              StreamWriter.class)
+                .apply(MoreFunctions
+                  .array(abdera,conventions,sw));
+        } catch (Exception e) {
+          throw ExceptionHelper.propogate(e);
+        }
+    }
+}

Propchange: abdera/abdera2-server/server/src/main/java/org/apache/abdera2/ext/serializer/ObjectResponseContext.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message