Java Code Examples for com.rometools.rome.feed.atom.Content#setValue()

The following examples show how to use com.rometools.rome.feed.atom.Content#setValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomerAtomFeedView.java    From event-driven-spring-boot with Apache License 2.0 6 votes vote down vote up
@Override
protected void buildFeedMetadata(Map<String, Object> model, Feed feed, HttpServletRequest request) {
	feed.setId("https://github.com/mploed/event-driven-spring-boot/customer");
	feed.setTitle("Customer");
	List<Link> alternateLinks = new ArrayList<>();
	Link link = new Link();
	link.setRel("self");
	link.setHref(baseUrl(request) + "feed");
	alternateLinks.add(link);
	List<SyndPerson> authors = new ArrayList<SyndPerson>();
	Person person = new Person();
	person.setName("Big Pug Bank");
	authors.add(person);
	feed.setAuthors(authors);

	feed.setAlternateLinks(alternateLinks);
	feed.setUpdated(customerRepository.lastUpdate());
	Content subtitle = new Content();
	subtitle.setValue("List of all customers");
	feed.setSubtitle(subtitle);
}
 
Example 2
Source File: CustomerAtomFeedView.java    From event-driven-spring-boot with Apache License 2.0 6 votes vote down vote up
@Override
protected List<Entry> buildFeedEntries(Map<String, Object> model, HttpServletRequest request,
                                       HttpServletResponse response) throws Exception {

	List<Entry> entries = new ArrayList<Entry>();
	List<Customer> customerlist = (List<Customer>) model.get("customers");

	for (Customer o : customerlist) {
		Entry entry = new Entry();
		entry.setId("https://github.com/mploed/event-driven-spring-boot/customer/" + Long.toString(o.getId()));
		entry.setUpdated(o.getUpdated());
		entry.setTitle("Customer " + o.getId());
		List<Content> contents = new ArrayList<Content>();
		Content content = new Content();
		content.setSrc(baseUrl(request) + "customer/rest/" + Long.toString(o.getId()));
		content.setType("application/json");
		contents.add(content);
		entry.setContents(contents);
		Content summary = new Content();
		summary.setValue("This is the customer " + o.getId());
		entry.setSummary(summary);
		entries.add(entry);
	}

	return entries;
}
 
Example 3
Source File: OrderAtomFeedView.java    From microservice-atom with Apache License 2.0 6 votes vote down vote up
@Override
protected void buildFeedMetadata(Map<String, Object> model, Feed feed, HttpServletRequest request) {
	feed.setId("tag:ewolff.com/microservice-atom/order");
	feed.setTitle("Order");
	List<Link> alternateLinks = new ArrayList<>();
	Link link = new Link();
	link.setRel("self");
	link.setHref(baseUrl(request) + "feed");
	alternateLinks.add(link);
	List<SyndPerson> authors = new ArrayList<SyndPerson>();
	Person person = new Person();
	person.setName("Big Money Online Commerce Inc.");
	authors.add(person);
	feed.setAuthors(authors);

	feed.setAlternateLinks(alternateLinks);
	feed.setUpdated(orderRepository.lastUpdate());
	Content subtitle = new Content();
	subtitle.setValue("List of all orders");
	feed.setSubtitle(subtitle);
}
 
Example 4
Source File: VetsAtomView.java    From activejpa with Apache License 2.0 6 votes vote down vote up
@Override
protected List<Entry> buildFeedEntries(Map<String, Object> model,
                                       HttpServletRequest request, HttpServletResponse response) throws Exception {

    Vets vets = (Vets) model.get("vets");
    List<Vet> vetList = vets.getVetList();
    List<Entry> entries = new ArrayList<Entry>(vetList.size());

    for (Vet vet : vetList) {
        Entry entry = new Entry();
        // see http://diveintomark.org/archives/2004/05/28/howto-atom-id#other
        entry.setId(String.format("tag:springsource.org,%s", vet.getId()));
        entry.setTitle(String.format("Vet: %s %s", vet.getFirstName(), vet.getLastName()));
        //entry.setUpdated(visit.getDate().toDate());

        Content summary = new Content();
        summary.setValue(vet.getSpecialties().toString());
        entry.setSummary(summary);

        entries.add(entry);
    }
    response.setContentType("blabla");
    return entries;

}
 
