Java Code Examples for org.w3c.dom.Node.CDATA_SECTION_NODE

The following are Jave code examples for showing how to use CDATA_SECTION_NODE of the org.w3c.dom.Node class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: java-tools   File: DOMNodeAsMFNodeAdapter.java   View Source Code Vote up 6 votes
public int getNodeKind() 
{
	switch (node.getNodeType())
	{
		case Node.ATTRIBUTE_NODE:
			return MFNodeKind_Attribute; // also field?
		case Node.CDATA_SECTION_NODE:
			return MFNodeKind_Text | MFNodeKind_CData;
		case Node.COMMENT_NODE:
			return MFNodeKind_Comment;
		case Node.DOCUMENT_NODE:
			return MFNodeKind_Document;
		case Node.ELEMENT_NODE:
			return MFNodeKind_Element;
		case Node.TEXT_NODE:
			return MFNodeKind_Text;
		case Node.PROCESSING_INSTRUCTION_NODE:
			return MFNodeKind_ProcessingInstruction;
		default:
			return 0;
	}
}
 
Example 2
Project: OSWf-OSWorkflow-fork   File: XMLHelper.java   View Source Code Vote up 6 votes
public static String getText(Element node) {
    StringBuffer sb = new StringBuffer();
    NodeList list = node.getChildNodes();

    for (int i = 0; i < list.getLength(); i++) {
        Node child = list.item(i);

        switch (child.getNodeType()) {
        case Node.CDATA_SECTION_NODE:
        case Node.TEXT_NODE:
            sb.append(child.getNodeValue());
        }
    }

    return sb.toString();
}
 
Example 3
Project: openjdk-jdk10   File: DOM3TreeWalker.java   View Source Code Vote up 6 votes
/**
 * End processing of given node
 *
 *
 * @param node Node we just finished processing
 *
 * @throws org.xml.sax.SAXException
 */
protected void endNode(Node node) throws org.xml.sax.SAXException {

    switch (node.getNodeType()) {
        case Node.DOCUMENT_NODE :
            break;
        case Node.DOCUMENT_TYPE_NODE :
            serializeDocType((DocumentType) node, false);
            break;
        case Node.ELEMENT_NODE :
            serializeElement((Element) node, false);
            break;
        case Node.CDATA_SECTION_NODE :
            break;
        case Node.ENTITY_REFERENCE_NODE :
            serializeEntityReference((EntityReference) node, false);
            break;
        default :
            }
}
 
Example 4
Project: OpenJSharp   File: AnyTypeBeanInfo.java   View Source Code Vote up 6 votes
public void serializeBody(Object element, XMLSerializer target) throws SAXException, IOException, XMLStreamException {
    NodeList childNodes = ((Element)element).getChildNodes();
    int len = childNodes.getLength();
    for( int i=0; i<len; i++ ) {
        Node child = childNodes.item(i);
        switch(child.getNodeType()) {
        case Node.CDATA_SECTION_NODE:
        case Node.TEXT_NODE:
            target.text(child.getNodeValue(),null);
            break;
        case Node.ELEMENT_NODE:
            target.writeDom((Element)child,domHandler,null,null);
            break;
        }
    }
}
 
Example 5
Project: OpenJSharp   File: TextImpl.java   View Source Code Vote up 5 votes
/**
 * Concatenates the text of all logically-adjacent text nodes to the
 * right of this node
 * @param node
 * @param buffer
 * @param parent
 * @return true - if execution was stopped because the type of node
 *         other than EntityRef, Text, CDATA is encountered, otherwise
 *         return false
 */
