abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1173209 [29/49] - in /abdera/abdera2: ./ .settings/ activities/ activities/src/ activities/src/main/ activities/src/main/java/ activities/src/main/java/org/ activities/src/main/java/org/apache/ activities/src/main/java/org/apache/abdera2/ ...
Date Tue, 20 Sep 2011 15:57:20 GMT
Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Thread.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Thread.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Thread.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Thread.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,59 @@
+/*
+ * 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.examples.ext;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.ext.thread.InReplyTo;
+import org.apache.abdera2.ext.thread.ThreadHelper;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.model.Link;
+
+/**
+ * The Atom Threading Extensions are described in RFC4685 and provide a means of representing threaded discussions and
+ * parent/child relationships in Atom.
+ */
+public class Thread {
+
+    public static void main(String... args) throws Exception {
+
+        Abdera abdera = Abdera.getInstance();
+        Entry e1 = abdera.newEntry();
+        Entry e2 = abdera.newEntry();
+
+        e1.newId();
+        e2.newId();
+
+        // Entry e2 is a reply to Entry e1
+        ThreadHelper.addInReplyTo(e2, e1);
+
+        // Get the in-reply-to information
+        InReplyTo irt = ThreadHelper.getInReplyTo(e2);
+        System.out.println(irt.getRef());
+
+        // Add a link to a feed containing replies to e1
+        Link replies = e1.addLink("replies.xml", Link.REL_REPLIES);
+
+        // Set the known number of replies as an attribute on the link
+        ThreadHelper.setCount(replies, 10);
+
+        // alternatively, use the thr:total element to specify the number of replies
+        ThreadHelper.addTotal(e1, 10);
+
+    }
+
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/ext/Thread.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/Bar.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/Bar.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/Bar.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/Bar.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,43 @@
+/*
+ * 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.examples.extension;
+
+import org.apache.abdera2.common.anno.QName;
+import org.apache.abdera2.factory.Factory;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.model.ExtensibleElementWrapper;
+
+@QName(value="bar",ns="tag:example.org,2006:foo",pfx="f")
+public class Bar extends ExtensibleElementWrapper {
+
+    public Bar(Element internal) {
+        super(internal);
+    }
+
+    public Bar(Factory factory, javax.xml.namespace.QName qname) {
+        super(factory, qname);
+    }
+
+    public void setFoo(Foo foo) {
+        addExtension(foo);
+    }
+
+    public Foo getFoo() {
+        return getExtension(Foo.class);
+    }
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/Bar.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/Example.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/Example.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/Example.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/Example.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,46 @@
+/*
+ * 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.examples.extension;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.model.Entry;
+
+/**
+ * Simple example showing the use of static extensions
+ */
+public class Example {
+
+    public static void main(String[] args) throws Exception {
+
+        Abdera abdera = Abdera.getInstance();
+        abdera.getFactory().registerExtension(new FooExtensionFactory());
+
+        Entry entry = abdera.getFactory().newEntry();
+
+        Foo foo = entry.addExtension(Foo.class);
+        foo.setFoo("foo");
+
+        Bar bar = entry.addExtension(Bar.class);
+        bar.setFoo((Foo)foo.clone());
+        bar.getFoo().setFoo("bar");
+
+        System.out.println(entry);
+
+    }
+
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/Example.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/Foo.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/Foo.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/Foo.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/Foo.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,44 @@
+/*
+ * 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.examples.extension;
+
+import org.apache.abdera2.common.anno.QName;
+import org.apache.abdera2.factory.Factory;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.model.ElementWrapper;
+
+@QName(value="foo",ns="tag:example.org,2006:foo",pfx="f")
+public class Foo extends ElementWrapper {
+
+    public Foo(Element internal) {
+        super(internal);
+    }
+
+    public Foo(Factory factory, javax.xml.namespace.QName qname) {
+        super(factory, qname);
+    }
+
+    public String getFoo() {
+        return getText();
+    }
+
+    public void setFoo(String foo) {
+        setText(foo);
+    }
+
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/Foo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/FooExtensionFactory.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/FooExtensionFactory.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/FooExtensionFactory.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/FooExtensionFactory.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,30 @@
+/*
+ * 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.examples.extension;
+
+import org.apache.abdera2.common.anno.Namespace;
+import org.apache.abdera2.factory.AbstractExtensionFactory;
+import org.apache.abdera2.factory.AbstractExtensionFactory.Impls;
+import org.apache.abdera2.factory.AbstractExtensionFactory.Impl;
+
+@Namespace("tag:example.org,2006:foo")
+@Impls({
+  @Impl(Foo.class),
+  @Impl(Bar.class)
+})
+public class FooExtensionFactory extends AbstractExtensionFactory {}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/FooExtensionFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/Geo.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/Geo.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/Geo.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/Geo.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,50 @@
+/*
+ * 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.examples.extension;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.model.Entry;
+
+/**
+ * Simple example showing the use of the dynamic extension APIs
+ */
+public class Geo {
+
+    private static final String GEO_NS = "http://www.postneo.com/icbm/";
+    private static final String GEO_PFX = "icbm";
+    private static final QName LAT = new QName(GEO_NS, "latitude", GEO_PFX);
+    private static final QName LONG = new QName(GEO_NS, "longitude", GEO_PFX);
+
+    public static void main(String[] args) throws Exception {
+
+        Abdera abdera = Abdera.getInstance();
+        Entry entry = abdera.getFactory().newEntry();
+
+        // Set the extension value
+        entry.addSimpleExtension(LAT, "39.02980");
+        entry.addSimpleExtension(LONG, "-77.07929");
+
+        // Get the extension value
+        System.out.println(entry.getSimpleExtension(LAT));
+        System.out.println(entry.getSimpleExtension(LONG));
+
+    }
+
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/extension/Geo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/html/HtmlExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/html/HtmlExample.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/html/HtmlExample.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/html/HtmlExample.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,50 @@
+/*
+ * 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.examples.html;
+
+import java.io.StringReader;
+import java.util.List;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.parser.Parser;
+import org.apache.abdera2.xpath.XPath;
+
+/**
+ * The optional HTML Parser extension allows Abdera to parse and work with HTML
+ */
+public class HtmlExample {
+
+    public static void main(String... args) throws Exception {
+
+        String html = "<html><body><p>this is <i>html</i></body></html>";
+        Abdera abdera = Abdera.getInstance();
+        Parser parser = abdera.getParserFactory().getParser("html");
+        Document<Element> doc = parser.parse(new StringReader(html));
+        Element root = doc.getRoot();
+        root.writeTo(System.out);
+        System.out.println();
+
+        XPath xpath = abdera.getXPath();
+        List<?> list = xpath.selectNodes("//i", doc.getRoot());
+        for (Object element : list)
+            System.out.println(element);
+    }
+
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/html/HtmlExample.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/DHEnc.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/DHEnc.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/DHEnc.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/DHEnc.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,81 @@
+/*
+ * 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.examples.security;
+
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.factory.Factory;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.security.Security;
+import org.apache.abdera2.security.Encryption;
+import org.apache.abdera2.security.EncryptionOptions;
+import org.apache.abdera2.security.util.DHContext;
+import org.apache.abdera2.security.util.KeyHelper;
+
+public class DHEnc {
+
+    public static void main(String[] args) throws Exception {
+
+        Abdera abdera = Abdera.getInstance();
+
+        // Register the bouncy castle jce provider
+        KeyHelper.prepareDefaultJceProvider();
+
+        // Create the entry to encrypt
+        Security absec = new Security(abdera);
+        Factory factory = abdera.getFactory();
+
+        Entry entry = factory.newEntry();
+        entry.setId("http://example.org/foo/entry");
+        entry.setUpdated(new java.util.Date());
+        entry.setTitle("This is an entry");
+        entry.setContentAsXhtml("This <b>is</b> <i>markup</i>");
+        entry.addAuthor("James");
+        entry.addLink("http://www.example.org");
+
+        // Prepare the Diffie-Hellman Key Exchange Session
+        // There are two participants in the session, A and B
+        // Each has their own DHContext. A creates their context and
+        // sends the request key parameters to B. B uses those parameters
+        // to create their context, the returns it's public key
+        // back to A.
+        DHContext context_a = new DHContext();
+        DHContext context_b = new DHContext(context_a.getRequestString());
+        context_a.setPublicKey(context_b.getResponseString());
+
+        // Prepare the encryption options
+        Encryption enc = absec.getEncryption();
+
+        // Encrypt the document using A's DHContext
+        EncryptionOptions options = context_a.getEncryptionOptions(enc);
+        Document<?> enc_doc = enc.encrypt(entry.getDocument(), options);
+
+        enc_doc.writeTo(System.out);
+
+        System.out.println("\n\n");
+
+        // Decrypt the document using B's DHContext
+        options = context_b.getEncryptionOptions(enc);
+        Document<Entry> entry_doc = enc.decrypt(enc_doc, options);
+
+        entry_doc.writeTo(System.out);
+
+    }
+
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/DHEnc.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/DSig.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/DSig.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/DSig.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/DSig.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,92 @@
+/*
+ * 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.examples.security;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.security.KeyStore;
+import java.security.PrivateKey;
+import java.security.cert.X509Certificate;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.factory.Factory;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.security.Security;
+import org.apache.abdera2.security.Signature;
+import org.apache.abdera2.security.SignatureOptions;
+
+public class DSig {
+
+    private static final String keystoreFile = "/key.jks";
+    private static final String keystoreType = "JKS";
+    private static final String keystorePass = "testing";
+    private static final String privateKeyAlias = "James";
+    private static final String privateKeyPass = "testing";
+    private static final String certificateAlias = "James";
+
+    public static void main(String[] args) throws Exception {
+
+        // Initialize the keystore
+        KeyStore ks = KeyStore.getInstance(keystoreType);
+        InputStream in = DSig.class.getResourceAsStream(keystoreFile);
+        ks.load(in, keystorePass.toCharArray());
+        PrivateKey signingKey = (PrivateKey)ks.getKey(privateKeyAlias, privateKeyPass.toCharArray());
+        X509Certificate cert = (X509Certificate)ks.getCertificate(certificateAlias);
+
+        // Create the entry to sign
+        Abdera abdera = Abdera.getInstance();
+        Security absec = new Security(abdera);
+        Factory factory = abdera.getFactory();
+
+        Entry entry = factory.newEntry();
+        entry.setId("http://example.org/foo/entry");
+        entry.setUpdated(new java.util.Date());
+        entry.setTitle("This is an entry");
+        entry.setContentAsXhtml("This <b>is</b> <i>markup</i>");
+        entry.addAuthor("James");
+        entry.addLink("http://www.example.org");
+
+        // Prepare the digital signature options
+        Signature sig = absec.getSignature();
+        SignatureOptions options = sig.getDefaultSignatureOptions();
+        options.setCertificate(cert);
+        options.setSigningKey(signingKey);
+
+        // Sign the entry
+        entry = sig.sign(entry, options);
+
+        // Check the round trip
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        entry.writeTo(out); // do not use the pretty writer, it will break the signature
+        ByteArrayInputStream bais = new ByteArrayInputStream(out.toByteArray());
+        Document<Entry> entry_doc = abdera.getParser().parse(bais);
+        entry = entry_doc.getRoot();
+
+        System.out.println("Valid? " + sig.verify(entry, null));
+
+        entry.setTitle("Change the title");
+
+        System.out.println("Valid after changing the title? " + sig.verify(entry, null));
+
+        entry = sig.removeInvalidSignatures(entry, options);
+
+    }
+
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/DSig.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/Enc.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/Enc.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/Enc.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/Enc.java Tue Sep 20 15:56:46 2011
@@ -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.examples.security;
+
+import javax.crypto.KeyGenerator;
+import javax.crypto.SecretKey;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.factory.Factory;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.security.Security;
+import org.apache.abdera2.security.Encryption;
+import org.apache.abdera2.security.EncryptionOptions;
+import org.apache.abdera2.security.util.KeyHelper;
+
+public class Enc {
+
+    public static void main(String[] args) throws Exception {
+
+        Abdera abdera = Abdera.getInstance();
+        
+        KeyHelper.prepareDefaultJceProvider();
+
+        // Generate Encryption Key
+        String jceAlgorithmName = "AES";
+        KeyGenerator keyGenerator = KeyGenerator.getInstance(jceAlgorithmName);
+        keyGenerator.init(128);
+        SecretKey key = keyGenerator.generateKey();
+
+        // Create the entry to encrypt
+        Security absec = new Security(abdera);
+        Factory factory = abdera.getFactory();
+
+        Entry entry = factory.newEntry();
+        entry.setId("http://example.org/foo/entry");
+        entry.setUpdated(new java.util.Date());
+        entry.setTitle("This is an entry");
+        entry.setContentAsXhtml("This <b>is</b> <i>markup</i>");
+        entry.addAuthor("James");
+        entry.addLink("http://www.example.org");
+
+        // Prepare the encryption options
+        Encryption enc = absec.getEncryption();
+        EncryptionOptions options = enc.getDefaultEncryptionOptions();
+        options.setDataEncryptionKey(key);
+
+        // Encrypt the document using the generated key
+        Document<?> enc_doc = enc.encrypt(entry.getDocument(), options);
+
+        enc_doc.writeTo(System.out);
+
+        System.out.println("\n\n");
+
+        // Decrypt the document using the generated key
+        Document<Entry> entry_doc = enc.decrypt(enc_doc, options);
+
+        entry_doc.writeTo(System.out);
+
+    }
+
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/security/Enc.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/Create.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/Create.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/Create.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/Create.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,107 @@
+/*
+ * 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.examples.simple;
+
+import java.net.URL;
+import java.util.Date;
+
+import javax.activation.DataHandler;
+import javax.activation.URLDataSource;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.factory.Factory;
+import org.apache.abdera2.model.Content;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.model.Feed;
+import org.apache.abdera2.common.iri.IRI;
+
+public class Create {
+
+    public static void main(String[] args) throws Exception {
+
+        Factory factory = Abdera.getInstance().getFactory();
+        Feed feed = factory.newFeed();
+        feed.setLanguage("en-US");
+        feed.setBaseUri("http://example.org");
+
+        feed.setTitle("Example Feed");
+        feed.addLink("http://example.org/");
+        feed.setUpdated(new Date());
+        feed.addAuthor("John Doe");
+        feed.setId("urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6");
+        feed.addContributor("Bob Jones");
+        feed.addCategory("example");
+
+        // Creates an entry and inserts it at the beginning of the list
+        Entry entry = feed.insertEntry();
+        entry.setTitle("Atom-Powered Robots Run Amok");
+        entry.addLink("http://example.org/2003/12/13/atom03");
+        entry.setId("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a");
+        entry.setUpdated(new Date());
+        entry.setSummary("Some text.");
+
+        // Creates an entry and inserts it at the beginning of the list
+        Entry entry2 = feed.insertEntry();
+        entry2.setTitle("re: Atom-Powered Robots Run Amok");
+        entry2.addLink("/2003/12/13/atom03/1");
+        entry2.setId("urn:uuid:1225c695-cfb8-4ebb-aaaa-80cb323feb5b");
+        entry2.setUpdated(new Date());
+        entry2.setSummary("A response");
+
+        // Creates an entry and appends it to the end of the list
+        Entry entry3 = feed.addEntry();
+        entry3.setTitleAsXhtml("<p>Test</p>");
+        entry3.addLink("/2003/12/13/atom03/2");
+        entry3.setId("HTTP://www.Example.org/foo/../bar", true); // normalizes the id to the value
+                                                                 // http://www.example.org/bar
+        entry3.setUpdated(new Date());
+        entry3.setSummaryAsHtml("<p><a href=\"foo\">Test</a></p>").setBaseUri("http://example.org/site/");
+        entry3.setSource(feed.getAsSource());
+
+        // Out-of-line content
+        Entry entry4 = feed.addEntry();
+        entry4.setTitle("re: Atom-Powered Robots Run Amok");
+        entry4.addLink("/2003/12/13/atom03/3");
+        entry4.setId("urn:uuid:1225c695-cfb8-4ebb-aaaa-cafebabecafe");
+        entry4.setUpdated(new Date());
+        entry4.setSummary("An entry with out-of-line content");
+        entry4.setContent(new IRI("http://example.org/0xcafebabe"), "text/html");
+
+        // Base64 binary content
+        Entry entry5 = feed.addEntry();
+        entry5.setTitle("re: Atom-Powered Robots Run Amok");
+        entry5.addLink("/2003/12/13/atom03/4");
+        entry5.setId("urn:uuid:1225c695-cfb8-4ebb-aaaa-80cb323feb5c");
+        entry5.setUpdated(new Date());
+        entry5.setSummary("A simple Base64 encoded binary image");
+        URL url = Create.class.getResource("/atom-logo75px.gif");
+        entry5.setContent(new DataHandler(new URLDataSource(url)), "image/gif");
+
+        // XML content
+        Entry entry6 = feed.addEntry();
+        entry6.setTitle("re: Atom-Powered Robots Run Amok");
+        entry6.addLink("/2003/12/13/atom03/5");
+        entry6.setId("urn:uuid:1225c695-cfb8-4ebb-aaaa-80cb323feb5d");
+        entry6.setUpdated(new Date());
+        entry6.setSummary("XML content");
+        entry6.setContent("<a xmlns='urn:foo'><b/></a>", Content.Type.XML);
+
+        feed.getDocument().writeTo(System.out);
+    }
+
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/Create.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/EntityProviderExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/EntityProviderExample.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/EntityProviderExample.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/EntityProviderExample.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,73 @@
+/*
+ * 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.examples.simple;
+
+import java.util.Date;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.protocol.EntityProvider;
+import org.apache.abdera2.common.http.EntityTag;
+import org.apache.abdera2.writer.StreamWriter;
+
+/**
+ * The EntityProvider interface allows developers to provide custom Object-to-Java serialization based on the
+ * StreamWriter interface.
+ */
+public class EntityProviderExample {
+
+    public static void main(String... args) throws Exception {
+        Abdera abdera = Abdera.getInstance();
+        StreamWriter sw = 
+          abdera.create(StreamWriter.class)
+                .setOutputStream(System.out)
+                .setAutoIndent(true);
+        Foo foo = new Foo();
+        foo.writeTo(sw);
+        sw.close();
+    }
+
+    public static class Foo implements EntityProvider {
+        private static final String NS = "urn:foo";
+        private String foo = "foo";
+        private String bar = "bar";
+        private String baz = "baz";
+
+        public String getContentType() {
+            return "application/foo+xml";
+        }
+
+        public EntityTag getEntityTag() {
+            return EntityTag.generate(foo, bar, baz);
+        }
+
+        public Date getLastModified() {
+            return null;
+        }
+
+        public boolean isRepeatable() {
+            return true;
+        }
+
+        public void writeTo(StreamWriter sw) {
+            sw.startDocument().startElement(foo, NS).startElement(bar, NS).startElement(baz, NS).endElement()
+                .endElement().endElement().endDocument();
+        }
+
+    }
+
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/EntityProviderExample.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/LangTagExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/LangTagExample.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/LangTagExample.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/LangTagExample.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,56 @@
+/*
+ * 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.examples.simple;
+
+import java.util.Locale;
+
+import org.apache.abdera2.common.lang.Lang;
+import org.apache.abdera2.common.lang.Range;
+import org.apache.abdera2.common.lang.Subtag;
+
+/**
+ * Example using the Lang tag implementation
+ */
+@SuppressWarnings("unused")
+public class LangTagExample {
+
+    public static void main(String... args) throws Exception {
+
+        // English, written in Latin script, as spoken in California
+        Lang lang = new Lang("en-Latn-US-calif");
+
+        // Iterate over the tags
+        for (Subtag tag : lang)
+            System.out.println(tag.type() + "\t" + tag.name());
+
+        // Access individual tags
+        String language = lang.language().name();
+        String script = lang.script().name();
+        String region = lang.region().name();
+        String variant = lang.variant().name();
+
+        // Perform extended range matching
+        Range range = new Range("en-US-*", true);
+        System.out.println(range.matches(lang, true));
+
+        // Locale integration
+        Locale locale = lang.locale();
+        System.out.println(locale);
+    }
+
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/LangTagExample.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/Parse.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/Parse.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/Parse.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/Parse.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,58 @@
+/*
+ * 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.examples.simple;
+
+import java.io.InputStream;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.model.Feed;
+import org.apache.abdera2.parser.Parser;
+
+public class Parse {
+
+    public static void main(String[] args) throws Exception {
+
+        Parser parser = Abdera.getInstance().getParser();
+
+        InputStream in = Parse.class.getResourceAsStream("/simple.xml");
+        Document<Feed> doc = parser.parse(in);
+        Feed feed = doc.getRoot();
+
+        System.out.println(feed.getTitle());
+        System.out.println(feed.getTitleType());
+        System.out.println(feed.getAlternateLink().getResolvedHref());
+        System.out.println(feed.getUpdated());
+        System.out.println(feed.getAuthor().getName());
+        System.out.println(feed.getId());
+
+        Entry entry = feed.getEntries().get(0);
+
+        System.out.println(entry.getTitle());
+        System.out.println(entry.getTitleType());
+        System.out.println(entry.getAlternateLink().getHref()); // relative URI
+        System.out.println(entry.getAlternateLink().getResolvedHref()); // absolute URI resolved against Base URI
+        System.out.println(entry.getId());
+        System.out.println(entry.getUpdated());
+        System.out.println(entry.getSummary());
+        System.out.println(entry.getSummaryType());
+
+    }
+
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/Parse.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/PrintTitles.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/PrintTitles.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/PrintTitles.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/PrintTitles.java Tue Sep 20 15:56:46 2011
@@ -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.abdera2.examples.simple;
+
+import java.io.InputStream;
+import java.util.List;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.model.Feed;
+import org.apache.abdera2.parser.Parser;
+import org.apache.abdera2.parser.ParserOptions;
+import org.apache.abdera2.parser.filter.SetParseFilter;
+import org.apache.abdera2.parser.filter.WhiteListParseFilter;
+import org.apache.abdera2.common.Constants;
+
+/**
+ * Illustrates the use of optimized-parsing using the WhiteListParseFilter. 
+ * Using this mechanism, only the elements added to the ParseFilter will be 
+ * parsed and added to the Feed Object Model instance. The resulting savings 
+ * in memory and CPU costs is significant.
+ */
+public class PrintTitles {
+    public static void main(String args[]) {
+
+        Parser parser = Abdera.getInstance().getParser();
+
+        InputStream in = Parse.class.getResourceAsStream("/simple.xml");
+
+        ParserOptions opts = parser.getDefaultParserOptions();
+
+        SetParseFilter filter = new WhiteListParseFilter();
+        filter.add(Constants.FEED);  // we only want entry titles, 
+        filter.add(Constants.ENTRY); // but we have to include
+        filter.add(Constants.TITLE); // the parent elements too
+        opts.setParseFilter(filter);
+
+        Document<Feed> doc;
+
+        try {
+            doc = parser.parse(in, "", opts);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return;
+        }
+
+        Feed feed = doc.getRoot();
+
+        List<Entry> entries = feed.getEntries();
+
+        for (Entry e : entries) {
+            System.out.println(e.getTitle());
+        }
+    }
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/PrintTitles.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/StreamBuilderExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/StreamBuilderExample.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/StreamBuilderExample.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/StreamBuilderExample.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,61 @@
+/*
+ * 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.examples.simple;
+
+import java.util.Date;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.factory.StreamBuilder;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Feed;
+
+/**
+ * The StreamBuilder is an instance of StreamWriter that constructs a Feed 
+ * Object Model instance.
+ */
+public class StreamBuilderExample {
+
+    public static void main(String... args) throws Exception {
+
+        Abdera abdera = Abdera.getInstance();
+
+        StreamBuilder out = abdera.getWriterFactory().newStreamWriter("fom");
+        out.startDocument().startFeed().writeBase("http://example.org").writeLanguage("en-US")
+            .writeId("http://example.org").writeTitle("<Testing 123>").writeSubtitle("Foo").writeAuthor("James",
+                                                                                                        null,
+                                                                                                        null)
+            .writeUpdated(new Date()).writeLink("http://example.org/foo").writeLink("http://example.org/bar", "self")
+            .writeCategory("foo").writeCategory("bar").writeLogo("logo").writeIcon("icon")
+            .writeGenerator("1.0", "http://example.org", "foo");
+
+        for (int n = 0; n < 100; n++) {
+            out.startEntry().writeId("http://example.org/" + n).writeTitle("Entry #" + n).writeUpdated(new Date())
+                .writePublished(new Date()).writeEdited(new Date()).writeSummary("This is text summary")
+                .writeAuthor("James", null, null).writeContributor("Joe", null, null).startContent("application/xml")
+                .startElement("a", "b", "c").startElement("x", "y", "z").writeElementText("This is a test")
+                .startElement("a").writeElementText("foo").endElement().startElement("b", "bar")
+                .writeAttribute("foo", new Date()).writeAttribute("bar", 123L).writeElementText(123.123).endElement()
+                .endElement().endElement().endContent().endEntry();
+        }
+
+        Document<Feed> doc = out.endFeed().endDocument().getBase();
+
+        doc.writeTo(System.out);
+    }
+
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/StreamBuilderExample.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/StreamWriterExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/StreamWriterExample.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/StreamWriterExample.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/StreamWriterExample.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,60 @@
+/*
+ * 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.examples.simple;
+
+import java.util.Date;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.writer.StreamWriter;
+
+/**
+ * Demonstrates the use of the Abdera StreamWriter interface
+ */
+public class StreamWriterExample {
+
+    public static void main(String... args) {
+
+        Abdera abdera = Abdera.getInstance();
+
+        StreamWriter out =
+            abdera.create(StreamWriter.class).setOutputStream(System.out, "UTF-8").setAutoflush(false).setAutoIndent(true)
+                .startDocument().startFeed().writeBase("http://example.org").writeLanguage("en-US")
+                .writeId("http://example.org").writeTitle("<Testing 123>").writeSubtitle("Foo").writeAuthor("James",
+                                                                                                            null,
+                                                                                                            null)
+                .writeUpdated(new Date()).writeLink("http://example.org/foo").writeLink("http://example.org/bar",
+                                                                                        "self").writeCategory("foo")
+                .writeCategory("bar").writeLogo("logo").writeIcon("icon").writeGenerator("1.0",
+                                                                                         "http://example.org",
+                                                                                         "foo").flush();
+
+        for (int n = 0; n < 100; n++) {
+            out.startEntry().writeId("http://example.org/" + n).writeTitle("Entry #" + n).writeUpdated(new Date())
+                .writePublished(new Date()).writeEdited(new Date()).writeSummary("This is text summary")
+                .writeAuthor("James", null, null).writeContributor("Joe", null, null).startContent("application/xml")
+                .startElement("a", "b", "c").startElement("x", "y", "z").writeElementText("This is a test")
+                .startElement("a").writeElementText("foo").endElement().startElement("b", "bar")
+                .writeAttribute("foo", new Date()).writeAttribute("bar", 123L).writeElementText(123.123).endElement()
+                .endElement().endElement().endContent().endEntry().flush();
+        }
+
+        out.endFeed().endDocument().flush();
+
+    }
+
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/StreamWriterExample.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/UnacceptableElementsExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/UnacceptableElementsExample.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/UnacceptableElementsExample.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/UnacceptableElementsExample.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,69 @@
+/*
+ * 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.examples.simple;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Feed;
+import org.apache.abdera2.parser.Parser;
+import org.apache.abdera2.parser.ParserOptions;
+import org.apache.abdera2.parser.filter.BlackListParseFilter;
+import org.apache.abdera2.parser.filter.SetParseFilter;
+
+public class UnacceptableElementsExample {
+
+    public static void main(String[] args) throws Exception {
+
+        Parser parser = Abdera.getInstance().getParser();
+
+        /**
+         * By subclassing BlackListParseFilter, we can throw an error when 
+         * the parsed XML contains any content we don't want
+         */
+        SetParseFilter exceptionFilter = new BlackListParseFilter() {
+            private static final long serialVersionUID = 7564587859561916928L;
+
+            @Override
+            public boolean acceptable(QName qname) {
+                boolean answer = super.acceptable(qname);
+                if (!(answer)) {
+                    throw new RuntimeException("Unacceptable element ::" + qname);
+                }
+                return answer;
+            }
+
+            @Override
+            public boolean acceptable(QName qname, QName attribute) {
+                return true;
+            }
+        };
+        exceptionFilter.add(new QName("http://example.org", "a"));
+
+        ParserOptions options = parser.getDefaultParserOptions();
+        options.setParseFilter(exceptionFilter);
+        Document<Feed> doc =
+            parser.parse(UnacceptableElementsExample.class.getResourceAsStream("/xmlcontent.xml"), null, options);
+
+        // this will throw a FOMException
+        doc.writeTo(System.out);
+
+    }
+
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/UnacceptableElementsExample.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/i18nExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/i18nExample.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/i18nExample.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/i18nExample.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,69 @@
+/*
+ * 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.examples.simple;
+
+import java.util.Date;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.ext.bidi.BidiHelper;
+import org.apache.abdera2.ext.bidi.BidiHelper.Direction;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.model.Feed;
+
+/**
+ * Simple example demonstrating Abdera's i18n support
+ */
+public class i18nExample {
+
+    public static void main(String... args) throws Exception {
+
+        Abdera abdera = Abdera.getInstance();
+        Feed feed = abdera.newFeed();
+        feed.getDocument().setCharset("UTF-8");
+
+        // Set the language context and default text direction
+        feed.setLanguage("ar"); // Arabic
+        BidiHelper.setDirection(Direction.RTL, feed);
+
+        feed.setBaseUri("http://\u0645\u062b\u0627\u0644.org/ar/feed.xml");
+        feed.setId("tag:\u0645\u062b\u0627\u0644.org,2007:/\u0645\u062b\u0627\u0644");
+        feed.setUpdated(new Date());
+        feed
+            .setTitle("\u0645\u062b\u0644\u0627\u0020\u0627\u0644\u0646\u0635\u0020\u0627\u0644\u0639\u0631\u0628\u064a");
+        feed.addAuthor("\u062c\u064a\u0645\u0633");
+        feed.addLink("", "self");
+        feed.addLink("http://\u0645\u062b\u0627\u0644.org/ar/blog");
+
+        Entry entry = feed.addEntry();
+        entry.setId("tag:\u0645\u062b\u0627\u0644.org,2007:/\u0645\u062b\u0627\u0644/1");
+        entry.setTitle("\u0645\u062b\u0627\u0644\u0020\u062f\u062e\u0648\u0644");
+        entry.setUpdated(new Date());
+        entry.addLink("http://\u0645\u062b\u0627\u0644.org/ar/blog/1");
+        entry
+            .setSummaryAsXhtml("<p xml:lang=\"ar\" dir=\"rtl\">\u0648\u0647\u0630\u0627\u0020\u0645\u062b\u0627\u0644\u0020\u0639\u0644\u0649\u0020\u0648\u062c\u0648\u062f\u0020\u0041\u0074\u006f\u006d\u0020\u0031\u002e\u0030\u0020\u0052\u0054\u004c\u0020\u0627\u0644\u0627\u0639\u0644\u0627\u0641\u0020\u0627\u0644\u062a\u064a\u0020\u062a\u062d\u062a\u0648\u064a\u0020\u0639\u0644\u0649\u0020\u0627\u0644\u0646\u0635\u0020\u0627\u0644\u0639\u0631\u0628\u064a</p>");
+
+        feed.writeTo("prettyxml", System.out);
+
+        System.out.println();
+        Element el = feed.getEntries().get(0).getSummaryElement().getValueElement().getFirstChild();
+        System.out.println("Incorrect: " + el.getText());
+        System.out.println("Correct: " + BidiHelper.getBidiElementText(el));
+    }
+
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/simple/i18nExample.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/unicode/NormalizationExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/unicode/NormalizationExample.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/unicode/NormalizationExample.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/unicode/NormalizationExample.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,52 @@
+/*
+ * 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.examples.unicode;
+
+import org.apache.abdera2.common.text.NormalizationForm;
+
+/**
+ * Example that demonstrates Abdera's basic support for Unicode normalization.
+ */
+public class NormalizationExample {
+
+    public static void main(String... args) throws Exception {
+
+        // Three different representations of the same character (Angstrom)
+        String s1 = "\u00c5";
+        String s2 = "\u0041\u030A";
+        String s3 = "\u212B";
+
+        System.out.println(s1 + "=" + s2 + " ?\t" + s1.equals(s2)); // false
+        System.out.println(s1 + "=" + s3 + " ?\t" + s1.equals(s3)); // false
+        System.out.println(s2 + "=" + s3 + " ?\t" + s2.equals(s3)); // false
+
+        // Normalize to NFC
+        String n1 = NormalizationForm.C.normalize(s1);
+        String n2 = NormalizationForm.C.normalize(s2);
+        String n3 = NormalizationForm.C.normalize(s3);
+
+        System.out.println(n1 + "=" + n2 + " ?\t" + n1.equals(n2)); // true
+        System.out.println(n1 + "=" + n3 + " ?\t" + n1.equals(n3)); // true
+        System.out.println(n2 + "=" + n3 + " ?\t" + n2.equals(n3)); // true
+
+        // s1 is already normalized to NFC
+        System.out.println(n1.equals(s1)); // true
+
+    }
+
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/unicode/NormalizationExample.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/unicode/SlugSanitization.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/unicode/SlugSanitization.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/unicode/SlugSanitization.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/unicode/SlugSanitization.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,59 @@
+/*
+ * 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.examples.unicode;
+
+import org.apache.abdera2.common.text.NormalizationForm;
+import org.apache.abdera2.common.text.Slug;
+
+
+/**
+ * In the Atom Publishing Protocol, the Slug HTTP header is used to allow a client to provide text that can be used to
+ * create a human-friendly URL for an entry. For instance, in many weblog software packages, it is not uncommon to find
+ * entries whose permalink URL's look like /my_trip_to_the_zoo. Slug text provided by the client, however, may not be
+ * directly suitable for use within a URL. It may, for instance, contain non-ascii characters, whitespace, or characters
+ * not allowed within a URL. The Slug class will take input text and output a modified result suitable for use in
+ * URL's
+ */
+public class SlugSanitization {
+
+    public static void main(String... args) throws Exception {
+
+        // french for "My trip to the beach".. note the accented character and the added superfluous whitespace characters
+        String input = "Mon\tvoyage à la\tplage";
+
+        // The default rules will replace whitespace with underscore characters
+        // and convert non-ascii characters to pct-encoded utf-8
+        Slug slug = Slug.create(input);
+        String output = slug.toString();
+        System.out.println(output);
+        // Output = Mon_voyage_%C3%A0_la_plage
+
+        // As an alternative to pct-encoding, a replacement string can be provided
+        output = Slug.create(input, "").toString();
+        System.out.println(output);
+        // Output = Mon_voyage__la_plage
+
+        // In certain cases, applying Unicode normalization form D to the
+        // input can produce a good ascii equivalent to the input text.
+        output = Slug.create(input, "", true, NormalizationForm.D).toString();
+        System.out.println(output);
+        // Output = mon_voyage_a_la_plage
+
+    }
+
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/unicode/SlugSanitization.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/AtomIDTemplate.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/AtomIDTemplate.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/AtomIDTemplate.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/AtomIDTemplate.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,67 @@
+/*
+ * 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.examples.uritemplates;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.common.anno.URITemplate;
+import org.apache.abdera2.common.templates.Template;
+import org.apache.abdera2.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;
+        }
+    }
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/AtomIDTemplate.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/AtomLinkTemplate.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/AtomLinkTemplate.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/AtomLinkTemplate.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/AtomLinkTemplate.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,72 @@
+/*
+ * 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.examples.uritemplates;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.common.templates.Template;
+import org.apache.abdera2.common.anno.Context;
+import org.apache.abdera2.common.anno.Name;
+import org.apache.abdera2.common.anno.Param;
+import org.apache.abdera2.common.anno.URITemplate;
+import org.apache.abdera2.writer.StreamWriter;
+
+public class AtomLinkTemplate {
+
+    public static void main(String... args) throws Exception {
+
+        Abdera abdera = Abdera.getInstance();
+        abdera.create(StreamWriter.class)
+              .setOutputStream(System.out)
+              .startDocument()
+              .startFeed()
+                .writeBase("http://example.org")
+                .writeLink(getPage(1, 10), "current")
+                .writeLink(getPage(2, 10), "self")
+                .writeLink(getPage(1, 10), "previous")
+                .writeLink(getPage(3, 10), "next")
+                .writeLink(getPage(1, 10), "first")
+                .writeLink(getPage(10, 10), "last")
+              .endFeed()
+              .endDocument()
+              .flush();
+
+    }
+
+    private static String getPage(int page, int count) {
+        return Template.expandAnnotated(new PagingLink(page, count));
+    }
+
+    @URITemplate("{/view}{?page,count}")
+    @Context(@Param(name="view",value="entries"))
+    public static class PagingLink {
+        private final int page;
+        private final int count;
+        public PagingLink(int page, int count) {
+            this.page = page;
+            this.count = count;
+        }
+        public int getPage() {
+            return page;
+        }
+        @Name("count")
+        public int getPageSize() {
+            return count;
+        }
+    }
+
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/AtomLinkTemplate.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/QueryContextExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/QueryContextExample.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/QueryContextExample.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/QueryContextExample.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,41 @@
+package org.apache.abdera2.examples.uritemplates;
+
+import java.util.List;
+
+import org.apache.abdera2.common.iri.IRI;
+import org.apache.abdera2.common.templates.QueryContext;
+import org.apache.abdera2.common.templates.Template;
+
+/**
+ * This example shows the use of the new QueryContext object to parse 
+ * the querystring out of an IRI, modify the query parameters, and 
+ * generate a new IRI with the new parameters. This is particularly 
+ * useful when an application needs to produce a modified querystring
+ * that includes all of the original querystring parameters.
+ */
+public class QueryContextExample {
+
+  @SuppressWarnings("unchecked")
+  public static void main(String... args) throws Exception {
+    
+    IRI iri = new IRI("http://example.org/foo?a=b&c=d&e=f&e=g");
+    
+    QueryContext queryContext = new QueryContext(iri);
+    
+    System.out.println(queryContext); // show the parsed components
+        
+    queryContext.put("a", "zzz");
+    queryContext.put("ext", "ext");
+    List<String> list = (List<String>) queryContext.get("e");
+    list.add("y");
+    
+    System.out.println(queryContext); // show the modified query context
+    
+    Template template = QueryContext.templateFromQuery(iri.toString(), false, queryContext);
+    
+    System.out.println(template); // show the generated query template
+    
+    System.out.println(template.expand(queryContext)); // expand with the modified query context;
+  }
+  
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/QueryContextExample.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/TemplateManagerExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/TemplateManagerExample.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/TemplateManagerExample.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/TemplateManagerExample.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,37 @@
+package org.apache.abdera2.examples.uritemplates;
+
+import org.apache.abdera2.common.templates.MapContext;
+import org.apache.abdera2.common.templates.TemplateManager;
+
+/**
+ * This example shows the use of the new TemplateManager mechanism for 
+ * expanding templates based on a key. This is particularly useful 
+ * for applications that require a consistent strategy for URI/IRI 
+ * generation
+ */
+public class TemplateManagerExample {
+
+  public enum Keys { A,B }
+  
+  public static void main(String... args) throws Exception {
+    
+    MapContext defaults = new MapContext();
+    defaults.put("a", "foo");
+    defaults.put("b", "bar");
+    
+    TemplateManager<Keys> tm = new TemplateManager<Keys>(defaults);
+    
+    tm.add(Keys.A, "http://example.org{?a}");
+    tm.add(Keys.B, "https://example.org{?b}");
+    
+    System.out.println("Template for Keys.A using Default Context: " + tm.expand(Keys.A));
+    System.out.println("Template for Keys.B using Default Context: " + tm.expand(Keys.B));
+    
+    MapContext other = new MapContext();
+    other.put("b", "baz"); // override the default context value
+    
+    System.out.println("Template for Keys.A using Other Context: " + tm.expand(Keys.A, other));
+    System.out.println("Template for Keys.B using Other Context: " + tm.expand(Keys.B, other));
+  }
+  
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/TemplateManagerExample.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/URITemplates.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/URITemplates.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/URITemplates.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/URITemplates.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,137 @@
+/*
+ * 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.examples.uritemplates;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.abdera2.common.templates.CachingContext;
+import org.apache.abdera2.common.templates.MapContext;
+import org.apache.abdera2.common.templates.Template;
+
+@SuppressWarnings("unchecked")
+public final class URITemplates {
+
+    private static final Template template =
+        new Template(
+                     "http://example.org/~{user}{/categories}{?foo,bar}");
+
+    public static void main(String... args) throws Exception {
+
+        // two examples of resolving the template
+        exampleWithObject();
+        exampleIRIWithObject();
+        exampleWithMap();
+        exampleWithHashMapContext();
+        exampleWithCustomContext();
+
+        // explain the template
+        System.out.println(template);
+    }
+
+    // Using a Java object
+    private static void exampleWithObject() {
+        MyObject myObject = new MyObject();
+        System.out.println(template.expand(myObject));
+    }
+
+    // Using a Java object
+    private static void exampleIRIWithObject() {
+        MyObject myObject = new MyObject();
+        System.out.println(template.expand(myObject, true));
+    }
+
+    // Using a Map
+    private static void exampleWithMap() {
+        Map<String, Object> map = new HashMap<String,Object>();
+        map.put("user", "james");
+        map.put("categories", new String[] {"a", "b", "c"});
+        map.put("foo", "abc");
+        map.put("bar", "xyz");
+        System.out.println(template.expand(map));
+    }
+
+    // Using a HashMap based context
+    private static void exampleWithHashMapContext() {
+        MapContext context = new MapContext();
+        context.put("user", "james");
+        context.put("categories", new String[] {"a", "b", "c"});
+        context.put("foo", "abc");
+        context.put("bar", "xyz");
+        System.out.println(template.expand(context));
+    }
+
+    // Using a custom context implementation
+    private static void exampleWithCustomContext() {
+        CachingContext context = new CachingContext() {
+            private static final long serialVersionUID = 4896250661828139020L;
+
+            protected <T> T resolveActual(String var) {
+                if (var.equals("user"))
+                    return (T)"james";
+                else if (var.equals("categories"))
+                    return (T)new String[] {"a", "b", "c"};
+                else if (var.equals("foo"))
+                    return (T)"abc";
+                else if (var.equals("bar"))
+                    return (T)"xyz";
+                else
+                    return null;
+            }
+
+            public Iterator<String> iterator() {
+                return Arrays.asList(new String[] {"user", "categories", "foo", "bar"}).iterator();
+            }
+
+            public boolean contains(String var) {
+              return resolveActual(var) != null;
+            }
+        };
+        System.out.println(template.expand(context));
+    }
+
+    public static class MyObject {
+        public String user = "james";
+
+        public List<String> getCategories() {
+            List<String> list = new ArrayList<String>();
+            list.add("a");
+            list.add("b");
+            list.add("c");
+            return list;
+        }
+
+        public Foo[] getFoo() {
+            return new Foo[] {new Foo(), new Foo()};
+        }
+
+        public String getBar() {
+            return "xyz";
+        }
+    }
+
+    private static class Foo {
+        public String toString() {
+            return "abcæ";
+        }
+    }
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/uritemplates/URITemplates.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/xsltxpath/XPathExample.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/xsltxpath/XPathExample.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/xsltxpath/XPathExample.java (added)
+++ abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/xsltxpath/XPathExample.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,52 @@
+/*
+ * 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.examples.xsltxpath;
+
+import java.io.InputStream;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Feed;
+import org.apache.abdera2.parser.Parser;
+import org.apache.abdera2.xpath.XPath;
+
+public class XPathExample {
+
+    public static void main(String[] args) throws Exception {
+
+        Abdera abdera = Abdera.getInstance();
+        Parser parser = abdera.getParser();
+        XPath xpath = abdera.getXPath();
+
+        InputStream in = XPathExample.class.getResourceAsStream("/simple.xml");
+        Document<Feed> doc = parser.parse(in);
+        Feed feed = doc.getRoot();
+
+        System.out.println(xpath.evaluate("count(/a:feed)", feed)); // 1.0
+        System.out.println(xpath.numericValueOf("count(/a:feed)", feed)); // 1.0
+        System.out.println(xpath.booleanValueOf("/a:feed/a:entry", feed)); // true (the feed has an entry)
+        System.out.println(xpath.valueOf("/a:feed/a:entry/a:title", feed)); // Atom-Powered Robots Run Amok
+        System.out.println(xpath.selectNodes("/a:feed/a:entry", feed)); // every entry
+        System.out.println(xpath.selectSingleNode("/a:feed", feed));
+        System.out.println(xpath.selectSingleNode("..", feed.getTitleElement()));
+        System.out.println(xpath.selectSingleNode("ancestor::*", feed.getEntries().get(0)));
+        System.out.println(xpath.valueOf("concat('The feed is is ',/a:feed/a:id)", feed)); // "The feed is is urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6"
+
+    }
+
+}

Propchange: abdera/abdera2/examples/src/main/java/org/apache/abdera2/examples/xsltxpath/XPathExample.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message