Java Code Examples for com.sun.org.apache.xml.internal.dtm.DTM#getNodeType()

The following examples show how to use com.sun.org.apache.xml.internal.dtm.DTM#getNodeType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FuncLang.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  String lang = m_arg0.execute(xctxt).str();
  int parent = xctxt.getCurrentNode();
  boolean isLang = false;
  DTM dtm = xctxt.getDTM(parent);

  while (DTM.NULL != parent)
  {
    if (DTM.ELEMENT_NODE == dtm.getNodeType(parent))
    {
      int langAttr = dtm.getAttributeNode(parent, "http://www.w3.org/XML/1998/namespace", "lang");

      if (DTM.NULL != langAttr)
      {
        String langVal = dtm.getNodeValue(langAttr);
        // %OPT%
        if (langVal.toLowerCase().startsWith(lang.toLowerCase()))
        {
          int valLen = lang.length();

          if ((langVal.length() == valLen)
                  || (langVal.charAt(valLen) == '-'))
          {
            isLang = true;
          }
        }

        break;
      }
    }

    parent = dtm.getParent(parent);
  }

  return isLang ? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
 
Example 2
Source File: FuncLang.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  String lang = m_arg0.execute(xctxt).str();
  int parent = xctxt.getCurrentNode();
  boolean isLang = false;
  DTM dtm = xctxt.getDTM(parent);

  while (DTM.NULL != parent)
  {
    if (DTM.ELEMENT_NODE == dtm.getNodeType(parent))
    {
      int langAttr = dtm.getAttributeNode(parent, "http://www.w3.org/XML/1998/namespace", "lang");

      if (DTM.NULL != langAttr)
      {
        String langVal = dtm.getNodeValue(langAttr);
        // %OPT%
        if (langVal.toLowerCase().startsWith(lang.toLowerCase()))
        {
          int valLen = lang.length();

          if ((langVal.length() == valLen)
                  || (langVal.charAt(valLen) == '-'))
          {
            isLang = true;
          }
        }

        break;
      }
    }

    parent = dtm.getParent(parent);
  }

  return isLang ? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
 
Example 3
Source File: FuncLang.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  String lang = m_arg0.execute(xctxt).str();
  int parent = xctxt.getCurrentNode();
  boolean isLang = false;
  DTM dtm = xctxt.getDTM(parent);

  while (DTM.NULL != parent)
  {
    if (DTM.ELEMENT_NODE == dtm.getNodeType(parent))
    {
      int langAttr = dtm.getAttributeNode(parent, "http://www.w3.org/XML/1998/namespace", "lang");

      if (DTM.NULL != langAttr)
      {
        String langVal = dtm.getNodeValue(langAttr);
        // %OPT%
        if (langVal.toLowerCase().startsWith(lang.toLowerCase()))
        {
          int valLen = lang.length();

          if ((langVal.length() == valLen)
                  || (langVal.charAt(valLen) == '-'))
          {
            isLang = true;
          }
        }

        break;
      }
    }

    parent = dtm.getParent(parent);
  }

  return isLang ? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
 
Example 4
Source File: FuncNamespace.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  int context = getArg0AsNode(xctxt);

  String s;
  if(context != DTM.NULL)
  {
    DTM dtm = xctxt.getDTM(context);
    int t = dtm.getNodeType(context);
    if(t == DTM.ELEMENT_NODE)
    {
      s = dtm.getNamespaceURI(context);
    }
    else if(t == DTM.ATTRIBUTE_NODE)
    {

      // This function always returns an empty string for namespace nodes.
      // We check for those here.  Fix inspired by Davanum Srinivas.

      s = dtm.getNodeName(context);
      if(s.startsWith("xmlns:") || s.equals("xmlns"))
        return XString.EMPTYSTRING;

      s = dtm.getNamespaceURI(context);
    }
    else
      return XString.EMPTYSTRING;
  }
  else
    return XString.EMPTYSTRING;

  return ((null == s) ? XString.EMPTYSTRING : new XString(s));
}
 
Example 5
Source File: FuncNamespace.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  int context = getArg0AsNode(xctxt);

  String s;
  if(context != DTM.NULL)
  {
    DTM dtm = xctxt.getDTM(context);
    int t = dtm.getNodeType(context);
    if(t == DTM.ELEMENT_NODE)
    {
      s = dtm.getNamespaceURI(context);
    }
    else if(t == DTM.ATTRIBUTE_NODE)
    {

      // This function always returns an empty string for namespace nodes.
      // We check for those here.  Fix inspired by Davanum Srinivas.

      s = dtm.getNodeName(context);
      if(s.startsWith("xmlns:") || s.equals("xmlns"))
        return XString.EMPTYSTRING;

      s = dtm.getNamespaceURI(context);
    }
    else
      return XString.EMPTYSTRING;
  }
  else
    return XString.EMPTYSTRING;

  return ((null == s) ? XString.EMPTYSTRING : new XString(s));
}
 
