You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@abdera.apache.org by jm...@apache.org on 2007/11/27 01:24:52 UTC

svn commit: r598470 - in /incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples: ext/URITemplates.java uritemplates/ uritemplates/AtomIDTemplate.java uritemplates/AtomLinkTemplate.java uritemplates/URITemplates.java

Author: jmsnell
Date: Mon Nov 26 16:24:48 2007
New Revision: 598470

URL: http://svn.apache.org/viewvc?rev=598470&view=rev
Log:
Examples showing URI Templates being used in a variety of ways

Added:
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/uritemplates/
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/uritemplates/AtomIDTemplate.java
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/uritemplates/AtomLinkTemplate.java
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/uritemplates/URITemplates.java
      - copied, changed from r598389, incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/URITemplates.java
Removed:
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/URITemplates.java

Added: incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/uritemplates/AtomIDTemplate.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/uritemplates/AtomIDTemplate.java?rev=598470&view=auto
==============================================================================
--- incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/uritemplates/AtomIDTemplate.java (added)
+++ incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/uritemplates/AtomIDTemplate.java Mon Nov 26 16:24:48 2007
@@ -0,0 +1,63 @@
+/*
+* 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.examples.uritemplates;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.i18n.templates.Template;
+import org.apache.abdera.i18n.templates.URITemplate;
+import org.apache.abdera.model.Entry;
+
+/**
+ * This example demonstrates the use of URI Templates to create an atom:id
+ * value from an annotated Java object.
+ */
+public class AtomIDTemplate {
+
+  public static void main(String... args) throws Exception {
+    
+    ID id = new ID("myblog","entries","abc123xyz");
+    
+    Abdera abdera = Abdera.getInstance();
+    Entry entry = abdera.newEntry();
+    entry.setId(Template.expandAnnotated(id));
+    entry.setTitle("This is a test");
+    entry.writeTo("prettyxml",System.out);
+    
+  }
+  
+  @URITemplate("tag:example.org,2007:/{collection}/{view}/{id}")
+  public static class ID {
+    private final String collection;
+    private final String view;
+    private final String id;
+    public ID(String collection, String view, String id) {
+      this.collection = collection;
+      this.view = view;
+      this.id = id;
+    }
+    public String getCollection() {
+      return collection;
+    }
+    public String getView() {
+      return view;
+    }
+    public String getId() {
+      return id;
+    }
+  }
+}

Added: incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/uritemplates/AtomLinkTemplate.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/uritemplates/AtomLinkTemplate.java?rev=598470&view=auto
==============================================================================
--- incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/uritemplates/AtomLinkTemplate.java (added)
+++ incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/uritemplates/AtomLinkTemplate.java Mon Nov 26 16:24:48 2007
@@ -0,0 +1,71 @@
+/*
+* 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.examples.uritemplates;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.i18n.templates.Template;
+import org.apache.abdera.i18n.templates.URITemplate;
+
+public class AtomLinkTemplate {
+
+  public static void main(String... args) throws Exception {
+    
+    Abdera abdera = Abdera.getInstance();
+    abdera.newStreamWriter()
+      .setOutputStream(System.out)
+      .startDocument()
+      .startFeed()
+        .writeBase("http://example.org")
+        .writeLink(getPage("entries",1,10), "current")
+        .writeLink(getPage("entries",2,10), "self")
+        .writeLink(getPage("entries",1,10), "previous")
+        .writeLink(getPage("entries",3,10), "next")
+        .writeLink(getPage("entries",1,10), "first")
+        .writeLink(getPage("entries",10,10), "last")
+      .endFeed()
+      .endDocument()
+      .flush();
+    
+  }
+  
+  private static String getPage(String view, int page, int count) {
+    return Template.expandAnnotated(new PagingLink(view,page,count));
+  }
+  
+  @URITemplate("/{view}?{-join|&|page,count}")
+  public static class PagingLink {
+    private final String view;
+    private final int page;
+    private final int count;
+    public PagingLink(String view, int page, int count) {
+      this.view = view;
+      this.page = page;
+      this.count = count;
+    }
+    public String getView() {
+      return view;
+    }
+    public int getPage() {
+      return page;
+    }
+    public int getCount() {
+      return count;
+    }
+  }
+  
+}

Copied: incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/uritemplates/URITemplates.java (from r598389, incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/URITemplates.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/uritemplates/URITemplates.java?p2=incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/uritemplates/URITemplates.java&p1=incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/URITemplates.java&r1=598389&r2=598470&rev=598470&view=diff
==============================================================================
--- incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/ext/URITemplates.java (original)
+++ incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/uritemplates/URITemplates.java Mon Nov 26 16:24:48 2007
@@ -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.examples.ext;
+package org.apache.abdera.examples.uritemplates;
 
 import java.util.ArrayList;
 import java.util.Arrays;