コード例 #1
0
 /**
  * Retrieves the XML located at the given URI. It's assumed the URI does point to a XML--the URI
  * will be accessed (using java.io or java.net), opened, read and then passed into the XML parser
  * (XMLReader) configured for Flying Saucer. The result is packed up into an XMLResource for later
  * consumption.
  *
  * @param uri Location of the XML source.
  * @return An XMLResource containing the image.
  */
 public XMLResource getXMLResource(String uri) {
   InputStream inputStream = resolveAndOpenStream(uri);
   XMLResource xmlResource;
   try {
     xmlResource = XMLResource.load(inputStream);
   } finally {
     if (inputStream != null)
       try {
         inputStream.close();
       } catch (IOException e) {
         // swallow
       }
   }
   return xmlResource;
 }
コード例 #2
0
  public static void renderImagefromGameXML(String gameXML, String XSL, BufferedImage backimage) {
    Graphics2DRenderer r = new Graphics2DRenderer();

    String xhtml = getXHTMLfromGameXML(gameXML, XSL);
    xhtml = xhtml.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "");

    xhtml = xhtml.replace("<body>", "<body><table width=\"560\" height=\"560\"><tr><td>");
    xhtml = xhtml.replace("</body>", "</td></tr></table></body>");

    InputSource is = new InputSource(new BufferedReader(new StringReader(xhtml)));
    Document dom = XMLResource.load(is).getDocument();

    r.setDocument(dom, "http://www.ggp.org/");
    final Graphics2D g2 = backimage.createGraphics();
    r.layout(g2, defaultSize);
    r.render(g2);
  }