コード例 #1
0
  /**
   * If the children of a variable is a single xsl:value-of or text literal, it is cheaper to
   * evaluate this as an expression, so try and adapt the child an an expression.
   *
   * @param varElem Should be a ElemParam, ElemVariable, or ElemWithParam.
   * @return An XPath if rewrite is possible, else null.
   * @throws javax.xml.transform.TransformerException
   */
  static XPath rewriteChildToExpression(ElemTemplateElement varElem) throws TransformerException {

    ElemTemplateElement t = varElem.getFirstChildElem();

    // Down the line this can be done with multiple string objects using
    // the concat function.
    if (null != t && null == t.getNextSiblingElem()) {
      int etype = t.getXSLToken();

      if (Constants.ELEMNAME_VALUEOF == etype) {
        ElemValueOf valueof = (ElemValueOf) t;

        // %TBD% I'm worried about extended attributes here.
        if (valueof.getDisableOutputEscaping() == false && valueof.getDOMBackPointer() == null) {
          varElem.m_firstChild = null;

          return new XPath(new XRTreeFragSelectWrapper(valueof.getSelect().getExpression()));
        }
      } else if (Constants.ELEMNAME_TEXTLITERALRESULT == etype) {
        ElemTextLiteral lit = (ElemTextLiteral) t;

        if (lit.getDisableOutputEscaping() == false && lit.getDOMBackPointer() == null) {
          String str = lit.getNodeValue();
          XString xstr = new XString(str);

          varElem.m_firstChild = null;

          return new XPath(new XRTreeFragSelectWrapper(xstr));
        }
      }
    }

    return null;
  }
コード例 #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);
  }