Example 6
Source File: FuncNamespace.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  int context = getArg0AsNode(xctxt);

  String s;
  if(context != DTM.NULL)
  {
    DTM dtm = xctxt.getDTM(context);
    int t = dtm.getNodeType(context);
    if(t == DTM.ELEMENT_NODE)
    {
      s = dtm.getNamespaceURI(context);
    }
    else if(t == DTM.ATTRIBUTE_NODE)
    {

      // This function always returns an empty string for namespace nodes.
      // We check for those here.  Fix inspired by Davanum Srinivas.

      s = dtm.getNodeName(context);
      if(s.startsWith("xmlns:") || s.equals("xmlns"))
        return XString.EMPTYSTRING;

      s = dtm.getNamespaceURI(context);
    }
    else
      return XString.EMPTYSTRING;
  }
  else
    return XString.EMPTYSTRING;

  return ((null == s) ? XString.EMPTYSTRING : new XString(s));
}
 
Example 7
Source File: FuncDoclocation.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
   * Execute the function.  The function must return
   * a valid object.
   * @param xctxt The current execution context.
   * @return A valid XObject.
   *
   * @throws javax.xml.transform.TransformerException
   */
  public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
  {

    int whereNode = getArg0AsNode(xctxt);
    String fileLocation = null;

    if (DTM.NULL != whereNode)
    {
      DTM dtm = xctxt.getDTM(whereNode);

      // %REVIEW%
      if (DTM.DOCUMENT_FRAGMENT_NODE ==  dtm.getNodeType(whereNode))
      {
        whereNode = dtm.getFirstChild(whereNode);
      }

      if (DTM.NULL != whereNode)
      {
        fileLocation = dtm.getDocumentBaseURI();
//        int owner = dtm.getDocument();
//        fileLocation = xctxt.getSourceTreeManager().findURIFromDoc(owner);
      }
    }

    return new XString((null != fileLocation) ? fileLocation : "");
  }
 
Example 8
Source File: FuncHere.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The here function returns a node-set containing the attribute or
 * processing instruction node or the parent element of the text node
 * that directly bears the XPath expression.  This expression results
 * in an error if the containing XPath expression does not appear in the
 * same XML document against which the XPath expression is being evaluated.
 *
 * @param xctxt
 * @return the xobject
 * @throws javax.xml.transform.TransformerException
 */
@Override
public XObject execute(XPathContext xctxt)
    throws javax.xml.transform.TransformerException {

    Node xpathOwnerNode = (Node) xctxt.getOwnerObject();

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

    int xpathOwnerNodeDTM = xctxt.getDTMHandleFromNode(xpathOwnerNode);

    int currentNode = xctxt.getCurrentNode();
    DTM dtm = xctxt.getDTM(currentNode);
    int docContext = dtm.getDocument();

    if (DTM.NULL == docContext) {
        error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null);
    }

    {
        // check whether currentNode and the node containing the XPath expression
        // are in the same document
        Document currentDoc =
            XMLUtils.getOwnerDocument(dtm.getNode(currentNode));
        Document xpathOwnerDoc = XMLUtils.getOwnerDocument(xpathOwnerNode);

        if (currentDoc != xpathOwnerDoc) {
            throw new TransformerException(I18n.translate("xpath.funcHere.documentsDiffer"));
        }
    }

    XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
    NodeSetDTM nodeSet = nodes.mutableNodeset();

    {
        int hereNode = DTM.NULL;

        switch (dtm.getNodeType(xpathOwnerNodeDTM)) {

        case Node.ATTRIBUTE_NODE :
        case Node.PROCESSING_INSTRUCTION_NODE : {
            // returns a node-set containing the attribute /  processing instruction node
            hereNode = xpathOwnerNodeDTM;

            nodeSet.addNode(hereNode);

            break;
        }
        case Node.TEXT_NODE : {
            // returns a node-set containing the parent element of the
            // text node that directly bears the XPath expression
            hereNode = dtm.getParent(xpathOwnerNodeDTM);

            nodeSet.addNode(hereNode);

            break;
        }
        default :
            break;
        }
    }

    /** $todo$ Do I have to do this detach() call? */
    nodeSet.detach();

    return nodes;
}
 