private boolean getWholeTextForward(Node node, StringBuffer buffer, Node parent){
    // boolean to indicate whether node is a child of an entity reference
    boolean inEntRef = false;

    if (parent!=null) {
            inEntRef = parent.getNodeType()==Node.ENTITY_REFERENCE_NODE;
    }

    while (node != null) {
        short type = node.getNodeType();
        if (type == Node.ENTITY_REFERENCE_NODE) {
            if (getWholeTextForward(node.getFirstChild(), buffer, node)){
                return true;
            }
        }
        else if (type == Node.TEXT_NODE ||
                 type == Node.CDATA_SECTION_NODE) {
            ((NodeImpl)node).getTextContent(buffer);
        }
        else {
            return true;
        }

        node = node.getNextSibling();
    }

    // if the parent node is an entity reference node, must
    // check nodes to the right of the parent entity reference node for logically adjacent
    // text nodes
    if (inEntRef) {
        getWholeTextForward(parent.getNextSibling(), buffer, parent.getParentNode());
                    return true;
    }

    return false;
}
 
Example 6
Project: OpenJSharp   File: DOM2DTM.java   View Source Code Vote up 5 votes
/**
 * Retrieve the text content of a DOM subtree, appending it into a
 * user-supplied FastStringBuffer object. Note that attributes are
 * not considered part of the content of an element.
 * <p>
 * There are open questions regarding whitespace stripping.
 * Currently we make no special effort in that regard, since the standard
 * DOM doesn't yet provide DTD-based information to distinguish
 * whitespace-in-element-context from genuine #PCDATA. Note that we
 * should probably also consider xml:space if/when we address this.
 * DOM Level 3 may solve the problem for us.
 * <p>
 * %REVIEW% Actually, since this method operates on the DOM side of the
 * fence rather than the DTM side, it SHOULDN'T do
 * any special handling. The DOM does what the DOM does; if you want
 * DTM-level abstractions, use DTM-level methods.
 *
 * @param node Node whose subtree is to be walked, gathering the
 * contents of all Text or CDATASection nodes.
 * @param buf FastStringBuffer into which the contents of the text
 * nodes are to be concatenated.
 */
protected static void getNodeData(Node node, FastStringBuffer buf)
{

  switch (node.getNodeType())
  {
  case Node.DOCUMENT_FRAGMENT_NODE :
  case Node.DOCUMENT_NODE :
  case Node.ELEMENT_NODE :
  {
    for (Node child = node.getFirstChild(); null != child;
            child = child.getNextSibling())
    {
      getNodeData(child, buf);
    }
  }
  break;
  case Node.TEXT_NODE :
  case Node.CDATA_SECTION_NODE :
  case Node.ATTRIBUTE_NODE :  // Never a child but might be our starting node
    buf.append(node.getNodeValue());
    break;
  case Node.PROCESSING_INSTRUCTION_NODE :
    // warning(XPATHErrorResources.WG_PARSING_AND_PREPARING);
    break;
  default :
    // ignore
    break;
  }
}
 
Example 7
Project: javaide   File: MergerXmlUtils.java   View Source Code Vote up 5 votes
public static void setSource(@NonNull Node node, @NonNull File source) {
    //noinspection ConstantConditions
    for (; node != null; node = node.getNextSibling()) {
        short nodeType = node.getNodeType();
        if (nodeType == Node.ELEMENT_NODE
                || nodeType == Node.COMMENT_NODE
                || nodeType == Node.DOCUMENT_NODE
                || nodeType == Node.CDATA_SECTION_NODE) {
            node.setUserData(DATA_ORIGIN_FILE, source, null);
        }
        Node child = node.getFirstChild();
        setSource(child, source);
    }
}
 
