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


Java Document.createComment方法代碼示例

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


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

示例1: addStatisticsAsText

import org.w3c.dom.Document; //導入方法依賴的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

示例2: copyXMLTree

import org.w3c.dom.Document; //導入方法依賴的package包/類
private static void copyXMLTree(Document doc, Element from, Element to, String newNamespace) {
    NodeList nl = from.getChildNodes();
    int length = nl.getLength();
    for (int i = 0; i < length; i++) {
        org.w3c.dom.Node node = nl.item(i);
        org.w3c.dom.Node newNode;
        switch (node.getNodeType()) {
            case org.w3c.dom.Node.ELEMENT_NODE:
                Element oldElement = (Element) node;
                newNode = doc.createElementNS(newNamespace, oldElement.getTagName());
                NamedNodeMap attrs = oldElement.getAttributes();
                int alength = attrs.getLength();
                for (int j = 0; j < alength; j++) {
                    org.w3c.dom.Attr oldAttr = (org.w3c.dom.Attr) attrs.item(j);
                    ((Element)newNode).setAttributeNS(oldAttr.getNamespaceURI(), oldAttr.getName(), oldAttr.getValue());
                }
                copyXMLTree(doc, oldElement, (Element) newNode, newNamespace);
                break;
            case org.w3c.dom.Node.TEXT_NODE:
                newNode = doc.createTextNode(((Text) node).getData());
                break;
            case org.w3c.dom.Node.COMMENT_NODE:
                newNode = doc.createComment(((Comment) node).getData());
                break;
            default:
                // Other types (e.g. CDATA) not yet handled.
                throw new AssertionError(node);
        }
        to.appendChild(newNode);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:32,代碼來源:LookupProviderImpl.java

示例3: handleInitials

import org.w3c.dom.Document; //導入方法依賴的package包/類
private AntLocation handleInitials(Document doc, Lookup context) {
    ensurePropertiesCopied(doc.getDocumentElement());
    Comment comm = doc.createComment(" " + NbBundle.getMessage(JavaActions.class, "COMMENT_edit_target") + " ");
    doc.getDocumentElement().appendChild(comm);
    comm = doc.createComment(" " + NbBundle.getMessage(JavaActions.class, "COMMENT_more_info_run.single") + " ");
    doc.getDocumentElement().appendChild(comm);
    return findPackageRoot(context);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:9,代碼來源:JavaActions.java

示例4: postGetDocument

import org.w3c.dom.Document; //導入方法依賴的package包/類
public Object postGetDocument(Document document) throws Exception {
Engine.logContext.debug("postGetDocument()");

String copyright = "\nGenerated by Convertigo Enterprise Mobility Server\n";
copyright += "Requester: " + getName() + "\n";

Comment comment = document.createComment(copyright);
document.appendChild(comment);

NodeList attachs = document.getDocumentElement().getElementsByTagName("attachment");
if ((attachs != null) && (attachs.getLength()>0)) {
	return document;
}

if (context.isXsltRequest) {
	if (context.absoluteSheetUrl == null) {
           String browser = findBrowserFromUserAgent(context.project, context.userAgent);
           Engine.logContext.debug("Browser for stylesheet: \"" + browser + "\"");
	
           findStyleSheet(browser);
	}
          setStyleSheet(document);

	Object result = performXSLT(document);
      	return result;
}
else {
	return document;
}
  }
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:31,代碼來源:GenericRequester.java

示例5: createChildTextWithComment

import org.w3c.dom.Document; //導入方法依賴的package包/類
public static void createChildTextWithComment(Document paramDocument, Element paramElement, String paramString1,
		String paramString2, String paramString3) {
	Element localElement = paramDocument.createElement(paramString1);
	localElement.appendChild(paramDocument.createTextNode((paramString2 == null) ? "" : paramString2));
	Comment localComment = paramDocument.createComment(paramString3);
	paramElement.appendChild(localComment);
	paramElement.appendChild(localElement);
}
 
開發者ID:inspingcc,項目名稱:LibraSock,代碼行數:9,代碼來源:XmlUtils.java

示例6: asXmlDocument

import org.w3c.dom.Document; //導入方法依賴的package包/類
/**
 * Return the XML DOM corresponding to this Configuration.
 */
private synchronized Document asXmlDocument() throws IOException {
  Document doc;
  try {
    doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
  } catch (ParserConfigurationException pe) {
    throw new IOException(pe);
  }
  Element conf = doc.createElement("configuration");
  doc.appendChild(conf);
  conf.appendChild(doc.createTextNode("\n"));
  handleDeprecation(); // ensure properties is set and deprecation is handled
  for (Enumeration e = properties.keys(); e.hasMoreElements();) {
    String name = (String) e.nextElement();
    Object object = properties.get(name);
    String value = null;
    if (object instanceof String) {
      value = (String) object;
    } else {
      continue;
    }
    Element propNode = doc.createElement("property");
    conf.appendChild(propNode);

    if (updatingResource != null) {
      Comment commentNode = doc.createComment("Loaded from " + updatingResource.get(name));
      propNode.appendChild(commentNode);
    }
    Element nameNode = doc.createElement("name");
    nameNode.appendChild(doc.createTextNode(name));
    propNode.appendChild(nameNode);

    Element valueNode = doc.createElement("value");
    valueNode.appendChild(doc.createTextNode(value));
    propNode.appendChild(valueNode);

    conf.appendChild(doc.createTextNode("\n"));
  }
  return doc;
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:43,代碼來源:Configuration.java

示例7: testCommentNode

import org.w3c.dom.Document; //導入方法依賴的package包/類
@Test
public void testCommentNode() {
    try {
        Document xmlDocument = createNewDocument();
        String commentStr = "This is a comment node";
        Comment cmtNode = xmlDocument.createComment(commentStr);
        String outerXML = getOuterXML(cmtNode);
        System.out.println("OuterXML of Comment Node is:" + outerXML);

    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("Exception occured: " + e.getMessage());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:Bug6354955.java

示例8: testComments001

import org.w3c.dom.Document; //導入方法依賴的package包/類
/**
 * Equivalence class partitioning with state and input values orientation
 * for public void setParameter(String name, Object value) throws
 * DOMException, <br>
 * <b>pre-conditions</b>: the root element has two Comment nodes, <br>
 * <b>name</b>: comments <br>
 * <b>value</b>: true. <br>
 * <b>Expected results</b>: the Comment nodes belong to the root element
 */
@Test
public void testComments001() {
    DOMImplementation domImpl = null;
    try {
        domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
    } catch (ParserConfigurationException pce) {
        Assert.fail(pce.toString());
    } catch (FactoryConfigurationError fce) {
        Assert.fail(fce.toString());
    }

    Document doc = domImpl.createDocument("namespaceURI", "ns:root", null);

    Comment comment1 = doc.createComment("comment1");
    Comment comment2 = doc.createComment("comment2");

    DOMConfiguration config = doc.getDomConfig();
    config.setParameter("comments", Boolean.TRUE);

    Element root = doc.getDocumentElement();
    root.appendChild(comment1);
    root.appendChild(comment2);

    setHandler(doc);
    doc.normalizeDocument();

    if (comment1.getParentNode() != root) {
        Assert.fail("comment1 is attached to " + comment1.getParentNode() + ", but expected to be a child of root");
    }

    if (comment2.getParentNode() != root) {
        Assert.fail("comment1 is attached to " + comment2.getParentNode() + ", but expected to be a child of root");
    }

    return; // Status.passed("OK");

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:47,代碼來源:DOMConfigurationTest.java

示例9: testComments002

import org.w3c.dom.Document; //導入方法依賴的package包/類
/**
 * Equivalence class partitioning with state and input values orientation
 * for public void setParameter(String name, Object value) throws
 * DOMException, <br>
 * <b>pre-conditions</b>: the root element has two Comment nodes, <br>
 * <b>name</b>: comments <br>
 * <b>value</b>: false. <br>
 * <b>Expected results</b>: the root element has no children
 */
@Test
public void testComments002() {
    DOMImplementation domImpl = null;
    try {
        domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
    } catch (ParserConfigurationException pce) {
        Assert.fail(pce.toString());
    } catch (FactoryConfigurationError fce) {
        Assert.fail(fce.toString());
    }

    Document doc = domImpl.createDocument("namespaceURI", "ns:root", null);

    Comment comment1 = doc.createComment("comment1");
    Comment comment2 = doc.createComment("comment2");

    DOMConfiguration config = doc.getDomConfig();
    config.setParameter("comments", Boolean.FALSE);

    Element root = doc.getDocumentElement();
    root.appendChild(comment1);
    root.appendChild(comment2);

    doc.normalizeDocument();

    if (root.getFirstChild() != null) {
        Assert.fail("root has a child " + root.getFirstChild() + ", but expected to has none");
    }

    return; // Status.passed("OK");

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:42,代碼來源:DOMConfigurationTest.java

示例10: importNode

import org.w3c.dom.Document; //導入方法依賴的package包/類
private Node importNode(final Document doc, final Node n, final boolean bDeep)
{
	Node dest;
	final int type = n.getNodeType();
	switch( type )
	{
		case Node.ELEMENT_NODE:
			dest = doc.createElement(n.getNodeName());
			final NamedNodeMap nnm = n.getAttributes();
			final int nnmCount = nnm.getLength();
			for( int i = 0; i < nnmCount; i++ )
			{
				final Attr attr = (Attr) nnm.item(i);
				((Element) dest).setAttribute(attr.getName(), attr.getValue());
			}
			break;

		case Node.TEXT_NODE:
			dest = doc.createTextNode(n.getNodeValue());
			break;

		case Node.CDATA_SECTION_NODE:
			dest = doc.createCDATASection(n.getNodeValue());
			break;

		case Node.ENTITY_REFERENCE_NODE:
			dest = doc.createEntityReference(n.getNodeValue());
			break;

		// see Jira Defect TLE-1832 :
		// http://apps.dytech.com.au/jira/browse/TLE-1832
		case Node.COMMENT_NODE:
			dest = doc.createComment(n.getNodeValue());
			break;

		default:
			throw new RuntimeException("Unsupported DOM Node: " + type);
	}
	if( bDeep )
	{
		for( Node child = n.getFirstChild(); child != null; child = child.getNextSibling() )
		{
			dest.appendChild(importNode(doc, child, true));
		}
	}
	return dest;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:48,代碼來源:PropBagEx.java

示例11: createComment

import org.w3c.dom.Document; //導入方法依賴的package包/類
public static void createComment(Document paramDocument, String paramString) {
	Comment localComment = paramDocument.createComment(paramString);
	paramDocument.getDocumentElement().appendChild(localComment);
}
 
開發者ID:inspingcc,項目名稱:LibraSock,代碼行數:5,代碼來源:XmlUtils.java

示例12: createCharacterData

import org.w3c.dom.Document; //導入方法依賴的package包/類
@Override
protected CharacterData createCharacterData(String text) throws IOException, SAXException, ParserConfigurationException {
    Document document = createNewDocument();
    return document.createComment(text);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:CommentTest.java


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