/**
   * This function is called after everything else has been recomposed, and allows the template to
   * set remaining values that may be based on some other property that depends on recomposition.
   */
  public void compose(StylesheetRoot sroot) throws TransformerException {
    // See if we can reduce an RTF to a select with a string expression.
    if (null == m_selectPattern && sroot.getOptimizer()) {
      XPath newSelect = rewriteChildToExpression(this);
      if (null != newSelect) m_selectPattern = newSelect;
    }

    StylesheetRoot.ComposeState cstate = sroot.getComposeState();

    // This should be done before addVariableName, so we don't have visibility
    // to the variable now being defined.
    java.util.Vector vnames = cstate.getVariableNames();
    if (null != m_selectPattern) m_selectPattern.fixupVariables(vnames, cstate.getGlobalsSize());

    // Only add the variable if this is not a global.  If it is a global,
    // it was already added by stylesheet root.
    if (!(m_parentNode instanceof Stylesheet) && m_qname != null) {
      m_index = cstate.addVariableName(m_qname) - cstate.getGlobalsSize();
    } else if (m_parentNode instanceof Stylesheet) {
      // If this is a global, then we need to treat it as if it's a xsl:template,
      // and count the number of variables it contains.  So we set the count to
      // zero here.
      cstate.resetStackFrameSize();
    }

    // This has to be done after the addVariableName, so that the variable
    // pushed won't be immediately popped again in endCompose.
    super.compose(sroot);
  }
Exemplo n.º 2
0
  public void compose(StylesheetRoot sroot) throws TransformerException {
    super.compose(sroot);
    String prefix = getPrefix();
    String declNamespace = getNamespaceForPrefix(prefix);
    String lang = null;
    String srcURL = null;
    String scriptSrc = null;
    if (null == declNamespace)
      throw new TransformerException(
          XSLMessages.createMessage(
              XSLTErrorResources.ER_NO_NAMESPACE_DECL, new Object[] {prefix}));
    // "Prefix " + prefix does not have a corresponding namespace declaration");
    for (ElemTemplateElement child = getFirstChildElem();
        child != null;
        child = child.getNextSiblingElem()) {
      if (Constants.ELEMNAME_EXTENSIONSCRIPT == child.getXSLToken()) {
        ElemExtensionScript sdecl = (ElemExtensionScript) child;
        lang = sdecl.getLang();
        srcURL = sdecl.getSrc();
        ElemTemplateElement childOfSDecl = sdecl.getFirstChildElem();
        if (null != childOfSDecl) {
          if (Constants.ELEMNAME_TEXTLITERALRESULT == childOfSDecl.getXSLToken()) {
            ElemTextLiteral tl = (ElemTextLiteral) childOfSDecl;
            char[] chars = tl.getChars();
            scriptSrc = new String(chars);
            if (scriptSrc.trim().length() == 0) scriptSrc = null;
          }
        }
      }
    }
    if (null == lang) lang = "javaclass";
    if (lang.equals("javaclass") && (scriptSrc != null))
      throw new TransformerException(
          XSLMessages.createMessage(
              XSLTErrorResources.ER_ELEM_CONTENT_NOT_ALLOWED, new Object[] {scriptSrc}));
    // "Element content not allowed for lang=javaclass " + scriptSrc);

    // Register the extension namespace if it has not already been registered.
    ExtensionNamespaceSupport extNsSpt = null;
    ExtensionNamespacesManager extNsMgr = sroot.getExtensionNamespacesManager();
    if (extNsMgr.namespaceIndex(declNamespace, extNsMgr.getExtensions()) == -1) {
      if (lang.equals("javaclass")) {
        if (null == srcURL) {
          extNsSpt = extNsMgr.defineJavaNamespace(declNamespace);
        } else if (extNsMgr.namespaceIndex(srcURL, extNsMgr.getExtensions()) == -1) {
          extNsSpt = extNsMgr.defineJavaNamespace(declNamespace, srcURL);
        }
      } else // not java
      {
        String handler = "org.apache.xalan.extensions.ExtensionHandlerGeneral";
        Object[] args = {
          declNamespace, this.m_elements, this.m_functions, lang, srcURL, scriptSrc, getSystemId()
        };
        extNsSpt = new ExtensionNamespaceSupport(declNamespace, handler, args);
      }
    }
    if (extNsSpt != null) extNsMgr.registerExtension(extNsSpt);
  }
Exemplo n.º 3
0
  /**
   * This function is called after everything else has been recomposed, and allows the template to
   * set remaining values that may be based on some other property that depends on recomposition.
   *
   * <p>NEEDSDOC @param sroot
   *
   * @throws TransformerException
   */
  public void compose(StylesheetRoot sroot) throws TransformerException {

    super.compose(sroot);

    int length = getSortElemCount();

    for (int i = 0; i < length; i++) {
      getSortElem(i).compose(sroot);
    }

    java.util.Vector vnames = sroot.getComposeState().getVariableNames();

    if (null != m_selectExpression)
      m_selectExpression.fixupVariables(vnames, sroot.getComposeState().getGlobalsSize());
    else {
      m_selectExpression = getStylesheetRoot().m_selectDefault.getExpression();
    }
  }