Example 8
Project: openjdk-jdk10   File: DOM2TO.java   View Source Code Vote up 5 votes
private String getNodeTypeFromCode(short code) {
    String retval = null;
    switch (code) {
    case Node.ATTRIBUTE_NODE :
        retval = "ATTRIBUTE_NODE"; break;
    case Node.CDATA_SECTION_NODE :
        retval = "CDATA_SECTION_NODE"; break;
    case Node.COMMENT_NODE :
        retval = "COMMENT_NODE"; break;
    case Node.DOCUMENT_FRAGMENT_NODE :
        retval = "DOCUMENT_FRAGMENT_NODE"; break;
    case Node.DOCUMENT_NODE :
        retval = "DOCUMENT_NODE"; break;
    case Node.DOCUMENT_TYPE_NODE :
        retval = "DOCUMENT_TYPE_NODE"; break;
    case Node.ELEMENT_NODE :
        retval = "ELEMENT_NODE"; break;
    case Node.ENTITY_NODE :
        retval = "ENTITY_NODE"; break;
    case Node.ENTITY_REFERENCE_NODE :
        retval = "ENTITY_REFERENCE_NODE"; break;
    case Node.NOTATION_NODE :
        retval = "NOTATION_NODE"; break;
    case Node.PROCESSING_INSTRUCTION_NODE :
        retval = "PROCESSING_INSTRUCTION_NODE"; break;
    case Node.TEXT_NODE:
        retval = "TEXT_NODE"; break;
    }
    return retval;
}
 
Example 9
Project: openjdk-jdk10   File: TextImpl.java   View Source Code Vote up 5 votes
/**
 * Concatenates the text of all logically-adjacent text nodes to the
 * right of this node
 * @param node
 * @param buffer
 * @param parent
 * @return true - if execution was stopped because the type of node
 *         other than EntityRef, Text, CDATA is encountered, otherwise
 *         return false
 */
private boolean getWholeTextForward(Node node, StringBuffer buffer, Node parent){
    // boolean to indicate whether node is a child of an entity reference
    boolean inEntRef = false;

    if (parent!=null) {
            inEntRef = parent.getNodeType()==Node.ENTITY_REFERENCE_NODE;
    }

    while (node != null) {
        short type = node.getNodeType();
        if (type == Node.ENTITY_REFERENCE_NODE) {
            if (getWholeTextForward(node.getFirstChild(), buffer, node)){
                return true;
            }
        }
        else if (type == Node.TEXT_NODE ||
                 type == Node.CDATA_SECTION_NODE) {
            ((NodeImpl)node).getTextContent(buffer);
        }
        else {
            return true;
        }

        node = node.getNextSibling();
    }

    // if the parent node is an entity reference node, must
    // check nodes to the right of the parent entity reference node for logically adjacent
    // text nodes
    if (inEntRef) {
        getWholeTextForward(parent.getNextSibling(), buffer, parent.getParentNode());
                    return true;
    }

    return false;
}
 
Example 10
Project: defense-solutions-proofs-of-concept   File: CoTAdapter.java   View Source Code Vote up 4 votes
public static String elementToString(Node n) {

		String name = n.getNodeName();
		short type = n.getNodeType();

		if (Node.CDATA_SECTION_NODE == type) {
			return "<![CDATA[" + n.getNodeValue() + "]]&gt;";
		}

		if (name.startsWith("#")) {
			return "";
		}

		StringBuffer sb = new StringBuffer();
		sb.append('<').append(name);

		NamedNodeMap attrs = n.getAttributes();
		if (attrs != null) {
			for (int i = 0; i < attrs.getLength(); i++) {
				Node attr = attrs.item(i);
				sb.append(' ').append(attr.getNodeName()).append("=\"")
				.append(attr.getNodeValue()).append("\"");
			}
		}

		String textContent = null;
		NodeList children = n.getChildNodes();

		if (children.getLength() == 0) {
			if ((textContent = n.getTextContent()) != null
					&& !"".equals(textContent)) {
				sb.append(textContent).append("</").append(name).append('>');
			} else {
				sb.append("/>").append('\n');
			}
		} else {
			sb.append('>').append('\n');
			boolean hasValidChildren = false;
			for (int i = 0; i < children.getLength(); i++) {
				String childToString = elementToString(children.item(i));
				if (!"".equals(childToString)) {
					sb.append(childToString);
					hasValidChildren = true;
				}
			}

			if (!hasValidChildren
					&& ((textContent = n.getTextContent()) != null)) {
				sb.append(textContent);
			}

			sb.append("</").append(name).append('>');
		}

		return sb.toString();
	}
 