Example 5
Source File: VetsAtomView.java    From audit4j-demo with Apache License 2.0 6 votes vote down vote up
@Override
protected List<Entry> buildFeedEntries(Map<String, Object> model,
                                       HttpServletRequest request, HttpServletResponse response) throws Exception {

    Vets vets = (Vets) model.get("vets");
    List<Vet> vetList = vets.getVetList();
    List<Entry> entries = new ArrayList<Entry>(vetList.size());

    for (Vet vet : vetList) {
        Entry entry = new Entry();
        // see http://diveintomark.org/archives/2004/05/28/howto-atom-id#other
        entry.setId(String.format("tag:springsource.org,%s", vet.getId()));
        entry.setTitle(String.format("Vet: %s %s", vet.getFirstName(), vet.getLastName()));
        //entry.setUpdated(visit.getDate().toDate());

        Content summary = new Content();
        summary.setValue(vet.getSpecialties().toString());
        entry.setSummary(summary);

        entries.add(entry);
    }
    response.setContentType("blabla");
    return entries;

}
 
Example 6
Source File: AtomFeedView.java    From wallride with Apache License 2.0 6 votes vote down vote up
protected void buildFeedMetadata(
			Map<String, Object> model,
			Feed feed,
			HttpServletRequest request) {
		Blog blog = blogService.getBlogById(Blog.DEFAULT_ID);
		String language = LocaleContextHolder.getLocale().getLanguage();

		feed.setTitle(blog.getTitle(language));
		Content info = new Content();
		info.setValue(blog.getTitle(language));
		feed.setInfo(info);

		ArrayList<Link> links = new ArrayList<>();
		Link link = new Link();
		UriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentContextPath();
		link.setHref(builder.buildAndExpand().toUriString());
		links.add(link);
		feed.setOtherLinks(links);
//		feed.setIcon("http://" + settings.getAsString(Setting.Key.SITE_URL) + "resources/default/img/favicon.ico");
	}
 
