/** * Set the description element in the web.xml document. * * @param description (required) * @param document the web.xml document (required) * @param comment (optional) */ public static void setDescription(final String description, final Document document, final String comment) { Validate.notNull(document, "Web XML document required"); Validate.notBlank(description, "Description required"); Element descriptionElement = XmlUtils.findFirstElement(WEB_APP_XPATH + "description", document.getDocumentElement()); if (descriptionElement == null) { descriptionElement = document.createElement("description"); insertBetween(descriptionElement, "display-name[last()]", "context-param", document); if (StringUtils.isNotBlank(comment)) { addCommentBefore(descriptionElement, comment, document); } } descriptionElement.setTextContent(description); }
public void removeFilter(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 removal 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 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), descriptionOfChange, false);
/** * Add Spring Cache starter to provided module. * * @param module the Pom where the starter should be installed. */ private void addSpringCacheDependency(Pom module) { // Parse the configuration.xml file final Element configuration = XmlUtils.getConfiguration(getClass()); final List<Dependency> dependencies = new ArrayList<Dependency>(); final List<Element> auditDependencies = XmlUtils.findElements("/configuration/cache/dependencies/dependency", configuration); for (final Element dependencyElement : auditDependencies) { dependencies.add(new Dependency(dependencyElement)); } getProjectOperations().addDependencies(module.getModuleName(), dependencies); }
/** * Write an XML document to the OutputStream provided. This will use the * pre-configured Roo provided Transformer. * * @param outputStream the output stream to write to. The stream is closed * upon completion. * @param document the document to write. */ public static void writeXml(final OutputStream outputStream, final Document document) { writeXml(createIndentingTransformer(), outputStream, document); }
/** * Convenience constructor for creating a repository instance from an XML * Element * * @param element containing the repository definition (required) */ public Repository(final Element element) { Validate.notNull(element, "Element required"); final Element name = XmlUtils.findFirstElement("name", element); final Element snapshotsElement = XmlUtils.findFirstElement("snapshots", element); enableSnapshots = snapshotsElement == null ? false : Boolean.valueOf(XmlUtils.findRequiredElement("enabled", snapshotsElement).getTextContent()); id = XmlUtils.findRequiredElement("id", element).getTextContent(); this.name = name == null ? null : name.getTextContent(); url = XmlUtils.findRequiredElement("url", element).getTextContent(); }
/** * Convenience constructor when an XML element is available that represents * a Maven <resource>. * * @param resource to parse (required) */ public Resource(final Element resource) { final Element directoryElement = XmlUtils.findFirstElement("directory", resource); Validate.notNull(directoryElement, "directory element required"); directory = directoryElement.getTextContent(); final Element filteringElement = XmlUtils.findFirstElement("filtering", resource); filtering = filteringElement == null ? null : Boolean.valueOf(filteringElement.getTextContent()); // Parsing for includes for (final Element include : XmlUtils.findElements("includes/include", resource)) { includes.add(include.getTextContent()); } }
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); }
final Document pom = XmlUtils.readXml(templateInputStream); final Element root = pom.getDocumentElement(); XmlUtils.findRequiredElement("/project/name", root).setTextContent(projectName); XmlUtils.findRequiredElement("/project/groupId", root).setTextContent(wrapperGroupId); XmlUtils.findRequiredElement("/project/artifactId", root).setTextContent( wrapperGroupId + "." + artifactId); XmlUtils.findRequiredElement("/project/version", root).setTextContent(version + ".0001"); XmlUtils.findRequiredElement("/project/dependencies/dependency/groupId", root).setTextContent( groupId); XmlUtils.findRequiredElement("/project/dependencies/dependency/artifactId", root) .setTextContent(artifactId); XmlUtils.findRequiredElement("/project/dependencies/dependency/version", root).setTextContent( version); XmlUtils.findRequiredElement("/project/properties/pkgArtifactId", root).setTextContent( artifactId); XmlUtils.findRequiredElement("/project/properties/pkgVersion", root).setTextContent(version); XmlUtils.findRequiredElement("/project/properties/pkgVendor", root).setTextContent(vendorName); XmlUtils.findRequiredElement("/project/properties/pkgLicense", root) XmlUtils.findRequiredElement("/project/properties/pkgDocUrl", root).setTextContent(docUrl); .findRequiredElement( "/project/build/plugins/plugin[artifactId = 'maven-bundle-plugin']/configuration/instructions", root); final Element descriptionE = XmlUtils.findRequiredElement("/project/description", root);
@Override public List<String> getEndPointsFromWsdlFile(String wsdlPath) { List<String> availableEndPoints = new ArrayList<String>(); // Check if provided wsdl file exists if (getFileManager().exists(wsdlPath)) { // Obtain document final Document document = XmlUtils.readXml(getFileManager().getInputStream(wsdlPath)); // Finding service elements List<Element> services = XmlUtils.findElements("service", document.getDocumentElement()); for (Element service : services) { NodeList ports = service.getChildNodes(); for (int i = 0; i < ports.getLength(); i++) { Element port = (Element) ports.item(1); if (port != null && port.getAttribute("name") != null) { availableEndPoints.add(port.getAttribute("name")); } } } } return availableEndPoints; }
Document document = XmlUtils.readXml(inputStream); Element documentElement = document.getDocumentElement(); Element firstViewState = XmlUtils.findFirstElement("//view-state", documentElement); String modelObjectName = StringUtils.uncapitalize(modelObject.getSimpleTypeName()); Element onStartElement = document.createElement("on-start"); Element setElement = document.createElement("set"); setElement.setAttribute("name", String.format("flowScope.%s", modelObjectName)); setElement.setAttribute("value", String.format("new %s()", modelObject.getFullyQualifiedTypeName())); onStartElement.appendChild(setElement); List<Element> viewElements = XmlUtils.findElements("//view-state", documentElement); for (Element element : viewElements) { element.setAttribute("model", modelObjectName);
final Document docXml = XmlUtils.readXml(templateInputStream); final Element document = docXml.getDocumentElement(); Element capabilityElement = XmlUtils.findFirstElement("resource/capability", document); topLevelPackageName.substring(topLevelPackageName.lastIndexOf(".") + 1).toLowerCase(); Element commandAddElement = docXml.createElement("p"); commandAddElement.setAttribute("n", "command-add"); commandAddElement.setAttribute("v", commandInit + " add"); Element commandAllElement = docXml.createElement("p"); commandAllElement.setAttribute("n", "command-all"); commandAllElement.setAttribute("v", commandInit + " all"); XmlUtils.writeXml( fileManager.updateFile( pathResolver.getIdentifier(rootPath, folder + "/" + "src/main/resources/obr.xml")) .getOutputStream(), docXml); XmlUtils.writeXml( fileManager.updateFile( pathResolver.getIdentifier(rootPath, "src/main/resources/obr.xml"))
folder + "/pom.xml"); Validate.isTrue(fileManager.exists(pomRooAddonSuite), folder + "/pom.xml not found"); InputStream inputStream = fileManager.getInputStream(pomRooAddonSuite); Document docXml = XmlUtils.readXml(inputStream); Element document = docXml.getDocumentElement(); Element dependenciesElement = XmlUtils.findFirstElement("dependencies", document); Element dependencyAdvancedElement = docXml.createElement("dependency"); Element groupIdAdvancedElement = docXml.createElement("groupId"); groupIdAdvancedElement.setTextContent(topLevelPackage.getFullyQualifiedPackageName()); Element artifactIdAdvancedElement = docXml.createElement("artifactId"); artifactIdAdvancedElement.setTextContent(topLevelPackage.getFullyQualifiedPackageName() + ".addon-advanced"); Element versionAdvancedElement = docXml.createElement("version"); versionAdvancedElement.setTextContent("${project.parent.version}"); dependencyAdvancedElement.appendChild(groupIdAdvancedElement); dependencyAdvancedElement.appendChild(artifactIdAdvancedElement); dependenciesElement.appendChild(dependencyAdvancedElement); XmlUtils.writeXml(fileManager.updateFile(pomRooAddonSuite).getOutputStream(), docXml);
@Override public String getTargetNameSpaceFromWsdlFile(String wsdlPath) { // Check if provided wsdl file exists if (getFileManager().exists(wsdlPath)) { // Obtain document final Document document = XmlUtils.readXml(getFileManager().getInputStream(wsdlPath)); // Return targetNamespace return document.getDocumentElement().getAttribute("targetNamespace"); } return null; }
Validate.isTrue(isModule || StringUtils.isNotBlank(javaVersion), "Java version required"); Validate.notNull(topLevelPackage, "Top level package required"); pom = XmlUtils.readXml(FileUtils.getInputStream(getClass(), pomTemplate)); groupId = getGroupId(topLevelPackage); } else { pom = XmlUtils.readXml(FileUtils.getInputStream(getClass(), pomModuleTemplate)); groupId = parentPom.getGroupId(); final Element root = pom.getDocumentElement(); Validate.notBlank(artifactId, "Maven artifactIds cannot be blank"); DomUtils.createChildIfNotExists("artifactId", root, pom).setTextContent(artifactId.trim()); XmlUtils.findElements("//*[.='" + JAVA_PRODUCT_VERSION_PLACEHOLDER + "']", root); for (final Element versionElement : javaProductVersionElements) { versionElement.setTextContent(javaVersion); XmlUtils.findElements("//*[.='" + ASPECTJ_PLUGIN_VERSION_PLACEHOLDER + "']", root); for (final Element aspectJPluginVersion : aspectJPluginVersionElements) { aspectJPluginVersion.setTextContent("1.8"); XmlUtils.findElements("//*[.='" + ASCIIDOCLET_PLUGIN_VERSION_PLACEHOLDER + "']", root); for (final Element versionElement : asciidocletPluginVersionElements) { versionElement.setTextContent("1.5.4"); getFileManager().createOrUpdateTextFileIfRequired(pomPath, XmlUtils.nodeToString(pom), true); return pomPath;
private void resolveChildModulePoms(final Element pomRoot, final String pomPath, final Map<String, String> pomSet) { for (final Element module : XmlUtils.findElements("/project/modules/module", pomRoot)) { final String moduleName = module.getTextContent(); if (StringUtils.isNotBlank(moduleName)) { final String modulePath = resolveRelativePath(pomPath, moduleName); final boolean alreadyDiscovered = pomSet.containsKey(modulePath); pomSet.put(modulePath, moduleName); if (!alreadyDiscovered) { final Document pomDocument = XmlUtils.readXml(getFileManager().getInputStream(modulePath)); final Element root = pomDocument.getDocumentElement(); resolvePoms(root, modulePath, pomSet); } } } }
FileUtils.getInputStream(getClass(), "xml/" + templateName); final Document assemblyDoc = XmlUtils.readXml(templateInputStream); final Element root = assemblyDoc.getDocumentElement(); XmlUtils.findRequiredElement("/assembly/moduleSets/moduleSet/binaries/outputDirectory", root) .setTextContent(projectFolder + "/${module.artifactId}/${module.version}"); Element includes = XmlUtils.findFirstElement("moduleSets/moduleSet/includes", root); Element includeAdvancedElement = assemblyDoc.createElement("include"); includeAdvancedElement.setTextContent(topLevelPackage.getFullyQualifiedPackageName() + ":" + topLevelPackage.getFullyQualifiedPackageName() + ".addon-advanced"); Element includeSimpleElement = assemblyDoc.createElement("include"); includeSimpleElement.setTextContent(topLevelPackage.getFullyQualifiedPackageName() + ":" + topLevelPackage.getFullyQualifiedPackageName() + ".addon-simple"); fileManager.createFile(pathResolver.getIdentifier(rootPath, "src/main/assembly/repo-assembly.xml")); XmlUtils.writeXml(assemblyFile.getOutputStream(), assemblyDoc);
private static void insertAfter(final Element element, final String afterElementName, final Document document) { final Element afterElement = XmlUtils.findFirstElement(WEB_APP_XPATH + afterElementName, document.getDocumentElement()); if (afterElement != null && afterElement.getNextSibling() != null && afterElement.getNextSibling() instanceof Element) { document.getDocumentElement().insertBefore(element, afterElement.getNextSibling()); addLineBreakBefore(element, document); addLineBreakBefore(element, document); return; } document.getDocumentElement().appendChild(element); addLineBreakBefore(element, document); addLineBreakBefore(element, document); }
final Document document = XmlUtils.readXml(fileManager.getInputStream(pom.getPath())); final Element root = document.getDocumentElement(); final Element dependencyElement = XmlUtils.findFirstElement( "/project/dependencies/dependency[groupId = '" + dependency.getGroupId() + "' and artifactId = '" + dependency.getArtifactId() + "' and version = '" final Element scopeElement = XmlUtils.findFirstElement("scope", dependencyElement); final String descriptionOfChange; if (scopeElement == null) { if (dependencyScope != null) { dependencyElement.appendChild(new XmlElementBuilder("scope", document).setText( dependencyScope.name().toLowerCase()).build()); descriptionOfChange = scopeElement.setTextContent(dependencyScope.name().toLowerCase()); descriptionOfChange = highlight(CHANGED + " scope") + " to " + dependencyScope.name().toLowerCase() + " in dependency " + dependency.getSimpleDescription(); } else { dependencyElement.removeChild(scopeElement); descriptionOfChange = highlight(REMOVED + " scope") + " from dependency " + dependency.getSimpleDescription(); fileManager.createOrUpdateTextFileIfRequired(pom.getPath(), XmlUtils.nodeToString(document), descriptionOfChange, false);
public String getHandledExceptionList() { String webXmlPath = pathResolver.getIdentifier( LogicalPath.getInstance(Path.SRC_MAIN_WEBAPP, ""), WEB_MVC_CONFIG); Validate.isTrue(fileManager.exists(webXmlPath), WEB_MVC_CONFIG_NOT_FOUND); MutableFile webXmlMutableFile = null; Document webXml; try { webXmlMutableFile = fileManager.updateFile(webXmlPath); webXml = XmlUtils.getDocumentBuilder().parse( webXmlMutableFile.getInputStream()); } catch (Exception e) { throw new IllegalStateException(e); } Element root = webXml.getDocumentElement(); List<Element> simpleMappingException = null; simpleMappingException = XmlUtils.findElements(RESOLVER_BEAN_MESSAGE + "/property[@name='exceptionMappings']/props/prop", root); Validate.notNull(simpleMappingException, "There aren't Exceptions handled by the application."); StringBuilder exceptionList = new StringBuilder("Handled Exceptions:\n"); for (Element element : simpleMappingException) { exceptionList.append(element.getAttribute("key") + "\n"); } return exceptionList.toString(); }
OutputStream out = null; try { if (fileManager.exists(loginJspx)) { mutableLoginJspx = fileManager.updateFile(loginJspx); loginJspxDoc = XmlUtils.getDocumentBuilder().parse( mutableLoginJspx.getInputStream()); Element form = XmlUtils.findFirstElementByName("form", loginJspxDoc.getDocumentElement()); Validate.notNull(form, "Could not find form in ".concat(loginJspx)); form.appendChild(new XmlElementBuilder("div", loginJspxDoc) .addChild( loginJspxDoc .createTextNode("<br/><a href =\"/" .concat(contextPath) .concat("/forgotpassword/index\">Forgot Password</a> | Not a User Yet? <a href =\"/") .build()); out = mutableLoginJspx.getOutputStream(); XmlUtils.writeXml(out, loginJspxDoc);