Package javax.xml.transform

Examples of javax.xml.transform.Transformer


      this.source = source;
    }
   
    @Override
    public void translate(Writer writer) throws TransformerException, IOException {
        Transformer t = TransformerFactory.newInstance().newTransformer();
        t.transform(source, new StreamResult(writer));
    }
View Full Code Here


        copyTag(aliasName, tmlTag, appendElement(taglib, "tag"));
      }
    }
   
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.transform(new DOMSource(tld), new StreamResult(targetFile));
  }
View Full Code Here

    try {
      styleSource = convertToSource(styleSheet);
      xmlSource = convertToSource(xml);
      final Source xmlParam = xmlSource;
      TransformerFactory factory = TransformerFactory.newInstance();
            final Transformer transformer = factory.newTransformer(styleSource);
           
      //this creates a non-validated sqlxml - it may not be valid xml/root-less xml
      SQLXMLImpl result = XMLSystemFunctions.saveToBufferManager(context.getBufferManager(), new XMLTranslator() {
       
        @Override
        public void translate(Writer writer) throws TransformerException {
                  //transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); //$NON-NLS-1$
                  // Feed the resultant I/O stream into the XSLT processor
          transformer.transform(xmlParam, new StreamResult(writer));
        }
      });
      return new ClobType(new ClobImpl(result.getStreamFactory(), -1));
    } finally {
      Util.closeSource(styleSource);
View Full Code Here

   {
      List<String> markupHeaders = new ArrayList<String>();
     
      if (extraMarkupHeaders != null && !extraMarkupHeaders.isEmpty())
      {
         Transformer transformer = TransformerFactory.newInstance().newTransformer();
         transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");

         for (Element element : extraMarkupHeaders)
         {
            DOMSource source = new DOMSource(element);
            StreamResult result = new StreamResult(new StringWriter());

            // we want to ouput xhtml text that will still work on html browsers.
            // In order to do this we need to have the script tag be not self closing
            // which it will try and do with the xml or xhtml method. If we just use
            // the html method then the other tags will not be closed.
            if (element.getNodeName().equalsIgnoreCase("script"))
            {
               transformer.setOutputProperty(OutputKeys.METHOD, "html");
            }
            else
            {
               transformer.setOutputProperty(OutputKeys.METHOD, "xml");
            }
            transformer.transform(source, result);
            markupHeaders.add(result.getWriter().toString());
         }
      }
     
       return markupHeaders;
View Full Code Here

            return null;
        }
       
        try {
            TransformerFactory factory = TransformerFactory.newInstance();
            Transformer transformer = factory.newTransformer();
            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
            StringWriter output = new StringWriter();
            transformer.transform(new DOMSource(target), new StreamResult(output));
           
            return output.toString();
        } catch (TransformerConfigurationException e) {
            // Things must be in pretty bad shape to get here so
            // rethrow as runtime exception
View Full Code Here

  }
 
  @Override
  public ChartOutput getChart(ChartInput getChartInput) {
    try {
      Transformer transformer = TransformerFactory.newInstance()
          .newTransformer();
      StringWriter reader = new StringWriter();

      CategoryDataset dataset = null;

      transformer.transform(getChartInput.getXmlData(), new StreamResult(
          reader));
      dataset = DatasetReader
          .readCategoryDatasetFromXML(new ByteArrayInputStream(reader
              .getBuffer().toString().getBytes()));
View Full Code Here

     * @param args
     * @throws TransformerFactoryConfigurationError
     * @throws TransformerException
     */
    public static void main(String[] args) throws TransformerException, TransformerFactoryConfigurationError {
        Transformer xsl =
        TransformerFactory.newInstance().newTransformer(
                new StreamSource(new File("src/com/hp/hpl/jena/iri/impl/viol2java.xsl"))
                );
        xsl.transform(
                new StreamSource(new File("src/com/hp/hpl/jena/iri/impl/violations.xml")),
                new StreamResult(new File("src/com/hp/hpl/jena/iri/ViolationCodes.java"))
                       
        );
       
View Full Code Here

    }
  }

  private void compile(File inDir, File outDir, File mapFile, String locale) throws HelpException {
    String xmlFiles[] = inDir.list(new DialogUtils.ExtensionFilter("xml", false));
    Transformer transformer = null;
    DocumentBuilder db = null;
    PrintWriter mapPrinter = null;

    log.debug("generating help file with locale [" + locale + "]");
    try {
      log.debug("loading xml parser ..");
      db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    } catch (Exception e) {
      throw new HelpException("Error while loading an XML parser", e);
    }

    try {
      log.debug("creating map file [" + mapFile.getPath() + "] ..");
      mapPrinter = new PrintWriter(new BufferedOutputStream(new FileOutputStream(mapFile)));
      mapPrinter.println("<?xml version='1.0' encoding='ISO-8859-1' ?>");
      mapPrinter.println(
        "<!DOCTYPE map PUBLIC \"-//Sun Microsystems Inc.//DTD JavaHelp Map Version 1.0//EN\""
          + " \"http://java.sun.com/products/javahelp/map_1_0.dtd\">\n");
      mapPrinter.println("<!-- Do not change, this file is automatically generated -->");
      mapPrinter.println("<map version=\"1.0\">");
    } catch (Exception e) {
      throw new HelpException("Error while creating the map file", e);
    }

    try {
      log.debug("loading transformer ..");
      URL xslFile = getClass().getResource("/resources/xmlgui/help.xsl");
      transformer = TransformerFactory.newInstance().newTransformer(new StreamSource(xslFile.openStream()));
      transformer.setParameter("locale", locale);
    } catch (Exception e) {
      throw new HelpException("Error while constructing the transformer", e);
    }

    for (int i = 0; i < xmlFiles.length; i++) {
      String xmlFile = xmlFiles[i];
      String idName = xmlFile.substring(0, xmlFile.length() - 4);
      File sourceFile = new File(inDir.getPath() + "/" + xmlFile);
      File outputFile = new File(outDir.getPath() + "/" + idName + "." + locale + ".html");
      Document document = null;

      log.debug("loading help file [" + xmlFile + "]");
      try {
        document = db.parse(sourceFile);
        mapPrinter.println(
          "  <mapID target=\""
            + document.getDocumentElement().getAttribute("id")
            + "\" url=\""
            + outputFile.getName()
            + "\" />");
      } catch (Exception e) {
        throw new HelpException("Error while loading [" + xmlFile + "]", e);
      }

      if (outputFile.exists() && outputFile.lastModified() >= sourceFile.lastModified())
        continue;

      log.debug("transforming help file to [" + outputFile.getPath() + "]");
      StreamResult result = new StreamResult(outputFile);

      try {
        transformer.transform(new DOMSource(document), result);
      } catch (Exception e) {
        throw new HelpException("Error during the transformation of [" + xmlFile + "]", e);
      }
    }
    mapPrinter.println("</map>");
View Full Code Here

     
      Element elem = doc.createElement("sqlMap");
      elem.setAttribute("resource", "sqlMap.xml");
      sqlMapElem.item(0).appendChild(elem);
     
      Transformer trans = TransformerFactory.newInstance().newTransformer();
      File tempFile = File.createTempFile("sqlMapConfig", ".xml");
      tempFile.deleteOnExit();
      trans.transform(new DOMSource(doc),new StreamResult(tempFile));
     
      //从临时的配置文件中初始化sqlMapClient
      input = new FileInputStream(tempFile);
      SqlMapClientHolder.sqlMapClient = SqlMapClientBuilder
          .buildSqlMapClient(input);
View Full Code Here

                    try {
                       
                        // write schema to output file
                        name += ".xsd";
                        FileOutputStream out = new FileOutputStream(name);
                        Transformer transformer =
                            TransformerFactory.newInstance().newTransformer();
                        transformer.setOutputProperty("indent", "no");
                        DOMSource source = new DOMSource(schema);
                        Result result = new StreamResult(out);
                        transformer.transform(source, result);
                        out.close();
                        System.out.print("Wrote schema " + name);
                        if (tns.length() == 0) {
                            System.out.println(" for default namespace");
                        } else {
View Full Code Here

TOP

Related Classes of javax.xml.transform.Transformer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.