private void serializeContents(ObjectNode root, JsonNodeFactory factory, List contents) { if (contents == null || contents.size() == 0) { return; } ArrayNode contentsArray = factory.arrayNode(); for (Object obj : contents) { ObjectNode content = factory.objectNode(); if (obj instanceof com.rometools.rome.feed.rss.Content) { com.rometools.rome.feed.rss.Content rssContent = (com.rometools.rome.feed.rss.Content) obj; content.put("type", rssContent.getType()); content.put("value", rssContent.getValue()); } if (obj instanceof com.rometools.rome.feed.atom.Content) { com.rometools.rome.feed.atom.Content atomContent = (com.rometools.rome.feed.atom.Content) obj; content.put("type", atomContent.getType()); content.put("value", atomContent.getValue()); content.put("mode", atomContent.getMode()); content.put("src", atomContent.getSrc()); } contentsArray.add(content); } root.put("contents", contentsArray); }
/** * 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"); } }
final String href = content.getSrc(); if (href != null) { final Attribute srcAttribute = new Attribute("src", href);
final String href = content.getSrc(); if (href != null) { final Attribute srcAttribute = new Attribute("src", href);
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); } }
content = new BlogEntry.Content(romeContent.getValue()); content.setType(romeContent.getType()); content.setSrc(romeContent.getSrc());