Examples of Templates


Examples of javax.xml.transform.Templates

        {
            return 0;
        }

        SAXTransformerFactory saxtf = (SAXTransformerFactory) tf;
        Templates templates = null;
        if (xslt != null) {
            templates = saxtf.newTemplates(xslt);
        }

        // configuring outHandlerFactory
View Full Code Here

Examples of javax.xml.transform.Templates

      else
        xsl = new StyleScript();

      xsl.setStylePath(stylePath);

      Templates stylesheet;

      stylesheet = xsl.newTemplates(xslName);

      for (; i < args.length; i++) {
        String name = args[i];

        Path xmlPath = Vfs.lookup(name);

        HashMap<String,Object> argMap = new HashMap<String,Object>();

        String []childArgs = new String[argList.size() + 1];
        argList.toArray(childArgs);
        childArgs[childArgs.length - 1] = name;

        argMap.put("arguments", childArgs);
        argMap.put("File", Vfs.lookup());

        ReadStream is = xmlPath.openRead();
        Document doc = null;
        try {
          if (isStrict)
            doc = new Xml().parseDocument(is);
          else {
            XmlParser parser = new Html();
            parser.setEntitiesAsText(true);
            doc = parser.parseDocument(is);
          }
        } finally {
          is.close();
        }

        //Document result = xsl.transform(doc, argMap);
        Document result = null;

        Path destPath = null;
        if (dest != null)
          destPath = Vfs.lookup(dest);
        else if (suffix != null)
          destPath = xmlPath.getParent();
        else
          destPath = Vfs.lookup("stdout:");

        if (suffix != null) {
          int p = name.lastIndexOf('.');
          if (p == -1) {
            System.err.println("suffix missing for `" + name + "'");
            System.exit(1);
          }

          String destName = name.substring(0, p);
          if (dest == null) {
            p = destName.lastIndexOf('/');
            if (p >= 0)
              destName = destName.substring(p + 1);
          }

          if (! destPath.isFile())
            destPath = destPath.lookup(destName + '.' + suffix);
          else {
            System.err.println("illegal output combination");
            System.exit(1);
          }
        }
        else if (destPath.isDirectory())
          destPath = destPath.lookup(name);

        try {
          destPath.getParent().mkdirs();
        } catch (IOException e) {
        }

        WriteStream os = destPath.openWrite();

        try {
          Properties output = stylesheet.getOutputProperties();

          String encoding = (String) output.get("encoding");
          String mimeType = (String) output.get("mime-type");
          String method = (String) output.get("method");

          if (encoding == null && (method == null || ! method.equals("html")))
            encoding = "UTF-8";

          TransformerImpl transformer =
            (TransformerImpl) stylesheet.newTransformer();

          if (encoding != null)
            os.setEncoding(encoding);

          transformer.setProperty("caucho.pwd", Vfs.lookup());
View Full Code Here

Examples of javax.xml.transform.Templates

          href = getStylesheetHref(doc);

        if (href == null)
          href = "default.xsl";

        Templates stylesheet = null;
       
        //Path path = Vfs.lookup(href);
        try {
          //ReadStream sis = path.openReadAndSaveBuffer();

          TransformerFactory factory;
         
          if (_chainingType.equals("x-application/stylescript"))
            factory = new StyleScript();
          else {
            factory = TransformerFactory.newInstance();
          }

          if (factory instanceof AbstractStylesheetFactory)
            ((AbstractStylesheetFactory) factory).setStylePath(_stylePath);

          Path path = null;

          if (href.startsWith("/"))
            path = Vfs.getPwd().lookup(_application.getRealPath(href));
          else {
            String servletPath = RequestAdapter.getPageServletPath(req);

            Path pwd = Vfs.getPwd();
            pwd = pwd.lookup(_application.getRealPath(servletPath));
            path = pwd.getParent().lookup(href);
          }

          if (! path.canRead()) {
            Thread thread = Thread.currentThread();
            ClassLoader loader = thread.getContextClassLoader();

            URL url = loader.getResource(href);

            if (url != null) {
              Path newPath = Vfs.getPwd().lookup(url.toString());
              if (newPath.canRead())
                path = newPath;
            }
          }

          Source source;
          if (path.canRead())
            source = new StreamSource(path.getURL());
          else
            source = new StreamSource(href);

          if (log.isLoggable(Level.FINE))
            log.fine(L.l("'{0}' XSLT filter using stylesheet {1}",
                         req.getRequestURI(), source.getSystemId()));

          stylesheet = factory.newTemplates(source);
        } finally {
          // is.close();
        }
       
        Transformer transformer = null;

        transformer = (Transformer) stylesheet.newTransformer();

        TransformerImpl cauchoTransformer = null;
        if (transformer instanceof TransformerImpl)
          cauchoTransformer = (TransformerImpl) transformer;
View Full Code Here

Examples of javax.xml.transform.Templates

              && ssNode instanceof ElemLiteralResult)
          {
            AVT avt = ((ElemLiteralResult)ssNode).getLiteralResultAttribute("href");
            String href = avt.evaluate(xctxt,xt, elem);
            String absURI = SystemIDResolver.getAbsoluteURI(href, sysId);
            Templates tmpl = saxTFactory.newTemplates(new StreamSource(absURI));
            TransformerHandler tHandler = saxTFactory.newTransformerHandler(tmpl);
            Transformer trans = tHandler.getTransformer();
           
            // AddTransformerHandler to vector
            vTHandler.addElement(tHandler);
View Full Code Here

Examples of javax.xml.transform.Templates

   */
  public XMLFilter newXMLFilter(Source src)
          throws TransformerConfigurationException
  {

    Templates templates = newTemplates(src);
    if( templates==null ) return null;
   
    return newXMLFilter(templates);
  }
View Full Code Here

Examples of javax.xml.transform.Templates

   */
  public TransformerHandler newTransformerHandler(Source src)
          throws TransformerConfigurationException
  {

    Templates templates = newTemplates(src);
    if( templates==null ) return null;
   
    return newTransformerHandler(templates);
  }
View Full Code Here

Examples of javax.xml.transform.Templates

   */
  public Transformer newTransformer(Source source)
          throws TransformerConfigurationException
  {
    try {
      Templates tmpl=newTemplates( source );
      /* this can happen if an ErrorListener is present and it doesn't
         throw any exception in fatalError.
         The spec says: "a Transformer must use this interface
         instead of throwing an exception" - the newTemplates() does
         that, and returns null.
      */
      if( tmpl==null ) return null;
      Transformer transformer = tmpl.newTransformer();
      transformer.setURIResolver(m_uriResolver);
      return transformer;
    } catch( TransformerConfigurationException ex ) {
      if( m_errorListener != null ) {
        try {
View Full Code Here

Examples of javax.xml.transform.Templates

        if (null != dumpFileName)
        {
          dumpWriter = new PrintWriter(new FileWriter(dumpFileName));
        }

        Templates stylesheet = null;

        if (null != xslFileName)
        {
          if (flavor.equals("d2d"))
          {

            // Parse in the xml data into a DOM
            DocumentBuilderFactory dfactory =
              DocumentBuilderFactory.newInstance();

            dfactory.setNamespaceAware(true);

            DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
            Node xslDOM = docBuilder.parse(new InputSource(xslFileName));

            stylesheet = tfactory.newTemplates(new DOMSource(xslDOM,
                    xslFileName));
          }
          else
          {
            // System.out.println("Calling newTemplates: "+xslFileName);
            stylesheet = tfactory.newTemplates(new StreamSource(xslFileName));
            // System.out.println("Done calling newTemplates: "+xslFileName);
          }
        }

        PrintWriter resultWriter;
        StreamResult strResult;

        if (null != outFileName)
        {
          strResult = new StreamResult(new FileOutputStream(outFileName));
          // One possible improvement might be to ensure this is
          //  a valid URI before setting the systemId, but that
          //  might have subtle changes that pre-existing users
          //  might notice; we can think about that later -sc r1.46
          strResult.setSystemId(outFileName);
        }
        else
        {
          strResult = new StreamResult(System.out);
    // We used to default to incremental mode in this case.
    // We've since decided that since the -INCREMENTAL switch is
    // available, that default is probably not necessary nor
    // necessarily a good idea.
        }

        SAXTransformerFactory stf = (SAXTransformerFactory) tfactory;
       
    // This is currently controlled via TransformerFactoryImpl.
        if (!useXSLTC && useSourceLocation)
           stf.setAttribute(XalanProperties.SOURCE_LOCATION, Boolean.TRUE);       

        // Did they pass in a stylesheet, or should we get it from the
        // document?
        if (null == stylesheet)
        {
          Source source =
            stf.getAssociatedStylesheet(new StreamSource(inFileName), media,
                                        null, null);

          if (null != source)
            stylesheet = tfactory.newTemplates(source);
          else
          {
            if (null != media)
              throw new TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_NO_STYLESHEET_IN_MEDIA, new Object[]{inFileName, media})); //"No stylesheet found in: "
                                            // + inFileName + ", media="
                                            // + media);
            else
              throw new TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_NO_STYLESHEET_PI, new Object[]{inFileName})); //"No xml-stylesheet PI found in: "
                                             //+ inFileName);
          }
        }

        if (null != stylesheet)
        {
          Transformer transformer = flavor.equals("th") ? null : stylesheet.newTransformer();

          // Override the output format?
          if (null != outputType)
          {
            transformer.setOutputProperty(OutputKeys.METHOD, outputType);
          }

          if (transformer instanceof org.apache.xalan.transformer.TransformerImpl)
          {
            org.apache.xalan.transformer.TransformerImpl impl = (org.apache.xalan.transformer.TransformerImpl)transformer;
            TraceManager tm = impl.getTraceManager();

            if (null != tracer)
              tm.addTraceListener(tracer);

            impl.setQuietConflictWarnings(quietConflictWarnings);

      // This is currently controlled via TransformerFactoryImpl.
            if (useSourceLocation)
              impl.setProperty(XalanProperties.SOURCE_LOCATION, Boolean.TRUE);

      if(recursionLimit>0)
        impl.setRecursionLimit(recursionLimit);

            // sc 28-Feb-01 if we re-implement this, please uncomment helpmsg in printArgOptions
            // impl.setDiagnosticsOutput( setQuietMode ? null : diagnosticsWriter );
          }

          int nParams = params.size();

          for (int i = 0; i < nParams; i += 2)
          {
            transformer.setParameter((String) params.elementAt(i),
                                     (String) params.elementAt(i + 1));
          }

          if (uriResolver != null)
            transformer.setURIResolver(uriResolver);

          if (null != inFileName)
          {
            if (flavor.equals("d2d"))
            {

              // Parse in the xml data into a DOM
              DocumentBuilderFactory dfactory =
                DocumentBuilderFactory.newInstance();

              dfactory.setCoalescing(true);
              dfactory.setNamespaceAware(true);

              DocumentBuilder docBuilder = dfactory.newDocumentBuilder();

              if (entityResolver != null)
                docBuilder.setEntityResolver(entityResolver);

              Node xmlDoc = docBuilder.parse(new InputSource(inFileName));
              Document doc = docBuilder.newDocument();
              org.w3c.dom.DocumentFragment outNode =
                doc.createDocumentFragment();

              transformer.transform(new DOMSource(xmlDoc, inFileName),
                                    new DOMResult(outNode));

              // Now serialize output to disk with identity transformer
              Transformer serializer = stf.newTransformer();
              Properties serializationProps =
                stylesheet.getOutputProperties();

              serializer.setOutputProperties(serializationProps);

              if (contentHandler != null)
              {
View Full Code Here

Examples of javax.xml.transform.Templates

     * Compile Templates from an input URL.
     */
    protected Templates compileTemplates(URL source) throws Exception
    {
        StreamSource xslin = new StreamSource(source.openStream());
        Templates root = tfactory.newTemplates(xslin);
        return root;
    }
View Full Code Here

Examples of javax.xml.transform.Templates

            if (url == null)
            {
                return null;
            }

            Templates sr = compileTemplates(url);

            if (caching)
            {
                cache.put(xslName, sr);
            }
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.