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: VetsAtomView.java From activejpa with Apache License 2.0 | 6 votes |
@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 #2
Source File: Atom10Generator.java From rome with Apache License 2.0 | 6 votes |
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 #3
Source File: Atom03Generator.java From rome with Apache License 2.0 | 6 votes |
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 #4
Source File: ClientMediaEntry.java From rome with Apache License 2.0 | 6 votes |
/** * 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 #5
Source File: AtomFeedView.java From wallride with Apache License 2.0 | 6 votes |
@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 #6
Source File: AtomFeedView.java From wallride with Apache License 2.0 | 6 votes |
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: VetsAtomView.java From audit4j-demo with Apache License 2.0 | 6 votes |
@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: VetsAtomView.java From docker-workflow-plugin with MIT License | 6 votes |
@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 #9
Source File: AtomClientTest.java From microservice-atom with Apache License 2.0 | 6 votes |
@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 #10
Source File: OrderAtomFeedView.java From microservice-atom with Apache License 2.0 | 6 votes |
@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 #11
Source File: OrderAtomFeedView.java From microservice-atom with Apache License 2.0 | 6 votes |
@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 #12
Source File: CustomerAtomFeedView.java From event-driven-spring-boot with Apache License 2.0 | 6 votes |
@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 #13
Source File: CustomerAtomFeedView.java From event-driven-spring-boot with Apache License 2.0 | 6 votes |
@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 #14
Source File: ClientEntry.java From rome with Apache License 2.0 | 5 votes |
/** * 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; }
Example #15
Source File: Atom10Parser.java From rome with Apache License 2.0 | 5 votes |
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 #16
Source File: TestAtomContent.java From rome with Apache License 2.0 | 5 votes |
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 #17
Source File: ClientMediaEntry.java From rome with Apache License 2.0 | 5 votes |
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 #18
Source File: ClientMediaEntry.java From rome with Apache License 2.0 | 5 votes |
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 #19
Source File: ClientMediaEntry.java From rome with Apache License 2.0 | 5 votes |
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 #20
Source File: ClientEntry.java From rome with Apache License 2.0 | 5 votes |
/** * 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 #21
Source File: BloggerDotComTest.java From rome with Apache License 2.0 | 5 votes |
/** * Verify that server returns service document containing workspaces containing collections. */ public void testGetEntries() throws Exception { // no auth necessary for iterating through entries ClientCollection col = AtomClientFactory.getCollection(collectionURI, new GDataAuthStrategy(email, password, "blogger")); assertNotNull(col); int count = 0; for (final Iterator<ClientEntry> it = col.getEntries(); it.hasNext();) { final ClientEntry entry = it.next(); assertNotNull(entry); count++; } assertTrue(count > 0); col = AtomClientFactory.getCollection(collectionURI, new GDataAuthStrategy(email, password, "blogger")); final ClientEntry p1 = col.createEntry(); p1.setTitle("Propono post"); final Content c = new Content(); c.setValue("This is content from ROME Propono"); p1.setContent(c); col.addEntry(p1); final ClientEntry p2 = col.getEntry(p1.getEditURI()); assertNotNull(p2); final ClientAtomService atomService = AtomClientFactory.getAtomService(collectionURI, new GDataAuthStrategy(email, password, "blogger")); assertNotNull(atomService); }
Example #22
Source File: FileBasedCollection.java From rome with Apache License 2.0 | 5 votes |
/** * Add media entry to collection. Accepts a media file to be added to collection. The file will * be saved to disk in a directory under the collection's directory and the path will follow the * pattern <code>[collection-plural]/[entryid]/media/[entryid]</code>. An Atom entry will be * created to store metadata for the entry and it will exist at the path * <code>[collection-plural]/[entryid]/entry.xml</code>. The entry will be added to the * collection's feed in [collection-plural]/feed.xml. * * @param entry Entry object * @param slug String to be used in file-name * @param is Source of media data * @throws java.lang.Exception On Error * @return Location URI of entry */ public String addMediaEntry(final Entry entry, final String slug, final InputStream is) throws Exception { synchronized (FileStore.getFileStore()) { // Save media file temp file final Content content = entry.getContents().get(0); if (entry.getTitle() == null) { entry.setTitle(slug); } final String fileName = createFileName(slug != null ? slug : entry.getTitle(), content.getType()); final File tempFile = File.createTempFile(fileName, "tmp"); final FileOutputStream fos = new FileOutputStream(tempFile); Utilities.copyInputToOutput(is, fos); fos.close(); // Save media file final FileInputStream fis = new FileInputStream(tempFile); saveMediaFile(fileName, content.getType(), tempFile.length(), fis); fis.close(); final File resourceFile = new File(getEntryMediaPath(fileName)); // Create media-link entry updateTimestamps(entry); // Save media-link entry final String entryPath = getEntryPath(fileName); final OutputStream os = FileStore.getFileStore().getFileOutputStream(entryPath); updateMediaEntryAppLinks(entry, resourceFile.getName(), true); Atom10Generator.serializeEntry(entry, new OutputStreamWriter(os, "UTF-8")); os.flush(); os.close(); // Update feed with new entry final Feed f = getFeedDocument(); updateMediaEntryAppLinks(entry, resourceFile.getName(), false); updateFeedDocumentWithNewEntry(f, entry); return getEntryEditURI(fileName, false, true); } }
Example #23
Source File: FileBasedCollection.java From rome with Apache License 2.0 | 5 votes |
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 #24
Source File: AtomClientTest.java From rome with Apache License 2.0 | 5 votes |
public void testFindWorkspace() throws Exception { assertNotNull(service); final ClientWorkspace ws = (ClientWorkspace) service.findWorkspace("adminblog"); if (ws != null) { final ClientCollection col = (ClientCollection) ws.findCollection(null, "entry"); final ClientEntry entry = col.createEntry(); entry.setTitle("NPE on submitting order query"); entry.setContent("This is a <b>bad</b> one!", Content.HTML); col.addEntry(entry); // entry should now exist on server final ClientEntry saved = col.getEntry(entry.getEditURI()); assertNotNull(saved); // remove entry saved.remove(); // fetching entry now should result in exception boolean failed = false; try { col.getEntry(saved.getEditURI()); } catch (final ProponoException e) { failed = true; } assertTrue(failed); } }
Example #25
Source File: AtomClientServerTest.java From rome with Apache License 2.0 | 5 votes |
@Test public void testFindWorkspace() throws Exception { assertNotNull(service); final ClientWorkspace ws = (ClientWorkspace) service.findWorkspace("adminblog"); if (ws != null) { final ClientCollection col = (ClientCollection) ws.findCollection(null, "entry"); final ClientEntry entry = col.createEntry(); entry.setTitle("NPE on submitting order query"); entry.setContent("This is a <b>bad</b> one!", Content.HTML); col.addEntry(entry); // entry should now exist on server final ClientEntry saved = col.getEntry(entry.getEditURI()); assertNotNull(saved); // remove entry saved.remove(); // fetching entry now should result in exception boolean failed = false; try { col.getEntry(saved.getEditURI()); } catch (final ProponoException e) { failed = true; } assertTrue(failed); } }
Example #26
Source File: AtomFeedViewTests.java From spring-analysis-note with MIT License | 5 votes |
@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 #27
Source File: AtomFeedViewTests.java From java-technology-stack with MIT License | 5 votes |
@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 #28
Source File: HrmsAtomViewBuilder.java From Spring-MVC-Blueprints with MIT License | 5 votes |
@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 #29
Source File: AtomFeedViewTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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 #30
Source File: GenericAtomFeedView.java From podcastpedia-web with MIT License | 5 votes |
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); }