Package org.apache.xalan.templates

Examples of org.apache.xalan.templates.ElemTemplate


     
    // loop from the top index down to the recursion limit (I don't think
    // there's any need to go below that).
    for (int i = (nTemplates - 1); i >= m_recursionLimit; i--)
    {
      ElemTemplate template = getNextMatchOrNamedTemplate(i);
     
      if(null == template)
        break;
       
      int loopCount = countLikeTemplates(template, i);
     
      if (loopCount >= m_recursionLimit)
      {
        // throw new TransformerException("Template nesting too deep. nesting = "+loopCount+
        //   ", template "+((null == template.getName()) ? "name = " : "match = ")+
        //   ((null != template.getName()) ? template.getName().toString()
        //   : template.getMatch().getPatternString()));
       
        String idIs = XSLMessages.createMessage(((null != template.getName()) ? "nameIs" : "matchPatternIs"), null);
          Object[] msgArgs = new Object[]{ new Integer(loopCount), idIs,
                     ((null != template.getName()) ? template.getName().toString()
           : template.getMatch().getPatternString()) };
          String msg = XSLMessages.createMessage("recursionTooDeep", msgArgs);

        throw new TransformerException(msg);
      }
    }
View Full Code Here


   * the function, null if none exists.
   */
  public ElemExsltFunction getFunction(String funcName)
  {
    QName qname = new QName(m_namespace, funcName);
    ElemTemplate templ = m_stylesheet.getTemplateComposed(qname);
    if (templ != null && templ instanceof ElemExsltFunction)
      return (ElemExsltFunction) templ;
    else
      return null;   
  }
