Java Code Examples for com.rometools.rome.feed.atom.Link#setHref()

The following examples show how to use com.rometools.rome.feed.atom.Link#setHref() . 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: 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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 13
Source File: AtomModuleParser.java    From rome with Apache License 2.0 5 votes vote down vote up
private Link parseLink(final Element eLink) {

        final Link link = new Link();

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

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

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

        final String title = getAttributeValue(eLink, AtomLinkAttribute.TITLE);
        if (title != null) {
            link.setTitle(title);
        }

        final String hrefLang = getAttributeValue(eLink, AtomLinkAttribute.HREF_LANG);
        if (hrefLang != null) {
            link.setHreflang(hrefLang);
        }

        final String length = getAttributeValue(eLink, AtomLinkAttribute.LENGTH);
        if (length != null) {
            final Long val = NumberParser.parseLong(length);
            if (val != null) {
                link.setLength(val.longValue());
            }
        }

        return link;

    }
 
Example 14
Source File: AtomLinkModuleImpl.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
public void copyFrom(CopyFrom obj) {
    AtomLinkModule other = (AtomLinkModule) obj;
    List<Link> links = other.getLinks();
    for (Link link : links) {
        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());
        this.links.add(l);
    }
}
 
Example 15
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 16
Source File: Atom10Parser.java    From rome with Apache License 2.0 4 votes vote down vote up
private Link parseLink(final Feed feed, final Entry entry, final String baseURI, 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);
            if (isRelativeURI(href)) {
                link.setHrefResolved(resolveURI(baseURI, eLink, href));
            }
        }

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

        final String hrefLang = getAttributeValue(eLink, "hreflang");
        if (hrefLang != null) {
            link.setHreflang(hrefLang);
        }

        final String length = getAttributeValue(eLink, "length");
        if (length != null) {
            final Long val = NumberParser.parseLong(length);
            if (val != null) {
                link.setLength(val.longValue());
            }
        }

        return link;

    }
 
Example 17
Source File: ClientMediaEntry.java    From rome with Apache License 2.0 4 votes vote down vote up
/** Package access, to be called by DefaultClientCollection */
@Override
void addToCollection(final ClientCollection col) throws ProponoException {
    setCollection(col);
    final EntityEnclosingMethod method = new PostMethod(col.getHrefResolved());
    getCollection().addAuthentication(method);
    try {
        final Content c = getContents().get(0);
        if (inputStream != null) {
            method.setRequestEntity(new InputStreamRequestEntity(inputStream));
        } else {
            method.setRequestEntity(new InputStreamRequestEntity(new ByteArrayInputStream(getBytes())));
        }
        method.setRequestHeader("Content-type", c.getType());
        method.setRequestHeader("Title", getTitle());
        method.setRequestHeader("Slug", getSlug());
        getCollection().getHttpClient().executeMethod(method);
        if (inputStream != null) {
            inputStream.close();
        }
        final InputStream is = method.getResponseBodyAsStream();
        if (method.getStatusCode() == 200 || method.getStatusCode() == 201) {
            final Entry romeEntry = Atom10Parser.parseEntry(new InputStreamReader(is), col.getHrefResolved(), Locale.US);
            BeanUtils.copyProperties(this, romeEntry);

        } else {
            throw new ProponoException("ERROR HTTP status-code=" + method.getStatusCode() + " status-line: " + method.getStatusLine());
        }
    } catch (final IOException ie) {
        throw new ProponoException("ERROR: saving media entry", ie);
    } catch (final JDOMException je) {
        throw new ProponoException("ERROR: saving media entry", je);
    } catch (final FeedException fe) {
        throw new ProponoException("ERROR: saving media entry", fe);
    } catch (final IllegalAccessException ae) {
        throw new ProponoException("ERROR: saving media entry", ae);
    } catch (final InvocationTargetException te) {
        throw new ProponoException("ERROR: saving media entry", te);
    }
    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 18
Source File: OpenSearchModuleParser.java    From rome with Apache License 2.0 4 votes vote down vote up
private static Link parseLink(final Element e, final URL baseURI) {

        final Link link = new Link();

        String att = e.getAttributeValue("rel");// getAtomNamespace()); DONT
        // KNOW WHY DOESN'T WORK

        if (att != null) {
            link.setRel(att);
        }

        att = e.getAttributeValue("type");// getAtomNamespace()); DONT KNOW WHY
        // DOESN'T WORK

        if (att != null) {
            link.setType(att);
        }

        att = e.getAttributeValue("href");// getAtomNamespace()); DONT KNOW WHY
        // DOESN'T WORK

        if (att != null) {

            if (isRelativeURI(att)) { //
                link.setHref(resolveURI(baseURI, e, ""));
            } else {
                link.setHref(att);
            }
        }

        att = e.getAttributeValue("hreflang");// getAtomNamespace()); DONT KNOW
        // WHY DOESN'T WORK

        if (att != null) {
            link.setHreflang(att);
        }

        att = e.getAttributeValue("length");// getAtomNamespace()); DONT KNOW
        // WHY DOESN'T WORK

        return link;
    }