/** * Adds a link pointing to an HTML representation. * * @param htmlUri * Link URI. * * @param lang * Optional language code. * * @param title * Optional title. */ public void addHtmlLink(String htmlUri, String lang, String title) { Link link = new Link(); link.setRel(Link.Rel.ALTERNATE); link.setType(Link.Type.HTML); link.setHref(htmlUri); if (lang != null) { link.setHrefLang(lang); } if (title != null) { link.setTitle(title); } addLink(link); }
/** Link URI. */ public String getHref() { return getAttributeValue(HREF); } public URI getHrefUri() {
/** * Returns whether this link matches the given {@code rel} and {@code type} * values. * * @param relToMatch {@code rel} value to match or {@code null} to match any * {@code rel} value. * @param typeToMatch {@code type} value to match or {@code null} to match any * {@code type} value. */ public boolean matches(String relToMatch, String typeToMatch) { return (relToMatch == null || relToMatch.equals(getRel())) && (typeToMatch == null || typeToMatch.equals(getType())); }
@Override public boolean startElement(XmlWriter xw, Element parent, Element e, ElementMetadata<?, ?> metadata) throws IOException { if (!(e instanceof Link)) { return super.startElement(xw, parent, e, metadata); } Link link = (Link) e; String rel = link.getRel(); String type = link.getType(); String href = link.getHref(); long length = link.getLength(); if (rel != null && rel.equals("enclosure")) { generateEnclosure(xw, type, href, length); } else if ("comments".equals(rel)) { xw.simpleElement(Namespaces.rssNs, "comments", null, href); } else if (Rel.ALTERNATE.equals(rel)) { xw.simpleElement(Namespaces.rssNs, "link", null, href); } else if (Rel.VIA.equals(rel)) { if (href != null) { List<XmlWriter.Attribute> attrs = Collections.singletonList(new XmlWriter.Attribute("url", href)); xw.simpleElement(Namespaces.rssNs, "source", attrs, null); } } return false; }
/** * Adds a link pointing to an HTML representation. * * @param htmlUrl link URL * * @param lang optional language code * * @param title optional title */ public void addHtmlLink(String htmlUrl, String lang, String title) { try { Link link = new Link(Link.Rel.ALTERNATE, Link.Type.HTML, new URI(htmlUrl)); if (lang != null) { link.setHrefLang(lang); } if (title != null) { link.setTitle(title); } addElement(Link.KEY, link); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
/** * Retrieves the first link with the supplied {@code rel} and/or {@code type} * value. * <p> * If either parameter is {@code null}, doesn't return matches for that * parameter. */ public Link getLink(String rel, String type) { for (Link link : getLinks()) { if (link.matches(rel, type)) { return link; } } return null; }
URI editUrl = editLink.getHrefUri(); throw new UnsupportedOperationException("Not supported yet");
public URI getHrefUri() { String href = getHref(); try { return href == null ? null : new URI(href); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } } public void setHref(String v) {
public Link addLink(String rel, String type, String href) { try { Link link = new Link(rel, type, new URI(href)); addLink(link); return link; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
/** * Return the content of the link, or {@code null} if no content has been set. * This is used to inline an atom:content element inside an atom:link element. * * @return the atom:content element, or null if none exists. */ public Content getContent() { return getElement(Content.KEY); }
@Override public boolean startElement(XmlWriter xw, Element parent, Element e, ElementMetadata<?, ?> metadata) throws IOException { if (!(e instanceof Link)) { return super.startElement(xw, parent, e, metadata); } Link link = (Link) e; String rel = link.getRel(); String type = link.getType(); String href = link.getHref(); long length = link.getLength(); if (rel != null && rel.equals("enclosure")) { generateEnclosure(xw, type, href, length); } else if ("comments".equals(rel)) { xw.simpleElement(Namespaces.rssNs, "comments", null, href); } else if (Rel.ALTERNATE.equals(rel)) { xw.simpleElement(Namespaces.rssNs, "link", null, href); } else if (Rel.VIA.equals(rel)) { if (href != null) { List<XmlWriter.Attribute> attrs = Collections.singletonList(new XmlWriter.Attribute("url", href)); xw.simpleElement(Namespaces.rssNs, "source", attrs, null); } } return false; }
/** * Adds a link pointing to an HTML representation. * * @param htmlUrl link URL * * @param lang optional language code * * @param title optional title */ public void addHtmlLink(String htmlUrl, String lang, String title) { try { Link link = new Link(Link.Rel.ALTERNATE, Link.Type.HTML, new URI(htmlUrl)); if (lang != null) { link.setHrefLang(lang); } if (title != null) { link.setTitle(title); } addElement(Link.KEY, link); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
/** * Retrieves the first link with the supplied {@code rel} and/or {@code type} * value. * <p> * If either parameter is {@code null}, doesn't return matches for that * parameter. */ public Link getLink(String rel, String type) { for (Link link : getLinks()) { if (link.matches(rel, type)) { return link; } } return null; }
throw new UnsupportedOperationException("Entry cannot be retrieved"); URI entryUrl = selfLink.getHrefUri(); throw new UnsupportedOperationException("Not supported yet");
/** * Returns whether this link matches the given {@code rel} and {@code type} * values. * * @param relToMatch {@code rel} value to match or {@code null} to match any * {@code rel} value. * @param typeToMatch {@code type} value to match or {@code null} to match any * {@code type} value. */ public boolean matches(String relToMatch, String typeToMatch) { return (relToMatch == null || relToMatch.equals(getRel())) && (typeToMatch == null || typeToMatch.equals(getType())); }
public URI getHrefUri() { String href = getHref(); try { return href == null ? null : new URI(href); } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } } public void setHref(String v) {
public Link addLink(String rel, String type, String href) { try { Link link = new Link(rel, type, new URI(href)); addLink(link); return link; } catch (URISyntaxException e) { throw new IllegalArgumentException(e); } }
/** * Return the content of the link, or {@code null} if no content has been set. * This is used to inline an atom:content element inside an atom:link element. * * @return the atom:content element, or null if none exists. */ public Content getContent() { return getElement(Content.KEY); }
/** * Adds a link pointing to an HTML representation. * * @param htmlUri Link URI. * * @param lang Optional language code. * * @param title Optional title. */ public void addHtmlLink(String htmlUri, String lang, String title) { Link link = new Link(); link.setRel(Link.Rel.ALTERNATE); link.setType(Link.Type.HTML); link.setHref(htmlUri); if (lang != null) { link.setHrefLang(lang); } if (title != null) { link.setTitle(title); } addLink(link); }