View Full Code Here

          processor.getExecContext().addExtensionNamespace ((String)key,
                                                            (ExtensionFunctionHandler)m_extensionNamespaces.get(key));
        }*/

        // Find the root pattern in the XSL.
        ElemTemplate rootRule = m_sRootObject.getTemplateComposed(processor.getTransformer().getXPathContext(), sourceTree, null, -1, false);
                               //this.findTemplate(processor, sourceTree, sourceTree);

        if(null == rootRule)
        {
          rootRule = m_sRootObject.getDefaultRootRule();
        }

        DocumentHandler docHandler = outputTarget.getDocumentHandler();

        OutputFormat formatter = getOutputFormat();

        if(null != outputTarget.getEncoding())
          formatter.setEncoding(outputTarget.getEncoding());

        if(null != docHandler)
        {
          processor.setDocumentHandler(docHandler);
        }
        else if(null != outputTarget.getByteStream())
        {
         /* if (!(processor.getXMLProcessorLiaison()..getIndent() < 0))
          {
            // This is to get around differences between Xalan and Xerces.
            // Xalan uses -1 as default for no indenting, Xerces uses 0.
            // So we just bump up the indent value here because we will
            // subtract from it at output time (FormatterToXML.init());
            formatter.setIndent(processor.m_parserLiaison.getIndent() + 1);
          }*/
          processor.setDocumentHandler(makeSAXSerializer(outputTarget.getByteStream(),
                                                               formatter));
        }
        else if(null != outputTarget.getCharacterStream())
        {
        /*  if (!(processor.m_parserLiaison.getIndent() < 0))
          {
            formatter.setIndent(processor.m_parserLiaison.getIndent() + 1);
          }*/
          processor.setDocumentHandler(makeSAXSerializer(outputTarget.getCharacterStream(),
                                                               formatter));
        }
        else if(null != outputTarget.getFileName())
        {
          /*if (!(processor.m_parserLiaison.getIndent() < 0))
          {
            formatter.setIndent(processor.m_parserLiaison.getIndent() + 1);
          }*/
          ostream = new FileOutputStream(outputTarget.getFileName());
          processor.setDocumentHandler( makeSAXSerializer(ostream, formatter));
        }
        else if(null != outputTarget.getNode())
        {
          ParserAdapter handler = new ParserAdapter(new org.apache.xerces.parsers.SAXParser());
          // Patch from Costin Manolache
//          if( "org.apache.xalan.xpath.dtm.DTMLiaison".equals( processor.getXMLProcessorLiaison().getClass().getName()))
//            processor.error(XSLTErrorResources.ER_CANT_USE_DTM_FOR_OUTPUT); //Can't use a DTMLiaison for an output DOM node... pass a org.apache.xalan.xpath.xdom.XercesLiaison instead!");
         
          switch(outputTarget.getNode().getNodeType())
          {
          case Node.DOCUMENT_NODE:           
            handler.setContentHandler(new FormatterToDOM((Document)outputTarget.getNode()).getSerializerObject());
            processor.setDocumentHandler(handler);
            break;
          case Node.DOCUMENT_FRAGMENT_NODE:
            handler.setContentHandler(new FormatterToDOM(outputTarget.getNode().getOwnerDocument(), // PR:DMAN4M6PK5 Submitted by:<bk@viae.de>
                                                       (DocumentFragment)outputTarget.getNode()).getSerializerObject());
            processor.setDocumentHandler(handler);
            break;
          case Node.ELEMENT_NODE:
            handler.setContentHandler(new FormatterToDOM(outputTarget.getNode().getOwnerDocument(), // PR:DMAN4M6PK5 Submitted by:<bk@viae.de>
                                                       (Element)outputTarget.getNode()).getSerializerObject());
            processor.setDocumentHandler(handler);
            break;
          default:
            m_sRootObject.error(XSLTErrorResources.ER_CAN_ONLY_OUTPUT_TO_ELEMENT); //"Can only output to an Element, DocumentFragment, Document, or PrintWriter.");
          }
        }
        else
        {
          ParserAdapter handler = new ParserAdapter(new org.apache.xerces.parsers.SAXParser());
          outputTarget.setNode(processor.getXMLProcessorLiaison().createDocument());
          handler.setContentHandler(new FormatterToDOM((Document)outputTarget.getNode()).getSerializerObject());
          processor.setDocumentHandler(handler);
        }

       // processor.resetCurrentState(sourceTree);
       // processor.m_rootDoc = sourceTree;

        if(null != processor.m_diagnosticsPrintWriter)
        {
          processor.diag("=============================");
          processor.diag("Transforming...");
          processor.pushTime(sourceTree);
        }

       // processor.getVarStack().pushContextMarker();
      //  try
      //  {
      //    processor.resolveTopLevelParams();
      //  }
      //  catch(Exception e)
      //  {
      //    throw new SAXException(XSLMessages.createMessage(XSLTErrorResources.ER_PROCESS_ERROR, null), e); //"StylesheetRoot.process error", e);
      //  }

        processor.getTransformer().getResultTreeHandler().startDocument();

        // Output the action of the found root rule.  All processing
        // occurs from here.  buildResultFromTemplate is highly recursive.
        rootRule.execute(processor.getTransformer(), sourceTree, null);

         processor.getTransformer().getResultTreeHandler().endDocument();

        // Reset the top-level params for the next round.
        // processor.m_topLevelParams = new Vector();