Example 9
Source File: NodeTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Tell what the test score is for the given node.
 *
 *
 * @param xctxt XPath runtime context.
 * @param context The node being tested.
 *
 * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt, int context,
                       DTM dtm, int expType)
        throws javax.xml.transform.TransformerException
{

  if (m_whatToShow == DTMFilter.SHOW_ALL)
    return m_score;

  int nodeBit = (m_whatToShow & (0x00000001
                 << ((dtm.getNodeType(context)) - 1)));

  switch (nodeBit)
  {
  case DTMFilter.SHOW_DOCUMENT_FRAGMENT :
  case DTMFilter.SHOW_DOCUMENT :
    return SCORE_OTHER;
  case DTMFilter.SHOW_COMMENT :
    return m_score;
  case DTMFilter.SHOW_CDATA_SECTION :
  case DTMFilter.SHOW_TEXT :

    // was:
    // return (!xctxt.getDOMHelper().shouldStripSourceNode(context))
    //       ? m_score : SCORE_NONE;
    return m_score;
  case DTMFilter.SHOW_PROCESSING_INSTRUCTION :
    return subPartMatch(dtm.getNodeName(context), m_name)
           ? m_score : SCORE_NONE;

  // From the draft: "Two expanded names are equal if they
  // have the same local part, and either both have no URI or
  // both have the same URI."
  // "A node test * is true for any node of the principal node type.
  // For example, child::* will select all element children of the
  // context node, and attribute::* will select all attributes of
  // the context node."
  // "A node test can have the form NCName:*. In this case, the prefix
  // is expanded in the same way as with a QName using the context
  // namespace declarations. The node test will be true for any node
  // of the principal type whose expanded name has the URI to which
  // the prefix expands, regardless of the local part of the name."
  case DTMFilter.SHOW_NAMESPACE :
  {
    String ns = dtm.getLocalName(context);

    return (subPartMatch(ns, m_name)) ? m_score : SCORE_NONE;
  }
  case DTMFilter.SHOW_ATTRIBUTE :
  case DTMFilter.SHOW_ELEMENT :
  {
    return (m_isTotallyWild || (subPartMatchNS(dtm.getNamespaceURI(context), m_namespace) && subPartMatch(dtm.getLocalName(context), m_name)))
           ? m_score : SCORE_NONE;
  }
  default :
    return SCORE_NONE;
  }  // end switch(testType)
}
 
Example 10
Source File: FuncHere.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The here function returns a node-set containing the attribute or
 * processing instruction node or the parent element of the text node
 * that directly bears the XPath expression.  This expression results
 * in an error if the containing XPath expression does not appear in the
 * same XML document against which the XPath expression is being evaluated.
 *
 * @param xctxt
 * @return the xobject
 * @throws javax.xml.transform.TransformerException
 */
@Override
public XObject execute(XPathContext xctxt)
    throws javax.xml.transform.TransformerException {

    Node xpathOwnerNode = (Node) xctxt.getOwnerObject();

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

    int xpathOwnerNodeDTM = xctxt.getDTMHandleFromNode(xpathOwnerNode);

    int currentNode = xctxt.getCurrentNode();
    DTM dtm = xctxt.getDTM(currentNode);
    int docContext = dtm.getDocument();

    if (DTM.NULL == docContext) {
        error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null);
    }

    {
        // check whether currentNode and the node containing the XPath expression
        // are in the same document
        Document currentDoc =
            XMLUtils.getOwnerDocument(dtm.getNode(currentNode));
        Document xpathOwnerDoc = XMLUtils.getOwnerDocument(xpathOwnerNode);

        if (currentDoc != xpathOwnerDoc) {
            throw new TransformerException(I18n.translate("xpath.funcHere.documentsDiffer"));
        }
    }

    XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
    NodeSetDTM nodeSet = nodes.mutableNodeset();

    {
        int hereNode = DTM.NULL;

        switch (dtm.getNodeType(xpathOwnerNodeDTM)) {

        case Node.ATTRIBUTE_NODE :
        case Node.PROCESSING_INSTRUCTION_NODE : {
            // returns a node-set containing the attribute /  processing instruction node
            hereNode = xpathOwnerNodeDTM;

            nodeSet.addNode(hereNode);

            break;
        }
        case Node.TEXT_NODE : {
            // returns a node-set containing the parent element of the
            // text node that directly bears the XPath expression
            hereNode = dtm.getParent(xpathOwnerNodeDTM);

            nodeSet.addNode(hereNode);

            break;
        }
        default :
            break;
        }
    }

    /** $todo$ Do I have to do this detach() call? */
    nodeSet.detach();

    return nodes;
}
 
