コード例 #1
1
  private final void roundTrip(boolean expand, boolean validating, String encoding, String expect) {
    String docloc =
        this.getClass().getPackage().getName().replaceAll("\\.", "/") + "/TestIssue008.xml";
    URL docurl = ClassLoader.getSystemResource(docloc);

    if (docurl == null) {
      throw new IllegalStateException("Unable to get resource " + docloc);
    }

    SAXBuilder builder = new SAXBuilder(validating);
    // builder.setValidation(validating);
    builder.setExpandEntities(expand);
    Document doc = null;
    try {
      doc = builder.build(docurl);
    } catch (JDOMException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    if (doc == null) {
      fail("Unable to parse document, see output.");
    }

    Format fmt = Format.getCompactFormat();
    if (encoding != null) {
      fmt.setEncoding(encoding);
    }
    XMLOutputter xout = new XMLOutputter(fmt);

    String actual = xout.outputString(doc.getRootElement());
    assertEquals(expect, actual);
  }
コード例 #2
0
  protected String buildJnlpResponse(JnlpTemplate launcher) throws ServletErrorException {

    launcher.rootElt.setAttribute(
        JNLP_TAG_ATT_CODEBASE,
        ServletUtil.getFirstParameter(launcher.parameterMap.get(PARAM_CODEBASE)));
    launcher.rootElt.removeAttribute(
        JNLP_TAG_ATT_HREF); // this tag has not to be used inside dynamic JNLP

    handleRequestPropertyParameter(launcher);
    handleRequestArgumentParameter(launcher);

    filterRequestParameterMarker(launcher);

    String outputStr = null;
    try {
      Format format = Format.getPrettyFormat();
      // Converts native encodings to ASCII with escaped Unicode like (ô è é...), necessary for jnlp
      format.setEncoding("US-ASCII");
      outputStr = new XMLOutputter(format).outputString(launcher.rootElt);
    } catch (Exception e) {
      throw new ServletErrorException(
          HttpServletResponse.SC_NOT_MODIFIED, "Can't build Jnlp launcher ", e);
    }

    return outputStr;
  }
コード例 #3
0
ファイル: WireFeedOutput.java プロジェクト: nea/rome
 /**
  * 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);
 }
コード例 #4
0
ファイル: WireFeedOutput.java プロジェクト: nea/rome
 /**
  * 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);
 }