View Full Code Here

          processor.getExecContext().addExtensionNamespace ((String)key,
                                                            (ExtensionFunctionHandler)m_extensionNamespaces.get(key));
        }*/

        // Find the root pattern in the XSL.
        ElemTemplate rootRule = m_sRootObject.getTemplateComposed(processor.getTransformer().getXPathContext(), sourceTree, null, -1, false);
                               //this.findTemplate(processor, sourceTree, sourceTree);

        if(null == rootRule)
        {
          rootRule = m_sRootObject.getDefaultRootRule();
        }

        DocumentHandler docHandler = outputTarget.getDocumentHandler();

        OutputFormat formatter = getOutputFormat();

        if(null != outputTarget.getEncoding())
          formatter.setEncoding(outputTarget.getEncoding());

        if(null != docHandler)
        {
          processor.setDocumentHandler(docHandler);
        }
        else if(null != outputTarget.getByteStream())
        {
         /* if (!(processor.getXMLProcessorLiaison()..getIndent() < 0))
          {
            // This is to get around differences between Xalan and Xerces.
            // Xalan uses -1 as default for no indenting, Xerces uses 0.
            // So we just bump up the indent value here because we will
            // subtract from it at output time (FormatterToXML.init());
            formatter.setIndent(processor.m_parserLiaison.getIndent() + 1);
          }*/
          processor.setDocumentHandler(makeSAXSerializer(outputTarget.getByteStream(),
                                                               formatter));
        }
        else if(null != outputTarget.getCharacterStream())
        {
        /*  if (!(processor.m_parserLiaison.getIndent() < 0))
          {
            formatter.setIndent(processor.m_parserLiaison.getIndent() + 1);
          }*/
          processor.setDocumentHandler(makeSAXSerializer(outputTarget.getCharacterStream(),
                                                               formatter));
        }
        else if(null != outputTarget.getFileName())
        {
          /*if (!(processor.m_parserLiaison.getIndent() < 0))
          {
            formatter.setIndent(processor.m_parserLiaison.getIndent() + 1);
          }*/
          ostream = new FileOutputStream(outputTarget.getFileName());
          processor.setDocumentHandler( makeSAXSerializer(ostream, formatter));
        }
        else if(null != outputTarget.getNode())
        {
          ParserAdapter handler = new ParserAdapter(new org.apache.xerces.parsers.SAXParser());
          // Patch from Costin Manolache
//          if( "org.apache.xalan.xpath.dtm.DTMLiaison".equals( processor.getXMLProcessorLiaison().getClass().getName()))
//            processor.error(XSLTErrorResources.ER_CANT_USE_DTM_FOR_OUTPUT); //Can't use a DTMLiaison for an output DOM node... pass a org.apache.xalan.xpath.xdom.XercesLiaison instead!");
         
          switch(outputTarget.getNode().getNodeType())
          {
          case Node.DOCUMENT_NODE:           
            handler.setContentHandler(new FormatterToDOM((Document)outputTarget.getNode()).getSerializerObject());
            processor.setDocumentHandler(handler);
            break;
          case Node.DOCUMENT_FRAGMENT_NODE:
            handler.setContentHandler(new FormatterToDOM(outputTarget.getNode().getOwnerDocument(), // PR:DMAN4M6PK5 Submitted by:<bk@viae.de>
                                                       (DocumentFragment)outputTarget.getNode()).getSerializerObject());
            processor.setDocumentHandler(handler);
            break;
          case Node.ELEMENT_NODE:
            handler.setContentHandler(new FormatterToDOM(outputTarget.getNode().getOwnerDocument(), // PR:DMAN4M6PK5 Submitted by:<bk@viae.de>
                                                       (Element)outputTarget.getNode()).getSerializerObject());
            processor.setDocumentHandler(handler);
            break;
          default:
            m_sRootObject.error(XSLTErrorResources.ER_CAN_ONLY_OUTPUT_TO_ELEMENT); //"Can only output to an Element, DocumentFragment, Document, or PrintWriter.");
          }
        }
        else
        {
          ParserAdapter handler = new ParserAdapter(new org.apache.xerces.parsers.SAXParser());
          outputTarget.setNode(processor.getXMLProcessorLiaison().createDocument());
          handler.setContentHandler(new FormatterToDOM((Document)outputTarget.getNode()).getSerializerObject());
          processor.setDocumentHandler(handler);
        }

       // processor.resetCurrentState(sourceTree);
       // processor.m_rootDoc = sourceTree;

        if(null != processor.m_diagnosticsPrintWriter)
        {
          processor.diag("=============================");
          processor.diag("Transforming...");
          processor.pushTime(sourceTree);
        }

       // processor.getVarStack().pushContextMarker();
      //  try
      //  {
      //    processor.resolveTopLevelParams();
      //  }
      //  catch(Exception e)
      //  {
      //    throw new SAXException(XSLMessages.createMessage(XSLTErrorResources.ER_PROCESS_ERROR, null), e); //"StylesheetRoot.process error", e);
      //  }

        processor.getTransformer().getResultTreeHandler().startDocument();

        // Output the action of the found root rule.  All processing
        // occurs from here.  buildResultFromTemplate is highly recursive.
        rootRule.execute(processor.getTransformer(), sourceTree, null);

         processor.getTransformer().getResultTreeHandler().endDocument();

        // Reset the top-level params for the next round.
        // processor.m_topLevelParams = new Vector();