Example 11
Project: openjdk-jdk10   File: DOM2DTM.java   View Source Code Vote up 4 votes
/**
   * Retrieve the text content of a DOM subtree, appending it into a
   * user-supplied FastStringBuffer object. Note that attributes are
   * not considered part of the content of an element.
   * <p>
   * There are open questions regarding whitespace stripping.
   * Currently we make no special effort in that regard, since the standard
   * DOM doesn't yet provide DTD-based information to distinguish
   * whitespace-in-element-context from genuine #PCDATA. Note that we
   * should probably also consider xml:space if/when we address this.
   * DOM Level 3 may solve the problem for us.
   * <p>
   * %REVIEW% Note that as a DOM-level operation, it can be argued that this
   * routine _shouldn't_ perform any processing beyond what the DOM already
   * does, and that whitespace stripping and so on belong at the DTM level.
   * If you want a stripped DOM view, wrap DTM2DOM around DOM2DTM.
   *
   * @param node Node whose subtree is to be walked, gathering the
   * contents of all Text or CDATASection nodes.
   */
  protected static void dispatchNodeData(Node node,
                                         org.xml.sax.ContentHandler ch,
                                         int depth)
            throws org.xml.sax.SAXException
  {

    switch (node.getNodeType())
    {
    case Node.DOCUMENT_FRAGMENT_NODE :
    case Node.DOCUMENT_NODE :
    case Node.ELEMENT_NODE :
    {
      for (Node child = node.getFirstChild(); null != child;
              child = child.getNextSibling())
      {
        dispatchNodeData(child, ch, depth+1);
      }
    }
    break;
    case Node.PROCESSING_INSTRUCTION_NODE : // %REVIEW%
    case Node.COMMENT_NODE :
      if(0 != depth)
        break;
        // NOTE: Because this operation works in the DOM space, it does _not_ attempt
        // to perform Text Coalition. That should only be done in DTM space.
    case Node.TEXT_NODE :
    case Node.CDATA_SECTION_NODE :
    case Node.ATTRIBUTE_NODE :
      String str = node.getNodeValue();
      if(ch instanceof CharacterNodeHandler)
      {
        ((CharacterNodeHandler)ch).characters(node);
      }
      else
      {
        ch.characters(str.toCharArray(), 0, str.length());
      }
      break;
//    /* case Node.PROCESSING_INSTRUCTION_NODE :
//      // warning(XPATHErrorResources.WG_PARSING_AND_PREPARING);
//      break; */
    default :
      // ignore
      break;
    }
  }
 
Example 12
Project: defense-solutions-proofs-of-concept   File: CoTAdapterInbound.java   View Source Code Vote up 4 votes
public static String elementToString(Node n) throws Exception {
	try {
		String name = n.getNodeName();
		short type = n.getNodeType();

		if (Node.CDATA_SECTION_NODE == type) {
			return "<![CDATA[" + n.getNodeValue() + "]]&gt;";
		}

		if (name.startsWith("#")) {
			return "";
		}

		StringBuffer sb = new StringBuffer();
		sb.append('<').append(name);

		NamedNodeMap attrs = n.getAttributes();
		if (attrs != null) {
			for (int i = 0; i < attrs.getLength(); i++) {
				Node attr = attrs.item(i);
				sb.append(' ').append(attr.getNodeName()).append("=\"")
						.append(attr.getNodeValue()).append("\"");
			}
		}

		String textContent = null;
		NodeList children = n.getChildNodes();

		if (children.getLength() == 0) {
			if ((textContent = n.getTextContent()) != null
					&& !"".equals(textContent)) {
				sb.append(textContent).append("</").append(name)
						.append('>');
			} else {
				sb.append("/>").append('\n');
			}
		} else {
			sb.append('>').append('\n');
			boolean hasValidChildren = false;
			for (int i = 0; i < children.getLength(); i++) {
				String childToString = elementToString(children.item(i));
				if (!"".equals(childToString)) {
					sb.append(childToString);
					hasValidChildren = true;
				}
			}

			if (!hasValidChildren
					&& ((textContent = n.getTextContent()) != null)) {
				sb.append(textContent);
			}

			sb.append("</").append(name).append('>');
		}

		return sb.toString();
	} catch (Exception e) {
		log.error(e);
		log.error(e.getStackTrace());
		throw (e);
	}
}
 
