abdera-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Constabaris <a...@clownsinmycoffee.net>
Subject Re: Controlling serialization w/extensions
Date Tue, 27 Feb 2007 16:46:25 GMT
Adam Constabaris wrote:

<snip>

> The hack I've adopted, for the time being, is to add extension 
> elements using all the namespaces that will appear in the entries to 
> the feed element;  since I don't need those  elements to appear, what 
> I'd like to do is just add the namespace declarations (and save a few 
> bits on the wire while I'm at it).  So there's a concrete RFE, at least.

And only after posting does he discover Element.declareNS().  Cue Emily 
Littella.

AC



> Stripping down to (what I believe are) the bare essentials, this is 
> the code:
>
> MyProvider extends AbstractProvider {
>  ...
>  public ResponseContext getFeed(RequestContext req) {
>        Factory factory = 
> req.getServiceContext().getAbdera().getNewFactory();
>        factory.registerExtension( new DCExtensionFactory() ); // 
> Dublin Core elements
>        Feed feed = factory.newFeed();
>        MyEntryFactory ef = new MyEntryFactory(factory);
>        feed.setTitle("My Feed With Extensions");
>        ...
>        for( MyObject object : myObjects ) {
>            feed.addEntry( ef.getEntry(object) );
>        }
>        return new BaseResponseContext(feed);
> }
>
> public class MyEntryFactory {
>   public MyEntryFactory(Factory factory) {
>     this.factory = factory;
>   }
>
>   public Entry getEntry(MyObject object) {
>      Entry entry = factory.newEntry();  // I've also tried passing in 
> the parent feed here and using factory.newEntry(feed)
>      entry.setTitle(myObject.getName());
>     ...
>
>    // DCTextElement -> ElementWrapper
>    DCTextElement publisher = 
> entry.addExtension(DCExtensionFactory.PUBLISHER);
>    publisher.setText(myObject.getOwner().getName());
>   ...
>    return entry;
>  }
>
> cheers,
>
> AC
>


Mime
View raw message