Examples of Transformer


Examples of javax.xml.transform.Transformer

  throws java.io.IOException,
         java.net.MalformedURLException,
         org.xml.sax.SAXException  {

    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer = null;
    try {
      transformer = tFactory.newTransformer(new StreamSource(xslDocUri));
//      transformer = tFactory.newTransformer(new StreamSource(new ByteArrayInputStream(xslDoc.getBytes())));
      transformer.transform(
        new StreamSource(new ByteArrayInputStream(xmlDoc)),
        new StreamResult(outputURL));
    }
    catch (Exception e) {
      throw new IOException(e.getMessage());
View Full Code Here

Examples of javax.xml.transform.Transformer

    ByteArrayInputStream iStream = new ByteArrayInputStream(xmlDoc);
    ByteArrayOutputStream boutArray = new ByteArrayOutputStream();

    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer = null;
    try {
      transformer = tFactory.newTransformer(new StreamSource(xslDocUri));
    }
    catch (Exception e) {
      logger.fatal(e.getMessage(), e);
      throw new IOException(e.getMessage());
    }
    try {
      transformer.transform(
        new StreamSource(iStream),
        new StreamResult(boutArray));
      return boutArray;
    }
    catch (Exception e) {
View Full Code Here

Examples of javax.xml.transform.Transformer

     */
    public String generateXMLString() throws IOException, TransformerConfigurationException,
                    TransformerException {
       
        StringWriter strWriter = new StringWriter();
        Transformer tr = TransformerFactory.newInstance().newTransformer();
        tr.setOutputProperty(OutputKeys.INDENT, "yes");
        tr.setOutputProperty(OutputKeys.METHOD, "xml");
        tr.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        tr.setOutputProperty(OutputKeys.VERSION, "1.0");
        tr.setOutputProperty(OutputKeys.ENCODING, "UTF-8");

        Document document = generateCapabilitiesDocument();
       
        // system id not transformed by default transformer
        tr.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, document.getDoctype().getSystemId());
       
        // Serialize XML Document
        tr.transform(new DOMSource(document), new StreamResult(strWriter));
        return strWriter.toString();
    }
View Full Code Here

Examples of javax.xml.transform.Transformer

        doc.appendChild(root);

        StringWriter strWriter = new StringWriter();
//        XMLSerializer serializer = null;
//        OutputFormat outFormat = null;
        Transformer tr = TransformerFactory.newInstance().newTransformer();
        tr.setOutputProperty(OutputKeys.INDENT, "yes");
        tr.setOutputProperty(OutputKeys.METHOD,"xml");
        tr.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        tr.setOutputProperty(OutputKeys.VERSION,"1.0");
        tr.setOutputProperty(OutputKeys.ENCODING,"UTF-8");
       
//      Serialize XML Document
        tr.transform( new DOMSource(doc),new StreamResult(strWriter));   

//        try {
//            serializer = new XMLSerializer();
//            strWriter = new StringWriter();
//            outFormat = new OutputFormat();
View Full Code Here

Examples of javax.xml.transform.Transformer

      } else if (eventName.equals("ok")) {
        String pkg = (String) dataModel.getValue("package");
        File file = (File) dataModel.getValue("file");

        URL url = this.getClass().getResource(SKELETON_XSL);
        Transformer transformer =
          TransformerFactory.newInstance().newTransformer(new StreamSource(url.openStream()));
        if (pkg.indexOf('.') != -1) {
          transformer.setParameter("package", pkg.substring(0, pkg.lastIndexOf('.')));
          transformer.setParameter("class", pkg.substring(pkg.lastIndexOf(".") + 1, pkg.length()));
        } else {
          transformer.setParameter("package", "");
          transformer.setParameter("class", pkg);
        }
       

        transformer.transform(new DOMSource(document), new StreamResult(file));

        dialog.dispose();
      } else {
        File newFile = DialogUtils.showSaveFileDialog(dialog, "java");
        if (newFile != null) {
View Full Code Here

Examples of javax.xml.transform.Transformer

      if (DebugFile.trace) DebugFile.writeln("WeakHashMap.put("+sFilePath+", SheetEntry)");
      oCache.put(sFilePath, oSheet);
    } // fi

    if (DebugFile.trace) DebugFile.writeln("javax.xml.transform.Templates.newTransformer()");
    Transformer oTransformer = oSheet.templates.newTransformer();

    if (DebugFile.trace) {
      DebugFile.decIdent();
      if (null==oTransformer)
        DebugFile.writeln("End StylesheetCache.newTransformer() : null");
    else
        DebugFile.writeln("End StylesheetCache.newTransformer() : " + oTransformer.toString());
    }

    return oTransformer;
  } // newTransformer()
View Full Code Here

Examples of javax.xml.transform.Transformer

      DebugFile.writeln("Begin StylesheetCache.transform(" + sStyleSheetPath + ", InputStream, Properties)");
      DebugFile.incIdent();
    }

    Transformer oTransformer = StylesheetCache.newTransformer(sStyleSheetPath);

    if (null!=oProps) setParameters(oTransformer, oProps);

    StreamSource oStreamSrcXML = new StreamSource(oXMLInputStream);

    StreamResult oStreamResult = new StreamResult(oOutputStream);

    if (DebugFile.trace) DebugFile.writeln("Transformer.transform(StreamSource,StreamResult)");

    oTransformer.transform(oStreamSrcXML, oStreamResult);

    if (DebugFile.trace) {
      DebugFile.writeln("done in " + String.valueOf(System.currentTimeMillis()-lElapsed) + " miliseconds");
      DebugFile.decIdent();
      DebugFile.writeln("End StylesheetCache.transform()");
View Full Code Here

Examples of javax.xml.transform.Transformer

      DebugFile.writeln("XML input file encoding is "+sEncoding);
    }

    ByteArrayOutputStream oOutputStream = new ByteArrayOutputStream();
    ByteArrayInputStream oXMLInputStream = new ByteArrayInputStream(sXMLInput.getBytes(sEncoding));
    Transformer oTransformer = StylesheetCache.newTransformer(sStyleSheetPath);
    if (null!=oProps) setParameters(oTransformer, oProps);
    StreamSource oStreamSrcXML = new StreamSource(oXMLInputStream);
    StreamResult oStreamResult = new StreamResult(oOutputStream);
    if (DebugFile.trace) DebugFile.writeln("Transformer.transform(StreamSource,StreamResult)");
    oTransformer.transform(oStreamSrcXML, oStreamResult);
    oStreamSrcXML = null;
    oXMLInputStream.close();
    String sRetVal = oOutputStream.toString(sEncoding);
    if (DebugFile.trace) {
      if (null==sRetVal)
View Full Code Here

Examples of javax.xml.transform.Transformer

    ByteArrayOutputStream oOutputStream = new ByteArrayOutputStream();

    TransformerFactory oFactory = TransformerFactory.newInstance();
    StreamSource oStreamSrc = new StreamSource(oStyleSheetStream);
    Templates oTemplates = oFactory.newTemplates(oStreamSrc);
    Transformer oTransformer = oTemplates.newTransformer();

    if (null!=oProps) setParameters(oTransformer, oProps);
    StreamSource oStreamSrcXML = new StreamSource(oXMLInputStream);
    StreamResult oStreamResult = new StreamResult(oOutputStream);
    if (DebugFile.trace) DebugFile.writeln("Transformer.transform(StreamSource,StreamResult)");
    oTransformer.transform(oStreamSrcXML, oStreamResult);
    oStreamSrcXML = null;
    oXMLInputStream.close();
    String sRetVal = oOutputStream.toString(sEncoding);
    if (DebugFile.trace) {
      if (null==sRetVal)
View Full Code Here

Examples of javax.xml.transform.Transformer

            throw new IllegalArgumentException("HTMLwithXSLBuilder2::transform : Illegal argument for HTML output");
        }

      try {
          TransformerFactory tFactory = TransformerFactory.newInstance();
          Transformer transformer = tFactory.newTransformer(tXslSource);

            // Set the Stylesheet params (if any)
            if (aParamList != null) {
                String tKey;
                Object tValue;
                for (Enumeration tKeys = aParamList.keys() ; tKeys.hasMoreElements() ;) {
                    tKey = (String) tKeys.nextElement();
                    tValue = aParamList.get(tKey);
                    if (tValue == null) {
                        // Should never happen
                        throw new ProgrammerException
                                    ("HTMLwithXSLBuilder2: internal error, problem with Hashtable aParamList");
                    }
                    transformer.setParameter(tKey,  /* parameter name */
                               tValue /* parameter value */ );
                }
            }

          // Use the transformer to apply the Stylesheet to an XML document
          // and write the output to the specified Result object.
          transformer.transform(tXmlSource, tOutputTarget);

         } catch(TransformerFactoryConfigurationError ex) {
            throw new ProgrammerException
                        ("HTMLwithXSLBuilder2: transform returns TransformerFactoryConfigurationError: " + ex.getMessage());
         } catch(TransformerConfigurationException ex) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.