Example #1
0
 /** Transform an InputStream to a TinyTree. */
 public static DocumentInfo readTinyTree(
     Configuration configuration,
     InputStream inputStream,
     String systemId,
     boolean handleXInclude,
     boolean handleLexical) {
   final TinyBuilder treeBuilder = new TinyBuilder();
   {
     final TransformerXMLReceiver identityHandler = getIdentityTransformerHandler(configuration);
     identityHandler.setResult(treeBuilder);
     final XMLReceiver xmlReceiver;
     if (handleXInclude) {
       // Insert XIncludeContentHandler
       xmlReceiver =
           new XIncludeProcessor.XIncludeXMLReceiver(
               null,
               identityHandler,
               null,
               new TransformerURIResolver(XMLUtils.ParserConfiguration.PLAIN));
     } else {
       xmlReceiver = identityHandler;
     }
     XMLUtils.inputStreamToSAX(
         inputStream, systemId, xmlReceiver, XMLUtils.ParserConfiguration.PLAIN, handleLexical);
   }
   return (DocumentInfo) treeBuilder.getCurrentRoot();
 }
  /** This main function is used for the ant task helpdocs. Don't change for testing!! */
  public static void main(String[] args) {
    if (args.length != 4) {
      System.out.println(
          "Usage: java ucl.physiol.neuroconstruct.utils.XMLUtils originalXMLFile xslFile targetFile\n");
      System.out.println("with: ");
      System.out.println("   originalXMLFile      the original XML file to be transformed");
      System.out.println(
          "                        (Note: if it's a directory will generate all xml files in dir)");
      System.out.println("   xslFile              the XSL file used to generate the file(s)");
      System.out.println("   targetDir            the target directory for the XML/HTML/etc.");
      System.out.println(
          "   extension            filename extension for the new files (.xml, .html, etc.)\n");
      return;
    }

    File origFile = new File(args[0]);
    File xslFile = new File(args[1]);
    File targetFile = new File(args[2]);
    String extension = args[3];
    /*
            File origFile = new File ("docs/XML/xmlForHtml/docs");
            File xslFile = new File ("docs/XML/helpViewer/helpdocs.xsl");
            File targetFile = new File ("../temp/tmm");
            String extension = ".html";
    */

    logger.logComment("Result: " + XMLUtils.transform(origFile, xslFile, targetFile, extension));
  }
Example #3
0
 /** Transform an InputStream to a dom4j Document. */
 public static Document readDom4j(
     InputStream inputStream, String systemId, boolean handleXInclude, boolean handleLexical) {
   final LocationSAXContentHandler dom4jResult = new LocationSAXContentHandler();
   {
     final XMLReceiver xmlReceiver;
     if (handleXInclude) {
       // Insert XIncludeContentHandler
       xmlReceiver =
           new XIncludeProcessor.XIncludeXMLReceiver(
               null,
               dom4jResult,
               null,
               new TransformerURIResolver(XMLUtils.ParserConfiguration.PLAIN));
     } else {
       xmlReceiver = dom4jResult;
     }
     XMLUtils.inputStreamToSAX(
         inputStream, systemId, xmlReceiver, XMLUtils.ParserConfiguration.PLAIN, handleLexical);
   }
   return dom4jResult.getDocument();
 }