abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r471008 - in /incubator/abdera/java/trunk/extensions/src: main/java/org/apache/abdera/ext/thread/ test/java/org/apache/abdera/test/ext/ test/java/org/apache/abdera/test/ext/thread/
Date Fri, 03 Nov 2006 21:59:20 GMT
Author: jmsnell
Date: Fri Nov  3 13:59:19 2006
New Revision: 471008

URL: http://svn.apache.org/viewvc?view=rev&rev=471008
Log:
Consolidating the Feed Thread interfaces / impl classes.
Adding a simple Feed Thread test case

Added:
    incubator/abdera/java/trunk/extensions/src/test/java/org/apache/abdera/test/ext/thread/
    incubator/abdera/java/trunk/extensions/src/test/java/org/apache/abdera/test/ext/thread/ThreadTest.java
Removed:
    incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/thread/InReplyToImpl.java
    incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/thread/TotalImpl.java
Modified:
    incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/thread/InReplyTo.java
    incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/thread/ThreadExtensionFactory.java
    incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/thread/ThreadHelper.java
    incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/thread/Total.java
    incubator/abdera/java/trunk/extensions/src/test/java/org/apache/abdera/test/ext/TestSuite.java

Modified: incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/thread/InReplyTo.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/thread/InReplyTo.java?view=diff&rev=471008&r1=471007&r2=471008
==============================================================================
--- incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/thread/InReplyTo.java
(original)
+++ incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/thread/InReplyTo.java
Fri Nov  3 13:59:19 2006
@@ -20,93 +20,85 @@
 import javax.activation.MimeType;
 import javax.activation.MimeTypeParseException;
 
+import org.apache.abdera.factory.Factory;
 import org.apache.abdera.model.Element;
+import org.apache.abdera.model.ElementWrapper;
 import org.apache.abdera.util.iri.IRI;
 import org.apache.abdera.util.iri.IRISyntaxException;
 
