本文整理汇总了Java中org.w3c.dom.Element.insertBefore方法的典型用法代码示例。如果您正苦于以下问题:Java Element.insertBefore方法的具体用法?Java Element.insertBefore怎么用?Java Element.insertBefore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.Element
的用法示例。
在下文中一共展示了Element.insertBefore方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insertXMLSchemaElement
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
* Creates a new XML Schema element of the given local name
* and insert it as the first child of the given parent node.
*
* @return
* Newly create element.
*/
private Element insertXMLSchemaElement( Element parent, String localName ) {
// use the same prefix as the parent node to avoid modifying
// the namespace binding.
String qname = parent.getTagName();
int idx = qname.indexOf(':');
if(idx==-1) qname = localName;
else qname = qname.substring(0,idx+1)+localName;
Element child = parent.getOwnerDocument().createElementNS( WellKnownNamespace.XML_SCHEMA, qname );
NodeList children = parent.getChildNodes();
if( children.getLength()==0 )
parent.appendChild(child);
else
parent.insertBefore( child, children.item(0) );
return child;
}
示例2: insertXMLSchemaElement
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
* Creates a new XML Schema element of the given local name
* and insert it as the first child of the given parent node.
*
* @return
* Newly create element.
*/
private Element insertXMLSchemaElement( Element parent, String localName ) {
// use the same prefix as the parent node to avoid modifying
// the namespace binding.
String qname = parent.getTagName();
int idx = qname.indexOf(':');
if(idx==-1) qname = localName;
else qname = qname.substring(0,idx+1)+localName;
Element child = parent.getOwnerDocument().createElementNS( Constants.NS_XSD, qname );
NodeList children = parent.getChildNodes();
if( children.getLength()==0 )
parent.appendChild(child);
else
parent.insertBefore( child, children.item(0) );
return child;
}
示例3: addParameters
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
* Adds the specified parameters to the xsl template as variables within the alfresco namespace.
*
* @param xsltModel
* the variables to place within the xsl template
* @param xslTemplate
* the xsl template
*/
protected void addParameters(final XSLTemplateModel xsltModel, final Document xslTemplate)
{
final Element docEl = xslTemplate.getDocumentElement();
final String XSL_NS = docEl.getNamespaceURI();
final String XSL_NS_PREFIX = docEl.getPrefix();
for (Map.Entry<QName, Object> e : xsltModel.entrySet())
{
if (ROOT_NAMESPACE.equals(e.getKey()))
{
continue;
}
final Element el = xslTemplate.createElementNS(XSL_NS, XSL_NS_PREFIX + ":variable");
el.setAttribute("name", e.getKey().toPrefixString());
final Object o = e.getValue();
if (o instanceof String || o instanceof Number || o instanceof Boolean)
{
el.appendChild(xslTemplate.createTextNode(o.toString()));
// ALF-15413. Add the variables at the end of the list of children
docEl.insertBefore(el, null);
}
}
}
示例4: createSubMenu
import org.w3c.dom.Element; //导入方法依赖的package包/类
private void createSubMenu(String menubarPath, int index, Document document, Element menuRootElt, Element eNewAction, String objectContributionId) {
String subMenuLabel = menubarPath.substring(menubarPath.lastIndexOf(".") + 1, index);
String subMenuId = objectContributionId + "." + subMenuLabel;
subMenuLabel = idMenuToLabel.get(subMenuLabel);
Element subMenuElt = (Element) xpathApi.selectNode(menuRootElt, "/menu[@id='" + subMenuId + "']");
// Create the sub menu if it does not exist
if (subMenuElt == null) {
subMenuElt = document.createElement("menu");
subMenuElt.setAttribute("label", subMenuLabel);
subMenuElt.setAttribute("id", subMenuId);
menuRootElt.insertBefore(subMenuElt, menuRootElt.getFirstChild());
}
addActionElt(subMenuElt, eNewAction, null, menubarPath);
}
示例5: getDefsElement
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
*
*/
protected Element getDefsElement()
{
if (defs == null)
{
defs = document.createElement("defs");
Element svgNode = document.getDocumentElement();
if (svgNode.hasChildNodes())
{
svgNode.insertBefore(defs, svgNode.getFirstChild());
}
else
{
svgNode.appendChild(defs);
}
}
return defs;
}
示例6: getDefsElement
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
*
*/
protected Element getDefsElement() {
if (defs == null) {
defs = document.createElement("defs");
Element svgNode = document.getDocumentElement();
if (svgNode.hasChildNodes()) {
svgNode.insertBefore(defs, svgNode.getFirstChild());
} else {
svgNode.appendChild(defs);
}
}
return defs;
}
示例7: setModuleType
import org.w3c.dom.Element; //导入方法依赖的package包/类
public void setModuleType(NbModuleType moduleType) {
Element _confData = getConfData();
Document doc = _confData.getOwnerDocument();
Element standaloneEl = findElement(_confData, ProjectXMLManager.STANDALONE);
if (standaloneEl != null && moduleType == NbModuleType.STANDALONE) {
// nothing needs to be done - standalone is already set
return;
}
Element suiteCompEl = findElement(_confData, ProjectXMLManager.SUITE_COMPONENT);
if (suiteCompEl != null && moduleType == NbModuleType.SUITE_COMPONENT) {
// nothing needs to be done - suiteCompEl is already set
return;
}
if (suiteCompEl == null && standaloneEl == null && moduleType == NbModuleType.NETBEANS_ORG) {
// nothing needs to be done - nb.org modules don't have any element
return;
}
// Ok, we get here. So clean up....
if (suiteCompEl != null) {
_confData.removeChild(suiteCompEl);
}
if (standaloneEl != null) {
_confData.removeChild(standaloneEl);
}
// ....and create element for new module type.
Element newModuleType = createTypeElement(doc, moduleType);
if (newModuleType != null) {
_confData.insertBefore(newModuleType, findModuleDependencies(_confData));
}
project.putPrimaryConfigurationData(_confData);
}
示例8: createModuleDependencyElement
import org.w3c.dom.Element; //导入方法依赖的package包/类
/** Package-private for unit tests only. */
static void createModuleDependencyElement(
Element moduleDependencies, ModuleDependency md, Element nextSibling) {
Document doc = moduleDependencies.getOwnerDocument();
Element modDepEl = createModuleElement(doc, ProjectXMLManager.DEPENDENCY);
moduleDependencies.insertBefore(modDepEl, nextSibling);
modDepEl.appendChild(createModuleElement(doc, ProjectXMLManager.CODE_NAME_BASE,
md.getModuleEntry().getCodeNameBase()));
if (md.buildPrerequisite) {
modDepEl.appendChild(createModuleElement(doc, ProjectXMLManager.BUILD_PREREQUISITE));
}
if (md.hasCompileDependency()) {
modDepEl.appendChild(createModuleElement(doc, ProjectXMLManager.COMPILE_DEPENDENCY));
}
if (!md.runDependency) {
return;
}
Element runDepEl = createModuleElement(doc, ProjectXMLManager.RUN_DEPENDENCY);
modDepEl.appendChild(runDepEl);
String rv = md.getReleaseVersion();
if (rv != null && !rv.trim().equals("")) {
runDepEl.appendChild(createModuleElement(
doc, ProjectXMLManager.RELEASE_VERSION, rv));
}
if (md.hasImplementationDependency()) {
runDepEl.appendChild(createModuleElement(
doc, ProjectXMLManager.IMPLEMENTATION_VERSION));
} else {
String sv = md.getSpecificationVersion();
if (sv != null && !"".equals(sv)) { // NOI18N
runDepEl.appendChild(createModuleElement(
doc, ProjectXMLManager.SPECIFICATION_VERSION, sv));
}
}
}
示例9: appendChildElement
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
* Append a child element to the parent at the specified location.
*
* Starting with a valid document, append an element according to the schema
* sequence represented by the <code>order</code>. All existing child elements must be
* include as well as the new element. The existing child element following
* the new child is important, as the element will be 'inserted before', not
* 'inserted after'.
*
* @param parent parent to which the child will be appended
* @param el element to be added
* @param order order of the elements which must be followed
* @throws IllegalArgumentException if the order cannot be followed, either
* a missing existing or new child element is not specified in order
*
* @since 8.4
*/
public static void appendChildElement(Element parent, Element el, String[] order) throws IllegalArgumentException {
List<String> l = Arrays.asList(order);
int index = l.indexOf(el.getLocalName());
// ensure the new new element is contained in the 'order'
if (index == -1) {
throw new IllegalArgumentException("new child element '"+ el.getLocalName() + "' not specified in order " + l); // NOI18N
}
List<Element> elements = findSubElements(parent);
Element insertBefore = null;
for (Element e : elements) {
int index2 = l.indexOf(e.getLocalName());
// ensure that all existing elements are in 'order'
if (index2 == -1) {
throw new IllegalArgumentException("Existing child element '" + e.getLocalName() + "' not specified in order " + l); // NOI18N
}
if (index2 > index) {
insertBefore = e;
break;
}
}
parent.insertBefore(el, insertBefore);
}
示例10: writeParameter
import org.w3c.dom.Element; //导入方法依赖的package包/类
private void writeParameter(Parameter parameter) {
Element parameterElement = parameter.getXML(document);
document.getDocumentElement().appendChild(parameterElement);
Element dataset = getDatasetElement();
dataset.insertBefore(parameterElement, dataset.getFirstChild());
document.getDocumentElement().insertBefore(parameterElement.cloneNode(true), dataset.getNextSibling());
Element datasetParameter = parameter.getDatasetParameterXML(document);
Node datasetRun = document.getDocumentElement().getElementsByTagName("datasetRun").item(0);
datasetRun.insertBefore(datasetParameter, datasetRun.getFirstChild());
}
示例11: addActionElt
import org.w3c.dom.Element; //导入方法依赖的package包/类
private void addActionElt(Element root, Element action, String attrObjectClass, String menubarPath) {
Element actionObjectClass = attrObjectClass == null ? null : (Element) xpathApi.selectNode(root, "(/action[@objectClass='" + attrObjectClass + "'])[last()]");
if (actionObjectClass == null) {
Node nLastSubMenu = xpathApi.selectNode(root, "(menu)[last()]");
root.insertBefore(action, nLastSubMenu != null ?
// Insert action after the last sub-menu
nLastSubMenu.getNextSibling() :
// Insert action at the beginning
root.getFirstChild());
}
else {
Element current = (Element) xpathApi.selectNode(root, "/action[@menubarPath='" + menubarPath + "']");
root.insertBefore(action, current == null ? actionObjectClass.getNextSibling() : current);
}
}
示例12: addSchemaImport
import org.w3c.dom.Element; //导入方法依赖的package包/类
public static void addSchemaImport(Element schemaElement, String namespace, String location) {
if (schemaElement != null) {
Element importElement = getSchemaImport(schemaElement, namespace);
if (importElement == null) {
Element imp = schemaElement.getOwnerDocument().createElementNS(Constants.URI_2001_SCHEMA_XSD, "import");
imp.setAttribute("namespace", namespace);
imp.setAttribute("schemaLocation", location);
schemaElement.insertBefore(imp, schemaElement.getFirstChild());
}
}
}
示例13: getResult
import org.w3c.dom.Element; //导入方法依赖的package包/类
public Object getResult(Object existing) {
Document dom = (Document)result.getNode();
Element e = dom.getDocumentElement();
if(existing instanceof Element) {
// merge all the children
Element prev = (Element) existing;
Node anchor = e.getFirstChild();
while(prev.getFirstChild()!=null) {
Node move = prev.getFirstChild();
e.insertBefore(e.getOwnerDocument().adoptNode(move), anchor );
}
}
return e;
}
示例14: insertJAXWSBindingsElement
import org.w3c.dom.Element; //导入方法依赖的package包/类
private Element insertJAXWSBindingsElement( Element parent, String localName ) {
String qname = "JAXWS:"+localName;
Element child = parent.getOwnerDocument().createElementNS(JAXWSBindingsConstants.NS_JAXWS_BINDINGS, qname );
NodeList children = parent.getChildNodes();
if( children.getLength()==0 )
parent.appendChild(child);
else
parent.insertBefore( child, children.item(0) );
return child;
}
示例15: testInsertBefore
import org.w3c.dom.Element; //导入方法依赖的package包/类
@Test
public void testInsertBefore() throws Exception {
Document document = createDOM("Node04.xml");
Element parentElement = (Element) document.getElementsByTagName("to").item(0);
Element element = (Element) document.getElementsByTagName("sender").item(0);
parentElement.insertBefore(createTestDocumentFragment(document), element);
String outputfile = USER_DIR + "InsertBefore.out";
String goldfile = GOLDEN_DIR + "InsertBeforeGF.out";
tryRunWithTmpPermission(() -> outputXml(document, outputfile), new PropertyPermission("user.dir", "read"));
assertTrue(compareWithGold(goldfile, outputfile));
}