@SuppressWarnings("unchecked") public static SyndFeed addOpenSearchModule( SyndFeed feed, int itemsPerPage, int startIdx, int totalResult, String searchDescriptionUrl) { if (feed == null) { throw new NullPointerException("feed is NULL"); } List<Module> mods = null; mods = feed.getModules(); if (mods == null) { mods = new ArrayList<Module>(); } OpenSearchModule osm = new OpenSearchModuleImpl(); osm.setItemsPerPage(itemsPerPage); osm.setStartIndex(startIdx); osm.setTotalResults(totalResult); if (searchDescriptionUrl != null) { Link link = new Link(); link.setHref(searchDescriptionUrl); link.setType("application/opensearchdescription+xml"); osm.setLink(link); } mods.add(osm); feed.setModules(mods); return feed; }
@SuppressWarnings("unchecked") private void addLink(Feed feed, String url, String rel) { Link link = new Link(); link.setHref(url); link.setRel(rel); feed.getOtherLinks().add(link); }
private Link parseLink( final Feed feed, final Entry entry, final String baseURI, final Element eLink) { final Link link = new Link(); String att = getAttributeValue(eLink, "rel"); if (att != null) { link.setRel(att); } att = getAttributeValue(eLink, "type"); if (att != null) { link.setType(att); } att = getAttributeValue(eLink, "href"); if (att != null) { link.setHref(att); if (isRelativeURI(att)) { link.setHrefResolved(resolveURI(baseURI, eLink, att)); } } att = getAttributeValue(eLink, "title"); if (att != null) { link.setTitle(att); } att = getAttributeValue(eLink, "hreflang"); if (att != null) { link.setHreflang(att); } att = getAttributeValue(eLink, "length"); if (att != null) { final Long val = NumberParser.parseLong(att); if (val != null) { link.setLength(val.longValue()); } } return link; }
private Link parseLink(Element eLink) { Link link = new Link(); String att = getAttributeValue(eLink, "rel"); if (att != null) { link.setRel(att); } att = getAttributeValue(eLink, "type"); if (att != null) { link.setType(att); } att = getAttributeValue(eLink, "href"); if (att != null) { link.setHref(att); } return link; }
void addToCollection(ClientCollection col) throws ProponoException { setCollection(col); EntityEnclosingMethod method = new PostMethod(getCollection().getHrefResolved()); addAuthentication(method); StringWriter sw = new StringWriter(); int code = -1; try { Atom10Generator.serializeEntry(this, sw); method.setRequestEntity(new StringRequestEntity(sw.toString())); method.setRequestHeader("Content-type", "application/atom+xml; charset=utf-8"); getHttpClient().executeMethod(method); InputStream is = method.getResponseBodyAsStream(); code = method.getStatusCode(); if (code != 200 && code != 201) { throw new ProponoException( "ERROR HTTP status=" + code + " : " + Utilities.streamToString(is)); } Entry romeEntry = Atom10Parser.parseEntry(new InputStreamReader(is), getCollection().getHrefResolved()); BeanUtils.copyProperties(this, romeEntry); } catch (Exception e) { String msg = "ERROR: saving entry, HTTP code: " + code; logger.debug(msg, e); throw new ProponoException(msg, e); } finally { method.releaseConnection(); } Header locationHeader = method.getResponseHeader("Location"); if (locationHeader == null) { logger.warn("WARNING added entry, but no location header returned"); } else if (getEditURI() == null) { List links = getOtherLinks(); Link link = new Link(); link.setHref(locationHeader.getValue()); link.setRel("edit"); links.add(link); setOtherLinks(links); } }