當前位置: 首頁>>代碼示例>>Java>>正文


Java Comment類代碼示例

本文整理匯總了Java中org.w3c.dom.Comment的典型用法代碼示例。如果您正苦於以下問題:Java Comment類的具體用法?Java Comment怎麽用?Java Comment使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Comment類屬於org.w3c.dom包,在下文中一共展示了Comment類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: print

import org.w3c.dom.Comment; //導入依賴的package包/類
protected void print(Node node, Map namespaces, boolean endWithComma) {
    switch (node.getNodeType()) {
        case Node.ELEMENT_NODE :
            printElement((Element) node, namespaces, endWithComma);
            break;
        case Node.PROCESSING_INSTRUCTION_NODE :
            printPI((ProcessingInstruction) node, endWithComma);
            break;
        case Node.TEXT_NODE :
            printText((Text) node, endWithComma);
            break;
        case Node.COMMENT_NODE :
            printComment((Comment) node, endWithComma);
            break;
    }
}
 
開發者ID:apache,項目名稱:groovy,代碼行數:17,代碼來源:DomToGroovy.java

示例2: addStatisticsAsText

import org.w3c.dom.Comment; //導入依賴的package包/類
protected Object addStatisticsAsText(String stats, Object result) throws UnsupportedEncodingException{ 
	if (result != null) { 
               if (stats == null) stats = context.statistics.printStatistics(); 
               if (result instanceof Document) { 
                       Document document = (Document) result; 
                       Comment comment = document.createComment("\n" + stats); 
                       document.appendChild(comment); 
               } 
               else if (result instanceof byte[]) { 
                       String encodingCharSet = "UTF-8"; 
                       if (context.requestedObject != null) 
                               encodingCharSet = context.requestedObject.getEncodingCharSet(); 
                       String sResult = new String((byte[]) result, encodingCharSet); 
                       sResult += "<!--\n" + stats + "\n-->"; 
                       result = sResult.getBytes(encodingCharSet); 
               } 
       } 
       return result;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:20,代碼來源:XmlServletRequester.java

示例3: nextElement

import org.w3c.dom.Comment; //導入依賴的package包/類
public static Element nextElement(Iterator iter) {
    while (iter.hasNext()) {
        Node n = (Node) iter.next();
        if (n instanceof Text) {
            Text t = (Text) n;
            if (t.getData().trim().length() == 0)
                continue;
            fail("parsing.nonWhitespaceTextFound", t.getData().trim());
        }
        if (n instanceof Comment)
            continue;
        if (!(n instanceof Element))
            fail("parsing.elementExpected");
        return (Element) n;
    }

    return null;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:19,代碼來源:Util.java

示例4: getText

import org.w3c.dom.Comment; //導入依賴的package包/類
/**
 * Extract the textual content from a Node.
 * This is rather like the XPath value of a Node.
 * @param node The node to extract the text from
 * @return The textual value of the node
 */
public static String getText(Node node)
{
    StringBuffer reply = new StringBuffer();

    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++)
    {
        Node child = children.item(i);

        if ((child instanceof CharacterData && !(child instanceof Comment)) || child instanceof EntityReference)
        {
            reply.append(child.getNodeValue());
        }
        else if (child.getNodeType() == Node.ELEMENT_NODE)
        {
            reply.append(getText(child));
        }
    }

    return reply.toString();
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:28,代碼來源:DomUtil.java

示例5: serializeComment

import org.w3c.dom.Comment; //導入依賴的package包/類
/**
 * Serializes a Comment Node.
 *
 * @param node The Comment Node to serialize
 */
protected void serializeComment(Comment node) throws SAXException {
    // comments=true
    if ((fFeatures & COMMENTS) != 0) {
        String data = node.getData();

        // well-formed=true
        if ((fFeatures & WELLFORMED) != 0) {
            isCommentWellFormed(data);
        }

        if (fLexicalHandler != null) {
            // apply the LSSerializer filter after the operations requested by the
            // DOMConfiguration parameters have been applied
            if (!applyFilter(node, NodeFilter.SHOW_COMMENT)) {
                return;
            }

            fLexicalHandler.comment(data.toCharArray(), 0, data.length());
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:DOM3TreeWalker.java

示例6: moveToChild

import org.w3c.dom.Comment; //導入依賴的package包/類
protected int moveToChild(final int currentChild) {
    content = getCurrentElement().getChildNodes().item(currentChild);

    if (content instanceof Text) {
        return CHARACTERS;
    } else if (content instanceof Element) {
        return START_ELEMENT;
    } else if (content instanceof CDATASection) {
        return CDATA;
    } else if (content instanceof Comment) {
        return CHARACTERS;
    } else if (content instanceof EntityReference) {
        return ENTITY_REFERENCE;
    }

    throw new IllegalStateException();
}
 
開發者ID:Microsoft,項目名稱:team-explorer-everywhere,代碼行數:18,代碼來源:DOMStreamReader.java

示例7: stripComments

import org.w3c.dom.Comment; //導入依賴的package包/類
private static void stripComments(NodeList children) {
    org.w3c.dom.Node child;
    List<Comment> remove;

    remove = new ArrayList<>();
    for (int i = 0, max = children.getLength(); i < max; i++) {
        child = children.item(i);
        if (child instanceof Element) {
            stripComments(child.getChildNodes());
        } else if (child instanceof Comment) {
            remove.add((Comment) child);
        } else {
            // nothing to do
        }
    }
    for (Comment c : remove) {
        c.getParentNode().removeChild(c);
    }
}
 
開發者ID:mlhartme,項目名稱:stool,代碼行數:20,代碼來源:ServerXml.java

示例8: parseNode

import org.w3c.dom.Comment; //導入依賴的package包/類
protected static XNode parseNode(Node domNode) {
  if (domNode instanceof Element) {
    return XElement.parse((Element) domNode);
  }
  if (domNode instanceof Text) {
    return new XText(((Text) domNode).getTextContent());
  }
  if (domNode instanceof Comment) {
    return new XComment(((Comment) domNode).getTextContent());
  }
  if (domNode instanceof ProcessingInstruction) {
    return new XProcessingInstruction(((ProcessingInstruction) domNode).getTarget(), ((ProcessingInstruction) domNode).getData());
  }
  if (domNode instanceof DocumentType) {
    return new XDocumentType(((DocumentType) domNode).getName(), ((DocumentType) domNode).getInternalSubset());
  }
  throw new UnsupportedOperationException("implement " + domNode);
}
 
開發者ID:teiid,項目名稱:oreva,代碼行數:19,代碼來源:XContainer.java

示例9: visitNode

import org.w3c.dom.Comment; //導入依賴的package包/類
static <R> R visitNode(Node node, NodeVisitor<R> visitor) {
  switch (node.getNodeType()) {
    case Node.ELEMENT_NODE: return visitor.visitElement((Element) node);
    case Node.ATTRIBUTE_NODE: return visitor.visitAttr((Attr) node);
    case Node.TEXT_NODE: return visitor.visitText((Text) node);
    case Node.CDATA_SECTION_NODE: return visitor.visitCDATASection((CDATASection) node);
    case Node.ENTITY_REFERENCE_NODE: return visitor.visitEntityReference((EntityReference) node);
    case Node.ENTITY_NODE: return visitor.visitEntity((Entity) node);
    case Node.PROCESSING_INSTRUCTION_NODE:
        return visitor.visitProcessingInstruction((ProcessingInstruction) node);
    case Node.COMMENT_NODE: return visitor.visitComment((Comment) node);
    case Node.DOCUMENT_NODE: return visitor.visitDocument((Document) node);
    case Node.DOCUMENT_TYPE_NODE: return visitor.visitDocumentType((DocumentType) node);
    case Node.DOCUMENT_FRAGMENT_NODE:
        return visitor.visitDocumentFragment((DocumentFragment) node);
    case Node.NOTATION_NODE: return visitor.visitNotation((Notation) node);
    default: throw new RuntimeException();
  }
}
 
開發者ID:jbosstools,項目名稱:chromedevtools,代碼行數:20,代碼來源:DomUtils.java

示例10: put

import org.w3c.dom.Comment; //導入依賴的package包/類
public Object put(Object key, Object value) {
	if (key.toString().equalsIgnoreCase("XmlRoot")) {
		return super.put(key, value);
	} else if (key.toString().equalsIgnoreCase("XmlComment")) {
		// Remove all comment nodes, and add 1 new one at the top
		remove(key);
		if (!((cfData) value).toString().trim().equals("")) {
			try {
				Comment c = ((Document) nodeData).createComment(((cfData) value).toString());
				nodeData.insertBefore(c, nodeData.getFirstChild());
			} catch (DOMException ex) {
				// Nothing else we can do here
				com.nary.Debug.printStackTrace(ex);
			}
		}
		nodeData.normalize();
		return null;
	} else if (key.toString().equalsIgnoreCase("XMLDocType")) {
		// Do nothing
		return null;
	} else {
		return super.put(key, value);
	}
}
 
開發者ID:OpenBD,項目名稱:openbd-core,代碼行數:25,代碼來源:XmlDocumentHashtable.java

示例11: serializeComment

import org.w3c.dom.Comment; //導入依賴的package包/類
/**
 * Serializes a Comment Node.
 * 
 * @param node The Comment Node to serialize
 */
protected void serializeComment(Comment node) throws SAXException {
    // comments=true
    if ((fFeatures & COMMENTS) != 0) {
        String data = node.getData();

        // well-formed=true
        if ((fFeatures & WELLFORMED) != 0) {
            isCommentWellFormed(data);
        }

        if (fLexicalHandler != null) {
            // apply the LSSerializer filter after the operations requested by the 
            // DOMConfiguration parameters have been applied 
            if (!applyFilter(node, NodeFilter.SHOW_COMMENT)) {
                return;
            }

            fLexicalHandler.comment(data.toCharArray(), 0, data.length());
        }
    }
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:27,代碼來源:DOM3TreeWalker.java

示例12: testInvalidCharactersComment

import org.w3c.dom.Comment; //導入依賴的package包/類
public void testInvalidCharactersComment() throws Exception {
    ErrorRecorder errorRecorder = new ErrorRecorder();
    domConfiguration.setParameter("error-handler", errorRecorder);
    domConfiguration.setParameter("namespaces", false);
    Element root = document.createElement("foo");
    document.appendChild(root);
    Comment comment = document.createComment("");
    root.appendChild(comment);

    for (int c = 0; c <= Character.MAX_VALUE; c++) {
        comment.setData(new String(new char[] { 'A', 'B', (char) c}));
        document.normalizeDocument();
        if (isValid((char) c)) {
            assertEquals(Collections.<DOMError>emptyList(), errorRecorder.errors);
        } else {
            errorRecorder.assertAllErrors("For character " + c,
                    DOMError.SEVERITY_ERROR, "wf-invalid-character");
        }
    }
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:21,代碼來源:NormalizeTest.java

示例13: duplicate

import org.w3c.dom.Comment; //導入依賴的package包/類
public static Node duplicate(Node node, Document ownerDocument)
{
    if (node instanceof Text)
        return ownerDocument.createTextNode(node.getNodeValue());
    if (node instanceof Comment)
        return ownerDocument.createComment(node.getNodeValue());
    Node newNode = ownerDocument.createElement(node.getNodeName());
    NamedNodeMap attribs = node.getAttributes();
    for (int i = 0; i < attribs.getLength(); i++)
    {
        Node attrib = attribs.item(i);
        addAttribute(newNode, attrib.getNodeName(), attrib.getNodeValue());
    }
    for (Node n = node.getFirstChild(); n != null; n = n.getNextSibling())
    {
        Node newN = duplicate(n, ownerDocument);
        newNode.appendChild(newN);
    }
    return newNode;
}
 
開發者ID:StarMade,項目名稱:SMEditClassic,代碼行數:21,代碼來源:XMLEditUtils.java

示例14: create

import org.w3c.dom.Comment; //導入依賴的package包/類
/**
 * Creates a new XmlComment as child of given parent.
 * @param parent The parent of the new XmlComment.
 * @param contents optional initial contents, ignored if empty
 * @return The created XmlElement.
 * @throws VilException if element could not be created.
 */
public static XmlComment create(XmlElement parent, @ParameterMeta(name = "contents") String contents) 
    throws VilException {
    XmlComment newElement = null;
    if (null == parent) {
        throw new VilException("Can not append child from NULL element!", VilException.ID_IS_NULL);
    }
    try {
        Comment newNode = parent.getNode().getOwnerDocument().createComment(contents);
        parent.getNode().appendChild(newNode); // notifies change
        newElement = new XmlComment(parent, newNode);
        parent.addChild(newElement); // notifies change
    } catch (DOMException exc) {
        throw new VilException("Invalid character, name or ID!", VilException.ID_INVALID);
    }
    if (null != contents && contents.length() > 0) {
        newElement.setCdata(contents);
    }
    return newElement;
}
 
開發者ID:SSEHUB,項目名稱:EASyProducer,代碼行數:27,代碼來源:XmlComment.java

示例15: duplicate

import org.w3c.dom.Comment; //導入依賴的package包/類
public static Node duplicate(Node node, Document ownerDocument) {
    if (node instanceof Text) {
        return ownerDocument.createTextNode(node.getNodeValue());
    }
    if (node instanceof Comment) {
        return ownerDocument.createComment(node.getNodeValue());
    }
    Node newNode = ownerDocument.createElement(node.getNodeName());
    NamedNodeMap attribs = node.getAttributes();
    for (int i = 0; i < attribs.getLength(); i++) {
        Node attrib = attribs.item(i);
        addAttribute(newNode, attrib.getNodeName(), attrib.getNodeValue());
    }
    for (Node n = node.getFirstChild(); n != null; n = n.getNextSibling()) {
        Node newN = duplicate(n, ownerDocument);
        newNode.appendChild(newN);
    }
    return newNode;
}
 
開發者ID:StarMade,項目名稱:SMEdit,代碼行數:20,代碼來源:XMLEditUtils.java


注:本文中的org.w3c.dom.Comment類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。