Package javax.xml.transform

Examples of javax.xml.transform.Transformer


    public SAXSource invoke(SAXSource request) {
        SAXSource response = new SAXSource();
        try {
           
            DOMResult domResult = new DOMResult();
            Transformer transformer = TransformerFactory.newInstance().newTransformer();
            transformer.transform(request, domResult);
            Node n = domResult.getNode().getFirstChild();

            while (n.getNodeType() != Node.ELEMENT_NODE) {
                n = n.getNextSibling();
            }
View Full Code Here


    public StreamSource invoke(StreamSource request) {
        StreamSource response = new StreamSource();
        try {
            DOMResult domResult = new DOMResult();
            Transformer transformer = TransformerFactory.newInstance().newTransformer();
            transformer.transform(request, domResult);
            Node n = domResult.getNode().getFirstChild();

            while (n.getNodeType() != Node.ELEMENT_NODE) {
                n = n.getNextSibling();
            }
View Full Code Here

            StreamSource xml = new StreamSource( xmlstream );

            /* Transform */
            StreamResult output = new StreamResult( response.getWriter(  ) );
            Transformer  transformer = factory.newTransformer( xsl );
            Map          params = getXslParameters( request, response );
            if ( params != null )
            {
                Iterator it = params.keySet(  ).iterator(  );
                while ( it.hasNext(  ) )
                {
                    String key = ( String ) it.next(  );
                    transformer.setParameter( key, params.get( key ) );
                }
            }

            transformer.transform( xml, output );
        }
        catch ( TransformerConfigurationException t )
        {
            throw new PortletException( t );
        }
View Full Code Here

          * this causes problems;
          * so we convert the stylesheet to byte[] and use this as input stream
          */
         {
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            Transformer transformer = tFactory.newTransformer();
            DOMSource source = new DOMSource(_xsltElement);
            StreamResult result = new StreamResult(os);

            transformer.transform(source, result);

            stylesheet =
               new StreamSource(new ByteArrayInputStream(os.toByteArray()));
         }

         Transformer transformer = tFactory.newTransformer(stylesheet);
         if (baos==null) {
               ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
               StreamResult outputTarget = new StreamResult(baos1);
               transformer.transform(xmlSource, outputTarget);
               return new XMLSignatureInput(baos1.toByteArray());

         }
         StreamResult outputTarget = new StreamResult(baos);

         transformer.transform(xmlSource, outputTarget);        
         XMLSignatureInput output=new XMLSignatureInput((byte[])null);
         output.setOutputStream(baos);
         return output;
      } catch (XMLSecurityException ex) {
         Object exArgs[] = { ex.getMessage() };
View Full Code Here

        StringWriter stringWriter = new StringWriter();
        StreamResult streamResult = new StreamResult(stringWriter);

        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer;
        try {
            transformer = transformerFactory.newTransformer();
        } catch (TransformerConfigurationException e) {
            throw new IllegalStateException("Unable to get a new transformer", e);
        }

        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

        // transform OUTPUT
        try {
            transformer.transform(new DOMSource(document), streamResult);
        } catch (TransformerException e) {
            throw new IllegalStateException("Unable to transform the document", e);
        }

        return stringWriter.toString();
View Full Code Here

    // Once again we are using a factory of some sort,
    // this time for getting a Transformer instance,
    // which we use to output the XML
    TransformerFactory transformerFactory = TransformerFactory
        .newInstance();
    Transformer transformer = transformerFactory.newTransformer();

    // Indenting the XML
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");

    // The actual output to a file goes here
    transformer.transform(source, result);

    return true;
  }
View Full Code Here

              String msg = Utils.messages.createMessage(
                  MsgKey.ER_ENCODING_NOT_SUPPORTED,new Object[]{ encoding });
              try
              {
                // Prepare to issue the warning message
                Transformer tran = super.getTransformer();
                if (tran != null) {
                  ErrorListener errHandler = tran.getErrorListener();
                  // Issue the warning message
                  if (null != errHandler && m_sourceLocator != null)
                    errHandler.warning(new TransformerException(msg, m_sourceLocator));
                  else
                    System.out.println(msg);
View Full Code Here

    public static void printDocument(Document document, String fname){
        try{

            TransformerFactory tf = TransformerFactory.newInstance();
            Transformer transformer = tf.newTransformer();
            DOMSource source = new DOMSource(document);
            StreamResult result;

            if (fname == null)
                result = new StreamResult(System.out);
            else
                result = new StreamResult(new FileWriter(fname));

            transformer.transform(source, result);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
View Full Code Here

  public String toString() {
    StringWriter sresult = new StringWriter();
       try {
           DOMSource source = new DOMSource(getDOMrepresentation());
           StreamResult result = new StreamResult(sresult);
           Transformer trans = TransformerFactory.newInstance().newTransformer();
           trans.setOutputProperty(OutputKeys.INDENT, "yes");
           trans.transform(source, result);
          }
          catch (Exception e) {
            throw new Error(e);
          }
        return sresult.toString();
View Full Code Here

  public String toString() {
    StringWriter sresult = new StringWriter();
       try {
           DOMSource source = new DOMSource(getDOMrepresentation());
           StreamResult result = new StreamResult(sresult);
           Transformer trans = TransformerFactory.newInstance().newTransformer();
           trans.setOutputProperty(OutputKeys.INDENT, "yes");
           trans.transform(source, result);
          }
          catch (Exception e) {
            throw new Error(e);
          }
        return sresult.toString();
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.