@Override protected final void renderMergedOutputModel( Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { T wireFeed = newFeed(); buildFeedMetadata(model, wireFeed, request); buildFeedEntries(model, wireFeed, request, response); setResponseContentType(request, response); if (!StringUtils.hasText(wireFeed.getEncoding())) { wireFeed.setEncoding("UTF-8"); } WireFeedOutput feedOutput = new WireFeedOutput(); ServletOutputStream out = response.getOutputStream(); feedOutput.output(wireFeed, new OutputStreamWriter(out, wireFeed.getEncoding())); out.flush(); }
/** * Utility method to serialize an entry to writer. */ public static void serializeEntry(final Entry entry, final Writer writer) throws IllegalArgumentException, FeedException, IOException { // Build a feed containing only the entry final List<Entry> entries = new ArrayList<Entry>(); entries.add(entry); final Feed feed1 = new Feed(); feed1.setFeedType("atom_1.0"); feed1.setEntries(entries); // Get Rome to output feed as a JDOM document final WireFeedOutput wireFeedOutput = new WireFeedOutput(); final Document feedDoc = wireFeedOutput.outputJDom(feed1); // Grab entry element from feed and get JDOM to serialize it final Element entryElement = feedDoc.getRootElement().getChildren().get(0); final XMLOutputter outputter = new XMLOutputter(); outputter.output(entryElement, writer); }
/** * Writes to an Writer the XML representation for the given WireFeed. * <p> * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is * the responsibility of the developer to ensure the Writer instance is using the same charset * encoding. * <p> * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'. * <p> * * @param feed Abstract feed to create XML representation from. The type of the WireFeed must * match the type given to the FeedOuptut constructor. * @param writer Writer to write the XML representation for the given WireFeed. * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed * don't match. * @throws IOException thrown if there was some problem writing to the Writer. * @throws FeedException thrown if the XML representation for the feed could not be created. * */ public void output(final WireFeed feed, final Writer writer) throws IllegalArgumentException, IOException, FeedException { this.output(feed, writer, true); }
/** * Creates a JDOM document for the given SyndFeedImpl. * <p> * This method does not use the feed encoding property. * <p> * * @param feed Abstract feed to create JDOM document from. The type of the SyndFeedImpl must * match the type given to the FeedOuptut constructor. * @return the JDOM document for the given SyndFeedImpl. * @throws FeedException thrown if the JDOM document for the feed could not be created. * */ public Document outputJDom(final SyndFeed feed) throws FeedException { return feedOutput.outputJDom(feed.createWireFeed()); }
/** * Creates a String with the XML representation for the given WireFeed. * <p> * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is * the responsibility of the developer to ensure that if the String is written to a character * stream the stream charset is the same as the feed encoding property. * <p> * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'. * <p> * * @param feed Abstract feed to create XML representation from. The type of the WireFeed must * match the type given to the FeedOuptut constructor. * @return a String with the XML representation for the given WireFeed. * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed * don't match. * @throws FeedException thrown if the XML representation for the feed could not be created. * */ public String outputString(final WireFeed feed) throws IllegalArgumentException, FeedException { return this.outputString(feed, true); }
/** * Returns the list of supported output feed types. * <p> * * @see WireFeed for details on the format of these strings. * <p> * @return a list of String elements with the supported output feed types. * */ public static List<String> getSupportedFeedTypes() { return getFeedGenerators().getSupportedFeedTypes(); }
/** * Utility method to serialize an entry to writer. */ public static void serializeEntry(final Entry entry, final Writer writer) throws IllegalArgumentException, FeedException, IOException { // Build a feed containing only the entry final List<Entry> entries = new ArrayList<Entry>(); entries.add(entry); final Feed feed1 = new Feed(); feed1.setFeedType("atom_1.0"); feed1.setEntries(entries); // Get Rome to output feed as a JDOM document final WireFeedOutput wireFeedOutput = new WireFeedOutput(); final Document feedDoc = wireFeedOutput.outputJDom(feed1); // Grab entry element from feed and get JDOM to serialize it final Element entryElement = feedDoc.getRootElement().getChildren().get(0); final XMLOutputter outputter = new XMLOutputter(); outputter.output(entryElement, writer); }
/** * Creates a File containing with the XML representation for the given WireFeed. * <p> * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. The * platform default charset encoding is used to write the feed to the file. It is the * responsibility of the developer to ensure the feed encoding is set to the platform charset * encoding. * <p> * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'. * <p> * * @param feed Abstract feed to create XML representation from. The type of the WireFeed must * match the type given to the FeedOuptut constructor. * @param file the file where to write the XML representation for the given WireFeed. * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed * don't match. * @throws IOException thrown if there was some problem writing to the File. * @throws FeedException thrown if the XML representation for the feed could not be created. * */ public void output(final WireFeed feed, final File file) throws IllegalArgumentException, IOException, FeedException { this.output(feed, file, true); }
/** * Creates a JDOM document for the given SyndFeedImpl. * <p> * This method does not use the feed encoding property. * <p> * * @param feed Abstract feed to create JDOM document from. The type of the SyndFeedImpl must * match the type given to the FeedOuptut constructor. * @return the JDOM document for the given SyndFeedImpl. * @throws FeedException thrown if the JDOM document for the feed could not be created. * */ public Document outputJDom(final SyndFeed feed) throws FeedException { return feedOutput.outputJDom(feed.createWireFeed()); }
/** * Creates a String with the XML representation for the given WireFeed. * <p> * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is * the responsibility of the developer to ensure that if the String is written to a character * stream the stream charset is the same as the feed encoding property. * <p> * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'. * <p> * * @param feed Abstract feed to create XML representation from. The type of the WireFeed must * match the type given to the FeedOuptut constructor. * @return a String with the XML representation for the given WireFeed. * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed * don't match. * @throws FeedException thrown if the XML representation for the feed could not be created. * */ public String outputString(final WireFeed feed) throws IllegalArgumentException, FeedException { return this.outputString(feed, true); }
/** * Returns the list of supported output feed types. * <p> * * @see WireFeed for details on the format of these strings. * <p> * @return a list of String elements with the supported output feed types. * */ public static List<String> getSupportedFeedTypes() { return getFeedGenerators().getSupportedFeedTypes(); }
@Override protected void writeInternal(T wireFeed, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { Charset charset = (StringUtils.hasLength(wireFeed.getEncoding()) ? Charset.forName(wireFeed.getEncoding()) : DEFAULT_CHARSET); MediaType contentType = outputMessage.getHeaders().getContentType(); if (contentType != null) { contentType = new MediaType(contentType.getType(), contentType.getSubtype(), charset); outputMessage.getHeaders().setContentType(contentType); } WireFeedOutput feedOutput = new WireFeedOutput(); try { Writer writer = new OutputStreamWriter(outputMessage.getBody(), charset); feedOutput.output(wireFeed, writer); } catch (FeedException ex) { throw new HttpMessageNotWritableException("Could not write WireFeed: " + ex.getMessage(), ex); } }
private void updateFeedDocument(final Feed f) throws AtomException { try { synchronized (FileStore.getFileStore()) { final WireFeedOutput wireFeedOutput = new WireFeedOutput(); final Document feedDoc = wireFeedOutput.outputJDom(f); final XMLOutputter outputter = new XMLOutputter(); // outputter.setFormat(Format.getPrettyFormat()); final OutputStream fos = FileStore.getFileStore().getFileOutputStream(getFeedPath()); outputter.output(feedDoc, new OutputStreamWriter(fos, "UTF-8")); } } catch (final FeedException fex) { throw new AtomException(fex); } catch (final IOException ex) { throw new AtomException(ex); } }
/** * Writes to an Writer the XML representation for the given WireFeed. * <p> * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is * the responsibility of the developer to ensure the Writer instance is using the same charset * encoding. * <p> * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'. * <p> * * @param feed Abstract feed to create XML representation from. The type of the WireFeed must * match the type given to the FeedOuptut constructor. * @param writer Writer to write the XML representation for the given WireFeed. * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed * don't match. * @throws IOException thrown if there was some problem writing to the Writer. * @throws FeedException thrown if the XML representation for the feed could not be created. * */ public void output(final WireFeed feed, final Writer writer) throws IllegalArgumentException, IOException, FeedException { this.output(feed, writer, true); }
/** * Creates a W3C DOM document for the given WireFeed. * <p> * This method does not use the feed encoding property. * <p> * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'. * <p> * * @param feed Abstract feed to create W3C DOM document from. The type of the WireFeed must * match the type given to the FeedOuptut constructor. * @return the W3C DOM document for the given WireFeed. * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed * don't match. * @throws FeedException thrown if the W3C DOM document for the feed could not be created. * */ public org.w3c.dom.Document outputW3CDom(final WireFeed feed) throws IllegalArgumentException, FeedException { final Document doc = outputJDom(feed); final DOMOutputter outputter = new DOMOutputter(); try { return outputter.output(doc); } catch (final JDOMException jdomEx) { throw new FeedException("Could not create DOM", jdomEx); } }
/** * Creates a String with the XML representation for the given SyndFeedImpl. * <p> * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is * the responsibility of the developer to ensure that if the String is written to a character * stream the stream charset is the same as the feed encoding property. * <p> * * @param feed Abstract feed to create XML representation from. The type of the SyndFeedImpl * must match the type given to the FeedOuptut constructor. * @return a String with the XML representation for the given SyndFeedImpl. * @throws FeedException thrown if the XML representation for the feed could not be created. * */ public String outputString(final SyndFeed feed) throws FeedException { return feedOutput.outputString(feed.createWireFeed()); }
/** * Creates a JDOM document for the given WireFeed. * <p> * This method does not use the feed encoding property. * <p> * NOTE: All other output methods delegate to this method. * <p> * * @param feed Abstract feed to create JDOM document from. The type of the WireFeed must match * the type given to the FeedOuptut constructor. * @return the JDOM document for the given WireFeed. * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed * don't match. * @throws FeedException thrown if the JDOM document for the feed could not be created. * */ public Document outputJDom(final WireFeed feed) throws IllegalArgumentException, FeedException { final String type = feed.getFeedType(); final WireFeedGenerator generator = getFeedGenerators().getGenerator(type); if (generator == null) { throw new IllegalArgumentException("Invalid feed type [" + type + "]"); } if (!generator.getType().equals(type)) { throw new IllegalArgumentException("WireFeedOutput type[" + type + "] and WireFeed type [" + type + "] don't match"); } return generator.generate(feed); }
@Override protected final void renderMergedOutputModel( Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { T wireFeed = newFeed(); buildFeedMetadata(model, wireFeed, request); buildFeedEntries(model, wireFeed, request, response); setResponseContentType(request, response); if (!StringUtils.hasText(wireFeed.getEncoding())) { wireFeed.setEncoding("UTF-8"); } WireFeedOutput feedOutput = new WireFeedOutput(); ServletOutputStream out = response.getOutputStream(); feedOutput.output(wireFeed, new OutputStreamWriter(out, wireFeed.getEncoding())); out.flush(); }
final WireFeedOutput wireFeedOutput = new WireFeedOutput(); final Document feedDoc = wireFeedOutput.outputJDom(col); res.setContentType("application/atom+xml; charset=utf-8"); final Writer writer = res.getWriter();
/** * Creates a File containing with the XML representation for the given WireFeed. * <p> * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. The * platform default charset encoding is used to write the feed to the file. It is the * responsibility of the developer to ensure the feed encoding is set to the platform charset * encoding. * <p> * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'. * <p> * * @param feed Abstract feed to create XML representation from. The type of the WireFeed must * match the type given to the FeedOuptut constructor. * @param file the file where to write the XML representation for the given WireFeed. * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed * don't match. * @throws IOException thrown if there was some problem writing to the File. * @throws FeedException thrown if the XML representation for the feed could not be created. * */ public void output(final WireFeed feed, final File file) throws IllegalArgumentException, IOException, FeedException { this.output(feed, file, true); }