View Full Code Here

    // Iterate over contents of old TemplateList
    org.apache.xalan.templates.TemplateList.TemplateWalker tw
      =root.getTemplateListComposed().getWalker();
   
    // Scan all templates in old list, compile, insert into new
    ElemTemplate et;
    while ( null != (et = tw.next()) )
    {
      ElemTemplate ct = compileTemplate(et);
     
      // If compilation succeeds, use it; else fall back on interp
      newTl.setTemplate( (ct!=null) ? ct : et);
    }
    // Postprocess/reconcile list
View Full Code Here

    Other nodes simply have their .evaluate() invoked
    TODO: Their children really should be walked for further compilation opportunities.
    */
  ElemTemplate compileTemplate(ElemTemplate source)
  {
    ElemTemplate instance=source;

    String className=generateUniqueClassName("org.apache.xalan.processor.ACompiledTemplate");
   
    try
    {
View Full Code Here

        // allowed on a stylesheet.
        stylesheetProcessor.setPropertiesFromAttributes(handler, "stylesheet",
                                                        stylesheetAttrs, stylesheet);
        handler.pushElemTemplateElement(stylesheet);

        ElemTemplate template = new ElemTemplate();

        appendAndPush(handler, template);

        XPath rootMatch = new XPath("/", stylesheet, stylesheet, XPath.MATCH,
             handler.getStylesheetProcessor().getErrorListener());

        template.setMatch(rootMatch);

        // template.setDOMBackPointer(handler.getOriginatingNode());
        stylesheet.setTemplate(template);

        p = handler.getElemTemplateElement();
View Full Code Here

      }
      break;
    case Constants.ELEMNAME_TEMPLATE :
      if (m_traceTemplates || m_traceElements)
      {
        ElemTemplate et = (ElemTemplate) ev.m_styleNode;

        m_pw.print("Line #" + et.getLineNumber() + ", " + "Column #"
                   + et.getColumnNumber() + ": " + et.getNodeName() + " ");

        if (null != et.getMatch())
        {
          m_pw.print("match='" + et.getMatch().getPatternString() + "' ");
        }

        if (null != et.getName())
        {
          m_pw.print("name='" + et.getName() + "' ");
        }

        m_pw.println();
      }
      break;
View Full Code Here

    // Iterate over contents of old TemplateList
    org.apache.xalan.templates.TemplateList.TemplateWalker tw
      =root.getTemplateListComposed().getWalker();
   
    // Scan all templates in old list, compile, insert into new
    ElemTemplate et;
    while ( null != (et = tw.next()) )
    {
      ElemTemplate ct = compileTemplate(et);
     
      // If compilation succeeds, use it; else fall back on interp
      newTl.setTemplate( (ct!=null) ? ct : et);
    }
    // Postprocess/reconcile list
View Full Code Here

    Other nodes simply have their .evaluate() invoked
    TODO: Their children really should be walked for further compilation opportunities.
    */
  ElemTemplate compileTemplate(ElemTemplate source)
  {
    ElemTemplate instance=source;

    String className=generateUniqueClassName("org.apache.xalan.processor.ACompiledTemplate");
   
    try
    {
View Full Code Here

TOP

Related Classes of org.apache.xalan.templates.ElemTemplate

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.