Example 13
Project: MybatisGeneatorUtil   File: DomWriter.java   View Source Code Vote up 4 votes
/**
 * Write any node.
 *
 * @param node
 *            the node
 * @throws ShellException
 *             the shell exception
 */
protected void writeAnyNode(Node node) throws ShellException {
    // is there anything to do?
    if (node == null) {
        return;
    }

    short type = node.getNodeType();
    switch (type) {
    case Node.DOCUMENT_NODE:
        write((Document) node);
        break;

    case Node.DOCUMENT_TYPE_NODE:
        write((DocumentType) node);
        break;

    case Node.ELEMENT_NODE:
        write((Element) node);
        break;

    case Node.ENTITY_REFERENCE_NODE:
        write((EntityReference) node);
        break;

    case Node.CDATA_SECTION_NODE:
        write((CDATASection) node);
        break;

    case Node.TEXT_NODE:
        write((Text) node);
        break;

    case Node.PROCESSING_INSTRUCTION_NODE:
        write((ProcessingInstruction) node);
        break;

    case Node.COMMENT_NODE:
        write((Comment) node);
        break;

    default:
        throw new ShellException(getString(
                "RuntimeError.18", Short.toString(type))); //$NON-NLS-1$
    }
}
 
Example 14
Project: jdk8u-jdk   File: ReferenceSubTreeData.java   View Source Code Vote up 4 votes
/**
 * Recursively traverses the subtree, and returns an XPath-equivalent
 * node-set of all nodes traversed, excluding any comment nodes,
 * if specified.
 *
 * @param node the node to traverse
 * @param nodeSet the set of nodes traversed so far
 * @param the previous sibling node
 */
@SuppressWarnings("fallthrough")
private void nodeSetMinusCommentNodes(Node node, List<Node> nodeSet,
                                      Node prevSibling)
{
    switch (node.getNodeType()) {
        case Node.ELEMENT_NODE :
            nodeSet.add(node);
            NamedNodeMap attrs = node.getAttributes();
            if (attrs != null) {
                for (int i = 0, len = attrs.getLength(); i < len; i++) {
                    nodeSet.add(attrs.item(i));
                }
            }
            Node pSibling = null;
            for (Node child = node.getFirstChild(); child != null;
                child = child.getNextSibling()) {
                nodeSetMinusCommentNodes(child, nodeSet, pSibling);
                pSibling = child;
            }
            break;
        case Node.DOCUMENT_NODE :
            pSibling = null;
            for (Node child = node.getFirstChild(); child != null;
                child = child.getNextSibling()) {
                nodeSetMinusCommentNodes(child, nodeSet, pSibling);
                pSibling = child;
            }
            break;
        case Node.TEXT_NODE :
        case Node.CDATA_SECTION_NODE:
            // emulate XPath which only returns the first node in
            // contiguous text/cdata nodes
            if (prevSibling != null &&
                (prevSibling.getNodeType() == Node.TEXT_NODE ||
                 prevSibling.getNodeType() == Node.CDATA_SECTION_NODE)) {
                return;
            }
            nodeSet.add(node);
            break;
        case Node.PROCESSING_INSTRUCTION_NODE :
            nodeSet.add(node);
            break;
        case Node.COMMENT_NODE:
            if (withComments) {
                nodeSet.add(node);
            }
    }
}
 
Example 15
Project: OpenJSharp   File: DOMSubTreeData.java   View Source Code Vote up 4 votes
/**
 * Recursively traverses the subtree, and returns an XPath-equivalent
 * node-set of all nodes traversed, excluding any comment nodes,
 * if specified.
 *
 * @param node the node to traverse
 * @param nodeSet the set of nodes traversed so far
 * @param the previous sibling node
 */
