@Override protected List<Entry> buildFeedEntries(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) { List<Entry> entries = new ArrayList<>(); for (String name : model.keySet()) { Entry entry = new Entry(); entry.setTitle(name); Content content = new Content(); content.setValue((String) model.get(name)); entry.setSummary(content); entries.add(entry); } return entries; } }
@Test public void read() throws IOException { InputStream is = getClass().getResourceAsStream("atom.xml"); MockHttpInputMessage inputMessage = new MockHttpInputMessage(is); inputMessage.getHeaders().setContentType(new MediaType("application", "atom+xml", StandardCharsets.UTF_8)); Feed result = converter.read(Feed.class, inputMessage); assertEquals("title", result.getTitle()); assertEquals("subtitle", result.getSubtitle().getValue()); List<?> entries = result.getEntries(); assertEquals(2, entries.size()); Entry entry1 = (Entry) entries.get(0); assertEquals("id1", entry1.getId()); assertEquals("title1", entry1.getTitle()); Entry entry2 = (Entry) entries.get(1); assertEquals("id2", entry2.getId()); assertEquals("title2", entry2.getTitle()); }
private Content parseContent(final Element e) { final String value = parseTextConstructToString(e); final String src = getAttributeValue(e, "src"); final String type = getAttributeValue(e, "type"); final Content content = new Content(); content.setSrc(src); content.setType(type); content.setValue(value); return content; }
protected void fillContentElement(final Element contentElement, final Content content) throws FeedException { final String type = content.getType(); if (type != null) { final Attribute typeAttribute = new Attribute("type", type); final String mode = content.getMode(); if (mode != null) { final Attribute modeAttribute = new Attribute("mode", mode); final String value = content.getValue(); if (value != null) {
protected void fillContentElement(final Element contentElement, final Content content) throws FeedException { final String type = content.getType(); final String href = content.getSrc(); if (href != null) { final Attribute srcAttribute = new Attribute("src", href); final String value = content.getValue(); if (value != null) {
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); }
public ClientMediaEntry(final ClientAtomService service, final ClientCollection collection, final String title, final String slug, final String contentType, final InputStream is) { this(service, collection); inputStream = is; setTitle(title); setSlug(slug); final Content content = new Content(); content.setType(contentType); final List<Content> contents = new ArrayList<Content>(); contents.add(content); setContents(contents); }
entry.setTitle(slug); final String fileName = createFileName(slug != null ? slug : entry.getTitle(), content.getType()); final File tempFile = File.createTempFile(fileName, "tmp"); final FileOutputStream fos = new FileOutputStream(tempFile); saveMediaFile(fileName, content.getType(), tempFile.length(), fis); fis.close(); final File resourceFile = new File(getEntryMediaPath(fileName));
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); }
/** * 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"); } }
/** * Set content of entry. * * @param contentString content string. * @param type Must be "text" for plain text, "html" for escaped HTML, "xhtml" for XHTML or a * valid MIME content-type. */ public void setContent(final String contentString, final String type) { final Content newContent = new Content(); newContent.setType(type == null ? Content.HTML : type); newContent.setValue(contentString); final ArrayList<Content> contents = new ArrayList<Content>(); contents.add(newContent); setContents(contents); }
private Content parseContent(final Element e) { final String value = parseTextConstructToString(e); final String src = getAttributeValue(e, "src"); final String type = getAttributeValue(e, "type"); final Content content = new Content(); content.setSrc(src); content.setType(type); content.setValue(value); return content; }
protected void fillContentElement(final Element contentElement, final Content content) throws FeedException { final String type = content.getType(); if (type != null) { final Attribute typeAttribute = new Attribute("type", type); final String mode = content.getMode(); if (mode != null) { final Attribute modeAttribute = new Attribute("mode", mode); final String value = content.getValue(); if (value != null) {
protected void fillContentElement(final Element contentElement, final Content content) throws FeedException { final String type = content.getType(); final String href = content.getSrc(); if (href != null) { final Attribute srcAttribute = new Attribute("src", href); final String value = content.getValue(); if (value != null) {