当前位置: 首页>>代码示例>>Java>>正文


Java DTM.getNodeType方法代码示例

本文整理汇总了Java中org.apache.xml.dtm.DTM.getNodeType方法的典型用法代码示例。如果您正苦于以下问题:Java DTM.getNodeType方法的具体用法?Java DTM.getNodeType怎么用?Java DTM.getNodeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.xml.dtm.DTM的用法示例。


在下文中一共展示了DTM.getNodeType方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPath

import org.apache.xml.dtm.DTM; //导入方法依赖的package包/类
public static String getPath(DTM dtm, int node) {
  String pre;
  switch (dtm.getNodeType(node)) {
    case Node.DOCUMENT_NODE:
      return "/";
    case Node.ELEMENT_NODE:
      pre = getPath(dtm, dtm.getParent(node));
      return (pre.equals("/") ? "" : pre) +
             "/" + dtm.getNodeName(node) + "[" + getNumberSimple(dtm, node) + "]";
    case Node.ATTRIBUTE_NODE:
      return getPath(dtm, dtm.getParent(node)) + "/@" + dtm.getNodeNameX(node);
    case Node.TEXT_NODE:
      pre = getPath(dtm, dtm.getParent(node));
      return (pre.equals("/") ? "" : pre) +
             "/text()[" + getNumberSimple(dtm, node) + "]";
    case Node.COMMENT_NODE:
      pre = getPath(dtm, dtm.getParent(node));
      return (pre.equals("/") ? "" : pre) +
             "/comment()[" + getNumberSimple(dtm, node) + "]";
    case Node.PROCESSING_INSTRUCTION_NODE:
      pre = getPath(dtm, dtm.getParent(node));
      return (pre.equals("/") ? "" : pre) +
             "/processing-instruction()[" + getNumberSimple(dtm, node) + "]";
  }
  return "?";
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:XalanSupport.java

示例2: isDefinedNSDecl

import org.apache.xml.dtm.DTM; //导入方法依赖的package包/类
/**
 * Returns whether a namespace is defined
 *
 *
 * @param attr Namespace attribute node
 * @param dtm The DTM that owns attr.
 *
 * @return True if the namespace is already defined in
 * list of namespaces
 */
public static boolean isDefinedNSDecl(
    SerializationHandler serializer,
    int attr,
    DTM dtm)
{

    if (DTM.NAMESPACE_NODE == dtm.getNodeType(attr))
    {

        // String prefix = dtm.getPrefix(attr);
        String prefix = dtm.getNodeNameX(attr);
        String uri = serializer.getNamespaceURIFromPrefix(prefix);
        //      String uri = getURI(prefix);

        if ((null != uri) && uri.equals(dtm.getStringValue(attr)))
            return true;
    }

    return false;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:31,代码来源:SerializerUtils.java

示例3: shouldStripWhiteSpace

import org.apache.xml.dtm.DTM; //导入方法依赖的package包/类
/**
 * Get information about whether or not an element should strip whitespace.
 * @see <a href="http://www.w3.org/TR/xslt#strip">strip in XSLT Specification</a>
 *
 * @param support The XPath runtime state.
 * @param targetElement Element to check
 *
 * @return true if the whitespace should be stripped.
 *
 * @throws TransformerException
 */
public boolean shouldStripWhiteSpace(
        XPathContext support, int targetElement) throws TransformerException
{
  if (null != m_whiteSpaceInfoList)
  {
    while(DTM.NULL != targetElement)
    {
      DTM dtm = support.getDTM(targetElement);
      WhiteSpaceInfo info = (WhiteSpaceInfo) m_whiteSpaceInfoList.getTemplate(support,
              targetElement, null, false, dtm);
      if(null != info)
        return info.getShouldStripSpace();
      
      int parent = dtm.getParent(targetElement);
      if(DTM.NULL != parent && DTM.ELEMENT_NODE == dtm.getNodeType(parent))
        targetElement = parent;
      else
        targetElement = DTM.NULL;
    }
  }
  return false;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:34,代码来源:StylesheetRoot.java

示例4: getNumberSimple

import org.apache.xml.dtm.DTM; //导入方法依赖的package包/类
private static int getNumberSimple(DTM dtm, int node) {
  final String localName = dtm.getLocalName(node);

  String uri = dtm.getNamespaceURI(node);
  if (uri == null) uri = "";

  final short type = dtm.getNodeType(node);

  int i = 1;
  int p = node;
  while ((p = dtm.getPreviousSibling(p)) != DTM.NULL) {
    if (dtm.getNodeType(p) == type) {
      switch (type) {
        case Node.TEXT_NODE:
        case Node.COMMENT_NODE:
        case Node.PROCESSING_INSTRUCTION_NODE:
          i++;
          break;
        default:
          if (localName.equals(dtm.getLocalName(p)) && uri.equals(dtm.getNamespaceURI(p))) {
            i++;
          }
      }
    }
  }
  return i;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:XalanSupport.java

示例5: outputResultTreeFragment

import org.apache.xml.dtm.DTM; //导入方法依赖的package包/类
/**
 * Given a result tree fragment, walk the tree and
 * output it to the SerializationHandler.
 *
 * @param obj Result tree fragment object
 * @param support XPath context for the result tree fragment
 *
 * @throws org.xml.sax.SAXException
 */
public static void outputResultTreeFragment(
    SerializationHandler handler,
    XObject obj,
    XPathContext support)
    throws org.xml.sax.SAXException
{

    int doc = obj.rtf();
    DTM dtm = support.getDTM(doc);

    if (null != dtm)
    {
        for (int n = dtm.getFirstChild(doc);
            DTM.NULL != n;
            n = dtm.getNextSibling(n))
        {
            handler.flushPending();

            // I think. . . . This used to have a (true) arg
            // to flush prefixes, will that cause problems ???
            if (dtm.getNodeType(n) == DTM.ELEMENT_NODE
                    && dtm.getNamespaceURI(n) == null)
                handler.startPrefixMapping("", "");
            dtm.dispatchToEvents(n, handler);
        }
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:37,代码来源:SerializerUtils.java

示例6: execute

import org.apache.xml.dtm.DTM; //导入方法依赖的package包/类
/**
 * 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));
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:43,代码来源:FuncNamespace.java

示例7: execute

import org.apache.xml.dtm.DTM; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:47,代码来源:FuncLang.java

示例8: execute

import org.apache.xml.dtm.DTM; //导入方法依赖的package包/类
/**
   * 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 : "");
  }
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:35,代码来源:FuncDoclocation.java

示例9: execute

import org.apache.xml.dtm.DTM; //导入方法依赖的package包/类
/**
 * 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
 */
public XObject execute(XPathContext xctxt) throws 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;
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:78,代码来源:FuncHere.java

示例10: getHead

import org.apache.xml.dtm.DTM; //导入方法依赖的package包/类
/**
 * Get the head of the most likely list of associations to check, based on 
 * the name and type of the targetNode argument.
 *
 * @param xctxt The XPath runtime context.
 * @param targetNode The target node that will be checked for a match.
 * @param dtm The dtm owner for the target node.
 *
 * @return The head of a linked list that contains all possible match pattern to 
 * template associations.
 */
public TemplateSubPatternAssociation getHead(XPathContext xctxt, 
                                             int targetNode, DTM dtm)
{
  short targetNodeType = dtm.getNodeType(targetNode);
  TemplateSubPatternAssociation head;

  switch (targetNodeType)
  {
  case DTM.ELEMENT_NODE :
  case DTM.ATTRIBUTE_NODE :
    head = (TemplateSubPatternAssociation) m_patternTable.get(
      dtm.getLocalName(targetNode));
    break;
  case DTM.TEXT_NODE :
  case DTM.CDATA_SECTION_NODE :
    head = m_textPatterns;
    break;
  case DTM.ENTITY_REFERENCE_NODE :
  case DTM.ENTITY_NODE :
    head = (TemplateSubPatternAssociation) m_patternTable.get(
      dtm.getNodeName(targetNode)); // %REVIEW% I think this is right
    break;
  case DTM.PROCESSING_INSTRUCTION_NODE :
    head = (TemplateSubPatternAssociation) m_patternTable.get(
      dtm.getLocalName(targetNode));
    break;
  case DTM.COMMENT_NODE :
    head = m_commentPatterns;
    break;
  case DTM.DOCUMENT_NODE :
  case DTM.DOCUMENT_FRAGMENT_NODE :
    head = m_docPatterns;
    break;
  case DTM.NOTATION_NODE :
  default :
    head = (TemplateSubPatternAssociation) m_patternTable.get(
      dtm.getNodeName(targetNode)); // %REVIEW% I think this is right
  }

  return (null == head) ? m_wildCardPatterns : head;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:53,代码来源:TemplateList.java

示例11: execute

import org.apache.xml.dtm.DTM; //导入方法依赖的package包/类
/**
 * The xsl:copy element provides an easy way of copying the current node.
 * Executing this function creates a copy of the current node into the
 * result tree.
 * <p>The namespace nodes of the current node are automatically
 * copied as well, but the attributes and children of the node are not
 * automatically copied. The content of the xsl:copy element is a
 * template for the attributes and children of the created node;
 * the content is instantiated only for nodes of types that can have
 * attributes or children (i.e. root nodes and element nodes).</p>
 * <p>The root node is treated specially because the root node of the
 * result tree is created implicitly. When the current node is the
 * root node, xsl:copy will not create a root node, but will just use
 * the content template.</p>
 *
 * @param transformer non-null reference to the the current transform-time state.
 *
 * @throws TransformerException
 */
public void execute(
        TransformerImpl transformer)
          throws TransformerException
{
              XPathContext xctxt = transformer.getXPathContext();
    
  try
  {
    int sourceNode = xctxt.getCurrentNode();
    xctxt.pushCurrentNode(sourceNode);
    DTM dtm = xctxt.getDTM(sourceNode);
    short nodeType = dtm.getNodeType(sourceNode);

    if ((DTM.DOCUMENT_NODE != nodeType) && (DTM.DOCUMENT_FRAGMENT_NODE != nodeType))
    {
      SerializationHandler rthandler = transformer.getSerializationHandler();

      // TODO: Process the use-attribute-sets stuff
      ClonerToResultTree.cloneToResultTree(sourceNode, nodeType, dtm, 
                                           rthandler, false);

      if (DTM.ELEMENT_NODE == nodeType)
      {
        super.execute(transformer);
        SerializerUtils.processNSDecls(rthandler, sourceNode, nodeType, dtm);
        transformer.executeChildTemplates(this, true);
        
        String ns = dtm.getNamespaceURI(sourceNode);
        String localName = dtm.getLocalName(sourceNode);
        transformer.getResultTreeHandler().endElement(ns, localName,
                                                      dtm.getNodeName(sourceNode));
      }
    }
    else
    {
      super.execute(transformer);
      transformer.executeChildTemplates(this, true);
    }
  }
  catch(org.xml.sax.SAXException se)
  {
    throw new TransformerException(se);
  }
  finally
  {
    xctxt.popCurrentNode();
  }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:68,代码来源:ElemCopy.java

示例12: execute

import org.apache.xml.dtm.DTM; //导入方法依赖的package包/类
/**
 * Tell what the test score is for the given node.
 *
 *
 * @param xctxt XPath runtime context.
 * @param context The node being tested.
 *
 * @return {@link org.apache.xpath.patterns.NodeTest#SCORE_NODETEST},
 *         {@link org.apache.xpath.patterns.NodeTest#SCORE_NONE},
 *         {@link org.apache.xpath.patterns.NodeTest#SCORE_NSWILD},
 *         {@link org.apache.xpath.patterns.NodeTest#SCORE_QNAME}, or
 *         {@link org.apache.xpath.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)
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:74,代码来源:NodeTest.java


注:本文中的org.apache.xml.dtm.DTM.getNodeType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。