Example 11
Source File: NodeTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Tell what the test score is for the given node.
 *
 *
 * @param xctxt XPath runtime context.
 * @param context The node being tested.
 *
 * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt, int context,
                       DTM dtm, int expType)
        throws javax.xml.transform.TransformerException
{

  if (m_whatToShow == DTMFilter.SHOW_ALL)
    return m_score;

  int nodeBit = (m_whatToShow & (0x00000001
                 << ((dtm.getNodeType(context)) - 1)));

  switch (nodeBit)
  {
  case DTMFilter.SHOW_DOCUMENT_FRAGMENT :
  case DTMFilter.SHOW_DOCUMENT :
    return SCORE_OTHER;
  case DTMFilter.SHOW_COMMENT :
    return m_score;
  case DTMFilter.SHOW_CDATA_SECTION :
  case DTMFilter.SHOW_TEXT :

    // was:
    // return (!xctxt.getDOMHelper().shouldStripSourceNode(context))
    //       ? m_score : SCORE_NONE;
    return m_score;
  case DTMFilter.SHOW_PROCESSING_INSTRUCTION :
    return subPartMatch(dtm.getNodeName(context), m_name)
           ? m_score : SCORE_NONE;

  // From the draft: "Two expanded names are equal if they
  // have the same local part, and either both have no URI or
  // both have the same URI."
  // "A node test * is true for any node of the principal node type.
  // For example, child::* will select all element children of the
  // context node, and attribute::* will select all attributes of
  // the context node."
  // "A node test can have the form NCName:*. In this case, the prefix
  // is expanded in the same way as with a QName using the context
  // namespace declarations. The node test will be true for any node
  // of the principal type whose expanded name has the URI to which
  // the prefix expands, regardless of the local part of the name."
  case DTMFilter.SHOW_NAMESPACE :
  {
    String ns = dtm.getLocalName(context);

    return (subPartMatch(ns, m_name)) ? m_score : SCORE_NONE;
  }
  case DTMFilter.SHOW_ATTRIBUTE :
  case DTMFilter.SHOW_ELEMENT :
  {
    return (m_isTotallyWild || (subPartMatchNS(dtm.getNamespaceURI(context), m_namespace) && subPartMatch(dtm.getLocalName(context), m_name)))
           ? m_score : SCORE_NONE;
  }
  default :
    return SCORE_NONE;
  }  // end switch(testType)
}
 
Example 12
Source File: NodeTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Tell what the test score is for the given node.
 *
 *
 * @param xctxt XPath runtime context.
 * @param context The node being tested.
 *
 * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt, int context)
        throws javax.xml.transform.TransformerException
{

  DTM dtm = xctxt.getDTM(context);
  short nodeType = dtm.getNodeType(context);

  if (m_whatToShow == DTMFilter.SHOW_ALL)
    return m_score;

  int nodeBit = (m_whatToShow & (0x00000001 << (nodeType - 1)));

  switch (nodeBit)
  {
  case DTMFilter.SHOW_DOCUMENT_FRAGMENT :
  case DTMFilter.SHOW_DOCUMENT :
    return SCORE_OTHER;
  case DTMFilter.SHOW_COMMENT :
    return m_score;
  case DTMFilter.SHOW_CDATA_SECTION :
  case DTMFilter.SHOW_TEXT :

    // was:
    // return (!xctxt.getDOMHelper().shouldStripSourceNode(context))
    //       ? m_score : SCORE_NONE;
    return m_score;
  case DTMFilter.SHOW_PROCESSING_INSTRUCTION :
    return subPartMatch(dtm.getNodeName(context), m_name)
           ? m_score : SCORE_NONE;

  // From the draft: "Two expanded names are equal if they
  // have the same local part, and either both have no URI or
  // both have the same URI."
  // "A node test * is true for any node of the principal node type.
  // For example, child::* will select all element children of the
  // context node, and attribute::* will select all attributes of
  // the context node."
  // "A node test can have the form NCName:*. In this case, the prefix
  // is expanded in the same way as with a QName using the context
  // namespace declarations. The node test will be true for any node
  // of the principal type whose expanded name has the URI to which
  // the prefix expands, regardless of the local part of the name."
  case DTMFilter.SHOW_NAMESPACE :
  {
    String ns = dtm.getLocalName(context);

    return (subPartMatch(ns, m_name)) ? m_score : SCORE_NONE;
  }
  case DTMFilter.SHOW_ATTRIBUTE :
  case DTMFilter.SHOW_ELEMENT :
  {
    return (m_isTotallyWild || (subPartMatchNS(dtm.getNamespaceURI(context), m_namespace) && subPartMatch(dtm.getLocalName(context), m_name)))
           ? m_score : SCORE_NONE;
  }
  default :
    return SCORE_NONE;
  }  // end switch(testType)
}
 
