Package javax.xml.transform

Examples of javax.xml.transform.Transformer


    Document xmlNew = null;
    DOMResult domResult = new DOMResult();

    try
    {
      Transformer transformer = getXSLTransformer(xslFile);
      transformer.transform(new DOMSource(xmlOld), domResult);
      xmlNew = (Document) domResult.getNode();
      applyStylets(xmlNew, message);
    }
    catch (TransformerConfigurationException e)
    {
View Full Code Here


   * processing. The <code>Transformers</code> are cached for every thread
   * and every XSLT stylesheet.
   */
  protected Transformer getXSLTransformer(String xslFile) throws XException
  {
    Transformer transformer = null;

    try
    {
      transformer = (Transformer) mTransformers.get(Thread
          .currentThread().getName()
View Full Code Here

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

    try
    {
      Transformer transformer = getXSLTransformer(xslFile);
      transformer.transform(streamSource, streamResult);
      xmlNew = result.toString();
      source.close();
      result.close();
    }
    catch (IOException e)
View Full Code Here

   * processing. The <code>Transformers</code> are cached for every thread
   * and every XSLT stylesheet.
   */
  protected Transformer getXSLTransformer(String xslFile) throws XException
  {
    Transformer transformer = null;

    try
    {
      transformer = (Transformer) mTransformers.get(Thread
          .currentThread().getName()
View Full Code Here

    *
    * @param filename
    * @return
    */
   private synchronized Transformer getTransformerAlsoFromCache(String filename, String secondChoice, String thirdChoice, ClassLoader cl) {
      Transformer ret = (Transformer)this.transformers.get(filename);
      if (ret != null)
         return ret;

      if (this.checkedTransformers.contains(filename))
         return null;
View Full Code Here

      if(systemId != null)
          xslStreamSource = new StreamSource(new StringReader(xslString), systemId);
      else
          xslStreamSource = new StreamSource(new StringReader(xslString));

      Transformer transformer = transformerFactory.newTransformer(xslStreamSource);
      if(params != null) {
          Iterator iter = params.entrySet().iterator();
          while(iter.hasNext()) {
              Map.Entry entry = (Map.Entry)iter.next();
              transformer.setParameter((String)entry.getKey(), (String)entry.getValue());
          }
      }
      return transformer;
   }
View Full Code Here

      String xslt = getXslStringFromFile(filename, cl);
      return newTransformer(systemId, xslt, uriResolver, map);
   }

   private byte[] doXSLTransformation(String filename, String secondChoice, String thirdChoice, byte[] in, ClassLoader cl) throws Exception {
      Transformer transformer = getTransformerAlsoFromCache(filename, secondChoice, thirdChoice, cl);
      if (transformer == null) {
         log.warning("Transformer for file '" + filename + "' not found (where second choice was '" + secondChoice + "' and third choice was '" + thirdChoice +  "', will return it without modification");
         return in;
      }
      else {
         StreamSource xmlStreamSource = new StreamSource(new ByteArrayInputStream(in));
         ByteArrayOutputStream baos = new ByteArrayOutputStream(in.length);
         StreamResult resultStream = new StreamResult(baos);
         transformer.transform(xmlStreamSource, resultStream);
         return baos.toByteArray();
      }
   }
View Full Code Here

   }
  
   public InputStream doXSLTransformation(String filename, InputStream in,
                  ClassLoader cl) throws Exception {
      // TODO: Add a cache!
      Transformer transformer = newTransformer(filename, cl);
      if (transformer == null) {
         log.warning("Transformer for file '" + filename + "' not found");
         return in;
      } else {
         StreamSource xmlStreamSource = new StreamSource(in);
         ByteArrayOutputStream baos = new ByteArrayOutputStream(2048);
         StreamResult resultStream = new StreamResult(baos);
         transformer.transform(xmlStreamSource, resultStream);
         ByteArrayInputStream bin = new ByteArrayInputStream(baos.toByteArray());
         return bin;
      }
   }
View Full Code Here

    public DOMSource invoke(DOMSource request) {
        DOMSource response = new DOMSource();
        try {
            System.out.println("Incoming Client Request as a DOMSource data in PAYLOAD Mode");
            Transformer transformer = TransformerFactory.newInstance().newTransformer();
            StreamResult result = new StreamResult(System.out);
            transformer.transform(request, result);
            System.out.println("\n");
           
            InputStream is = getClass().getResourceAsStream("GreetMeDocLiteralResp3.xml");
           
            SOAPMessage greetMeResponse =  MessageFactory.newInstance().createMessage(null, is);
View Full Code Here

        return this.indent != -1;
    }
   
    public void writeTo(Node node, OutputStream os) {
        try {
            Transformer it = newTransformer();
           
            it.setOutputProperty(OutputKeys.METHOD, "xml");
            if (indent()) {
                it.setOutputProperty(OutputKeys.INDENT, "yes");
                it.setOutputProperty("{http://xml.apache.org/xslt}indent-amount",
                                     Integer.toString(this.indent));
            }
            it.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, omitXmlDecl);
            it.setOutputProperty(OutputKeys.ENCODING, charset);
            it.transform(new DOMSource(node), new StreamResult(os));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
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.