-/**
- * Provides an interface for the Atom Threading Extension in-reply-to
- * element.  The in-reply-to element allows an entry to be marked as 
- * a response to another resource.
- */
-public interface InReplyTo 
-  extends Element {
-  
-  /**
-   * Returns the persistent and universally unique identifier of the 
-   * resource the entry is a response to.
-   */
-  IRI getRef() throws IRISyntaxException;
-  
-  /**
-   * Sets the persistent and universally unique identifier of the 
-   * resource that this entry is a response to
-   */
-  void setRef(IRI ref);
-
-  /**
-   * Sets the persistent and universally unique identifier of the 
-   * resource that this entry is a response to
-   */
-  void setRef(String ref) throws IRISyntaxException;
-  
-  /**
-   * Returns the resolved value of the href attribute
-   */
-  IRI getResolvedHref() throws IRISyntaxException;
-  
-  /**
-   * Returns a dereferenceable URI indicating where a representation of the 
-   * resource being responded to may be retrieved
-   */
-  IRI getHref() throws IRISyntaxException;
-  
-  /**
-   * Sets a dereferenceable URI indicating where a representation of the 
-   * resource being responded to may be retrieved
-   */
-  void setHref(IRI ref);
-  
-  /**
-   * Sets a dereferenceable URI indicating where a representation of the 
-   * resource being responded to may be retrieved
-   */
-  void setHref(String ref) throws IRISyntaxException;
-  
-  /**
-   * Returns the media type of the resource referenced by the href attribute
-   */
-  MimeType getMimeType() throws MimeTypeParseException;
-
-  /**
-   * Sets the media type of the resource referenced by the href attribute
-   */
-  void setMimeType(MimeType mimeType);
-  
-  /**
-   * Sets the media type of the resource referenced by the href attribute
-   */
-  void setMimeType(String mimeType) throws MimeTypeParseException;
-  
-  /**
-   * Returns a dereferenceable URI of an Atom Feed or Entry Document resolved
-   * against the in-scope Base URI
-   */
-  IRI getResolvedSource() throws IRISyntaxException;
-  
-  /**
-   * Returns a dereferenceable URI of an Atom Feed or Entry Document
-   */
-  IRI getSource() throws IRISyntaxException;
-  
-  /**
-   * Sets a dereferenceable URI of an Atom Feed or Entry Document
-   */
-  void setSource(IRI source);
-  
-  /**
-   * Sets a dereferenceable URI of an Atom Feed or Entry Document
-   */
-  void setSource(String source) throws IRISyntaxException;
-  
+public class InReplyTo 
+  extends ElementWrapper {
+
+  public InReplyTo(Element internal) {
+    super(internal);
+  }
+
+  public InReplyTo(Factory factory) {
+    super(factory, ThreadConstants.IN_REPLY_TO);
+  }
+
+  public IRI getHref() throws IRISyntaxException {
+    String href = getAttributeValue("href");
+    return (href != null) ? new IRI(href) : null;
+  }
+
+  public MimeType getMimeType() throws MimeTypeParseException {
+    String type = getAttributeValue("type");
+    return (type != null) ? new MimeType(type) : null;
+  }
+
+  public IRI getRef() throws IRISyntaxException {
+    String ref = getAttributeValue("ref");
+    return (ref != null) ? new IRI(ref) : null;
+  }
+
+  public IRI getResolvedHref() throws IRISyntaxException {
+    IRI href = getHref();
+    IRI base = getBaseUri();
+    return (base == null) ? href : (href != null) ? base.resolve(href) : null; 
+  }
+
+  public IRI getResolvedSource() throws IRISyntaxException {
+    IRI href = getSource();
+    IRI base = getBaseUri();
+    return (base == null) ? href : (href != null) ? base.resolve(href) : null;
+  }
+
+  public IRI getSource() throws IRISyntaxException {
+    String source = getAttributeValue("source");
+    return (source != null) ? new IRI(source) : null;
+  }
+
+  public void setHref(IRI ref) {
+    setAttributeValue("href", ref.toString());
+  }
+
+  public void setHref(String ref) throws IRISyntaxException {
+    setAttributeValue("href", ref);
+  }
+
+  public void setMimeType(MimeType mimeType) {
+    setAttributeValue("type", mimeType.toString());
+  }
+
+  public void setMimeType(String mimeType) throws MimeTypeParseException {
+    setAttributeValue("type", mimeType);
+  }
+
+  public void setRef(IRI ref) {
+    setAttributeValue("ref", ref.toString());
+  }
+
+  public void setRef(String ref) throws IRISyntaxException {
+    setAttributeValue("ref", ref);
+  }
+
+  public void setSource(IRI source) {
+    setAttributeValue("source", source.toString());
+  }
+
+  public void setSource(String source) throws IRISyntaxException {
+    setAttributeValue("source", source);
+  }
+
 }

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=471008&r1=471007&r2=471008
==============================================================================
--- 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
Fri Nov  3 13:59:19 2006
@@ -42,9 +42,9 @@
   public <T extends Element> T getElementWrapper(Element internal) {
     QName qname = internal.getQName();
     if (ThreadConstants.IN_REPLY_TO.equals(qname)) 
-      return (T)new InReplyToImpl(internal);
+      return (T)new InReplyTo(internal);
     else if (ThreadConstants.THRTOTAL.equals(qname))
-      return (T)new TotalImpl(internal);
+      return (T)new Total(internal);
     else return (T)internal;
   }
 

Modified: incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/thread/ThreadHelper.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/thread/ThreadHelper.java?view=diff&rev=471008&r1=471007&r2=471008
==============================================================================
--- incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/thread/ThreadHelper.java
(original)
+++ incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/thread/ThreadHelper.java
Fri Nov  3 13:59:19 2006
@@ -188,11 +188,11 @@
   }
 
   public static InReplyTo newInReplyTo(Factory factory) {
-    return new InReplyToImpl(factory);
+    return new InReplyTo(factory);
   }
   
   public static Total newTotal(Factory factory) {
-    return new TotalImpl(factory);
+    return new Total(factory);
   }
   
 }