Example 13
Source File: FuncHere.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The here function returns a node-set containing the attribute or
 * processing instruction node or the parent element of the text node
 * that directly bears the XPath expression.  This expression results
 * in an error if the containing XPath expression does not appear in the
 * same XML document against which the XPath expression is being evaluated.
 *
 * @param xctxt
 * @return the xobject
 * @throws javax.xml.transform.TransformerException
 */
@Override
public XObject execute(XPathContext xctxt)
    throws javax.xml.transform.TransformerException {

    Node xpathOwnerNode = (Node) xctxt.getOwnerObject();

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

    int xpathOwnerNodeDTM = xctxt.getDTMHandleFromNode(xpathOwnerNode);

    int currentNode = xctxt.getCurrentNode();
    DTM dtm = xctxt.getDTM(currentNode);
    int docContext = dtm.getDocument();

    if (DTM.NULL == docContext) {
        error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null);
    }

    {
        // check whether currentNode and the node containing the XPath expression
        // are in the same document
        Document currentDoc =
            XMLUtils.getOwnerDocument(dtm.getNode(currentNode));
        Document xpathOwnerDoc = XMLUtils.getOwnerDocument(xpathOwnerNode);

        if (currentDoc != xpathOwnerDoc) {
            throw new TransformerException(I18n.translate("xpath.funcHere.documentsDiffer"));
        }
    }

    XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
    NodeSetDTM nodeSet = nodes.mutableNodeset();

    {
        int hereNode = DTM.NULL;

        switch (dtm.getNodeType(xpathOwnerNodeDTM)) {

        case Node.ATTRIBUTE_NODE :
        case Node.PROCESSING_INSTRUCTION_NODE : {
            // returns a node-set containing the attribute /  processing instruction node
            hereNode = xpathOwnerNodeDTM;

            nodeSet.addNode(hereNode);

            break;
        }
        case Node.TEXT_NODE : {
            // returns a node-set containing the parent element of the
            // text node that directly bears the XPath expression
            hereNode = dtm.getParent(xpathOwnerNodeDTM);

            nodeSet.addNode(hereNode);

            break;
        }
        default :
            break;
        }
    }

    /** $todo$ Do I have to do this detach() call? */
    nodeSet.detach();

    return nodes;
}
 
Example 14
Source File: FuncHere.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The here function returns a node-set containing the attribute or
 * processing instruction node or the parent element of the text node
 * that directly bears the XPath expression.  This expression results
 * in an error if the containing XPath expression does not appear in the
 * same XML document against which the XPath expression is being evaluated.
 *
 * @param xctxt
 * @return the xobject
 * @throws javax.xml.transform.TransformerException
 */
@Override
public XObject execute(XPathContext xctxt)
    throws javax.xml.transform.TransformerException {

    Node xpathOwnerNode = (Node) xctxt.getOwnerObject();

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

    int xpathOwnerNodeDTM = xctxt.getDTMHandleFromNode(xpathOwnerNode);

    int currentNode = xctxt.getCurrentNode();
    DTM dtm = xctxt.getDTM(currentNode);
    int docContext = dtm.getDocument();

    if (DTM.NULL == docContext) {
        error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null);
    }

    {
        // check whether currentNode and the node containing the XPath expression
        // are in the same document
        Document currentDoc =
            XMLUtils.getOwnerDocument(dtm.getNode(currentNode));
        Document xpathOwnerDoc = XMLUtils.getOwnerDocument(xpathOwnerNode);

        if (currentDoc != xpathOwnerDoc) {
            throw new TransformerException(I18n.translate("xpath.funcHere.documentsDiffer"));
        }
    }

    XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
    NodeSetDTM nodeSet = nodes.mutableNodeset();

    {
        int hereNode = DTM.NULL;

        switch (dtm.getNodeType(xpathOwnerNodeDTM)) {

        case Node.ATTRIBUTE_NODE :
        case Node.PROCESSING_INSTRUCTION_NODE : {
            // returns a node-set containing the attribute /  processing instruction node
            hereNode = xpathOwnerNodeDTM;

            nodeSet.addNode(hereNode);

            break;
        }
        case Node.TEXT_NODE : {
            // returns a node-set containing the parent element of the
            // text node that directly bears the XPath expression
            hereNode = dtm.getParent(xpathOwnerNodeDTM);

            nodeSet.addNode(hereNode);

            break;
        }
        default :
            break;
        }
    }

    /** $todo$ Do I have to do this detach() call? */
    nodeSet.detach();

    return nodes;
}
 