@SuppressWarnings("fallthrough")
private void nodeSetMinusCommentNodes(Node node, List<Node> nodeSet,
                                      Node prevSibling)
{
    switch (node.getNodeType()) {
        case Node.ELEMENT_NODE :
            NamedNodeMap attrs = node.getAttributes();
            if (attrs != null) {
                for (int i = 0, len = attrs.getLength(); i < len; i++) {
                    nodeSet.add(attrs.item(i));
                }
            }
            nodeSet.add(node);
            Node pSibling = null;
            for (Node child = node.getFirstChild(); child != null;
                child = child.getNextSibling()) {
                nodeSetMinusCommentNodes(child, nodeSet, pSibling);
                pSibling = child;
            }
            break;
        case Node.DOCUMENT_NODE :
            pSibling = null;
            for (Node child = node.getFirstChild(); child != null;
                child = child.getNextSibling()) {
                nodeSetMinusCommentNodes(child, nodeSet, pSibling);
                pSibling = child;
            }
            break;
        case Node.TEXT_NODE :
        case Node.CDATA_SECTION_NODE:
            // emulate XPath which only returns the first node in
            // contiguous text/cdata nodes
            if (prevSibling != null &&
                (prevSibling.getNodeType() == Node.TEXT_NODE ||
                 prevSibling.getNodeType() == Node.CDATA_SECTION_NODE)) {
                return;
            }
            nodeSet.add(node);
            break;
        case Node.PROCESSING_INSTRUCTION_NODE :
            nodeSet.add(node);
            break;
        case Node.COMMENT_NODE:
            if (withComments) {
                nodeSet.add(node);
            }
    }
}
 
Example 16
Project: convertigo-engine   File: DOMNodePointer.java   View Source Code Vote up 4 votes
/**
 * Test a Node.
 * @param node to test
 * @param test to execute
 * @return true if node passes test
 */
public static boolean testNode(Node node, NodeTest test) {
    if (test == null) {
        return true;
    }
    if (test instanceof NodeNameTest) {
        if (node.getNodeType() != Node.ELEMENT_NODE) {
            return false;
        }

        NodeNameTest nodeNameTest = (NodeNameTest) test;
        QName testName = nodeNameTest.getNodeName();
        String namespaceURI = nodeNameTest.getNamespaceURI();
        boolean wildcard = nodeNameTest.isWildcard();
        String testPrefix = testName.getPrefix();
        if (wildcard && testPrefix == null) {
            return true;
        }
        if (wildcard
            || testName.getName()
                    .equals(DOMNodePointer.getLocalName(node))) {
            String nodeNS = DOMNodePointer.getNamespaceURI(node);
            return equalStrings(namespaceURI, nodeNS) || nodeNS == null
                    && equalStrings(testPrefix, getPrefix(node));
        }
        return false;
    }
    if (test instanceof NodeTypeTest) {
        int nodeType = node.getNodeType();
        switch (((NodeTypeTest) test).getNodeType()) {
            case Compiler.NODE_TYPE_NODE :
                return true;
            case Compiler.NODE_TYPE_TEXT :
                return nodeType == Node.CDATA_SECTION_NODE
                    || nodeType == Node.TEXT_NODE;
            case Compiler.NODE_TYPE_COMMENT :
                return nodeType == Node.COMMENT_NODE;
            case Compiler.NODE_TYPE_PI :
                return nodeType == Node.PROCESSING_INSTRUCTION_NODE;
            default:
                return false;
        }
    }
    if (test instanceof ProcessingInstructionTest
            && node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
        String testPI = ((ProcessingInstructionTest) test).getTarget();
        String nodePI = ((ProcessingInstruction) node).getTarget();
        return testPI.equals(nodePI);
    }
    return false;
}
 
Example 17
Project: summer-mybatis-generator   File: DomWriter.java   View Source Code Vote up 4 votes
/**
 * Write any node.
 *
 * @param node
 *            the node
 * @throws ShellException
 *             the shell exception
 */