Modified: incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/thread/Total.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/thread/Total.java?view=diff&rev=471008&r1=471007&r2=471008
==============================================================================
--- incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/thread/Total.java
(original)
+++ incubator/abdera/java/trunk/extensions/src/main/java/org/apache/abdera/ext/thread/Total.java
Fri Nov  3 13:59:19 2006
@@ -17,16 +17,28 @@
 */
 package org.apache.abdera.ext.thread;
 
+import org.apache.abdera.factory.Factory;
 import org.apache.abdera.model.Element;
+import org.apache.abdera.model.ElementWrapper;
+
+public class Total 
+  extends ElementWrapper {
+
+  public Total(Element internal) {
+    super(internal);
+  }
+
+  public Total(Factory factory) {
+    super(factory, ThreadConstants.THRTOTAL);
+  }
+
+  public int getValue() {
+    String val = getText();
+    return (val != null) ? Integer.parseInt(val) : -1;
+  }
+
+  public void setValue(int value) {
+    setText(String.valueOf(value));
+  }
 
-/**
- * Provides an interface for the Atom Threading Extension total
- * element.
- */
-public interface Total extends Element {
-
-  int getValue();
-  
-  void setValue(int value);
-  
 }

Modified: incubator/abdera/java/trunk/extensions/src/test/java/org/apache/abdera/test/ext/TestSuite.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/src/test/java/org/apache/abdera/test/ext/TestSuite.java?view=diff&rev=471008&r1=471007&r2=471008
==============================================================================
--- incubator/abdera/java/trunk/extensions/src/test/java/org/apache/abdera/test/ext/TestSuite.java
(original)
+++ incubator/abdera/java/trunk/extensions/src/test/java/org/apache/abdera/test/ext/TestSuite.java
Fri Nov  3 13:59:19 2006
@@ -18,6 +18,7 @@
 package org.apache.abdera.test.ext;
 
 import org.apache.abdera.test.ext.opensearch.*;
+import org.apache.abdera.test.ext.thread.ThreadTest;
 import org.apache.abdera.test.ext.history.FeedPagingTest;
 
 public class TestSuite extends junit.framework.TestSuite {
@@ -30,5 +31,6 @@
   {
     addTestSuite(OpenSearchTest.class);
     addTestSuite(FeedPagingTest.class);
+    addTestSuite(ThreadTest.class);
   }
 }

Added: incubator/abdera/java/trunk/extensions/src/test/java/org/apache/abdera/test/ext/thread/ThreadTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/src/test/java/org/apache/abdera/test/ext/thread/ThreadTest.java?view=auto&rev=471008
==============================================================================
--- incubator/abdera/java/trunk/extensions/src/test/java/org/apache/abdera/test/ext/thread/ThreadTest.java
(added)
+++ incubator/abdera/java/trunk/extensions/src/test/java/org/apache/abdera/test/ext/thread/ThreadTest.java
Fri Nov  3 13:59:19 2006
@@ -0,0 +1,48 @@
+/*
+* 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.abdera.test.ext.thread;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.ext.thread.InReplyTo;
+import org.apache.abdera.ext.thread.ThreadConstants;
+import org.apache.abdera.ext.thread.ThreadHelper;
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.model.Entry;
+
+import junit.framework.TestCase;
+
+public class ThreadTest extends TestCase {
+
+  public static void testThread() throws Exception {
+    
+    Abdera abdera = new Abdera();
+    Factory factory = abdera.getFactory();
+    Entry e1 = factory.newEntry();
+    Entry e2 = factory.newEntry();
+    
+    e1.setId("tag:example.org,2006:first");
+    e2.setId("tag:example.org,2006:second");
+    
+    ThreadHelper.addInReplyTo(e2,e1); // e2 is a response to e1
+    assertNotNull(e2.getExtension(ThreadConstants.IN_REPLY_TO));
+    InReplyTo irt = e2.getExtension(ThreadConstants.IN_REPLY_TO);
+    assertEquals(irt.getRef(), e1.getId());
+    
+  }
+  
+}



Mime
View raw message