com.rometools.rome.feed.atom.Content Java Examples

The following examples show how to use com.rometools.rome.feed.atom.Content. 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: 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 #5
Source File: AtomClientTest.java    From microservice-atom with Apache License 2.0 6 votes vote down vote up
@Test
public void feedReturnsNewlyCreatedOrder() {
	Order order = new Order();
	order.setCustomer(customerRepository.findAll().iterator().next());
	orderRepository.save(order);
	Feed feed = retrieveFeed();
	boolean foundLinkToCreatedOrder = false;
	List<Entry> entries = feed.getEntries();
	for (Entry entry : entries) {
		for (Content content : entry.getContents()) {
			if (content.getSrc().contains(Long.toString(order.getId()))) {
				foundLinkToCreatedOrder = true;
			}
		}
	}
	assertTrue(foundLinkToCreatedOrder);
}
 
Example #6
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 #7
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 #8
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 #9
Source File: AtomFeedView.java    From wallride with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected List<Entry> buildFeedEntries(
		Map<String, Object> model,
		HttpServletRequest request,
		HttpServletResponse response)
throws Exception {
	Set<Article> articles = (Set<Article>)model.get("articles");
	List<Entry> entries = new ArrayList<>(articles.size());
	for (Article article : articles) {
		Entry entry = new Entry();
		entry.setTitle(article.getTitle());
		entry.setPublished(Date.from(article.getDate().atZone(ZoneId.systemDefault()).toInstant()));
		Content content = new Content();
		content.setValue(article.getBody());
		entry.setSummary(content);

		Link link = new Link();
		link.setHref(link(article));
		List<Link> links = new ArrayList<Link>();
		links.add(link);
		entry.setAlternateLinks(links);
		entries.add(entry);
	}
	return entries;
}
 
Example #10
Source File: Atom03Generator.java    From rome with Apache License 2.0 6 votes vote down vote up
protected Element generateTagLineElement(final Content tagline) {

        final Element taglineElement = new Element("tagline", getFeedNamespace());

        final String type = tagline.getType();
        if (type != null) {
            final Attribute typeAttribute = new Attribute("type", type);
            taglineElement.setAttribute(typeAttribute);
        }

        final String value = tagline.getValue();
        if (value != null) {
            taglineElement.addContent(value);
        }

        return taglineElement;

    }
 
Example #11
Source File: Atom10Generator.java    From rome with Apache License 2.0 6 votes vote down vote up
protected Element generateTagLineElement(final Content tagline) {

        final Element taglineElement = new Element("subtitle", getFeedNamespace());

        final String type = tagline.getType();
        if (type != null) {
            final Attribute typeAttribute = new Attribute("type", type);
            taglineElement.setAttribute(typeAttribute);
        }

        final String value = tagline.getValue();
        if (value != null) {
            taglineElement.addContent(value);
        }

        return taglineElement;

    }
 
Example #12
Source File: ClientMediaEntry.java    From rome with Apache License 2.0 6 votes vote down vote up
/**
 * Get media resource as an InputStream, should work regardless of whether you set the media
 * resource data as an InputStream or as a byte array.
 */
public InputStream getAsStream() throws ProponoException {
    if (getContents() != null && !getContents().isEmpty()) {
        final Content c = getContents().get(0);
        if (c.getSrc() != null) {
            return getResourceAsStream();
        } else if (inputStream != null) {
            return inputStream;
        } else if (bytes != null) {
            return new ByteArrayInputStream(bytes);
        } else {
            throw new ProponoException("ERROR: no src URI or binary data to return");
        }
    } else {
        throw new ProponoException("ERROR: no content found in entry");
    }
}
 