Example 15
Source File: NodeTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Tell what the test score is for the given node.
 *
 *
 * @param xctxt XPath runtime context.
 * @param context The node being tested.
 *
 * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt, int context)
        throws javax.xml.transform.TransformerException
{

  DTM dtm = xctxt.getDTM(context);
  short nodeType = dtm.getNodeType(context);

  if (m_whatToShow == DTMFilter.SHOW_ALL)
    return m_score;

  int nodeBit = (m_whatToShow & (0x00000001 << (nodeType - 1)));

  switch (nodeBit)
  {
  case DTMFilter.SHOW_DOCUMENT_FRAGMENT :
  case DTMFilter.SHOW_DOCUMENT :
    return SCORE_OTHER;
  case DTMFilter.SHOW_COMMENT :
    return m_score;
  case DTMFilter.SHOW_CDATA_SECTION :
  case DTMFilter.SHOW_TEXT :

    // was:
    // return (!xctxt.getDOMHelper().shouldStripSourceNode(context))
    //       ? m_score : SCORE_NONE;
    return m_score;
  case DTMFilter.SHOW_PROCESSING_INSTRUCTION :
    return subPartMatch(dtm.getNodeName(context), m_name)
           ? m_score : SCORE_NONE;

  // From the draft: "Two expanded names are equal if they
  // have the same local part, and either both have no URI or
  // both have the same URI."
  // "A node test * is true for any node of the principal node type.
  // For example, child::* will select all element children of the
  // context node, and attribute::* will select all attributes of
  // the context node."
  // "A node test can have the form NCName:*. In this case, the prefix
  // is expanded in the same way as with a QName using the context
  // namespace declarations. The node test will be true for any node
  // of the principal type whose expanded name has the URI to which
  // the prefix expands, regardless of the local part of the name."
  case DTMFilter.SHOW_NAMESPACE :
  {
    String ns = dtm.getLocalName(context);

    return (subPartMatch(ns, m_name)) ? m_score : SCORE_NONE;
  }
  case DTMFilter.SHOW_ATTRIBUTE :
  case DTMFilter.SHOW_ELEMENT :
  {
    return (m_isTotallyWild || (subPartMatchNS(dtm.getNamespaceURI(context), m_namespace) && subPartMatch(dtm.getLocalName(context), m_name)))
           ? m_score : SCORE_NONE;
  }
  default :
    return SCORE_NONE;
  }  // end switch(testType)
}
 
Example 16
Source File: FuncHere.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The here function returns a node-set containing the attribute or
 * processing instruction node or the parent element of the text node
 * that directly bears the XPath expression.  This expression results
 * in an error if the containing XPath expression does not appear in the
 * same XML document against which the XPath expression is being evaluated.
 *
 * @param xctxt
 * @return the xobject
 * @throws javax.xml.transform.TransformerException
 */
@Override
public XObject execute(XPathContext xctxt)
    throws javax.xml.transform.TransformerException {

    Node xpathOwnerNode = (Node) xctxt.getOwnerObject();

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

    int xpathOwnerNodeDTM = xctxt.getDTMHandleFromNode(xpathOwnerNode);

    int currentNode = xctxt.getCurrentNode();
    DTM dtm = xctxt.getDTM(currentNode);
    int docContext = dtm.getDocument();

    if (DTM.NULL == docContext) {
        error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null);
    }

    {
        // check whether currentNode and the node containing the XPath expression
        // are in the same document
        Document currentDoc =
            XMLUtils.getOwnerDocument(dtm.getNode(currentNode));
        Document xpathOwnerDoc = XMLUtils.getOwnerDocument(xpathOwnerNode);

        if (currentDoc != xpathOwnerDoc) {
            throw new TransformerException(I18n.translate("xpath.funcHere.documentsDiffer"));
        }
    }

    XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
    NodeSetDTM nodeSet = nodes.mutableNodeset();

    {
        int hereNode = DTM.NULL;

        switch (dtm.getNodeType(xpathOwnerNodeDTM)) {

        case Node.ATTRIBUTE_NODE :
        case Node.PROCESSING_INSTRUCTION_NODE : {
            // returns a node-set containing the attribute /  processing instruction node
            hereNode = xpathOwnerNodeDTM;

            nodeSet.addNode(hereNode);

            break;
        }
        case Node.TEXT_NODE : {
            // returns a node-set containing the parent element of the
            // text node that directly bears the XPath expression
            hereNode = dtm.getParent(xpathOwnerNodeDTM);

            nodeSet.addNode(hereNode);

            break;
        }
        default :
            break;
        }
    }

    /** $todo$ Do I have to do this detach() call? */
    nodeSet.detach();

    return nodes;
}
 