protected void writeAnyNode(Node node) throws ShellException {
    // is there anything to do?
    if (node == null) {
        return;
    }

    short type = node.getNodeType();
    switch (type) {
    case Node.DOCUMENT_NODE:
        write((Document) node);
        break;

    case Node.DOCUMENT_TYPE_NODE:
        write((DocumentType) node);
        break;

    case Node.ELEMENT_NODE:
        write((Element) node);
        break;

    case Node.ENTITY_REFERENCE_NODE:
        write((EntityReference) node);
        break;

    case Node.CDATA_SECTION_NODE:
        write((CDATASection) node);
        break;

    case Node.TEXT_NODE:
        write((Text) node);
        break;

    case Node.PROCESSING_INSTRUCTION_NODE:
        write((ProcessingInstruction) node);
        break;

    case Node.COMMENT_NODE:
        write((Comment) node);
        break;

    default:
        throw new ShellException(getString(
                "RuntimeError.18", Short.toString(type))); //$NON-NLS-1$
    }
}
 
Example 18
Project: openjdk-jdk10   File: DOMValidatorHelper.java   View Source Code Vote up 4 votes
/** Do processing for the start of a node. */
private void beginNode(Node node) {
    switch (node.getNodeType()) {
        case Node.ELEMENT_NODE:
            fCurrentElement = node;
            // push namespace context
            fNamespaceContext.pushContext();
            // start element
            fillQName(fElementQName, node);
            processAttributes(node.getAttributes());
            fSchemaValidator.startElement(fElementQName, fAttributes, null);
            break;
        case Node.TEXT_NODE:
            if (fDOMValidatorHandler != null) {
                fDOMValidatorHandler.setIgnoringCharacters(true);
                sendCharactersToValidator(node.getNodeValue());
                fDOMValidatorHandler.setIgnoringCharacters(false);
                fDOMValidatorHandler.characters((Text) node);
            }
            else {
                sendCharactersToValidator(node.getNodeValue());
            }
            break;
        case Node.CDATA_SECTION_NODE:
            if (fDOMValidatorHandler != null) {
                fDOMValidatorHandler.setIgnoringCharacters(true);
                fSchemaValidator.startCDATA(null);
                sendCharactersToValidator(node.getNodeValue());
                fSchemaValidator.endCDATA(null);
                fDOMValidatorHandler.setIgnoringCharacters(false);
                fDOMValidatorHandler.cdata((CDATASection) node);
            }
            else {
                fSchemaValidator.startCDATA(null);
                sendCharactersToValidator(node.getNodeValue());
                fSchemaValidator.endCDATA(null);
            }
            break;
        case Node.PROCESSING_INSTRUCTION_NODE:
            /**
             * The validator does nothing with processing instructions so bypass it.
             * Send the ProcessingInstruction node directly to the result builder.
             */
            if (fDOMValidatorHandler != null) {
                fDOMValidatorHandler.processingInstruction((ProcessingInstruction) node);
            }
            break;
        case Node.COMMENT_NODE:
            /**
             * The validator does nothing with comments so bypass it.
             * Send the Comment node directly to the result builder.
             */
            if (fDOMValidatorHandler != null) {
                fDOMValidatorHandler.comment((Comment) node);
            }
            break;
        case Node.DOCUMENT_TYPE_NODE:
            /**
             * Send the DocumentType node directly to the result builder.
             */
            if (fDOMValidatorHandler != null) {
                fDOMValidatorHandler.doctypeDecl((DocumentType) node);
            }
            break;
        default: // Ignore other node types.
            break;
    }
}
 
