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

The following examples show how to use com.rometools.rome.feed.atom.Link. 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: 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 #2
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 #3
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 #4
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 #5
Source File: AtomLinkModuleImpl.java    From rome with Apache License 2.0 6 votes vote down vote up
@Override
public Object clone() {
    final AtomLinkModuleImpl m = new AtomLinkModuleImpl();
    List<Link> result = new LinkedList<Link>();
    for(Link link : this.getLinks()) {
        Link l = new Link();
        l.setHref(link.getHref());
        l.setType(link.getType());
        l.setRel(link.getRel());
        l.setHreflang(link.getHreflang());
        l.setTitle(link.getTitle());
        l.setLength(link.getLength());
        result.add(l);
    }
    links.subList(0, links.size());
    m.setLinks(result);
    return m;
}
 
Example #6
Source File: OpenSearchModuleGenerator.java    From rome with Apache License 2.0 6 votes vote down vote up
protected Element generateLinkElement(final Link link) {
    final Element linkElement = new Element("link", OS_NS);

    if (link.getRel() != null) {
        final Attribute relAttribute = new Attribute("rel", "search");
        linkElement.setAttribute(relAttribute);
    }

    if (link.getType() != null) {
        final Attribute typeAttribute = new Attribute("type", link.getType());
        linkElement.setAttribute(typeAttribute);
    }

    if (link.getHref() != null) {
        final Attribute hrefAttribute = new Attribute("href", link.getHref());
        linkElement.setAttribute(hrefAttribute);
    }

    if (link.getHreflang() != null) {
        final Attribute hreflangAttribute = new Attribute("hreflang", link.getHreflang());
        linkElement.setAttribute(hreflangAttribute);
    }
    return linkElement;
}
 
Example #7
Source File: Atom03Generator.java    From rome with Apache License 2.0 6 votes vote down vote up
protected Element generateLinkElement(final Link link) {

        final Element linkElement = new Element("link", getFeedNamespace());

        final String rel = link.getRel();
        if (rel != null) {
            final Attribute relAttribute = new Attribute("rel", rel);
            linkElement.setAttribute(relAttribute);
        }

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

        final String href = link.getHref();
        if (href != null) {
            final Attribute hrefAttribute = new Attribute("href", href);
            linkElement.setAttribute(hrefAttribute);
        }

        return linkElement;

    }
 
Example #8
Source File: Atom03Parser.java    From rome with Apache License 2.0 6 votes vote down vote up
private List<Link> parseLinks(final List<Element> eLinks, final boolean alternate) {

        final List<Link> links = new ArrayList<Link>();

        for (final Element eLink : eLinks) {
            final String rel = getAttributeValue(eLink, "rel");
            if (alternate) {
                if ("alternate".equals(rel)) {
                    links.add(parseLink(eLink));
                }
            } else {
                if (!"alternate".equals(rel)) {
                    links.add(parseLink(eLink));
                }
            }
        }

        return Lists.emptyToNull(links);

    }
 
Example #9
Source File: Atom03Parser.java    From rome with Apache License 2.0 6 votes vote down vote up
private Link parseLink(final Element eLink) {

        final Link link = new Link();

        final String rel = getAttributeValue(eLink, "rel");
        if (rel != null) {
            link.setRel(rel);
        }

        final String type = getAttributeValue(eLink, "type");
        if (type != null) {
            link.setType(type);
        }

        final String href = getAttributeValue(eLink, "href");
        if (href != null) {
            link.setHref(href);
        }

        return link;

    }
 
Example #10
Source File: ConverterForAtom03.java    From rome with Apache License 2.0 5 votes vote down vote up
public SyndLink createSyndLink(final Link link) {
    final SyndLink syndLink = new SyndLinkImpl();
    syndLink.setRel(link.getRel());
    syndLink.setType(link.getType());
    syndLink.setHref(link.getHrefResolved());
    syndLink.setTitle(link.getTitle());
    return syndLink;
}
 
Example #11
Source File: AtomLinkTest.java    From rome with Apache License 2.0 5 votes vote down vote up
public void test() throws Exception {

        final File testdata = new File(super.getTestFile("atom/atom.xml"));
        final SyndFeed feed = new SyndFeedInput().build(testdata);

        final AtomLinkModule atomLinkModule = (AtomLinkModule) feed.getModule(AtomLinkModule.URI);
        List<Link> links = atomLinkModule.getLinks();
        for (int i = 0; i < links.size(); i++) {
            Link link = links.get(i);
            assertEquals(href[i], link.getHref());
            assertEquals(rel[i], link.getRel());
            assertEquals(type[i], link.getType());
        }

    }
 
Example #12
Source File: ConverterForAtom03.java    From rome with Apache License 2.0 5 votes vote down vote up
protected List<SyndLink> createSyndLinks(final List<Link> atomLinks) {
    final ArrayList<SyndLink> syndLinks = new ArrayList<SyndLink>();
    for (final Link atomLink : atomLinks) {
        final Link link = atomLink;
        if (!link.getRel().equals("enclosure")) {
            final SyndLink syndLink = createSyndLink(link);
            syndLinks.add(syndLink);
        }
    }
    return syndLinks;
}
 
