/** * Checks in under a given root element whether it can find a child element * which matches the name supplied. Returns {@link Element} if exists. * * @param name the Element name (required) * @param root the parent DOM element (required) * @return the Element if discovered * @deprecated use {@link DomUtils#findFirstElementByName(String, Element)} * instead */ @Deprecated public static Element findFirstElementByName(final String name, final Element root) { return DomUtils.findFirstElementByName(name, root); }
final Element parentPomElement = DomUtils.createChildIfNotExists("parent", root, pom); final Element projectGroupIdElement = DomUtils.createChildIfNotExists("groupId", root, pom); DomUtils.createChildIfNotExists("groupId", parentPomElement, pom).setTextContent( parentPom.getGroupId()); DomUtils.createChildIfNotExists("artifactId", parentPomElement, pom).setTextContent( parentPom.getArtifactId()); DomUtils.createChildIfNotExists(VERSION_ELEMENT, parentPomElement, pom).setTextContent( parentPom.getVersion()); root.removeChild(projectGroupIdElement); DomUtils.removeTextNodes(root); } else {
/** * Returns the Maven POM element for this resource * * @param document the POM document (required) * @return a non-<code>null</code> element */ public Element getElement(final Document document) { final Element resourceElement = document.createElement("resource"); resourceElement.appendChild(XmlUtils.createTextElement(document, "directory", directory)); if (filtering != null) { resourceElement.appendChild(XmlUtils.createTextElement(document, "filtering", filtering.toString())); } if (!includes.isEmpty()) { final Element includes = DomUtils.createChildElement("includes", resourceElement, document); for (final String include : this.includes) { includes.appendChild(XmlUtils.createTextElement(document, "include", include)); } } return resourceElement; }
/** * Returns the first child element value identified by its name. * * @param element the DOM element to analyze * @param childElementName the child element name to look for * @return the extracted text value, or <code>null</code> if no child * element found */ public static String getChildElementValueByTagName(final Element element, final String childElementName) { final Element child = getChildElementByTagName(element, childElementName); return child != null ? getTextValue(child) : null; }
fileManager); Element docRoot = docXml.getDocumentElement(); form = docRoot.getElementsByTagName("form:create").item(0); form = docRoot.getElementsByTagName("form:update").item(0); form = docRoot.getElementsByTagName("page:show").item(0); Element fieldElement = XmlUtils.findFirstElement( "//*[@field='".concat(field.concat("']")), form); Element baseLayer = docXml.createElement("layer:" + type); String layerId = fieldElement.getAttribute("id").concat("_") .concat("baselayer"); Element layerNodes = XmlUtils.findFirstElement( "//*[@id='".concat(layerId.concat("']")), fieldElement); DomUtils.removeTextNodes(fieldElement); XmlUtils.nodeToString(docXml), true);
private static boolean addOrUpdateElements(final Element original, final Element proposed, boolean originalDocumentChanged) { final NodeList proposedChildren = proposed.getChildNodes(); if (node != null && node.getNodeType() == Node.ELEMENT_NODE) { final Element proposedElement = (Element) node; final String proposedId = proposedElement.getAttribute("id"); XmlUtils.findFirstElement("//*[@id='" + proposedId + "']", original); DomUtils.findFirstElementByName("util:placeholder", original); if (placeHolder != null) { // Insert right before place placeHolder.getParentNode().insertBefore( original.getOwnerDocument().importNode(proposedElement, false), placeHolder); originalParent.appendChild(original.getOwnerDocument().importNode( proposedElement, false)); original.appendChild(original.getOwnerDocument().importNode(proposedElement, false)); XmlUtils.findFirstElement( "//*[@id='" + child.getAttribute("id") + "']", proposed); proposedElementToReplace.getParentNode().replaceChild(
final Document document = XmlUtils.readXml(fileManager.getInputStream(pom.getPath())); final Element root = document.getDocumentElement(); final Element filtersElement = XmlUtils.findFirstElement("/project/build/filters", root); if (filtersElement == null) { return; for (final Element candidate : XmlUtils.findElements("filter", filtersElement)) { if (filter.equals(new Filter(candidate))) { filtersElement.removeChild(candidate); descriptionOfChange = highlight(REMOVED + " filter") + " '" + filter.getValue() + "'"; final List<Element> filterElements = XmlUtils.findElements("filter", filtersElement); if (filterElements.isEmpty()) { filtersElement.getParentNode().removeChild(filtersElement); DomUtils.removeTextNodes(root); fileManager.createOrUpdateTextFileIfRequired(pom.getPath(), XmlUtils.nodeToString(document),
Document pom = getInputDocument(pomMutableFile.getInputStream()); Element root = pom.getDocumentElement(); .getDocumentElement(); .findFirstElementByName(EXECUTIONS, plugin); if (executions == null) { executions = pom.createElement(EXECUTIONS); plugin.appendChild(executions); Element configuration = DomUtils.findFirstElementByName(CONFIGURATION2, execution); if (configuration == null) { Element sourceRoot = DomUtils.findFirstElementByName("sourceRoot", configuration); if (sourceRoot == null) { Element defaultOptions = DomUtils.findFirstElementByName( "defaultOptions", configuration); if (defaultOptions == null) { Element wsdlOptions = DomUtils.findFirstElementByName("wsdlOptions", configuration); if (wsdlOptions == null) {
MutableFile pomMutableFile = getFileManager().updateFile(pomPath); Document pom = getInputDocument(pomMutableFile.getInputStream()); Element root = pom.getDocumentElement(); .findFirstElement( "/project/build/plugins/plugin[groupId='org.apache.cxf' and artifactId='cxf-java2ws-plugin']", root); Element serviceExecution = XmlUtils.findFirstElement( "/project/build/plugins/plugin/executions/execution/configuration[className='" .concat(serviceClass.getFullyQualifiedTypeName()) serviceExecution = XmlUtils.findFirstElement( "/project/build/plugins/plugin/executions/execution/configuration[className='" .concat(fullyQualifiedTypeName).concat("']"), root); if (serviceExecution != null && serviceExecution.hasChildNodes()) { updateServiceExecution = (serviceExecution.getFirstChild() != null) ? serviceExecution .getFirstChild().getNextSibling() : null; Element oldExecutions = DomUtils.findFirstElementByName(EXECUTIONS, jaxWsPlugin); newExecutions = pom.createElement(EXECUTIONS); newExecutions.appendChild(serviceExecution);
/** * Check if login.jspx is modified with bootstrap * * @return */ @Override public boolean isLoginModified() { String dirPath = pathResolver.getIdentifier(getWebappPath(), "WEB-INF/views/login.jspx"); final Document document = XmlUtils.readXml(fileManager .getInputStream(dirPath)); final Element config = document.getDocumentElement(); final Element urlElement = DomUtils.findFirstElementByName("div", config); String value = urlElement.getAttribute("class"); return value.contains("alert alert-danger"); }
DomUtils.createChildIfNotExists("dependencyManagement/dependencies", parentElement, parentDocument); final List<Element> existingDependencyManagementElements = XmlUtils.findElements("dependency", dependencyManagementElement); dependencyManagementElement.appendChild(newDependencyElement); finalDependencies.add(newDependency); addedDependencies.add(newDependency.getSimpleDescription()); DomUtils.createChildIfNotExists("dependencies", element, document); final List<Element> existingDependencyElements = XmlUtils.findElements("dependency", dependenciesElement); dependenciesElement.insertBefore(newDependencyElement, existingDependencyElement); inserted = true; Dependency newDependencyWithoutVersion = new Dependency(newDependencyElement); dependenciesElement.removeChild(existingDependencyElement); getPomDependenciesUpdateMessage(addedDependencies, removedDependencies, skippedDependencies); fileManager.createOrUpdateTextFileIfRequired(pom.getPath(), XmlUtils.nodeToString(document), message, false);
public void addFilter(final String moduleName, final Filter filter) { Validate.isTrue(isProjectAvailable(moduleName), "Filter modification prohibited at this time"); Validate.notNull(filter, "Filter required"); final Pom pom = getPomFromModuleName(moduleName); Validate.notNull(pom, "The pom is not available, so filter addition cannot be performed"); if (filter == null || pom.isFilterRegistered(filter)) { return; } final Document document = XmlUtils.readXml(fileManager.getInputStream(pom.getPath())); final Element root = document.getDocumentElement(); final String descriptionOfChange; final Element buildElement = XmlUtils.findFirstElement("/project/build", root); final Element existingFilter = XmlUtils.findFirstElement("filters/filter['" + filter.getValue() + "']", buildElement); if (existingFilter == null) { // No such filter; add it final Element filtersElement = DomUtils.createChildIfNotExists("filters", buildElement, document); filtersElement.appendChild(XmlUtils.createTextElement(document, "filter", filter.getValue())); descriptionOfChange = highlight(ADDED + " filter") + " '" + filter.getValue() + "'"; } else { existingFilter.setTextContent(filter.getValue()); descriptionOfChange = highlight(UPDATED + " filter") + " '" + filter.getValue() + "'"; } fileManager.createOrUpdateTextFileIfRequired(pom.getPath(), XmlUtils.nodeToString(document), descriptionOfChange, false); }
Element root = pom.getDocumentElement(); .findFirstElement( "/project/build/plugins/plugin[groupId='org.apache.cxf' and artifactId='cxf-codegen-plugin']", root); Element oldGenerateSourcesCxfServer = XmlUtils.findFirstElement( "/project/build/plugins/plugin/executions/execution[id='" + CXF_WSDL2JAVA_EXECUTION_ID + "']", root); Element oldExecutions = DomUtils.findFirstElementByName(EXECUTIONS, codegenWsPlugin); oldGenerateSourcesCxfServer.getParentNode().replaceChild( newGenerateSourcesCxfServer, oldGenerateSourcesCxfServer); newExecutions = pom.createElement(EXECUTIONS); newExecutions.appendChild(newGenerateSourcesCxfServer); codegenWsPlugin.appendChild(newExecutions); XmlUtils.writeXml(pomMutableFile.getOutputStream(), pom);
private void updateParentModulePom(final String moduleName) { final String parentPomPath = pomManagementService.getFocusedModule().getPath(); final Document parentPomDocument = XmlUtils.readXml(fileManager.getInputStream(parentPomPath)); final Element parentPomRoot = parentPomDocument.getDocumentElement(); DomUtils.createChildIfNotExists("packaging", parentPomRoot, parentPomDocument).setTextContent( "pom"); addModuleDeclaration(moduleName, parentPomDocument, parentPomRoot); final String addModuleMessage = getDescriptionOfChange(ADDED, Collections.singleton(moduleName), "module", "modules"); fileManager.createOrUpdateTextFileIfRequired(getFocusedModule().getPath(), XmlUtils.nodeToString(parentPomDocument), addModuleMessage, false); }
try { pomMutableFile = getFileManager().updateFile(pomPath); pom = XmlUtils.getDocumentBuilder().parse( pomMutableFile.getInputStream()); Element root = pom.getDocumentElement(); .findFirstElement( "/project/build/plugins/plugin[groupId='org.apache.cxf' and artifactId='cxf-codegen-plugin']", root); Element oldGenerateSourcesCxfServer = XmlUtils.findFirstElement( "/project/build/plugins/plugin/executions/execution[id='" + CXF_WSDL2JAVA_EXECUTION_ID + "']", root); Element executionPhase = DomUtils.findFirstElementByName(PHASE2, oldGenerateSourcesCxfServer); Element newPhase = pom.createElement(PHASE2); newPhase.setTextContent("none"); executionPhase.getParentNode().replaceChild(newPhase, executionPhase);
public Document getFinderDocument( final FinderMetadataDetails finderMetadataDetails) { final DocumentBuilder builder = XmlUtils.getDocumentBuilder(); final Document document = builder.newDocument(); .appendChild(new XmlElementBuilder("div", document) .addAttribute("xmlns:form", "urn:jsptagdir:/WEB-INF/tags/form") .addAttribute( "id", XmlUtils.convertId("ff:" + formBackingType.getFullyQualifiedTypeName())) .addAttribute("path", controllerPath) .getPlural(), "")) .build(); formFind.setAttribute("z", XmlRoundTripUtils.calculateUniqueKeyFor(formFind)); div.appendChild(formFind); if (field.getCustomData().keySet() .contains(CustomDataKeys.MANY_TO_MANY_FIELD)) { fieldElement.setAttribute("multiple", "true"); fieldElement = document.createElement("field:checkbox"); DomUtils.removeTextNodes(document); return document;
public void addResource(final String moduleName, final Resource resource) { Validate .isTrue(isProjectAvailable(moduleName), "Resource modification prohibited at this time"); Validate.notNull(resource, "Resource to add required"); final Pom pom = getPomFromModuleName(moduleName); Validate.notNull(pom, "The pom is not available, so resource addition cannot be performed"); if (pom.isResourceRegistered(resource)) { return; } final Document document = XmlUtils.readXml(fileManager.getInputStream(pom.getPath())); final Element buildElement = XmlUtils.findFirstElement("/project/build", document.getDocumentElement()); final Element resourcesElement = DomUtils.createChildIfNotExists("resources", buildElement, document); resourcesElement.appendChild(resource.getElement(document)); final String descriptionOfChange = highlight(ADDED + " resource") + " " + resource.getSimpleDescription(); fileManager.createOrUpdateTextFileIfRequired(pom.getPath(), XmlUtils.nodeToString(document), descriptionOfChange, false); }
if (addToPluginManagement) { pluginsElement = DomUtils.createChildIfNotExists("build/pluginManagement/plugins", parentRoot, parentDocument); } else { pluginsElement = DomUtils.createChildIfNotExists("/project/build/plugins", root, document); DomUtils.createChildIfNotExists(parentElementName, execution.getConfiguration() .getConfiguration(), document); for (Entry<String, String> element : elementValues.entrySet()) { if (elementValues.size() == 1 && element.getKey().equals(DEFAULT_VALUE_TEXT)) { final String elem = DomUtils.getTextContent(existingElement, ""); if (elem.equals(element.getValue())) { return; DomUtils.getChildElementByTagName(existingElement, element.getKey()); if (childElement != null && DomUtils.getTextContent(childElement, "").equals(element.getValue())) { return; if (newParentElement == null) { newParentElement = DomUtils.createChildIfNotExists(elementName, execution.getConfiguration() .getConfiguration(), parentDocument); elementsElement.appendChild(newParentElement); if (newParentElement == null) { newParentElement =
final Document document = XmlUtils.readXml(fileManager.getInputStream(pom.getPath())); final Element repositoriesElement = DomUtils.createChildIfNotExists(containingPath, document.getDocumentElement(), document); for (Element exisitingRepElement : XmlUtils.findElements(path, repositoriesElement)) { existingRepositories.add(new Repository(exisitingRepElement)); repositoriesElement.appendChild(repository.getElement(document, path)); addedRepositories.add(repository.getUrl()); fileManager.createOrUpdateTextFileIfRequired(pom.getPath(), XmlUtils.nodeToString(document), message, false);
defaultJspxXml = XmlUtils.getDocumentBuilder().parse(defulatJspxIs); Element lsHtml = defaultJspxXml.getDocumentElement(); lsHtml.setAttribute("xmlns:dialog", "urn:jsptagdir:/WEB-INF/tags/dialog/modal"); Element messageBoxElement = DomUtils.findFirstElementByName( "dialog:message-box", lsHtml); if (messageBoxElement == null) { Element divMain = XmlUtils.findFirstElement( "/html/body/div/div[@id='main']", lsHtml); Element insertAttributeBodyElement = XmlUtils.findFirstElement( "/html/body/div/div/insertAttribute[@name='body']", lsHtml); Element messageBox = new XmlElementBuilder("dialog:message-box", defaultJspxXml).build(); divMain.insertBefore(messageBox, insertAttributeBodyElement); writeToDiskIfNecessary(defaultJspx, defaultJspxXml.getDocumentElement());