Example #13
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 #14
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 #15
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 #16
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 #17
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 #18
Source File: GenericAtomFeedView.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 #19
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 #20
Source File: FoundEpisodesAtomFeedView.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 #21
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 #22
Source File: ConverterForAtom10.java    From rome with Apache License 2.0 5 votes vote down vote up
protected List<Content> createAtomContents(final List<SyndContent> syndContents) {
    final List<Content> atomContents = new ArrayList<Content>();
    for (final SyndContent syndContent : syndContents) {
        atomContents.add(createAtomContent(syndContent));
    }
    return atomContents;
}
 
Example #23
Source File: Atom10Parser.java    From rome with Apache License 2.0 5 votes vote down vote up
private Content parseContent(final Element e) {

        final String value = parseTextConstructToString(e);
        final String src = getAttributeValue(e, "src");
        final String type = getAttributeValue(e, "type");

        final Content content = new Content();
        content.setSrc(src);
        content.setType(type);
        content.setValue(value);
        return content;

    }
 
Example #24
Source File: Atom10Parser.java    From rome with Apache License 2.0 5 votes vote down vote up
private String parseTextConstructToString(final Element e) {

        String type = getAttributeValue(e, "type");
        if (type == null) {
            type = Content.TEXT;
        }

        String value = null;
        if (type.equals(Content.XHTML) || type.indexOf("/xml") != -1 || type.indexOf("+xml") != -1) {
            // XHTML content needs special handling
            final XMLOutputter outputter = new XMLOutputter();
            final List<org.jdom2.Content> contents = e.getContent();
            for (final org.jdom2.Content content : contents) {
                if (content instanceof Element) {
                    final Element element = (Element) content;
                    if (element.getNamespace().equals(getAtomNamespace())) {
                        element.setNamespace(Namespace.NO_NAMESPACE);
                    }
                }
            }
            value = outputter.outputString(contents);
        } else {
            // Everything else comes in verbatim
            value = e.getText();
        }

        return value;

    }
 
Example #25
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 #26
Source File: ClientMediaEntry.java    From rome with Apache License 2.0 5 votes vote down vote up
public ClientMediaEntry(final ClientAtomService service, final ClientCollection collection, final String title, final String slug,
        final String contentType, final InputStream is) {
    this(service, collection);
    inputStream = is;
    setTitle(title);
    setSlug(slug);
    final Content content = new Content();
    content.setType(contentType);
    final List<Content> contents = new ArrayList<Content>();
    contents.add(content);
    setContents(contents);
}
 
Example #27
Source File: ClientMediaEntry.java    From rome with Apache License 2.0 5 votes vote down vote up
public ClientMediaEntry(final ClientAtomService service, final ClientCollection collection, final String title, final String slug,
        final String contentType, final byte[] bytes) {
    this(service, collection);
    this.bytes = bytes;
    setTitle(title);
    setSlug(slug);
    final Content content = new Content();
    content.setType(contentType);
    final List<Content> contents = new ArrayList<Content>();
    contents.add(content);
    setContents(contents);
}
 
Example #28
Source File: ClientMediaEntry.java    From rome with Apache License 2.0 5 votes vote down vote up
private InputStream getResourceAsStream() throws ProponoException {
    if (getEditURI() == null) {
        throw new ProponoException("ERROR: not yet saved to server");
    }
    final GetMethod method = new GetMethod(((Content) getContents()).getSrc());
    try {
        getCollection().getHttpClient().executeMethod(method);
        if (method.getStatusCode() != 200) {
            throw new ProponoException("ERROR HTTP status=" + method.getStatusCode());
        }
        return method.getResponseBodyAsStream();
    } catch (final IOException e) {
        throw new ProponoException("ERROR: getting media entry", e);
    }
}
 
Example #29
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 #30
Source File: ClientEntry.java    From rome with Apache License 2.0 5 votes vote down vote up
/**
 * Convenience method to get first content object in content collection. Atom 1.0 allows only
 * one content element per entry.
 */
public Content getContent() {
    if (getContents() != null && !getContents().isEmpty()) {
        final Content c = getContents().get(0);
        return c;
    }
    return null;
}