当前位置: 首页>>代码示例>>Java>>正文


Java Element.detach方法代码示例

本文整理汇总了Java中org.dom4j.Element.detach方法的典型用法代码示例。如果您正苦于以下问题:Java Element.detach方法的具体用法?Java Element.detach怎么用?Java Element.detach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.dom4j.Element的用法示例。


在下文中一共展示了Element.detach方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: removeChild

import org.dom4j.Element; //导入方法依赖的package包/类
/**
 * If some node is to be skipped, we do it in this method
 * 
 * @param matchedNode
 */
public void removeChild( Element matchedNode ) {

    // remove the matched node
    matchedNode.detach();

    // now we have to regenerate info that might have been affected
    this.value = this.node.getTextTrim();

    this.children.clear();
    List<Element> childrenElements = this.node.elements();
    for (Element child : childrenElements) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            this.children.add(new XmlNode(this, child));
        }
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:22,代码来源:XmlNode.java

示例2: remove

import org.dom4j.Element; //导入方法依赖的package包/类
/**
 * Remove a XML element
 *
 * @param xpath XPath , pointing to a XML element
 * @return this instance
 * @throws XMLException
 */
@PublicAtsApi
public XmlText remove(
                       String xpath ) throws XMLException {

    if (StringUtils.isNullOrEmpty(xpath)) {
        throw new XMLException("Null/empty xpath is not allowed.");
    }

    Element element = findElement(xpath);

    if (element != null) {

        if (element.isRootElement()) {
            throw new XMLException("You cannot remove the root element of the XML document.");
        }

        element.detach();
    } else {
        throw new XMLException("'" + xpath + "' is not a valid path");
    }

    return this;
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:31,代码来源:XmlText.java

示例3: removeAllChildren

import org.dom4j.Element; //导入方法依赖的package包/类
public void removeAllChildren() {
    List list = element.elements();
    Iterator iterator = list.iterator();

    while (iterator.hasNext()) {
        Element child = (Element) iterator.next();
        child.detach();
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:10,代码来源:DOM4JSettingsNode.java

示例4: exportToFile

import org.dom4j.Element; //导入方法依赖的package包/类
public static void exportToFile(ExportInteraction exportInteraction, ExtensionFileFilter fileFilter, DOM4JSettingsNode settingsNode) {
    File file = promptForFile(exportInteraction, fileFilter);
    if (file == null) {
        //the user canceled.
        return;
    }

    FileOutputStream fileOutputStream = null;
    try {
        fileOutputStream = new FileOutputStream(file);
    } catch (FileNotFoundException e) {
        LOGGER.error("Could not write to file: " + file.getAbsolutePath(), e);
        exportInteraction.reportError("Could not write to file: " + file.getAbsolutePath());
        return;
    }

    try {
        XMLWriter xmlWriter = new XMLWriter(fileOutputStream, OutputFormat.createPrettyPrint());
        Element rootElement = settingsNode.getElement();
        rootElement.detach();

        Document document = DocumentHelper.createDocument(rootElement);

        xmlWriter.write(document);
    } catch (Throwable t) {
        LOGGER.error("Internal error. Failed to save.", t);
        exportInteraction.reportError("Internal error. Failed to save.");
    } finally {
        closeQuietly(fileOutputStream);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:32,代码来源:DOM4JSerializer.java

示例5: deleteStatusEntry

import org.dom4j.Element; //导入方法依赖的package包/类
/**
 *  Remove specified status entry from the status entry list
 *
 * @param  changeDate     key used to specify existing status entry
 * @exception  Exception  NOT YET DOCUMENTED
 */
public synchronized void deleteStatusEntry(String changeDate) throws Exception {
	Element historyElement = getHistoryElement(changeDate);

	if (historyElement == null) {
		throw new Exception("historyElement not found for " + changeDate);
	}
	historyElement.detach();
	entryList = null;
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:16,代码来源:DcsDataRecord.java

示例6: replaceNode

import org.dom4j.Element; //导入方法依赖的package包/类
protected static void replaceNode(Node container, Element value) {
	if ( container!=value ) { //not really necessary, I guess...
		Element parent = container.getParent();
		container.detach();
		value.setName( container.getName() );
		value.detach();
		parent.add(value);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:AbstractType.java

示例7: migrate1

import org.dom4j.Element; //导入方法依赖的package包/类
private void migrate1(File dataDir, Stack<Integer> versions) {
	for (File file: dataDir.listFiles()) {
		if (file.getName().startsWith("CodeComments.xml")) {
			VersionedDocument dom = VersionedDocument.fromFile(file);
			for (Element element: dom.getRootElement().elements()) {
				Element branchRefElement = element.element("branchRef");
				if (branchRefElement != null)
					branchRefElement.detach();
			}
			dom.writeToFile(file, false);
		}
	}	
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:14,代码来源:DatabaseMigrator.java

示例8: migrate2

import org.dom4j.Element; //导入方法依赖的package包/类
private void migrate2(File dataDir, Stack<Integer> versions) {
	for (File file: dataDir.listFiles()) {
		if (file.getName().startsWith("Depots.xml")) {
			VersionedDocument dom = VersionedDocument.fromFile(file);
			for (Element element: dom.getRootElement().elements()) {
				Element gateKeeperElement = element.element("gateKeeper");
				gateKeeperElement.detach();
				element.addElement("gateKeepers");
			}
			dom.writeToFile(file, false);
		}
	}	
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:14,代码来源:DatabaseMigrator.java

示例9: migrate4

import org.dom4j.Element; //导入方法依赖的package包/类
private void migrate4(File dataDir, Stack<Integer> versions) {
	for (File file: dataDir.listFiles()) {
		if (file.getName().startsWith("Accounts.xml")) {
			VersionedDocument dom = VersionedDocument.fromFile(file);
			for (Element element: dom.getRootElement().elements()) {
				Element avatarUploadDateElement = element.element("avatarUploadDate");
				if (avatarUploadDateElement != null)
					avatarUploadDateElement.detach();
			}
			dom.writeToFile(file, false);
		}
	}	
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:14,代码来源:DatabaseMigrator.java

示例10: importData

import org.dom4j.Element; //导入方法依赖的package包/类
@Sessional
@Override
public void importData(Metadata metadata, File dataDir) {
	Session session = dao.getSession();
	List<Class<?>> entityTypes = getEntityTypes(sessionFactory);
	Collections.reverse(entityTypes);
	for (Class<?> entityType: entityTypes) {
		File[] dataFiles = dataDir.listFiles(new FilenameFilter() {

			@Override
			public boolean accept(File dir, String name) {
				return name.startsWith(entityType.getSimpleName() + "s.xml");
			}
			
		});
		for (File file: dataFiles) {
			try {
				logger.info("Importing from data file '" + file.getName() + "'...");
				session.beginTransaction();
				VersionedDocument dom = VersionedDocument.fromFile(file);
				
				for (Element element: dom.getRootElement().elements()) {
					element.detach();
					AbstractEntity entity = (AbstractEntity) new VersionedDocument(DocumentHelper.createDocument(element)).toBean();
					session.replicate(entity, ReplicationMode.EXCEPTION);
				}
				session.flush();
				session.clear();
				session.getTransaction().commit();
			} catch (Throwable e) {
				session.getTransaction().rollback();
				throw Throwables.propagate(e);
			}
		}
	}	
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:37,代码来源:DefaultPersistManager.java

示例11: validateData

import org.dom4j.Element; //导入方法依赖的package包/类
protected void validateData(Metadata metadata, File dataDir) {
	List<Class<?>> entityTypes = getEntityTypes(sessionFactory);
	Collections.reverse(entityTypes);
	for (Class<?> entityType: entityTypes) {
		File[] dataFiles = dataDir.listFiles(new FilenameFilter() {

			@Override
			public boolean accept(File dir, String name) {
				return name.startsWith(entityType.getSimpleName() + "s.xml");
			}
			
		});
		for (File file: dataFiles) {
			try {
				logger.info("Validating data file '" + file.getName() + "'...");
				VersionedDocument dom = VersionedDocument.fromFile(file);
				
				for (Element element: dom.getRootElement().elements()) {
					element.detach();
					AbstractEntity entity = (AbstractEntity) new VersionedDocument(DocumentHelper.createDocument(element)).toBean();
					validator.validate(entity);
				}
			} catch (Throwable e) {
				throw Throwables.propagate(e);
			}
		}
	}	
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:29,代码来源:DefaultPersistManager.java

示例12: extractIncrement

import org.dom4j.Element; //导入方法依赖的package包/类
/**
 * 从两个xml中提取增量文本xml
 * 
 * @param document
 * @param documentInc
 * @param autoMaxDiffereceLimit 定义差异度超过 xx % 才会添加到增量文本中
 * @param printAll 是否打印结果
 * @return
 * @throws Exception
 */
@Override
public Document extractIncrement(Document document, Document documentInc,
    int autoMaxDiffereceLimit, boolean print) throws Exception {
  if (autoMaxDiffereceLimit > 0) {
    double f = autoMaxDiffereceLimit * 1.0 / 100.0;
    /**
     * 以第一个文本为比较基准,比较两版汉化文本,输出差异程度
     */
    List<DiffResult> list =
        TextUtils.diff(documentInc, document, documentToMap, true, false, false);
    List<DiffResult> result = new ArrayList<DiffResult>(list.size());
    List<DiffResult> ignore = new ArrayList<DiffResult>(list.size());
    for (DiffResult res : list) {
      if (res.getDifference() >= f) {
        result.add(res);
      } else {
        ignore.add(res);
      }
    }
    /**
     * 根据节点数据,生成增量文本xml
     */
    boolean buildNew = false;
    Document doc = extractIncrement(result, buildNew, print);
    if (print) {
      System.out.println("\n\n----------------------------以下文本低于差异度" + (autoMaxDiffereceLimit)
          + "%不会替换生成增量文本-----------------");
      // 打印不处理的部分
      for (DiffResult nodeResult : ignore) {
        System.out.println(nodeResult.getContentuid() + "="
            + (buildNew ? (nodeResult.getText() + "|" + nodeResult.getNewText())
                : (nodeResult.getNewText() + "|" + nodeResult.getText())));
      }
    }
    return doc;
  }
  Map<String, String> mOri = documentToMap.toMap(document);
  // 获取根节点元素对象
  Element root = documentInc.getRootElement();
  // 子节点
  List<Element> es = root.elements();
  // 使用递归
  Iterator<Element> iterator = es.iterator();
  while (iterator.hasNext()) {
    Element e = iterator.next();
    Attribute attribute = e.attribute("contentuid");
    // System.out.println("属性"+attribute.getName() +":" + attribute.getValue());
    String contentuid = attribute.getValue();
    String newText = e.getText().trim();
    String text = (String) mOri.get(contentuid);
    if (("".equals(text) && "".equals(newText)) || (text.trim().equals(newText))) {
      e.detach();
    } else {
      if (print)
        System.out.println(contentuid + "=" + text + "|" + newText);
    }
  }

  return documentInc;
}
 
开发者ID:SvenAugustus,项目名称:Divinity_Original_Sin_2_zhCN,代码行数:71,代码来源:DOS2Extract.java


注:本文中的org.dom4j.Element.detach方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。