Example 17
Source File: NodeTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Tell what the test score is for the given node.
 *
 *
 * @param xctxt XPath runtime context.
 * @param context The node being tested.
 *
 * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt, int context)
        throws javax.xml.transform.TransformerException
{

  DTM dtm = xctxt.getDTM(context);
  short nodeType = dtm.getNodeType(context);

  if (m_whatToShow == DTMFilter.SHOW_ALL)
    return m_score;

  int nodeBit = (m_whatToShow & (0x00000001 << (nodeType - 1)));

  switch (nodeBit)
  {
  case DTMFilter.SHOW_DOCUMENT_FRAGMENT :
  case DTMFilter.SHOW_DOCUMENT :
    return SCORE_OTHER;
  case DTMFilter.SHOW_COMMENT :
    return m_score;
  case DTMFilter.SHOW_CDATA_SECTION :
  case DTMFilter.SHOW_TEXT :

    // was:
    // return (!xctxt.getDOMHelper().shouldStripSourceNode(context))
    //       ? m_score : SCORE_NONE;
    return m_score;
  case DTMFilter.SHOW_PROCESSING_INSTRUCTION :
    return subPartMatch(dtm.getNodeName(context), m_name)
           ? m_score : SCORE_NONE;

  // From the draft: "Two expanded names are equal if they
  // have the same local part, and either both have no URI or
  // both have the same URI."
  // "A node test * is true for any node of the principal node type.
  // For example, child::* will select all element children of the
  // context node, and attribute::* will select all attributes of
  // the context node."
  // "A node test can have the form NCName:*. In this case, the prefix
  // is expanded in the same way as with a QName using the context
  // namespace declarations. The node test will be true for any node
  // of the principal type whose expanded name has the URI to which
  // the prefix expands, regardless of the local part of the name."
  case DTMFilter.SHOW_NAMESPACE :
  {
    String ns = dtm.getLocalName(context);

    return (subPartMatch(ns, m_name)) ? m_score : SCORE_NONE;
  }
  case DTMFilter.SHOW_ATTRIBUTE :
  case DTMFilter.SHOW_ELEMENT :
  {
    return (m_isTotallyWild || (subPartMatchNS(dtm.getNamespaceURI(context), m_namespace) && subPartMatch(dtm.getLocalName(context), m_name)))
           ? m_score : SCORE_NONE;
  }
  default :
    return SCORE_NONE;
  }  // end switch(testType)
}
 
Example 18
Source File: FuncHere.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The here function returns a node-set containing the attribute or
 * processing instruction node or the parent element of the text node
 * that directly bears the XPath expression.  This expression results
 * in an error if the containing XPath expression does not appear in the
 * same XML document against which the XPath expression is being evaluated.
 *
 * @param xctxt
 * @return the xobject
 * @throws javax.xml.transform.TransformerException
 */
@Override
public XObject execute(XPathContext xctxt)
    throws javax.xml.transform.TransformerException {

    Node xpathOwnerNode = (Node) xctxt.getOwnerObject();

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

    int xpathOwnerNodeDTM = xctxt.getDTMHandleFromNode(xpathOwnerNode);

    int currentNode = xctxt.getCurrentNode();
    DTM dtm = xctxt.getDTM(currentNode);
    int docContext = dtm.getDocument();

    if (DTM.NULL == docContext) {
        error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null);
    }

    {
        // check whether currentNode and the node containing the XPath expression
        // are in the same document
        Document currentDoc =
            XMLUtils.getOwnerDocument(dtm.getNode(currentNode));
        Document xpathOwnerDoc = XMLUtils.getOwnerDocument(xpathOwnerNode);

        if (currentDoc != xpathOwnerDoc) {
            throw new TransformerException(I18n.translate("xpath.funcHere.documentsDiffer"));
        }
    }

    XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
    NodeSetDTM nodeSet = nodes.mutableNodeset();

    {
        int hereNode = DTM.NULL;

        switch (dtm.getNodeType(xpathOwnerNodeDTM)) {

        case Node.ATTRIBUTE_NODE :
        case Node.PROCESSING_INSTRUCTION_NODE : {
            // returns a node-set containing the attribute /  processing instruction node
            hereNode = xpathOwnerNodeDTM;

            nodeSet.addNode(hereNode);

            break;
        }
        case Node.TEXT_NODE : {
            // returns a node-set containing the parent element of the
            // text node that directly bears the XPath expression
            hereNode = dtm.getParent(xpathOwnerNodeDTM);

            nodeSet.addNode(hereNode);

            break;
        }
        default :
            break;
        }
    }

    /** $todo$ Do I have to do this detach() call? */
    nodeSet.detach();

    return nodes;
}
 