Example #13
Source File: ConverterForAtom10.java    From rome with Apache License 2.0 5 votes vote down vote up
public Link createAtomLink(final SyndLink syndLink) {
    final Link link = new Link();
    link.setRel(syndLink.getRel());
    link.setType(syndLink.getType());
    link.setHref(syndLink.getHref());
    link.setHreflang(syndLink.getHreflang());
    link.setLength(syndLink.getLength());
    link.setTitle(syndLink.getTitle());
    return link;
}
 
Example #14
Source File: ConverterForAtom10.java    From rome with Apache License 2.0 5 votes vote down vote up
public SyndLink createSyndLink(final Link link) {
    final SyndLink syndLink = new SyndLinkImpl();
    syndLink.setRel(link.getRel());
    syndLink.setType(link.getType());
    syndLink.setHref(link.getHrefResolved());
    syndLink.setHreflang(link.getHreflang());
    syndLink.setLength(link.getLength());
    syndLink.setTitle(link.getTitle());
    return syndLink;
}
 
Example #15
Source File: ConverterForAtom10.java    From rome with Apache License 2.0 5 votes vote down vote up
public Link createAtomEnclosure(final SyndEnclosure syndEnclosure) {
    final Link link = new Link();
    link.setRel("enclosure");
    link.setType(syndEnclosure.getType());
    link.setHref(syndEnclosure.getUrl());
    link.setLength(syndEnclosure.getLength());
    return link;
}
 
Example #16
Source File: ConverterForAtom10.java    From rome with Apache License 2.0 5 votes vote down vote up
public SyndEnclosure createSyndEnclosure(final Feed feed, final Entry entry, final Link link) {
    final SyndEnclosure syndEncl = new SyndEnclosureImpl();
    syndEncl.setUrl(link.getHrefResolved());
    syndEncl.setType(link.getType());
    syndEncl.setLength(link.getLength());
    return syndEncl;
}
 
Example #17
Source File: ConverterForAtom10.java    From rome with Apache License 2.0 5 votes vote down vote up
protected List<SyndLink> createSyndLinks(final List<Link> atomLinks) {
    final ArrayList<SyndLink> syndLinks = new ArrayList<SyndLink>();
    for (final Link atomLink : atomLinks) {
        final SyndLink syndLink = createSyndLink(atomLink);
        syndLinks.add(syndLink);
    }
    return syndLinks;
}
 
Example #18
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 #19
Source File: ConverterForAtom03.java    From rome with Apache License 2.0 5 votes vote down vote up
public SyndEnclosure createSyndEnclosure(final Entry entry, final Link link) {
    final SyndEnclosure syndEncl = new SyndEnclosureImpl();
    syndEncl.setUrl(link.getHrefResolved());
    syndEncl.setType(link.getType());
    syndEncl.setLength(link.getLength());
    return syndEncl;
}
 
Example #20
Source File: ConverterForAtom03.java    From rome with Apache License 2.0 5 votes vote down vote up
public Link createAtomLink(final SyndLink syndLink) {
    final Link link = new Link();
    link.setRel(syndLink.getRel());
    link.setType(syndLink.getType());
    link.setHref(syndLink.getHref());
    link.setTitle(syndLink.getTitle());
    return link;
}
 
Example #21
Source File: ConverterForAtom03.java    From rome with Apache License 2.0 5 votes vote down vote up
public Link createAtomEnclosure(final SyndEnclosure syndEnclosure) {
    final Link link = new Link();
    link.setRel("enclosure");
    link.setType(syndEnclosure.getType());
    link.setHref(syndEnclosure.getUrl());
    link.setLength(syndEnclosure.getLength());
    return link;
}
 
Example #22
Source File: Atom10Parser.java    From rome with Apache License 2.0 5 votes vote down vote up
private List<Link> parseAlternateLinks(final Feed feed, final Entry entry, final String baseURI, final List<Element> eLinks) {

        final List<Link> links = new ArrayList<Link>();
        for (final Element eLink : eLinks) {
            final Link link = parseLink(feed, entry, baseURI, eLink);
            if (link.getRel() == null || "".equals(link.getRel().trim()) || "alternate".equals(link.getRel())) {
                links.add(link);
            }
        }

        return Lists.emptyToNull(links);

    }
 
Example #23
Source File: Atom10Parser.java    From rome with Apache License 2.0 5 votes vote down vote up
private List<Link> parseOtherLinks(final Feed feed, final Entry entry, final String baseURI, final List<Element> eLinks) {

        final List<Link> links = new ArrayList<Link>();
        for (final Element eLink : eLinks) {
            final Link link = parseLink(feed, entry, baseURI, eLink);
            if (!"alternate".equals(link.getRel())) {
                links.add(link);
            }
        }

        return Lists.emptyToNull(links);

    }
 
