本文整理汇总了Java中nu.xom.Comment类的典型用法代码示例。如果您正苦于以下问题:Java Comment类的具体用法?Java Comment怎么用?Java Comment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Comment类属于nu.xom包,在下文中一共展示了Comment类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serializeNodeContents
import nu.xom.Comment; //导入依赖的package包/类
public void serializeNodeContents(Node pNode) {
try {
startSerialiser();
for(int i=0; i < pNode.getChildCount(); i++) {
writeChild(pNode.getChild(i));
//Place line breaks between elements
if(mPrettyPrint && (pNode instanceof Element || pNode instanceof Comment || pNode instanceof ProcessingInstruction || pNode instanceof DocType) && i < pNode.getChildCount() - 1) {
breakLine();
}
}
flush();
}
catch (IOException e) {
throw new ExInternal("XML serialisation failed", e);
}
}
示例2: NodeWrapper
import nu.xom.Comment; //导入依赖的package包/类
/**
* This constructor is protected: nodes should be created using the wrap
* factory method on the DocumentWrapper class
*
* @param node
* The XOM node to be wrapped
* @param parent
* The NodeWrapper that wraps the parent of this node
* @param index
* Position of this node among its siblings
*/
protected NodeWrapper(Node node, NodeWrapper parent, int index) {
short kind;
if (node instanceof Element) {
kind = Type.ELEMENT;
} else if (node instanceof Text) {
kind = Type.TEXT;
} else if (node instanceof Attribute) {
kind = Type.ATTRIBUTE;
} else if (node instanceof Comment) {
kind = Type.COMMENT;
} else if (node instanceof ProcessingInstruction) {
kind = Type.PROCESSING_INSTRUCTION;
} else if (node instanceof Document) {
kind = Type.DOCUMENT;
} else {
throwIllegalNode(node); // moved out of fast path to enable better inlining
return; // keep compiler happy
}
this.nodeKind = kind;
this.node = node;
this.parent = parent;
this.index = index;
}
示例3: withRoot
import nu.xom.Comment; //导入依赖的package包/类
@Override
@Nonnull
public DocumentBuilderImpl withRoot(@Nonnull ElementBuilder rootElement) {
checkNotNull(rootElement, "rootElement");
// Can contain any number of PIs and comments, but exactly 1 createRoot node
final Nodes nodes = rootElement.build();
for (int i = 0; i < nodes.size(); i++) {
final Node node = nodes.get(i);
if (node instanceof Element) {
withRoot((Element) node);
} else if (node instanceof ProcessingInstruction
|| node instanceof Comment) {
_addChild(node);
} else {
// should only happen if the NodeFactory is behaving badly.
throw new AssertionError("Document node can "
+ "contain child nodes of type Element, Comment, or"
+ " ProcessingInstruction.");
}
}
return this;
}
示例4: saveFile
import nu.xom.Comment; //导入依赖的package包/类
/**
* Saves the valid resource to a file.
*
* @param filename the filename
* @throws IOException
*/
private void saveFile(String filename, Resource resource) throws IOException {
FileOutputStream os = null;
try {
Document doc = new Document(resource.getXOMElementCopy());
doc.insertChild(new Comment(" Generated by Escort in DDMSence v" + PropertyReader.getProperty("version")
+ " "), 0);
File outputFile = new File(PropertyReader.getProperty("sample.data"), filename);
os = new FileOutputStream(outputFile);
Serializer serializer = new Serializer(os);
serializer.setIndent(3);
serializer.write(doc);
println("File saved at \"" + outputFile.getAbsolutePath() + "\".");
}
finally {
if (os != null)
os.close();
}
}
示例5: getNodeType
import nu.xom.Comment; //导入依赖的package包/类
/**
* Gets the generic NodeType of a XOM node.
* @param pNode An arbitrary XOM node.
* @return The NodeType of pNode.
*/
public static NodeType getNodeType(Node pNode){
//Note: order of tests is in likelihood of occurrence
if (pNode instanceof Element){
return ELEMENT;
}
else if (pNode instanceof Text){
return TEXT;
}
else if (pNode instanceof Attribute){
return ATTRIBUTE;
}
else if (pNode instanceof Comment){
return COMMENT;
}
else if (pNode instanceof Document){
return DOCUMENT;
}
else if (pNode instanceof ProcessingInstruction){
return PROCESSING_INSTRUCTION;
}
else if (pNode instanceof DocType){
return DOCTYPE;
}
else {
return null;
}
}
示例6: shallowCloneIncludingAttrs
import nu.xom.Comment; //导入依赖的package包/类
/**
* Convenience method to create a shallow clone of a node. If pNode is an Element, its Attributes are also cloned.
* @param pNode The node to be cloned.
* @return A clone of pNode including its attributes if applicable.
*/
static Node shallowCloneIncludingAttrs(Node pNode){
// Previous Xerces implementation cloned attributes even on a shallow copy, XOM does not, so we do it ourselves.
// Also XOM only provides deep copy functionality so we need to do it all ourselves.
if(pNode instanceof Element){
Element lNodeAsElement = (Element) pNode;
Element lNewElement;
if(!"".equals(lNodeAsElement.getNamespaceURI())){
//Create new element in a namespace
lNewElement = new Element(lNodeAsElement.getQualifiedName(), lNodeAsElement.getNamespaceURI());
}
else {
//Create new element in no namespace
lNewElement = new Element(lNodeAsElement.getLocalName());
}
//Copy the attributes - sadly XOM doesn't give us a way of doing this in a one-r
for(int i=0; i<lNodeAsElement.getAttributeCount(); i++){
Attribute lAttr = lNodeAsElement.getAttribute(i);
lNewElement.addAttribute((Attribute) lAttr.copy());
}
return lNewElement;
}
else if (pNode instanceof Comment){
return ((Comment) pNode).copy();
}
else if (pNode instanceof ProcessingInstruction){
return ((ProcessingInstruction) pNode).copy();
}
else {
throw new ExInternal("Failed to clone pNode as it was an unsupported type: " + pNode.getClass().getName());
}
}
示例7: addComment
import nu.xom.Comment; //导入依赖的package包/类
public void addComment(Node pNode, String pCommentText) {
mDocControl.setDocumentModifiedCount();
// Cast to Element (checks is an element)
Element lElement;
try {
lElement = (Element)pNode;
}
catch (ClassCastException x) {
throw new ExInternal("Not an Element", x);
}
// Add Comment
lElement.appendChild(new Comment(pCommentText));
}
示例8: addComment
import nu.xom.Comment; //导入依赖的package包/类
@Override
@Nonnull
public B addComment(@Nonnull final Comment comment) {
return _addChild(comment);
}
示例9: isComment
import nu.xom.Comment; //导入依赖的package包/类
public boolean isComment(Object o) {
return o instanceof Comment;
}
示例10: getCommentStringValue
import nu.xom.Comment; //导入依赖的package包/类
public String getCommentStringValue(Object o) {
return (isComment(o) ? ((Comment)o).getValue() : null);
}
示例11: isComment
import nu.xom.Comment; //导入依赖的package包/类
/**
* Tests if this DOM represents a Comment node.
* @return True if this DOM is a Comment.
*/
public boolean isComment() {
return mXOMNode instanceof Comment;
}
示例12: makeComment
import nu.xom.Comment; //导入依赖的package包/类
/**
* <code>return new Comment(string);</code>
* @param string
* @return
*/
public Comment makeComment(String string) {
return new Comment(string);
}
示例13: addComment
import nu.xom.Comment; //导入依赖的package包/类
/**
* @param comment
* @return
* @throws NullPointerException if data is null
*/
@Nonnull
B addComment(@Nonnull Comment comment);