Example 19
Source File: NodeTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Tell what the test score is for the given node.
 *
 *
 * @param xctxt XPath runtime context.
 * @param context The node being tested.
 *
 * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt, int context)
        throws javax.xml.transform.TransformerException
{

  DTM dtm = xctxt.getDTM(context);
  short nodeType = dtm.getNodeType(context);

  if (m_whatToShow == DTMFilter.SHOW_ALL)
    return m_score;

  int nodeBit = (m_whatToShow & (0x00000001 << (nodeType - 1)));

  switch (nodeBit)
  {
  case DTMFilter.SHOW_DOCUMENT_FRAGMENT :
  case DTMFilter.SHOW_DOCUMENT :
    return SCORE_OTHER;
  case DTMFilter.SHOW_COMMENT :
    return m_score;
  case DTMFilter.SHOW_CDATA_SECTION :
  case DTMFilter.SHOW_TEXT :

    // was:
    // return (!xctxt.getDOMHelper().shouldStripSourceNode(context))
    //       ? m_score : SCORE_NONE;
    return m_score;
  case DTMFilter.SHOW_PROCESSING_INSTRUCTION :
    return subPartMatch(dtm.getNodeName(context), m_name)
           ? m_score : SCORE_NONE;

  // From the draft: "Two expanded names are equal if they
  // have the same local part, and either both have no URI or
  // both have the same URI."
  // "A node test * is true for any node of the principal node type.
  // For example, child::* will select all element children of the
  // context node, and attribute::* will select all attributes of
  // the context node."
  // "A node test can have the form NCName:*. In this case, the prefix
  // is expanded in the same way as with a QName using the context
  // namespace declarations. The node test will be true for any node
  // of the principal type whose expanded name has the URI to which
  // the prefix expands, regardless of the local part of the name."
  case DTMFilter.SHOW_NAMESPACE :
  {
    String ns = dtm.getLocalName(context);

    return (subPartMatch(ns, m_name)) ? m_score : SCORE_NONE;
  }
  case DTMFilter.SHOW_ATTRIBUTE :
  case DTMFilter.SHOW_ELEMENT :
  {
    return (m_isTotallyWild || (subPartMatchNS(dtm.getNamespaceURI(context), m_namespace) && subPartMatch(dtm.getLocalName(context), m_name)))
           ? m_score : SCORE_NONE;
  }
  default :
    return SCORE_NONE;
  }  // end switch(testType)
}
 
Example 20
Source File: FuncHere.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The here function returns a node-set containing the attribute or
 * processing instruction node or the parent element of the text node
 * that directly bears the XPath expression.  This expression results
 * in an error if the containing XPath expression does not appear in the
 * same XML document against which the XPath expression is being evaluated.
 *
 * @param xctxt
 * @return the xobject
 * @throws javax.xml.transform.TransformerException
 */
@Override
public XObject execute(XPathContext xctxt)
    throws javax.xml.transform.TransformerException {

    Node xpathOwnerNode = (Node) xctxt.getOwnerObject();

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

    int xpathOwnerNodeDTM = xctxt.getDTMHandleFromNode(xpathOwnerNode);

    int currentNode = xctxt.getCurrentNode();
    DTM dtm = xctxt.getDTM(currentNode);
    int docContext = dtm.getDocument();

    if (DTM.NULL == docContext) {
        error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null);
    }

    {
        // check whether currentNode and the node containing the XPath expression
        // are in the same document
        Document currentDoc =
            XMLUtils.getOwnerDocument(dtm.getNode(currentNode));
        Document xpathOwnerDoc = XMLUtils.getOwnerDocument(xpathOwnerNode);

        if (currentDoc != xpathOwnerDoc) {
            throw new TransformerException(I18n.translate("xpath.funcHere.documentsDiffer"));
        }
    }

    XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
    NodeSetDTM nodeSet = nodes.mutableNodeset();

    {
        int hereNode = DTM.NULL;

        switch (dtm.getNodeType(xpathOwnerNodeDTM)) {

        case Node.ATTRIBUTE_NODE :
        case Node.PROCESSING_INSTRUCTION_NODE : {
            // returns a node-set containing the attribute /  processing instruction node
            hereNode = xpathOwnerNodeDTM;

            nodeSet.addNode(hereNode);

            break;
        }
        case Node.TEXT_NODE : {
            // returns a node-set containing the parent element of the
            // text node that directly bears the XPath expression
            hereNode = dtm.getParent(xpathOwnerNodeDTM);

            nodeSet.addNode(hereNode);

            break;
        }
        default :
            break;
        }
    }

    /** $todo$ Do I have to do this detach() call? */
    nodeSet.detach();

    return nodes;
}