Example #24
Source File: AtomResource.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
void copyFromRomeEntry(final ClientEntry entry) {
    super.copyFromRomeEntry(entry);
    final List<Link> links = entry.getOtherLinks();
    if (links != null) {
        for (final Link link : links) {
            if ("edit-media".equals(link.getRel())) {
                id = link.getHrefResolved();
                break;
            }
        }
    }
}
 
Example #25
Source File: ClientMediaEntry.java    From rome with Apache License 2.0 5 votes vote down vote up
/**
 * Get media link URI for editing the media resource associated with this entry via HTTP PUT or
 * DELETE.
 */
public String getMediaLinkURI() {
    for (int i = 0; i < getOtherLinks().size(); i++) {
        final Link link = getOtherLinks().get(i);
        if (link.getRel() != null && link.getRel().equals("edit-media")) {
            return link.getHrefResolved();
        }
    }
    return null;
}
 
Example #26
Source File: ClientEntry.java    From rome with Apache License 2.0 5 votes vote down vote up
/**
 * Get the URI that can be used to edit the entry via HTTP PUT or DELETE.
 */
public String getEditURI() {
    for (int i = 0; i < getOtherLinks().size(); i++) {
        final Link link = getOtherLinks().get(i);
        if (link.getRel() != null && link.getRel().equals("edit")) {
            return link.getHrefResolved();
        }
    }
    return null;
}
 
Example #27
Source File: ClientEntry.java    From rome with Apache License 2.0 5 votes vote down vote up
void addToCollection(final ClientCollection col) throws ProponoException {
    setCollection(col);
    final EntityEnclosingMethod method = new PostMethod(getCollection().getHrefResolved());
    addAuthentication(method);
    final StringWriter sw = new StringWriter();
    int code = -1;
    try {
        Atom10Generator.serializeEntry(this, sw);
        method.setRequestEntity(new StringRequestEntity(sw.toString(), null, null));
        method.setRequestHeader("Content-type", "application/atom+xml; charset=utf-8");
        getHttpClient().executeMethod(method);
        final InputStream is = method.getResponseBodyAsStream();
        code = method.getStatusCode();
        if (code != 200 && code != 201) {
            throw new ProponoException("ERROR HTTP status=" + code + " : " + Utilities.streamToString(is));
        }
        final Entry romeEntry = Atom10Parser.parseEntry(new InputStreamReader(is), getCollection().getHrefResolved(), Locale.US);
        BeanUtils.copyProperties(this, romeEntry);

    } catch (final Exception e) {
        final String msg = "ERROR: saving entry, HTTP code: " + code;
        LOG.debug(msg, e);
        throw new ProponoException(msg, e);
    } finally {
        method.releaseConnection();
    }
    final Header locationHeader = method.getResponseHeader("Location");
    if (locationHeader == null) {
        LOG.warn("WARNING added entry, but no location header returned");
    } else if (getEditURI() == null) {
        final List<Link> links = getOtherLinks();
        final Link link = new Link();
        link.setHref(locationHeader.getValue());
        link.setRel("edit");
        links.add(link);
        setOtherLinks(links);
    }
}
 
Example #28
Source File: EntryIterator.java    From rome with Apache License 2.0 5 votes vote down vote up
private void getNextEntries() throws ProponoException {
    if (nextURI == null) {
        return;
    }
    final GetMethod colGet = new GetMethod(collection.getHrefResolved(nextURI));
    collection.addAuthentication(colGet);
    try {
        collection.getHttpClient().executeMethod(colGet);
        final SAXBuilder builder = new SAXBuilder();
        final Document doc = builder.build(colGet.getResponseBodyAsStream());
        final WireFeedInput feedInput = new WireFeedInput();
        col = (Feed) feedInput.build(doc);
    } catch (final Exception e) {
        throw new ProponoException("ERROR: fetching or parsing next entries, HTTP code: " + (colGet != null ? colGet.getStatusCode() : -1), e);
    } finally {
        colGet.releaseConnection();
    }
    members = col.getEntries().iterator();
    col.getEntries().size();

    nextURI = null;
    final List<Link> altLinks = col.getOtherLinks();
    if (altLinks != null) {
        for (final Link link : altLinks) {
            if ("next".equals(link.getRel())) {
                nextURI = link.getHref();
            }
        }
    }
}
 
Example #29
Source File: Bookmark.java    From rome with Apache License 2.0 5 votes vote down vote up
/**
 * Set the value of thumbnail
 *
 * @param newthumbnail new value of thumbnail
 */
public void setThumbnail(final Link newthumbnail) {
    Link old = null;
    for (final Link l : getOtherLinks()) {
        if ("thumbnail".equals(l.getRel())) {
            old = l;
            break;
        }
    }
    if (old != null) {
        getOtherLinks().remove(old);
        newthumbnail.setRel("thumbnail");
    }
    getOtherLinks().add(newthumbnail);
}
 
Example #30
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;
}