Exemplo n.º 1
0
  /**
   * 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, final boolean ignoreOptionalErrors)
      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, ignoreOptionalErrors);
  }
Exemplo n.º 2
0
 /**
  * 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.
  * @param prettyPrint pretty-print XML (true) oder collapsed
  * @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, final boolean prettyPrint)
     throws IllegalArgumentException, IOException, FeedException {
   final Document doc = outputJDom(feed, false);
   final String encoding = feed.getEncoding();
   Format format;
   if (prettyPrint) {
     format = Format.getPrettyFormat();
   } else {
     format = Format.getCompactFormat();
   }
   if (encoding != null) {
     format.setEncoding(encoding);
   }
   final XMLOutputter outputter = new XMLOutputter(format);
   outputter.output(doc, writer);
 }
Exemplo n.º 3
0
 /**
  * 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.
  * @param prettyPrint pretty-print XML (true) oder collapsed
  * @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, final boolean prettyPrint, final boolean ignoreOptionalErrors)
     throws IllegalArgumentException, FeedException {
   final Document doc = outputJDom(feed, ignoreOptionalErrors);
   final String encoding = feed.getEncoding();
   Format format;
   if (prettyPrint) {
     format = Format.getPrettyFormat();
   } else {
     format = Format.getCompactFormat();
   }
   if (encoding != null) {
     format.setEncoding(encoding);
   }
   final XMLOutputter outputter = new XMLOutputter(format);
   return outputter.outputString(doc);
 }