abdera-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James M Snell <jasn...@gmail.com>
Subject Re: [PATCH] add Feed.removeEntry()
Date Thu, 14 Dec 2006 04:05:05 GMT
There is already an Element.discard() that does this.

e.g.,

  Entry entry = feed.getEntries().get(0);
  entry.discard();

- James

Garrett Rooney wrote:
> So, I'm playing around with a servlet filter that strips out entries
> that are older than a certain date, and I finally get to the point
> where I want to actually write the code to do that, and I notice that
> we don't actually have a way to remove an entry from a feed.  Any
> objection to the following patch that adds a removeEntry() element to
> Feed?
> 
> Or, alternatively, am I just missing the way to do this with our current
> API?
> 
> -garrett
> 
> Index:
> parser/src/test/java/org/apache/abdera/test/parser/stax/ParserTest.java
> ===================================================================
> --- parser/src/test/java/org/apache/abdera/test/parser/stax/ParserTest.java
>    (revision 482870)
> +++ parser/src/test/java/org/apache/abdera/test/parser/stax/ParserTest.java
>    (working copy)
> @@ -90,6 +90,20 @@
>     assertEquals(entryDoc.getCharset(), "utf-8");
> 
>   }
> -
> +
> +  public static void testRemoveEntry() throws Exception {
> +    InputStream is = ParserTest.class.getResourceAsStream("/feed.xml");
> +    Document<Feed> feedDoc = getParser().parse(is);
> +    Feed feed = feedDoc.getRoot();
> +
> +    assertTrue(feed.getEntries().size() == 1);
> +
> +    Entry e =
> feed.getEntry("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a");
> +
> +    feed.removeEntry(e);
> +
> +    assertTrue(feed.getEntries().size() == 0);
> +  }
> +
>   //TODO: need lots more unit tests
> }
> Index: parser/src/main/java/org/apache/abdera/parser/stax/FOMFeed.java
> ===================================================================
> --- parser/src/main/java/org/apache/abdera/parser/stax/FOMFeed.java
> (revision 482870)
> +++ parser/src/main/java/org/apache/abdera/parser/stax/FOMFeed.java
> (working copy)
> @@ -119,6 +119,15 @@
>     return entry;
>   }
> 
> +  public void removeEntry(Entry entry) {
> +    for (Iterator i = this.getChildElements(); i.hasNext();) {
> +      OMElement _child = (OMElement) i.next();
> +      if (_child.equals(entry)) {
> +        _child.discard();
> +      }
> +    }
> +  }
> +
>   public Source getAsSource() {
>     FOMSource source = (FOMSource) ((FOMFactory)factory).newSource(null);
>     OMElement _source = source;
> 

Mime
View raw message