Java Code Examples for com.rometools.rome.feed.atom.Entry#setId()

The following examples show how to use com.rometools.rome.feed.atom.Entry#setId() . 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 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 2
Source File: OrderAtomFeedView.java    From microservice-atom 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<Order> orderlist = (List<Order>) model.get("orders");

	for (Order o : orderlist) {
		Entry entry = new Entry();
		entry.setId("tag:ewolff.com/microservice-atom/order/" + Long.toString(o.getId()));
		entry.setUpdated(o.getUpdated());
		entry.setTitle("Order " + o.getId());
		List<Content> contents = new ArrayList<Content>();
		Content content = new Content();
		content.setSrc(baseUrl(request) + "order/" + Long.toString(o.getId()));
		content.setType("application/json");
		contents.add(content);
		entry.setContents(contents);
		Content summary = new Content();
		summary.setValue("This is the order " + o.getId());
		entry.setSummary(summary);
		entries.add(entry);
	}

	return entries;
}
 
Example 3
Source File: VetsAtomView.java    From docker-workflow-plugin with MIT License 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 4
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 5
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 6
Source File: AtomFeedHttpMessageConverterTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void write() throws IOException, SAXException {
	Feed feed = new Feed("atom_1.0");
	feed.setTitle("title");

	Entry entry1 = new Entry();
	entry1.setId("id1");
	entry1.setTitle("title1");

	Entry entry2 = new Entry();
	entry2.setId("id2");
	entry2.setTitle("title2");

	List<Entry> entries = new ArrayList<>(2);
	entries.add(entry1);
	entries.add(entry2);
	feed.setEntries(entries);

	MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
	converter.write(feed, null, outputMessage);

	assertEquals("Invalid content-type", new MediaType("application", "atom+xml", StandardCharsets.UTF_8),
			outputMessage.getHeaders().getContentType());
	String expected = "<feed xmlns=\"http://www.w3.org/2005/Atom\">" + "<title>title</title>" +
			"<entry><id>id1</id><title>title1</title></entry>" +
			"<entry><id>id2</id><title>title2</title></entry></feed>";
	NodeMatcher nm = new DefaultNodeMatcher(ElementSelectors.byName);
	assertThat(outputMessage.getBodyAsString(StandardCharsets.UTF_8),
			isSimilarTo(expected).ignoreWhitespace().withNodeMatcher(nm));
}
 
Example 7
Source File: AtomFeedHttpMessageConverterTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void write() throws IOException, SAXException {
	Feed feed = new Feed("atom_1.0");
	feed.setTitle("title");

	Entry entry1 = new Entry();
	entry1.setId("id1");
	entry1.setTitle("title1");

	Entry entry2 = new Entry();
	entry2.setId("id2");
	entry2.setTitle("title2");

	List<Entry> entries = new ArrayList<>(2);
	entries.add(entry1);
	entries.add(entry2);
	feed.setEntries(entries);

	MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
	converter.write(feed, null, outputMessage);

	assertEquals("Invalid content-type", new MediaType("application", "atom+xml", StandardCharsets.UTF_8),
			outputMessage.getHeaders().getContentType());
	String expected = "<feed xmlns=\"http://www.w3.org/2005/Atom\">" + "<title>title</title>" +
			"<entry><id>id1</id><title>title1</title></entry>" +
			"<entry><id>id2</id><title>title2</title></entry></feed>";
	NodeMatcher nm = new DefaultNodeMatcher(ElementSelectors.byName);
	assertThat(outputMessage.getBodyAsString(StandardCharsets.UTF_8),
			isSimilarTo(expected).ignoreWhitespace().withNodeMatcher(nm));
}
 
Example 8
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 9
Source File: AtomFeedHttpMessageConverterTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void write() throws IOException, SAXException {
	Feed feed = new Feed("atom_1.0");
	feed.setTitle("title");

	Entry entry1 = new Entry();
	entry1.setId("id1");
	entry1.setTitle("title1");

	Entry entry2 = new Entry();
	entry2.setId("id2");
	entry2.setTitle("title2");

	List<Entry> entries = new ArrayList<Entry>(2);
	entries.add(entry1);
	entries.add(entry2);
	feed.setEntries(entries);

	MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
	converter.write(feed, null, outputMessage);

	assertEquals("Invalid content-type", new MediaType("application", "atom+xml", utf8),
			outputMessage.getHeaders().getContentType());
	String expected = "<feed xmlns=\"http://www.w3.org/2005/Atom\">" + "<title>title</title>" +
			"<entry><id>id1</id><title>title1</title></entry>" +
			"<entry><id>id2</id><title>title2</title></entry></feed>";
	assertXMLEqual(expected, outputMessage.getBodyAsString(utf8));
}
 
Example 10
Source File: VetsAtomView.java    From enhanced-pet-clinic with Apache License 2.0 5 votes vote down vote up
@Override
protected List<Entry> buildFeedEntries(Map<String, Object> model, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

	log.info("In buildFeedEntries: " + model);

	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(new Date());

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

		entries.add(entry);
	}
	response.setContentType("blabla");
	return entries;
}
 
Example 11
Source File: FileBasedCollection.java    From rome with Apache License 2.0 5 votes vote down vote up
private void updateMediaEntryAppLinks(final Entry entry, final String fileName, final boolean singleEntry) {

        // TODO: figure out why PNG is missing from Java MIME types
        final FileTypeMap map = FileTypeMap.getDefaultFileTypeMap();
        if (map instanceof MimetypesFileTypeMap) {
            try {
                ((MimetypesFileTypeMap) map).addMimeTypes("image/png png PNG");
            } catch (final Exception ignored) {
            }
        }
        entry.setId(getEntryMediaViewURI(fileName));
        entry.setTitle(fileName);
        entry.setUpdated(new Date());

        final List<Link> otherlinks = new ArrayList<Link>();
        entry.setOtherLinks(otherlinks);

        final Link editlink = new Link();
        editlink.setRel("edit");
        editlink.setHref(getEntryEditURI(fileName, relativeURIs, singleEntry));
        otherlinks.add(editlink);

        final Link editMedialink = new Link();
        editMedialink.setRel("edit-media");
        editMedialink.setHref(getEntryMediaEditURI(fileName, relativeURIs, singleEntry));
        otherlinks.add(editMedialink);

        final Content content = entry.getContents().get(0);
        content.setSrc(getEntryMediaViewURI(fileName));
        final List<Content> contents = new ArrayList<Content>();
        contents.add(content);
        entry.setContents(contents);
    }
 
Example 12
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 13
Source File: Atom03Parser.java    From rome with Apache License 2.0 4 votes vote down vote up
private Entry parseEntry(final Element eEntry, final Locale locale) {

        final Entry entry = new Entry();

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

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

        final Element author = eEntry.getChild("author", getAtomNamespace());
        if (author != null) {
            final List<SyndPerson> authors = new ArrayList<SyndPerson>();
            authors.add(parsePerson(author));
            entry.setAuthors(authors);
        }

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

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

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

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

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

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

        final List<Element> contents = eEntry.getChildren("content", getAtomNamespace());
        if (!contents.isEmpty()) {
            final List<Content> content = new ArrayList<Content>();
            for (final Element eContent : contents) {
                content.add(parseContent(eContent));
            }
            entry.setContents(content);
        }

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

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

        return entry;

    }