Example 7
Source File: AtomFeedViewTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected List<Entry> buildFeedEntries(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {
	List<Entry> entries = new ArrayList<>();
	for (String name : model.keySet()) {
		Entry entry = new Entry();
		entry.setTitle(name);
		Content content = new Content();
		content.setValue((String) model.get(name));
		entry.setSummary(content);
		entries.add(entry);
	}
	return entries;
}
 
Example 8
Source File: TestAtomContent.java    From rome with Apache License 2.0 5 votes vote down vote up
private Feed createFeed() {
    final Feed feed = new Feed();
    final Content content = new Content();
    content.setType("application/xml");
    content.setValue("<test>Hello Hello</test>");
    feed.setTitleEx(content);
    feed.setFeedType("atom_1.0");
    return feed;
}
 
Example 9
Source File: HrmsAtomViewBuilder.java    From Spring-MVC-Blueprints with MIT License 5 votes vote down vote up
@Override
protected List<Entry> buildFeedEntries(Map<String, Object> model,
		HttpServletRequest req, HttpServletResponse response) throws Exception {
	// get data model which is passed by the Spring container
	  List<HrmsNews> news = (List<HrmsNews>) model.get("allNews");
       List<Entry> entries = new ArrayList<Entry>(news.size());
		
		for(HrmsNews topic : news ){
		
			Entry entry = new Entry();
			
			
			entry.setId(topic.getId()+"");
						
			entry.setTitle(topic.getDescription());
			
			Content summary = new Content();
			summary.setValue(topic.getSummary());
		    entry.setSummary(summary);
		       
		    Link link = new Link();
		    link.setType("text/html");
		    link.setHref(topic.getLink()); //because I have a different controller to show news at http://yourfanstasticsiteUrl.com/news/ID
		    List arrLinks = new ArrayList();
		    arrLinks.add(link);
		    entry.setAlternateLinks(arrLinks);
		    entry.setUpdated(new Date());
			
		    entries.add(entry);
		}
		
		return entries;
}
 
Example 10
Source File: AtomFeedViewTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected List<Entry> buildFeedEntries(Map model, HttpServletRequest request, HttpServletResponse response)
		throws Exception {
	List<Entry> entries = new ArrayList<Entry>();
	for (Iterator iterator = model.keySet().iterator(); iterator.hasNext();) {
		String name = (String) iterator.next();
		Entry entry = new Entry();
		entry.setTitle(name);
		Content content = new Content();
		content.setValue((String) model.get(name));
		entry.setSummary(content);
		entries.add(entry);
	}
	return entries;
}
 
Example 11
Source File: AtomFeedViewTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected List<Entry> buildFeedEntries(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {
	List<Entry> entries = new ArrayList<>();
	for (String name : model.keySet()) {
		Entry entry = new Entry();
		entry.setTitle(name);
		Content content = new Content();
		content.setValue((String) model.get(name));
		entry.setSummary(content);
		entries.add(entry);
	}
	return entries;
}
 
Example 12
Source File: FoundPodcastsAtomFeedView.java    From podcastpedia-web with MIT License 5 votes vote down vote up
protected void buildFeedMetadata(Map model, Feed feed, HttpServletRequest request) {
    feed.setId("" + model.get("feed_id"));
    feed.setTitle("" + model.get("feed_title"));
    Content subTitle = new Content();
    subTitle.setValue("" + model.get("feed_description"));
    feed.setSubtitle(subTitle);
}
 
Example 13
Source File: ClientEntry.java    From rome with Apache License 2.0 5 votes vote down vote up
/**
 * Set content of entry.
 *
 * @param contentString content string.
 * @param type Must be "text" for plain text, "html" for escaped HTML, "xhtml" for XHTML or a
 *            valid MIME content-type.
 */
public void setContent(final String contentString, final String type) {
    final Content newContent = new Content();
    newContent.setType(type == null ? Content.HTML : type);
    newContent.setValue(contentString);
    final ArrayList<Content> contents = new ArrayList<Content>();
    contents.add(newContent);
    setContents(contents);
}
 
Example 14
Source File: Atom10Parser.java    From rome with Apache License 2.0 4 votes vote down vote up
protected Entry parseEntry(final Feed feed, final Element eEntry, final String baseURI, final Locale locale) {

        final Entry entry = new Entry();

        final String xmlBase = eEntry.getAttributeValue("base", Namespace.XML_NAMESPACE);
        if (xmlBase != null) {
            entry.setXmlBase(xmlBase);
        }

        final Element title = eEntry.getChild("title", getAtomNamespace());
        if (title != null) {
            final Content c = new Content();
            c.setValue(parseTextConstructToString(title));
            c.setType(getAttributeValue(title, "type"));
            entry.setTitleEx(c);
        }

        final List<Element> links = eEntry.getChildren("link", getAtomNamespace());
        entry.setAlternateLinks(parseAlternateLinks(feed, entry, baseURI, links));
        entry.setOtherLinks(parseOtherLinks(feed, entry, baseURI, links));

        final List<Element> authors = eEntry.getChildren("author", getAtomNamespace());
        if (!authors.isEmpty()) {
            entry.setAuthors(parsePersons(baseURI, authors, locale));
        }

        final List<Element> contributors = eEntry.getChildren("contributor", getAtomNamespace());
        if (!contributors.isEmpty()) {
            entry.setContributors(parsePersons(baseURI, contributors, locale));
        }

        final Element id = eEntry.getChild("id", getAtomNamespace());
        if (id != null) {
            entry.setId(id.getText());
        }

        final Element updated = eEntry.getChild("updated", getAtomNamespace());
        if (updated != null) {
            entry.setUpdated(DateParser.parseDate(updated.getText(), locale));
        }

        final Element published = eEntry.getChild("published", getAtomNamespace());
        if (published != null) {
            entry.setPublished(DateParser.parseDate(published.getText(), locale));
        }

        final Element summary = eEntry.getChild("summary", getAtomNamespace());
        if (summary != null) {
            entry.setSummary(parseContent(summary));
        }

        final Element content = eEntry.getChild("content", getAtomNamespace());
        if (content != null) {
            final List<Content> contents = new ArrayList<Content>();
            contents.add(parseContent(content));
            entry.setContents(contents);
        }

        final Element rights = eEntry.getChild("rights", getAtomNamespace());
        if (rights != null) {
            entry.setRights(rights.getText());
        }

        final List<Element> categories = eEntry.getChildren("category", getAtomNamespace());
        entry.setCategories(parseCategories(baseURI, categories));

        // TODO: SHOULD handle Atom entry source element
        final Element source = eEntry.getChild("source", getAtomNamespace());
        if (source != null) {
            entry.setSource(parseFeedMetadata(baseURI, source, locale));
        }

        entry.setModules(parseItemModules(eEntry, locale));

        final List<Element> foreignMarkup = extractForeignMarkup(eEntry, entry, getAtomNamespace());
        if (!foreignMarkup.isEmpty()) {
            entry.setForeignMarkup(foreignMarkup);
        }

        return entry;
    }
 
Example 15
Source File: AtomClientServerTest.java    From rome with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that entries can be posted and removed in all collections that accept entries. Fails if
 * no collections found that accept entries.
 */
@Test
public void testSimpleEntryPostAndRemove() throws Exception {
    assertNotNull(service);
    assertTrue(!service.getWorkspaces().isEmpty());
    int count = 0;
    for (final Object element : service.getWorkspaces()) {
        final ClientWorkspace space = (ClientWorkspace) element;
        assertNotNull(space.getTitle());

        for (final Object element2 : space.getCollections()) {
            final ClientCollection col = (ClientCollection) element2;
            if (col.accepts(Collection.ENTRY_TYPE)) {

                // we found a collection that accepts entries, so post one
                final ClientEntry m1 = col.createEntry();
                m1.setTitle("Test post");
                final Content c = new Content();
                c.setValue("This is a test post");
                c.setType("html");
                m1.setContent(c);

                col.addEntry(m1);

                // entry should now exist on server
                final ClientEntry m2 = col.getEntry(m1.getEditURI());
                assertNotNull(m2);

                // remove entry
                m2.remove();

                // fetching entry now should result in exception
                boolean failed = false;
                try {
                    col.getEntry(m1.getEditURI());
                } catch (final ProponoException e) {
                    failed = true;
                }
                assertTrue(failed);
                count++;
            }
        }
    }
    assertTrue(count > 0);
}
 
Example 16
Source File: Atom10Parser.java    From rome with Apache License 2.0 4 votes vote down vote up
private Feed parseFeedMetadata(final String baseURI, final Element eFeed, final Locale locale) {

        final com.rometools.rome.feed.atom.Feed feed = new com.rometools.rome.feed.atom.Feed(getType());

        final Element title = eFeed.getChild("title", getAtomNamespace());
        if (title != null) {
            final Content c = new Content();
            c.setValue(parseTextConstructToString(title));
            c.setType(getAttributeValue(title, "type"));
            feed.setTitleEx(c);
        }

        final List<Element> links = eFeed.getChildren("link", getAtomNamespace());
        feed.setAlternateLinks(parseAlternateLinks(feed, null, baseURI, links));
        feed.setOtherLinks(parseOtherLinks(feed, null, baseURI, links));

        final List<Element> categories = eFeed.getChildren("category", getAtomNamespace());
        feed.setCategories(parseCategories(baseURI, categories));

        final List<Element> authors = eFeed.getChildren("author", getAtomNamespace());
        if (!authors.isEmpty()) {
            feed.setAuthors(parsePersons(baseURI, authors, locale));
        }

        final List<Element> contributors = eFeed.getChildren("contributor", getAtomNamespace());
        if (!contributors.isEmpty()) {
            feed.setContributors(parsePersons(baseURI, contributors, locale));
        }

        final Element subtitle = eFeed.getChild("subtitle", getAtomNamespace());
        if (subtitle != null) {
            final Content content = new Content();
            content.setValue(parseTextConstructToString(subtitle));
            content.setType(getAttributeValue(subtitle, "type"));
            feed.setSubtitle(content);
        }

        final Element id = eFeed.getChild("id", getAtomNamespace());
        if (id != null) {
            feed.setId(id.getText());
        }

        final Element generator = eFeed.getChild("generator", getAtomNamespace());
        if (generator != null) {

            final Generator gen = new Generator();
            gen.setValue(generator.getText());

            final String uri = getAttributeValue(generator, "uri");
            if (uri != null) {
                gen.setUrl(uri);
            }

            final String version = getAttributeValue(generator, "version");
            if (version != null) {
                gen.setVersion(version);
            }

            feed.setGenerator(gen);

        }

        final Element rights = eFeed.getChild("rights", getAtomNamespace());
        if (rights != null) {
            feed.setRights(parseTextConstructToString(rights));
        }

        final Element icon = eFeed.getChild("icon", getAtomNamespace());
        if (icon != null) {
            feed.setIcon(icon.getText());
        }

        final Element logo = eFeed.getChild("logo", getAtomNamespace());
        if (logo != null) {
            feed.setLogo(logo.getText());
        }

        final Element updated = eFeed.getChild("updated", getAtomNamespace());
        if (updated != null) {
            feed.setUpdated(DateParser.parseDate(updated.getText(), locale));
        }

        return feed;

    }
 
Example 17
Source File: ConverterForAtom10.java    From rome with Apache License 2.0 4 votes vote down vote up
protected Content createAtomContent(final SyndContent sContent) {
    final Content content = new Content();
    content.setType(sContent.getType());
    content.setValue(sContent.getValue());
    return content;
}
 
Example 18
Source File: AtomClientServerTest.java    From rome with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that entries can be posted, updated and removed in all collections that accept entries.
 * Fails if no collections found that accept entries.
 */
@Test
public void testSimpleEntryPostUpdateAndRemove() throws Exception {
    assertNotNull(service);
    assertTrue(!service.getWorkspaces().isEmpty());
    int count = 0;
    for (final Object element : service.getWorkspaces()) {
        final ClientWorkspace space = (ClientWorkspace) element;
        assertNotNull(space.getTitle());

        for (final Object element2 : space.getCollections()) {
            final ClientCollection col = (ClientCollection) element2;
            if (col.accepts(Collection.ENTRY_TYPE)) {

                // we found a collection that accepts entries, so post one
                final ClientEntry m1 = col.createEntry();
                m1.setTitle(col.getTitle() + ": Test post");
                final Content c = new Content();
                c.setValue("This is a test post");
                c.setType("html");
                m1.setContent(c);

                col.addEntry(m1);

                // entry should now exist on server
                final ClientEntry m2 = col.getEntry(m1.getEditURI());
                assertNotNull(m2);

                m2.setTitle(col.getTitle() + ": Updated title");
                m2.update();

                // entry should now be updated on server
                final ClientEntry m3 = col.getEntry(m1.getEditURI());
                assertEquals(col.getTitle() + ": Updated title", m3.getTitle());

                // remove entry
                m3.remove();

                // fetching entry now should result in exception
                boolean failed = false;
                try {
                    col.getEntry(m1.getEditURI());
                } catch (final ProponoException e) {
                    failed = true;
                }
                assertTrue(failed);
                count++;
            }
        }
    }
    assertTrue(count > 0);
}
 
Example 19
Source File: AtomClientTest.java    From rome with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that entries can be posted, updated and removed in all collections that accept entries.
 * Fails if no collections found that accept entries.
 */
public void testSimpleEntryPostUpdateAndRemove() throws Exception {
    assertNotNull(service);
    assertTrue(!service.getWorkspaces().isEmpty());
    int count = 0;
    for (final Object element : service.getWorkspaces()) {
        final ClientWorkspace space = (ClientWorkspace) element;
        assertNotNull(space.getTitle());

        for (final Object element2 : space.getCollections()) {
            final ClientCollection col = (ClientCollection) element2;
            if (col.accepts(Collection.ENTRY_TYPE)) {

                // we found a collection that accepts entries, so post one
                final ClientEntry m1 = col.createEntry();
                m1.setTitle(col.getTitle() + ": Test post");
                final Content c = new Content();
                c.setValue("This is a test post");
                c.setType("html");
                m1.setContent(c);

                col.addEntry(m1);

                // entry should now exist on server
                final ClientEntry m2 = col.getEntry(m1.getEditURI());
                assertNotNull(m2);

                m2.setTitle(col.getTitle() + ": Updated title");
                m2.update();

                // entry should now be updated on server
                final ClientEntry m3 = col.getEntry(m1.getEditURI());
                assertEquals(col.getTitle() + ": Updated title", m3.getTitle());

                // remove entry
                m3.remove();

                // fetching entry now should result in exception
                boolean failed = false;
                try {
                    col.getEntry(m1.getEditURI());
                } catch (final ProponoException e) {
                    failed = true;
                }
                assertTrue(failed);
                count++;
            }
        }
    }
    assertTrue(count > 0);
}
 
Example 20
Source File: AtomClientTest.java    From rome with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that entries can be posted and removed in all collections that accept entries. Fails if
 * no collections found that accept entries.
 */
public void testSimpleEntryPostAndRemove() throws Exception {
    assertNotNull(service);
    assertTrue(!service.getWorkspaces().isEmpty());
    int count = 0;
    for (final Object element : service.getWorkspaces()) {
        final ClientWorkspace space = (ClientWorkspace) element;
        assertNotNull(space.getTitle());

        for (final Object element2 : space.getCollections()) {
            final ClientCollection col = (ClientCollection) element2;
            if (col.accepts(Collection.ENTRY_TYPE)) {

                // we found a collection that accepts entries, so post one
                final ClientEntry m1 = col.createEntry();
                m1.setTitle("Test post");
                final Content c = new Content();
                c.setValue("This is a test post");
                c.setType("html");
                m1.setContent(c);

                col.addEntry(m1);

                // entry should now exist on server
                final ClientEntry m2 = col.getEntry(m1.getEditURI());
                assertNotNull(m2);

                // remove entry
                m2.remove();

                // fetching entry now should result in exception
                boolean failed = false;
                try {
                    col.getEntry(m1.getEditURI());
                } catch (final ProponoException e) {
                    failed = true;
                }
                assertTrue(failed);
                count++;
            }
        }
    }
    assertTrue(count > 0);
}