Package javax.xml.transform

Examples of javax.xml.transform.Transformer


  public static void toString(Document doc, String encoding, Writer w, boolean indent) throws TransformerFactoryConfigurationError, TransformerException {
    Source source = new DOMSource(doc);
    Result result = new StreamResult(w);

    Transformer xformer = TransformerFactory.newInstance().newTransformer();
    xformer.setOutputProperty(OutputKeys.ENCODING, encoding);

    if (indent) {
      xformer.setOutputProperty(OutputKeys.INDENT, "yes");
    }

    xformer.transform(source, result);
  }
View Full Code Here


    Source source = new DOMSource(doc);

    // Prepare the output file
    Result result = new StreamResult(file);

    Transformer xformer = TransformerFactory.newInstance().newTransformer();

    xformer.setOutputProperty(OutputKeys.ENCODING, encoding);
   
    if (indent) {
      xformer.setOutputProperty(OutputKeys.INDENT, "yes");
    }

    xformer.transform(source, result);

  }
View Full Code Here

    // Prepare the output file
    Result result = new StreamResult(file);

    // Write the DOM document to the file
    Transformer xformer = TransformerFactory.newInstance().newTransformer();

    if(outputKeys != null){

      for(Entry<String,String> entry : outputKeys){

        xformer.setOutputProperty(entry.getKey(), entry.getValue());
      }
    }

    xformer.transform(source, result);

  }
View Full Code Here

            AttributesImpl attrs = new AttributesImpl();
            StreamResult result = new StreamResult(stream);
            SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory
                    .newInstance();
            TransformerHandler handler = factory.newTransformerHandler();
            Transformer serializer = handler.getTransformer();
            serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
            serializer.setOutputProperty(OutputKeys.INDENT, "yes");
            serializer.setOutputProperty(OutputKeys.METHOD, "xml");
            serializer.setOutputProperty(
                    "{http://xml.apache.org/xslt}indent-amount", "4");
            handler.setResult(result);
            handler.startDocument();
            addAttribute("name", getProject().getProjectName(), attrs);
            addAttribute("company", getProject().getOrganization(), attrs);
View Full Code Here

    }

    protected TransformerHandler createHandler(String xsltPath) {
        try {
            TransformerHandler result = getTransformerFactory().newTransformerHandler(new StreamSource(xsltPath));
            Transformer transformer = result.getTransformer();
            transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            transformer.setOutputProperty(
                    "{http://xml.apache.org/xslt}indent-amount", "4");
            return result;

        } catch (TransformerConfigurationException e) {
            myUIFacade.showErrorDialog(e);
View Full Code Here

            AttributesImpl attrs = new AttributesImpl();
            StreamResult result = new StreamResult(os);
            SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory
                    .newInstance();
            TransformerHandler handler = factory.newTransformerHandler();
            Transformer serializer = handler.getTransformer();
            serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
            serializer.setOutputProperty(OutputKeys.INDENT, "yes");
            serializer.setOutputProperty(
                    "{http://xml.apache.org/xslt}indent-amount", "4");
            handler.setResult(result);
            handler.startDocument();

            handler.endDocument();
View Full Code Here

            AttributesImpl attrs = new AttributesImpl();
            StreamResult result = new StreamResult(os);
            SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory
                    .newInstance();
            TransformerHandler handler = factory.newTransformerHandler();
            Transformer serializer = handler.getTransformer();
            serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
            serializer.setOutputProperty(OutputKeys.INDENT, "yes");
            serializer.setOutputProperty(
                    "{http://xml.apache.org/xslt}indent-amount", "4");
            handler.setResult(result);
            handler.startDocument();

            handler.endDocument();
View Full Code Here

                    + System.getProperty("file.separator") + sFileName);
            // DataOutputStream fout = new DataOutputStream(new
            // FileOutputStream(file));
            TransformerHandler handler = ((SAXTransformerFactory) SAXTransformerFactory
                    .newInstance()).newTransformerHandler();
            Transformer serializer = handler.getTransformer();
            serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
            serializer.setOutputProperty(OutputKeys.INDENT, "yes");
            serializer.setOutputProperty(
                    "{http://xml.apache.org/xslt}indent-amount", "4");
            handler.setResult(new StreamResult(file));
            handler.startDocument();
            // handler.startDTD("ganttproject.sourceforge.net",
            // "-//GanttProject.org//DTD GanttProject-1.x//EN",
View Full Code Here

    }
  }

  private void saveXml(String fileName){
     TransformerFactory transFactory=TransformerFactory.newInstance();
     Transformer transformer = null;
    try {
      transformer = transFactory.newTransformer();
      transformer.setOutputProperty("indent", "yes");
          DOMSource source=new DOMSource();
          source.setNode(doc);
          StreamResult result=new StreamResult();
          FileOutputStream fileOutputStream =  new FileOutputStream(fileName);
          result.setOutputStream(fileOutputStream);
      transformer.transform(source, result);
      fileOutputStream.close();

    } catch (TransformerConfigurationException e) {
      e.printStackTrace();
    }catch (FileNotFoundException e) {
View Full Code Here

        if (source == null) {
            throw Util.nullArgument("source");
        }

        Transformer           transformer =
            JDBCSQLXML.getIdentityTransformer();
        StreamResult          result      = new StreamResult();
        ByteArrayOutputStream baos        = new ByteArrayOutputStream();
        GZIPOutputStream      gzos;

        try {
            gzos = new GZIPOutputStream(baos);
        } catch (IOException ex) {
            throw Exceptions.transformFailed(ex);
        }
        result.setOutputStream(gzos);

        try {
            transformer.transform(source, result);
        } catch (TransformerException ex) {
            throw Exceptions.transformFailed(ex);
        }

        try {
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.