abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r609077 - in /incubator/abdera/java/trunk/extensions/main/src/main: java/org/apache/abdera/ext/tombstones/ resources/META-INF/services/
Date Sat, 05 Jan 2008 01:29:13 GMT
Author: jmsnell
Date: Fri Jan  4 17:29:03 2008
New Revision: 609077

URL: http://svn.apache.org/viewvc?rev=609077&view=rev
Log:
Experimental implementation of the Tombstones specification.
The tombstone spec is a work-in-progress and will continue to evolve. This
extension should only be used for experimentation or prototype development.
 
 http://www.ietf.org/internet-drafts/draft-snell-atompub-tombstones-04.txt
 

Added:
    incubator/abdera/java/trunk/extensions/main/src/main/java/org/apache/abdera/ext/tombstones/
    incubator/abdera/java/trunk/extensions/main/src/main/java/org/apache/abdera/ext/tombstones/Tombstone.java
    incubator/abdera/java/trunk/extensions/main/src/main/java/org/apache/abdera/ext/tombstones/TombstonesExtensionFactory.java
    incubator/abdera/java/trunk/extensions/main/src/main/java/org/apache/abdera/ext/tombstones/TombstonesHelper.java
Modified:
    incubator/abdera/java/trunk/extensions/main/src/main/resources/META-INF/services/org.apache.abdera.factory.ExtensionFactory

