本文整理汇总了Java中org.jdom2.Content.detach方法的典型用法代码示例。如果您正苦于以下问题:Java Content.detach方法的具体用法?Java Content.detach怎么用?Java Content.detach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jdom2.Content
的用法示例。
在下文中一共展示了Content.detach方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getOriginalHeadContent
import org.jdom2.Content; //导入方法依赖的package包/类
private List<Content> getOriginalHeadContent(org.jdom2.Document doc)
{
org.jdom2.Element root = doc.getRootElement();
List<Content> contentList = new ArrayList<>();
if (root != null)
{
org.jdom2.Element headElement = root.getChild("head", Constants.NAMESPACE_XHTML);
if (headElement != null)
{
List<Content> contents = headElement.getContent();
contentList.addAll(contents);
}
}
//erst ausserhalb der Schleife detachen
for (Content content : contentList)
{
content.detach();
}
return contentList;
}
示例2: swap
import org.jdom2.Content; //导入方法依赖的package包/类
public static MCRChangeData swap(Element parent, int posA, Content a, int posB, Content b) {
if (posA > posB)
return swap(parent, posB, b, posA, a);
b.detach(); // x a x x x
parent.addContent(posA, b); // x b a x x x
a.detach(); // x b x x x
parent.addContent(posB, a); // x b x x a x
return new MCRChangeData("swapped-elements", posA + " " + posB, posB, parent);
}
示例3: doRemove
import org.jdom2.Content; //导入方法依赖的package包/类
private static void doRemove(Element patch, Object node) throws JDOMException {
if (node instanceof Element || node instanceof Comment || node instanceof ProcessingInstruction) {
String ws = patch.getAttributeValue("ws");
boolean before = "both".equals(ws) || "before".equals(ws);
boolean after = "both".equals(ws) || "after".equals(ws);
Content c = (Content) node;
Element e = c.getParentElement();
if (e == null) {
throw new PatchException(ErrorCondition.INVALID_ROOT_ELEMENT_OPERATION,
"can't remove root element");
}
int index = e.indexOf(c);
List<Content> nodesToDetach = new ArrayList<>();
nodesToDetach.add(c);
if (before) {
nodesToDetach.add(getWhitespace(e, index - 1));
}
if (after) {
nodesToDetach.add(getWhitespace(e, index + 1));
}
for (Content detachMe : nodesToDetach) {
detachMe.detach();
}
return;
}
if (patch.getAttribute("ws") != null) {
throw new PatchException(ErrorCondition.INVALID_PATCH_DIRECTIVE,
"The 'ws' attribute is not allowed when removing " +
"Attribute, Text or Namespace nodes.");
}
if (node instanceof Attribute) {
Attribute a = (Attribute) node;
a.getParent().removeAttribute(a);
return;
}
if (node instanceof Text) {
((Content) node).detach();
return;
}
if (node instanceof Namespace) {
throw new UnsupportedOperationException("removing namespace declarations is not yet implemented");
// return;
}
}