Author: ieb
Date: Wed Nov 19 10:37:21 2008
New Revision: 719019

URL: http://svn.apache.org/viewvc?rev=719019&view=rev
Log:
   SHINDIG-497

   Missed the source link serialization, and the content type on the content 
element.

Added:
    
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomAttribute.java
      - copied, changed from r718985, 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomLink.java
    
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomAttributeConverter.java
   (with props)
    
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomLinkConverter.java
   (with props)
Modified:
    
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomContent.java
    
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomLink.java
    
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/xstream/XStream081Configuration.java
    
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXStreamAtomConverterTest.java

Copied: 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomAttribute.java
 (from r718985, 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomLink.java)
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomAttribute.java?p2=incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomAttribute.java&p1=incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomLink.java&r1=718985&r2=719019&rev=719019&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomLink.java
 (original)
+++ 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomAttribute.java
 Wed Nov 19 10:37:21 2008
@@ -18,22 +18,27 @@
 package org.apache.shindig.social.core.util.atom;
 
 /**
- * represents an atom:link element
+ * Represents an attribute in atom, ties into attribute converters.
  */
-public class AtomLink {
+public class AtomAttribute {
 
-  @SuppressWarnings("unused")
-  private String href;
-  @SuppressWarnings("unused")
-  private String rel;
+  private String value;
 
   /**
-   * @param string
-   * @param string2
+   * @param value
    */
-  public AtomLink(String rel, String href) {
-    this.rel = rel;
-    this.href = href;
+  public AtomAttribute(String value) {
+    this.value = value;
+  }
+
+  /**
+   * [EMAIL PROTECTED]
+   * 
+   * @see java.lang.Object#toString()
+   */
+  @Override
+  public String toString() {
+    return value;
   }
 
 }

Added: 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomAttributeConverter.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomAttributeConverter.java?rev=719019&view=auto
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomAttributeConverter.java
 (added)
+++ 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomAttributeConverter.java
 Wed Nov 19 10:37:21 2008
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. 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.
+ */
+package org.apache.shindig.social.core.util.atom;
+
+import com.thoughtworks.xstream.converters.Converter;
+import com.thoughtworks.xstream.converters.MarshallingContext;
+import com.thoughtworks.xstream.converters.SingleValueConverter;
+import com.thoughtworks.xstream.converters.UnmarshallingContext;
+import com.thoughtworks.xstream.io.HierarchicalStreamReader;
+import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+
+/**
+ * Serializes attributes correctly.
+ */
+public class AtomAttributeConverter implements SingleValueConverter {
+
+  /**
+   * [EMAIL PROTECTED]
+   * @see 
com.thoughtworks.xstream.converters.SingleValueConverter#fromString(java.lang.String)
+   */
+  public Object fromString(String value) {
+    return new AtomAttribute(value);
+  }
+
+  /**
+   * [EMAIL PROTECTED]
+   * @see 
com.thoughtworks.xstream.converters.SingleValueConverter#toString(java.lang.Object)
+   */
+  public String toString(Object object) {
+    return object.toString();
+  }
+
+  /**
+   * [EMAIL PROTECTED]
+   * @see 
com.thoughtworks.xstream.converters.ConverterMatcher#canConvert(java.lang.Class)
+   */
+  public boolean canConvert(Class clazz) {
+    return AtomAttribute.class.equals(clazz);
+  }
+
+
+}

Propchange: 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomAttributeConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomAttributeConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Modified: 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomContent.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomContent.java?rev=719019&r1=719018&r2=719019&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomContent.java
 (original)
+++ 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomContent.java
 Wed Nov 19 10:37:21 2008
@@ -34,8 +34,8 @@
   private Person person;
   @SuppressWarnings("unused")
   private Activity activity;
-  // @SuppressWarnings("unused")
-  // private String type = "application/xml";
+  @SuppressWarnings("unused")
+  private AtomAttribute type = new AtomAttribute("application/xml");
   @SuppressWarnings("unused")
   private Object entry;
   @SuppressWarnings("unused")

Modified: 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomLink.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomLink.java?rev=719019&r1=719018&r2=719019&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomLink.java
 (original)
+++ 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomLink.java
 Wed Nov 19 10:37:21 2008
@@ -22,9 +22,7 @@
  */
 public class AtomLink {
 
-  @SuppressWarnings("unused")
   private String href;
-  @SuppressWarnings("unused")
   private String rel;
 
   /**
@@ -36,4 +34,18 @@
     this.href = href;
   }
 
+  /**
+   * @return
+   */
+  public String getHref() {
+    return href;
+  }
+  
+  /**
+   * @return the rel
+   */
+  public String getRel() {
+    return rel;
+  }
+
 }

Added: 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomLinkConverter.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomLinkConverter.java?rev=719019&view=auto
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomLinkConverter.java
 (added)
+++ 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomLinkConverter.java
 Wed Nov 19 10:37:21 2008
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. 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.
+ */
+package org.apache.shindig.social.core.util.atom;
+
+import com.thoughtworks.xstream.converters.Converter;
+import com.thoughtworks.xstream.converters.MarshallingContext;
+import com.thoughtworks.xstream.converters.UnmarshallingContext;
+import com.thoughtworks.xstream.io.HierarchicalStreamReader;
+import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+
+/**
+ * Serializes links for atom, taking account of attributes.
+ */
+public class AtomLinkConverter implements Converter {
+
+  /**
+   * [EMAIL PROTECTED]
+   * 
+   * @see 
com.thoughtworks.xstream.converters.Converter#marshal(java.lang.Object,
+   *      com.thoughtworks.xstream.io.HierarchicalStreamWriter,
+   *      com.thoughtworks.xstream.converters.MarshallingContext)
+   */
+  public void marshal(Object object, HierarchicalStreamWriter writer,
+      MarshallingContext context) {
+    AtomLink link = (AtomLink) object;
+    if (link.getRel() != null) {
+      writer.addAttribute("rel", link.getRel());
+    }
+    if (link.getHref() != null) {
+      writer.setValue(link.getHref());
+    }
+  }
+
+  /**
+   * [EMAIL PROTECTED]
+   * 
+   * @see 
com.thoughtworks.xstream.converters.Converter#unmarshal(com.thoughtworks.xstream.io.HierarchicalStreamReader,
+   *      com.thoughtworks.xstream.converters.UnmarshallingContext)
+   */
+  public Object unmarshal(HierarchicalStreamReader reader,
+      UnmarshallingContext context) {
+    reader.moveDown();
+    AtomLink al = new AtomLink(reader.getAttribute("rel"), reader.getValue());
+    reader.moveUp();
+    return al;
+  }
+
+  /**
+   * [EMAIL PROTECTED]
+   * 
+   * @see 
com.thoughtworks.xstream.converters.ConverterMatcher#canConvert(java.lang.Class)
+   */
+  public boolean canConvert(Class clazz) {
+    return AtomLink.class.equals(clazz);
+  }
+
+}

Propchange: 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomLinkConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/atom/AtomLinkConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Modified: 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/xstream/XStream081Configuration.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/xstream/XStream081Configuration.java?rev=719019&r1=719018&r2=719019&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/xstream/XStream081Configuration.java
 (original)
+++ 
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/xstream/XStream081Configuration.java
 Wed Nov 19 10:37:21 2008
@@ -27,13 +27,17 @@
 import 
com.thoughtworks.xstream.converters.extended.ISO8601SqlTimestampConverter;
 import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
+import com.thoughtworks.xstream.mapper.AttributeMapper;
 import com.thoughtworks.xstream.mapper.Mapper;
 
 import org.apache.shindig.social.core.model.EnumImpl;
+import org.apache.shindig.social.core.util.atom.AtomAttribute;
+import org.apache.shindig.social.core.util.atom.AtomAttributeConverter;
 import org.apache.shindig.social.core.util.atom.AtomContent;
 import org.apache.shindig.social.core.util.atom.AtomEntry;
 import org.apache.shindig.social.core.util.atom.AtomFeed;
 import org.apache.shindig.social.core.util.atom.AtomKeyValue;
+import org.apache.shindig.social.core.util.atom.AtomLinkConverter;
 import org.apache.shindig.social.opensocial.model.Account;
 import org.apache.shindig.social.opensocial.model.Activity;
 import org.apache.shindig.social.opensocial.model.Address;
@@ -361,7 +365,8 @@
   private Converter[] getConverters(Mapper mapper, ConverterSet c) {
     return new Converter[] { new MapConverter(mapper),
         new RestfullCollectionConverter(mapper),
-        new DataCollectionConverter(mapper) };
+        new DataCollectionConverter(mapper),
+        new AtomLinkConverter()};
   }
 
   /**
@@ -408,9 +413,13 @@
     InterfaceClassMapper fmapper = new InterfaceClassMapper(writerStack, 
emapper,
         getElementMappingList(c), getListElementMappingList(c),
         getItemFieldMappings(c), getOmitMap(c), getElementClassMap(c));
+    AttributeMapper amapper = new AttributeMapper(fmapper);
+    
+    
 
-    XStream xstream = new XStream(rp, fmapper, driver);
-
+    
+    XStream xstream = new XStream(rp, amapper, driver);
+    amapper.addAttributeFor(AtomAttribute.class);
     for (Converter converter : getConverters(fmapper, c)) {
       xstream.registerConverter(converter);
     }
@@ -418,6 +427,7 @@
     xstream.registerConverter(new ISO8601GregorianCalendarConverter());
     xstream.registerConverter(new ISO8601SqlTimestampConverter());
     xstream.registerConverter(new GuiceBeanConverter(fmapper, injector));
+    xstream.registerConverter(new AtomAttributeConverter());
     xstream.setMode(XStream.NO_REFERENCES);
 
     return new ConverterConfig(fmapper,xstream);

Modified: 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXStreamAtomConverterTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXStreamAtomConverterTest.java?rev=719019&r1=719018&r2=719019&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXStreamAtomConverterTest.java
 (original)
+++ 
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXStreamAtomConverterTest.java
 Wed Nov 19 10:37:21 2008
@@ -127,7 +127,6 @@
 
   public void testPersonToXml() throws Exception {
     String xml = beanXmlConverter.convertToString(johnDoe);
-
     Element element = XmlUtil.parse(xml);
     Node id = element.getElementsByTagName("id").item(0);
     assertEquals("urn:guid:" + johnDoe.getId(), id.getTextContent());
@@ -158,8 +157,8 @@
     XmlUtil.parse(xml);
 
     String expectedXml = " <feed 
xmlns=\"http://ns.opensocial.org/2008/opensocial\"; 
xmlos:osearch=\"http://a9.com/-/spec/opensearch/1.1\"; > "
-        + " 
<entry><id>item1</id><content><entry><key>value</key><value>1</value></entry></content></entry>
 "
-        + " 
<entry><id>item2</id><content><entry><key>value</key><value>2</value></entry></content></entry>
 "
+        + " <entry><id>item1</id><content type=\"application/xml\" 
><entry><key>value</key><value>1</value></entry></content></entry> "
+        + " <entry><id>item2</id><content type=\"application/xml\" 
><entry><key>value</key><value>2</value></entry></content></entry> "
         + " <osearch:startIndex>0</osearch:startIndex> "
         + " <osearch:totalResults>2</osearch:totalResults> "
         + " <osearch:itemsPerPage>2</osearch:itemsPerPage></feed> ";
@@ -175,8 +174,8 @@
     XmlUtil.parse(xml);
     String expectedXml = "<feed 
xmlns=\"http://ns.opensocial.org/2008/opensocial\"; "
         + " xmlos:osearch=\"http://a9.com/-/spec/opensearch/1.1\";>"
-        + "   
<entry><id>key1</id><content><value>value1</value></content></entry>"
-        + "   
<entry><id>key2</id><content><value>value2</value></content></entry>"
+        + "   <entry><id>key1</id><content type=\"application/xml\" 
><value>value1</value></content></entry>"
+        + "   <entry><id>key2</id><content type=\"application/xml\" 
><value>value2</value></content></entry>"
         + "  <osearch:startIndex>0</osearch:startIndex>"
         + "  <osearch:totalResults>2</osearch:totalResults>"
         + "  <osearch:itemsPerPage>2</osearch:itemsPerPage></feed>";


Reply via email to