当前位置: 首页>>代码示例>>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;未经允许,请勿转载。