Added: incubator/abdera/java/trunk/extensions/main/src/main/java/org/apache/abdera/ext/tombstones/Tombstone.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/main/src/main/java/org/apache/abdera/ext/tombstones/Tombstone.java?rev=609077&view=auto
==============================================================================
--- incubator/abdera/java/trunk/extensions/main/src/main/java/org/apache/abdera/ext/tombstones/Tombstone.java
(added)
+++ incubator/abdera/java/trunk/extensions/main/src/main/java/org/apache/abdera/ext/tombstones/Tombstone.java
Fri Jan  4 17:29:03 2008
@@ -0,0 +1,134 @@
+/*
+* 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.ext.tombstones;
+
+import java.util.Calendar;
+import java.util.Date;
+
+import org.apache.abdera.factory.Factory;
+import org.apache.abdera.i18n.iri.IRI;
+import org.apache.abdera.model.AtomDate;
+import org.apache.abdera.model.Element;
+import org.apache.abdera.model.ExtensibleElementWrapper;
+import org.apache.abdera.model.Person;
+import org.apache.abdera.model.Text;
+
+public class Tombstone
+  extends ExtensibleElementWrapper {
+
+  public Tombstone(Element internal) {
+    super(internal);
+  }
+  
+  public Tombstone(Factory factory) {
+    super(factory, TombstonesHelper.DELETED_ENTRY);
+  }
+
+  public String getRef() {
+    return getAttributeValue("ref");
+  }
+  
+  public Tombstone setRef(String id) {
+    if (id != null) {
+      setAttributeValue("ref", id);
+    } else {
+      removeAttribute("ref");
+    }
+    return this;
+  }
+  
+  public Tombstone setRef(IRI id) {
+    return setRef(id.toString());
+  }
+  
+  public Date getWhen() {
+    String v = getAttributeValue("when");
+    return v != null ? AtomDate.parse(v) : null;
+  }
+  
+  public Tombstone setWhen(Date date) {
+    return setWhen(AtomDate.format(date));
+  }
+  
+  public Tombstone setWhen(String date) {
+    if (date != null) {
+      setAttributeValue("when", date);
+    } else {
+      removeAttribute("when");
+    }
+    return this;
+  }
+  
+  public Tombstone setWhen(long date) {
+    return setWhen(AtomDate.valueOf(date));
+  }
+  
+  public Tombstone setWhen(Calendar date) {
+    return setWhen(AtomDate.valueOf(date));
+  }
+  
+  public Tombstone setWhen(AtomDate date) {
+    return setWhen(date.toString());
+  }
+  
+  public Person getBy() {
+    return getExtension(TombstonesHelper.BY);
+  }
+  
+  public Tombstone setBy(Person person) {
+    if (getBy() != null) getBy().discard();
+    addExtension(person);
+    return this;
+  }
+  
+  public Person setBy(String name) {
+    return setBy(name, null, null);
+  }
+  
+  public Person setBy(String name, String email, String uri) {
+    if (name != null) {
+      Person person = getFactory().newPerson(TombstonesHelper.BY, this);
+      person.setName(name);
+      person.setEmail(email);
+      person.setUri(uri);
+      return person;
+    } else {
+      if (getBy() != null) getBy().discard();
+      return null;
+    }
+  }
+  
+  public Text getComment() {
+    return getExtension(TombstonesHelper.COMMENT);
+  }
+  
+  public Text setComment(String comment) {
+    return setComment(Text.Type.TEXT, comment);
+  }
+  
+  public Text setComment(Text.Type type, String comment) {
+    if (comment != null) {
+      Text text = getFactory().newText(TombstonesHelper.COMMENT, type, this);
+      text.setValue(comment);
+      return text;
+    } else {
+      if (getComment() != null) getComment().discard();
+      return null;
+    }
+  }
+}

Added: incubator/abdera/java/trunk/extensions/main/src/main/java/org/apache/abdera/ext/tombstones/TombstonesExtensionFactory.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/main/src/main/java/org/apache/abdera/ext/tombstones/TombstonesExtensionFactory.java?rev=609077&view=auto
==============================================================================
--- incubator/abdera/java/trunk/extensions/main/src/main/java/org/apache/abdera/ext/tombstones/TombstonesExtensionFactory.java
(added)
+++ incubator/abdera/java/trunk/extensions/main/src/main/java/org/apache/abdera/ext/tombstones/TombstonesExtensionFactory.java
Fri Jan  4 17:29:03 2008
@@ -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.abdera.ext.tombstones;
+
+import org.apache.abdera.util.AbstractExtensionFactory;
+
+public final class TombstonesExtensionFactory 
+  extends AbstractExtensionFactory {
+
+  public TombstonesExtensionFactory() {
+    super(TombstonesHelper.TNS);
+    addImpl(TombstonesHelper.DELETED_ENTRY,Tombstone.class);
+  }
+  
+}

Added: incubator/abdera/java/trunk/extensions/main/src/main/java/org/apache/abdera/ext/tombstones/TombstonesHelper.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/main/src/main/java/org/apache/abdera/ext/tombstones/TombstonesHelper.java?rev=609077&view=auto
==============================================================================
--- incubator/abdera/java/trunk/extensions/main/src/main/java/org/apache/abdera/ext/tombstones/TombstonesHelper.java
(added)
+++ incubator/abdera/java/trunk/extensions/main/src/main/java/org/apache/abdera/ext/tombstones/TombstonesHelper.java
Fri Jan  4 17:29:03 2008
@@ -0,0 +1,209 @@
+/*
+* 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.ext.tombstones;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera.model.AtomDate;
+import org.apache.abdera.model.Entry;
+import org.apache.abdera.model.Feed;
+
+/**
+ * Note this is an experimental implementation of the Tombstones specification.
+ * The tombstone spec is a work-in-progress and will continue to evolve. This
+ * extension should only be used for experimentation or prototype development.
+ * 
+ * http://www.ietf.org/internet-drafts/draft-snell-atompub-tombstones-04.txt
+ */
+public class TombstonesHelper {
+
+  public static final String TNS = "http://purl.org/atompub/tombstones/1.0";
+  
+  public static final QName DELETED_ENTRY = new QName(TNS, "deleted-entry");
+  public static final QName BY = new QName(TNS, "by");
+  public static final QName COMMENT = new QName(TNS, "comment");
+  
+  public static List<Tombstone> getTombstones(
+    Feed source) {
+      return source.getExtensions(DELETED_ENTRY);
+  }
+  
+  public static void addTombstone(
+    Feed source, 
+    Tombstone tombstone) {
+      source.addExtension(tombstone);
+  }
+  
+  public static Tombstone addTombstone(
+    Feed source, 
+    Entry entry) {
+      Tombstone tombstone = 
+        source.getFactory().newExtensionElement(DELETED_ENTRY, source);
+      tombstone.setRef(entry.getId());
+      if (entry.getParentElement().equals(source))
+        entry.discard();
+      return tombstone;
+  }
+  
+  public static Tombstone addTombstone(
+    Feed source, 
+    Entry entry, 
+    Date when, 
+    String by, 
+    String comment) {
+      Tombstone ts = addTombstone(source,entry);
+      ts.setWhen(when);
+      ts.setBy(by);
+      ts.setComment(comment);
+      return ts;
+  }
+  
+  public static Tombstone addTombstone(
+    Feed source, 
+    Entry entry, 
+    String when, 
+    String by, 
+    String comment) {
+      Tombstone ts = addTombstone(source,entry);
+      ts.setWhen(when);
+      return ts;
+  }
+  
+  public static Tombstone addTombstone(
+    Feed source, 
+    Entry entry, 
+    Calendar when, 
+    String by, 
+    String comment) {
+      Tombstone ts = addTombstone(source,entry);
+      ts.setWhen(when);
+      ts.setBy(by);
+      ts.setComment(comment);
+      return ts;
+  }
+  
+  public static Tombstone addTombstone(
+    Feed source, 
+    Entry entry, 
+    long when, 
+    String by, 
+    String comment) {
+      Tombstone ts = addTombstone(source,entry);
+      ts.setWhen(when);
+      ts.setBy(by);
+      ts.setComment(comment);
+      return ts;
+  }
+  
+  public static Tombstone addTombstone(
+    Feed source, 
+    Entry entry, 
+    AtomDate when, 
+    String by, 
+    String comment) {
+      Tombstone ts = addTombstone(source,entry);
+      ts.setWhen(when);
+      ts.setBy(by);
+      ts.setComment(comment);
+      return ts;
+  
+  }
+
+  public static boolean hasTombstones(
+    Feed source) {
+      return source.getExtension(DELETED_ENTRY) != null;
+  }
+  
+  public static Tombstone addTombstone(
+    Feed source, 
+    String id) {
+      Tombstone tombstone = 
+        source.getFactory().newExtensionElement(DELETED_ENTRY);
+      tombstone.setRef(id);
+      return tombstone;
+  }
+    
+  public static Tombstone addTombstone(
+    Feed source, 
+    String id, 
+    Date when, 
+    String by, 
+    String comment) {
+      Tombstone ts = addTombstone(source,id);
+      ts.setWhen(when);
+      ts.setBy(by);
+      ts.setComment(comment);
+      return ts;
+  }
+  
+  public static Tombstone addTombstone(
+    Feed source, 
+    String id,
+    String when, 
+    String by, 
+    String comment) {
+      Tombstone ts = addTombstone(source,id);
+      ts.setWhen(when);
+      return ts;
+  }
+  
+  public static Tombstone addTombstone(
+    Feed source, 
+    String id,
+    Calendar when, 
+    String by, 
+    String comment) {
+      Tombstone ts = addTombstone(source,id);
+      ts.setWhen(when);
+      ts.setBy(by);
+      ts.setComment(comment);
+      return ts;
+  }
+  
+  public static Tombstone addTombstone(
+    Feed source, 
+    String id,
+    long when, 
+    String by, 
+    String comment) {
+      Tombstone ts = addTombstone(source,id);
+      ts.setWhen(when);
+      ts.setBy(by);
+      ts.setComment(comment);
+      return ts;
+  }
+  
+  public static Tombstone addTombstone(
+    Feed source, 
+    String id,
+    AtomDate when, 
+    String by, 
+    String comment) {
+      Tombstone ts = addTombstone(source,id);
+      ts.setWhen(when);
+      ts.setBy(by);
+      ts.setComment(comment);
+      return ts;
+  }
+
+ 
+}

Modified: incubator/abdera/java/trunk/extensions/main/src/main/resources/META-INF/services/org.apache.abdera.factory.ExtensionFactory
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/extensions/main/src/main/resources/META-INF/services/org.apache.abdera.factory.ExtensionFactory?rev=609077&r1=609076&r2=609077&view=diff
==============================================================================
--- incubator/abdera/java/trunk/extensions/main/src/main/resources/META-INF/services/org.apache.abdera.factory.ExtensionFactory
(original)
+++ incubator/abdera/java/trunk/extensions/main/src/main/resources/META-INF/services/org.apache.abdera.factory.ExtensionFactory
Fri Jan  4 17:29:03 2008
@@ -1,2 +1,3 @@
 org.apache.abdera.ext.thread.ThreadExtensionFactory
 org.apache.abdera.ext.features.FeaturesExtensionFactory
+org.apache.abdera.ext.tombstones.TombstonesExtensionFactory
\ No newline at end of file



Mime
View raw message