Package org.apache.xpath

Examples of org.apache.xpath.DOMHelper


    try
    {
      boolean stripWhiteSpace = false;
      XPathContext xctxt = m_transformer.getXPathContext();
      DOMHelper dhelper = xctxt.getDOMHelper();

      switch (node.getNodeType())
      {
      case Node.TEXT_NODE :
        {
          Text tx = (Text) node;
          String data = null;

          // System.out.println("stripWhiteSpace = "+stripWhiteSpace+", "+tx.getData());
          if (stripWhiteSpace)
          {
            if (!dhelper.isIgnorableWhitespace(tx))
            {
              data = tx.getData();

              if ((null != data) && (0 == data.trim().length()))
              {
                data = null;
              }
            }
          }
          else
          {
            Node parent = node.getParentNode();

            if (null != parent)
            {
              if (Node.DOCUMENT_NODE != parent.getNodeType())
              {
                data = tx.getData();

                if ((null != data) && (0 == data.length()))
                {
                  data = null;
                }
              }
            }
            else
            {
              data = tx.getData();

              if ((null != data) && (0 == data.length()))
              {
                data = null;
              }
            }
          }

          if (null != data)
          {

            // TODO: Hack around the issue of comments next to literals.
            // This would be, when a comment is present, the whitespace
            // after the comment must be added to the literal.  The
            // parser should do this, but XML4J doesn't seem to.
            // <foo>some lit text
            //     <!-- comment -->
            //     </foo>
            // Loop through next siblings while they are comments, then,
            // if the node after that is a ignorable text node, append
            // it to the text node just added.
            if (dhelper.isIgnorableWhitespace(tx))
            {
              m_rth.ignorableWhitespace(data.toCharArray(), 0, data.length());
            }
            else
            {
              m_rth.characters(data.toCharArray(), 0, data.length());
            }
          }
        }
        break;
      case Node.DOCUMENT_FRAGMENT_NODE :
      case Node.DOCUMENT_NODE :

        // Can't clone a document, but refrain from throwing an error
        // so that copy-of will work
        break;
      case Node.ELEMENT_NODE :
        {
          Attributes atts;

          if (shouldCloneAttributes)
          {
            m_rth.addAttributes(node);
            m_rth.processNSDecls(node);
          }

          String ns = dhelper.getNamespaceOfNode(node);
          String localName = dhelper.getLocalNameOfNode(node);

          m_rth.startElement(ns, localName, node.getNodeName(), null);
        }
        break;
      case Node.CDATA_SECTION_NODE :
        {
          m_rth.startCDATA();

          String data = ((CDATASection) node).getData();

          m_rth.characters(data.toCharArray(), 0, data.length());
          m_rth.endCDATA();
        }
        break;
      case Node.ATTRIBUTE_NODE :
        {
          if (m_rth.isDefinedNSDecl((Attr) node))
            break;

          String ns = dhelper.getNamespaceOfNode(node);
          String localName = dhelper.getLocalNameOfNode(node);

          m_rth.addAttribute(ns, localName, node.getNodeName(), "CDATA",
                             ((Attr) node).getValue());
        }
        break;
View Full Code Here


  {

    if (isDefinedNSDecl(attr))
      return;

    DOMHelper helper = m_transformer.getXPathContext().getDOMHelper();
   
    String ns = helper.getNamespaceOfNode(attr);
    if(ns == null)
      ns = "";

    addAttribute(ns,
                 helper.getLocalNameOfNode(attr), attr.getNodeName(),
                 "CDATA", attr.getValue());
  // end copyAttributeToTarget method
View Full Code Here

    {
      int isNamespace = (m_whatToShow & SHOW_NAMESPACE);

      if (0 == isNamespace)
      {
        DOMHelper dh = xctxt.getDOMHelper();

        if (!dh.isNamespaceNode(context))
          return (m_isTotallyWild || (subPartMatchNS(dh.getNamespaceOfNode(context), m_namespace) && subPartMatch(dh.getLocalNameOfNode(context), m_name)))
                 ? m_score : SCORE_NONE;
        else
          return SCORE_NONE;
      }
      else
      {
        if (xctxt.getDOMHelper().isNamespaceNode(context))
        {
          String ns = context.getNodeValue();

          return (subPartMatch(ns, m_name)) ? m_score : SCORE_NONE;
        }
        else
          return SCORE_NONE;
      }
    }
    case NodeFilter.SHOW_ELEMENT :
    {
      DOMHelper dh = xctxt.getDOMHelper();

      return (m_isTotallyWild || (subPartMatchNS(dh.getNamespaceOfNode(context), m_namespace) && subPartMatch(dh.getLocalNameOfNode(context), m_name)))
             ? m_score : SCORE_NONE;
    }
    default :
      return SCORE_NONE;
    // end switch(testType)
View Full Code Here

    try
    {
      if ((Node.ELEMENT_NODE == node.getNodeType()) && (m_startNode == node))
      {
        DOMHelper dhelper = m_transformer.getXPathContext().getDOMHelper();
        String elemName = node.getNodeName();
        String localName = dhelper.getLocalNameOfNode(node);
        String namespace = dhelper.getNamespaceOfNode(node);

        m_handler.startElement(namespace, localName, elemName, null);

        for (Node parent = node; parent != null;
             parent = parent.getParentNode())
        {
          if (Node.ELEMENT_NODE != parent.getNodeType())
            continue;

          NamedNodeMap atts = ((Element) parent).getAttributes();
          int n = atts.getLength();

          for (int i = 0; i < n; i++)
          {
            String nsDeclPrefix = null;
            Attr attr = (Attr) atts.item(i);
            String name = attr.getName();
            String value = attr.getValue();

            if (name.startsWith("xmlns:"))
            {

              // get the namespace prefix
              nsDeclPrefix = name.substring(name.indexOf(":") + 1);
            }
            else if (name.equals("xmlns"))
            {
              nsDeclPrefix = "";
            }

            if ((nsDeclPrefix == null) && (node != parent))
              continue;

            /*
            else if(nsDeclPrefix != null)
            {
            String desturi = m_processor.getURI(nsDeclPrefix);
            // Look for an alias for this URI. If one is found, use it as the result URI
            String aliasURI = m_elem.m_stylesheet.lookForAlias(value);
            if(aliasURI.equals(desturi)) // TODO: Check for extension namespaces
            {
            continue;
            }
            }
            */
            m_handler.addAttribute(dhelper.getNamespaceOfNode(attr),
                                   dhelper.getLocalNameOfNode(attr), name,
                                   "CDATA", value);

            // Make sure namespace is not in the excluded list then
            // add to result tree

View Full Code Here

        {
          super.startNode(node);
        }
        else
        {
          DOMHelper dhelper = xcntxt.getDOMHelper();
          String elemName = node.getNodeName();
          String localName = dhelper.getLocalNameOfNode(node);
          String namespace = dhelper.getNamespaceOfNode(node);
 
          xcntxt.pushCurrentNode(node);
          m_handler.startElement(namespace, localName, elemName, null);
 
          for (Node parent = node; parent != null;
               parent = parent.getParentNode())
          {
            if (Node.ELEMENT_NODE != parent.getNodeType())
              continue;
 
            NamedNodeMap atts = ((Element) parent).getAttributes();
            int n = atts.getLength();
 
            for (int i = 0; i < n; i++)
            {
              String nsDeclPrefix = null;
              Attr attr = (Attr) atts.item(i);
              String name = attr.getName();
              String value = attr.getValue();
 
              if (name.startsWith("xmlns:"))
              {
 
                // get the namespace prefix
                nsDeclPrefix = name.substring(name.indexOf(":") + 1);
              }
              else if (name.equals("xmlns"))
              {
                nsDeclPrefix = "";
              }
 
              if ((nsDeclPrefix == null) && (node != parent))
                continue;
 
              /*
              else if(nsDeclPrefix != null)
              {
              String desturi = m_processor.getURI(nsDeclPrefix);
              // Look for an alias for this URI. If one is found, use it as the result URI
              String aliasURI = m_elem.m_stylesheet.lookForAlias(value);
              if(aliasURI.equals(desturi)) // TODO: Check for extension namespaces
              {
              continue;
              }
              }
              */
              m_handler.addAttribute(dhelper.getNamespaceOfNode(attr),
                                     dhelper.getLocalNameOfNode(attr), name,
                                     "CDATA", value);
 
              // Make sure namespace is not in the excluded list then
              // add to result tree
 
View Full Code Here

  {

    if (isDefinedNSDecl(attr))
      return;

    DOMHelper helper = m_transformer.getXPathContext().getDOMHelper();
   
    String ns = helper.getNamespaceOfNode(attr);
    if(ns == null)
      ns = "";

    addAttribute(ns,
                 helper.getLocalNameOfNode(attr), attr.getNodeName(),
                 "CDATA", attr.getValue());
  // end copyAttributeToTarget method
View Full Code Here

    {
      int isNamespace = (m_whatToShow & SHOW_NAMESPACE);

      if (0 == isNamespace)
      {
        DOMHelper dh = xctxt.getDOMHelper();

        if (!dh.isNamespaceNode(context))
          return (m_isTotallyWild || (subPartMatch(dh.getNamespaceOfNode(context), m_namespace) && subPartMatch(dh.getLocalNameOfNode(context), m_name)))
                 ? m_score : SCORE_NONE;
        else
          return SCORE_NONE;
      }
      else
      {
        if (xctxt.getDOMHelper().isNamespaceNode(context))
        {
          String ns = context.getNodeValue();

          return (subPartMatch(ns, m_name)) ? m_score : SCORE_NONE;
        }
        else
          return SCORE_NONE;
      }
    }
    case NodeFilter.SHOW_ELEMENT :
    {
      DOMHelper dh = xctxt.getDOMHelper();

      return (m_isTotallyWild || (subPartMatch(dh.getNamespaceOfNode(context), m_namespace) && subPartMatch(dh.getLocalNameOfNode(context), m_name)))
             ? m_score : SCORE_NONE;
    }
    default :
      return SCORE_NONE;
    // end switch(testType)
View Full Code Here

    try
    {
      boolean stripWhiteSpace = false;
      XPathContext xctxt = m_transformer.getXPathContext();
      DOMHelper dhelper = xctxt.getDOMHelper();

      switch (node.getNodeType())
      {
      case Node.TEXT_NODE :
        {
          Text tx = (Text) node;
          String data = null;

          // System.out.println("stripWhiteSpace = "+stripWhiteSpace+", "+tx.getData());
          if (stripWhiteSpace)
          {
            if (!dhelper.isIgnorableWhitespace(tx))
            {
              data = tx.getData();

              if ((null != data) && (0 == data.trim().length()))
              {
                data = null;
              }
            }
          }
          else
          {
            Node parent = node.getParentNode();

            if (null != parent)
            {
              if (Node.DOCUMENT_NODE != parent.getNodeType())
              {
                data = tx.getData();

                if ((null != data) && (0 == data.length()))
                {
                  data = null;
                }
              }
            }
            else
            {
              data = tx.getData();

              if ((null != data) && (0 == data.length()))
              {
                data = null;
              }
            }
          }

          if (null != data)
          {

            // TODO: Hack around the issue of comments next to literals.
            // This would be, when a comment is present, the whitespace
            // after the comment must be added to the literal.  The
            // parser should do this, but XML4J doesn't seem to.
            // <foo>some lit text
            //     <!-- comment -->
            //     </foo>
            // Loop through next siblings while they are comments, then,
            // if the node after that is a ignorable text node, append
            // it to the text node just added.
            if (dhelper.isIgnorableWhitespace(tx))
            {
              m_rth.ignorableWhitespace(data.toCharArray(), 0, data.length());
            }
            else
            {
              m_rth.characters(data.toCharArray(), 0, data.length());
            }
          }
        }
        break;
      case Node.DOCUMENT_FRAGMENT_NODE :
      case Node.DOCUMENT_NODE :

        // Can't clone a document, but refrain from throwing an error
        // so that copy-of will work
        break;
      case Node.ELEMENT_NODE :
        {
          Attributes atts;

          if (shouldCloneAttributes)
          {
            m_rth.addAttributes(node);
            m_rth.processNSDecls(node);
          }

          String ns = dhelper.getNamespaceOfNode(node);
          String localName = dhelper.getLocalNameOfNode(node);

          m_rth.startElement(ns, localName, node.getNodeName());
        }
        break;
      case Node.CDATA_SECTION_NODE :
        {
          m_rth.startCDATA();

          String data = ((CDATASection) node).getData();

          m_rth.characters(data.toCharArray(), 0, data.length());
          m_rth.endCDATA();
        }
        break;
      case Node.ATTRIBUTE_NODE :
        {
          if (m_rth.isDefinedNSDecl((Attr) node))
            break;

          String ns = dhelper.getNamespaceOfNode(node);
          String localName = dhelper.getLocalNameOfNode(node);

          m_rth.addAttribute(ns, localName, node.getNodeName(), "CDATA",
                             ((Attr) node).getValue());
        }
        break;
View Full Code Here

    try
    {
      if ((Node.ELEMENT_NODE == node.getNodeType()) && (m_startNode == node))
      {
        DOMHelper dhelper = m_transformer.getXPathContext().getDOMHelper();
        String elemName = node.getNodeName();
        String localName = dhelper.getLocalNameOfNode(node);
        String namespace = dhelper.getNamespaceOfNode(node);

        m_handler.startElement(namespace, localName, elemName);

        for (Node parent = node; parent != null;
             parent = parent.getParentNode())
        {
          if (Node.ELEMENT_NODE != parent.getNodeType())
            continue;

          NamedNodeMap atts = ((Element) parent).getAttributes();
          int n = atts.getLength();

          for (int i = 0; i < n; i++)
          {
            String nsDeclPrefix = null;
            Attr attr = (Attr) atts.item(i);
            String name = attr.getName();
            String value = attr.getValue();

            if (name.startsWith("xmlns:"))
            {

              // get the namespace prefix
              nsDeclPrefix = name.substring(name.indexOf(":") + 1);
            }
            else if (name.equals("xmlns"))
            {
              nsDeclPrefix = "";
            }

            if ((nsDeclPrefix == null) && (node != parent))
              continue;

            /*
            else if(nsDeclPrefix != null)
            {
            String desturi = m_processor.getURI(nsDeclPrefix);
            // Look for an alias for this URI. If one is found, use it as the result URI
            String aliasURI = m_elem.m_stylesheet.lookForAlias(value);
            if(aliasURI.equals(desturi)) // TODO: Check for extension namespaces
            {
            continue;
            }
            }
            */
            m_handler.addAttribute(dhelper.getNamespaceOfNode(attr),
                                   dhelper.getLocalNameOfNode(attr), name,
                                   "CDATA", value);

            // Make sure namespace is not in the excluded list then
            // add to result tree

View Full Code Here

  {

    if (null != refval)
    {
      String ref = null;
      DOMHelper dh = xctxt.getDOMHelper();
      StringTokenizer tokenizer = new StringTokenizer(refval);
      boolean hasMore = tokenizer.hasMoreTokens();

      while (hasMore)
      {
        ref = tokenizer.nextToken();
        hasMore = tokenizer.hasMoreTokens();

        if ((null != usedrefs) && usedrefs.contains(ref))
        {
          ref = null;

          continue;
        }

        Node node = dh.getElementByID(ref, docContext);

        if (null != node)
          nodeSet.addNodeInDocOrder(node, xctxt);

        if ((null != ref) && (hasMore || mayBeMore))
View Full Code Here

TOP

Related Classes of org.apache.xpath.DOMHelper

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.