abdera-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James M Snell <jasn...@gmail.com>
Subject Re: Adding more elements within an extension
Date Tue, 30 Oct 2007 15:14:52 GMT
You can do the following:

  ExtensibleElement e = entry.addExtension(MYLIST_QNAME);
  e.setAttributeValue("name", "listName");
  e.addSimpleExtension(VALUE_QNAME,"one");
  e.addSimpleExtension(VALUE_QNAME,"two");


Or you can implement a static extension.  Implement a class that extends
the ExtensibleElementWrapper class.  Implement an ExtensionFactory for
it. Register the ExtensionFactory with Abdera. Code below.

foo/MyListElement.java
==================
  package foo;
  import javax.xml.namespace.QName;

  import org.apache.abdera.factory.Factory;
  import org.apache.abdera.model.Element;
  import org.apache.abdera.model.ExtensibleElementWrapper;

  public class MyListElement
    extends ExtensibleElementWrapper {
    public static final String NS = "http://example.org";
    public static final QName MYLIST =
      new QName("http://example.org","mylist");
    public static final QName VALUE =
      new QName("http://example.org","value");
    public MyListElement(Element internal) {
      super(internal);
    }
    public MyListElement(Factory factory, QName qname) {
      super(factory, qname);
    }
    public void setName(String name) {
      setAttributeValue("listName",name);
    }
    public void addValue(String value) {
      addSimpleExtension(VALUE, value);
    }
  }

foo/MyListExtensionFactory.java
===========================
  package foo;
  import org.apache.abdera.util.AbstractExtensionFactory;

  public class MyListExtensionFactory
    extends AbstractExtensionFactory {
    public MyListExtensionFactory() {
      super(MyListElement.NS);
      addImpl(MyListElement.MYLIST,MyListElement.class);
    }
  }

META-INF/services/org.apache.abdera.factory.ExtensionFactory
=============================================================
  foo.MyListExtensionFactory


To use it:
==========
  MyListElement list = entry.addExtension(MyListElement.MYLIST);
  list.setName("listName");
  list.addValue("one");
  list.addValue("two");

Enjoy!

- James

Neale wrote:
> Hi,
> 
> I'm making use of extensions to put some of our own data into entries
> and feeds.
> 
> What I'd ideally want to be able to do is something like:
> 
>    MyListElement list = new MyListElement( "listName" );  // extends
> Element
>    list.addValue("one");
>    list.addValue("two");
>    entry.addExtension( list );
> 
> For this to generate:
> 
>    <myns:mylistelement name="listName">
>      <value>one</value>
>      <value>two</value>
>    </mylistelement>
> 
> Looking at the code for FOMEntry, the above looks like a rather onerous
> task.
> 
> Instead, I can use the existing code to do:
> 
>    Element e = entry.addExtension(MYLIST_QNAME);
>    e.setAttributeValue("name", "listName");
>      And what I now want is:
>    Element value1 = e.createElement(VALUE_QNAME);
>    value1.setText("one");
> 
> This doesn't seem possible.. what should I do?
> 
> Cheers,
> 
> Neale
> 
> 

Mime
View raw message