Example 19
Project: lams   File: AbstractXMLObjectUnmarshaller.java   View Source Code Vote up 4 votes
/** {@inheritDoc} */
public XMLObject unmarshall(Element domElement) throws UnmarshallingException {
    if (log.isTraceEnabled()) {
        log.trace("Starting to unmarshall DOM element {}", XMLHelper.getNodeQName(domElement));
    }
    
    checkElementIsTarget(domElement);

    XMLObject xmlObject = buildXMLObject(domElement);

    if (log.isTraceEnabled()) {
        log.trace("Unmarshalling attributes of DOM Element {}", XMLHelper.getNodeQName(domElement));
    }
    
    NamedNodeMap attributes = domElement.getAttributes();
    Node attribute;
    for (int i = 0; i < attributes.getLength(); i++) {
        attribute = attributes.item(i);

        // These should allows be attribute nodes, but just in case...
        if (attribute.getNodeType() == Node.ATTRIBUTE_NODE) {
            unmarshallAttribute(xmlObject, (Attr) attribute);
        }
    }

    if (log.isTraceEnabled()) {
        log.trace("Unmarshalling other child nodes of DOM Element {}", XMLHelper.getNodeQName(domElement));
    }
    
    Node childNode = domElement.getFirstChild();
    while (childNode != null) {

        if (childNode.getNodeType() == Node.ATTRIBUTE_NODE) {
            unmarshallAttribute(xmlObject, (Attr) childNode);
        } else if (childNode.getNodeType() == Node.ELEMENT_NODE) {
            unmarshallChildElement(xmlObject, (Element) childNode);
        } else if (childNode.getNodeType() == Node.TEXT_NODE
                || childNode.getNodeType() == Node.CDATA_SECTION_NODE) {
            unmarshallTextContent(xmlObject, (Text) childNode);
        }
        
        childNode = childNode.getNextSibling();
    }

    xmlObject.setDOM(domElement);
    return xmlObject;
}
 
Example 20
Project: OpenJSharp   File: DOMValidatorHelper.java   View Source Code Vote up 4 votes
/** Do processing for the start of a node. */
private void beginNode(Node node) {
    switch (node.getNodeType()) {
        case Node.ELEMENT_NODE:
            fCurrentElement = node;
            // push namespace context
            fNamespaceContext.pushContext();
            // start element
            fillQName(fElementQName, node);
            processAttributes(node.getAttributes());
            fSchemaValidator.startElement(fElementQName, fAttributes, null);
            break;
        case Node.TEXT_NODE:
            if (fDOMValidatorHandler != null) {
                fDOMValidatorHandler.setIgnoringCharacters(true);
                sendCharactersToValidator(node.getNodeValue());
                fDOMValidatorHandler.setIgnoringCharacters(false);
                fDOMValidatorHandler.characters((Text) node);
            }
            else {
                sendCharactersToValidator(node.getNodeValue());
            }
            break;
        case Node.CDATA_SECTION_NODE:
            if (fDOMValidatorHandler != null) {
                fDOMValidatorHandler.setIgnoringCharacters(true);
                fSchemaValidator.startCDATA(null);
                sendCharactersToValidator(node.getNodeValue());
                fSchemaValidator.endCDATA(null);
                fDOMValidatorHandler.setIgnoringCharacters(false);
                fDOMValidatorHandler.cdata((CDATASection) node);
            }
            else {
                fSchemaValidator.startCDATA(null);
                sendCharactersToValidator(node.getNodeValue());
                fSchemaValidator.endCDATA(null);
            }
            break;
        case Node.PROCESSING_INSTRUCTION_NODE:
            /**
             * The validator does nothing with processing instructions so bypass it.
             * Send the ProcessingInstruction node directly to the result builder.
             */
            if (fDOMValidatorHandler != null) {
                fDOMValidatorHandler.processingInstruction((ProcessingInstruction) node);
            }
            break;
        case Node.COMMENT_NODE:
            /**
             * The validator does nothing with comments so bypass it.
             * Send the Comment node directly to the result builder.
             */
            if (fDOMValidatorHandler != null) {
                fDOMValidatorHandler.comment((Comment) node);
            }
            break;
        case Node.DOCUMENT_TYPE_NODE:
            /**
             * Send the DocumentType node directly to the result builder.
             */
            if (fDOMValidatorHandler != null) {
                fDOMValidatorHandler.doctypeDecl((DocumentType) node);
            }
            break;
        default: // Ignore other node types.
            break;
    }
}