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


Java Element.replaceChild方法代码示例

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


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

示例1: getFullProjectDOM

import org.w3c.dom.Element; //导入方法依赖的package包/类
public static void getFullProjectDOM(Document document,String projectName, StreamSource xslFilter) throws TransformerFactoryConfigurationError, EngineException, TransformerException{
	Element root = document.getDocumentElement();
	getFullProjectDOM(document,projectName);
	
	// transformation du dom
	Transformer xslt = TransformerFactory.newInstance().newTransformer(xslFilter);				
	Element xsl = document.createElement("xsl");
	xslt.transform(new DOMSource(document), new DOMResult(xsl));
	root.replaceChild(xsl.getFirstChild(), root.getFirstChild());
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:11,代码来源:ProjectUtils.java

示例2: preconfigure

import org.w3c.dom.Element; //导入方法依赖的package包/类
@Override
public void preconfigure(Element element) throws Exception {
	super.preconfigure(element);
	
	try {
		NodeList properties = element.getElementsByTagName("property");
		
		// If needed: migration of itemtitle from MobileSmartSourceType to String (scriptable)
		Element propElement = (Element) XMLUtils.findNodeByAttributeValue(properties, "name", "itemtitle");
		if (propElement != null) {
			Element valueElement = (Element) XMLUtils.findChildNode(propElement, Node.ELEMENT_NODE);
			if (valueElement != null) {
				Document document = valueElement.getOwnerDocument();
				Object content = XMLUtils.readObjectFromXml(valueElement);
				if (content instanceof MobileSmartSourceType) {
					MobileSmartSourceType itemTitle = (MobileSmartSourceType) content;
					String itemText = Mode.PLAIN.equals(itemTitle.getMode()) ? "'"+itemTitle.getSmartValue()+"'" : itemTitle.getSmartValue();
					Element newValueElement = (Element)XMLUtils.writeObjectToXml(document, itemText);
					propElement.replaceChild(newValueElement, valueElement);
					hasChanged = true;
					Engine.logBeans.warn("(UIDynamicMenuItem) 'itemtitle' has been updated for the object \"" + getName() + "\"");
				}
			}
		}
	}
       catch(Exception e) {
           throw new EngineException("Unable to preconfigure the menuitem component \"" + getName() + "\".", e);
       }
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:30,代码来源:UIDynamicMenuItem.java

示例3: preconfigure

import org.w3c.dom.Element; //导入方法依赖的package包/类
@Override
public void preconfigure(Element element) throws Exception {
	super.preconfigure(element);
	
	try {
		long priority = new Long(element.getAttribute("priority")).longValue();
		if (priority == 0L) {
			priority = getNewOrderValue();
			element.setAttribute("priority", ""+priority);
			element.setAttribute("newPriority", ""+priority);
		}
		
		NodeList properties = element.getElementsByTagName("property");
		
		// migration of scriptContent from String to FormatedContent
		Element propElement = (Element) XMLUtils.findNodeByAttributeValue(properties, "name", "scriptContent");
		if (propElement != null) {
			Element valueElement = (Element) XMLUtils.findChildNode(propElement, Node.ELEMENT_NODE);
			if (valueElement != null) {
				Document document = valueElement.getOwnerDocument();
				Object content = XMLUtils.readObjectFromXml(valueElement);
				if (content instanceof String) {
					FormatedContent formated = new FormatedContent((String) content);
					Element newValueElement = (Element)XMLUtils.writeObjectToXml(document, formated);
					propElement.replaceChild(newValueElement, valueElement);
					hasChanged = true;
					Engine.logBeans.warn("(PageComponent) 'scriptContent' has been updated for the object \"" + getName() + "\"");
				}
			}
		}
	}
       catch(Exception e) {
           throw new EngineException("Unable to preconfigure the page component \"" + getName() + "\".", e);
       }
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:36,代码来源:PageComponent.java

示例4: preconfigure

import org.w3c.dom.Element; //导入方法依赖的package包/类
@Override
public void preconfigure(Element element) throws Exception {
	super.preconfigure(element);
	
	try {
		NodeList properties = element.getElementsByTagName("property");
		
		// migration of styleContent from String to FormatedContent
		Element propElement = (Element) XMLUtils.findNodeByAttributeValue(properties, "name", "styleContent");
		if (propElement != null) {
			Element valueElement = (Element) XMLUtils.findChildNode(propElement, Node.ELEMENT_NODE);
			if (valueElement != null) {
				Document document = valueElement.getOwnerDocument();
				Object content = XMLUtils.readObjectFromXml(valueElement);
				if (content instanceof String) {
					FormatedContent formated = new FormatedContent((String) content);
					Element newValueElement = (Element)XMLUtils.writeObjectToXml(document, formated);
					propElement.replaceChild(newValueElement, valueElement);
					hasChanged = true;
					Engine.logBeans.warn("(UIStyle) 'styleContent' has been updated for the object \"" + getName() + "\"");
				}
			}
		}
	}
       catch(Exception e) {
           throw new EngineException("Unable to preconfigure the style component \"" + getName() + "\".", e);
       }
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:29,代码来源:UIStyle.java

示例5: preconfigure

import org.w3c.dom.Element; //导入方法依赖的package包/类
@Override
public void preconfigure(Element element) throws Exception {
	super.preconfigure(element);
	
	try {
		NodeList properties = element.getElementsByTagName("property");
		
		// migration of componentScriptContent from String to FormatedContent
		Element propElement = (Element) XMLUtils.findNodeByAttributeValue(properties, "name", "componentScriptContent");
		if (propElement != null) {
			Element valueElement = (Element) XMLUtils.findChildNode(propElement, Node.ELEMENT_NODE);
			if (valueElement != null) {
				Document document = valueElement.getOwnerDocument();
				Object content = XMLUtils.readObjectFromXml(valueElement);
				if (content instanceof String) {
					FormatedContent formated = new FormatedContent((String) content);
					Element newValueElement = (Element)XMLUtils.writeObjectToXml(document, formated);
					propElement.replaceChild(newValueElement, valueElement);
					hasChanged = true;
					Engine.logBeans.warn("(ApplicationComponent) 'componentScriptContent' has been updated for the object \"" + getName() + "\"");
				}
			}
		}
	}
       catch(Exception e) {
           throw new EngineException("Unable to preconfigure the application component \"" + getName() + "\".", e);
       }
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:29,代码来源:ApplicationComponent.java

示例6: testReplaceChild

import org.w3c.dom.Element; //导入方法依赖的package包/类
@Test
public void testReplaceChild() throws Exception {
    Document document = createDOM("Node04.xml");

    Element parentElement = (Element) document.getElementsByTagName("to").item(0);
    Element element = (Element) document.getElementsByTagName("sender").item(0);
    parentElement.replaceChild(createTestDocumentFragment(document), element);

    String outputfile = USER_DIR + "ReplaceChild3.out";
    String goldfile = GOLDEN_DIR + "ReplaceChild3GF.out";
    tryRunWithTmpPermission(() -> outputXml(document, outputfile), new PropertyPermission("user.dir", "read"));
    assertTrue(compareWithGold(goldfile, outputfile));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:NodeTest.java

示例7: testReplaceChildNeg

import org.w3c.dom.Element; //导入方法依赖的package包/类
@Test(expectedExceptions = DOMException.class)
public void testReplaceChildNeg() throws Exception {
    Document document = createDOM("Node04.xml");
    Document doc2 = createNewDocument();

    Element parentElement = (Element) document.getElementsByTagName("to").item(0);
    Element element = (Element) document.getElementsByTagName("sender").item(0);
    parentElement.replaceChild(createTestDocumentFragment(doc2), element);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:NodeTest.java

示例8: testCreateUserAccount

import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
 * This will check if adoptNode works will adoptNode from
 * @see <a href="content/userInfo.xml">userInfo.xml</a>
 * @see <a href="content/accountInfo.xml">accountInfo.xml</a>. This is
 * adopting a node from the XML file which is validated by a DTD and
 * into an XML file which is validated by the schema This covers Row 5
 * for the table
 * http://javaweb.sfbay/~jsuttor/JSR206/jsr-206-html/ch03s05.html. Filed
 * bug 4893745 because there was a difference in behavior.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testCreateUserAccount() throws Exception {
    String userXmlFile = XML_DIR + "userInfo.xml";
    String accountXmlFile = XML_DIR + "accountInfo.xml";
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    dbf.setValidating(true);

    DocumentBuilder docBuilder = dbf.newDocumentBuilder();
    MyErrorHandler eh = new MyErrorHandler();
    docBuilder.setErrorHandler(eh);

    Document document = docBuilder.parse(userXmlFile);
    Element user = (Element) document.getElementsByTagName("FirstName").item(0);
    // Set schema after parsing userInfo.xml. Otherwise it will conflict
    // with DTD validation.
    dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI);
    DocumentBuilder docBuilder1 = dbf.newDocumentBuilder();
    docBuilder1.setErrorHandler(eh);
    Document accDocument = docBuilder1.parse(accountXmlFile);

    Element firstName = (Element) accDocument
            .getElementsByTagNameNS(PORTAL_ACCOUNT_NS, "FirstName").item(0);
    Element adoptedAccount = (Element) accDocument.adoptNode(user);

    Element parent = (Element) firstName.getParentNode();
    parent.replaceChild(adoptedAccount, firstName);

    DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
    DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
    LSSerializer writer = impl.createLSSerializer();

    MyDOMOutput mydomoutput = new MyDOMOutput();
    mydomoutput.setByteStream(System.out);

    writer.write(document, mydomoutput);
    writer.write(accDocument, mydomoutput);

    assertFalse(eh.isAnyError());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:53,代码来源:UserController.java


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