@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; }
fileManager.createFile(pathResolver.getIdentifier(rootPath, folder + "/" + "src/main/resources/obr.xml")); } else { LogicalPath rootPath = LogicalPath.getInstance(Path.ROOT, ""); fileManager.createFile(pathResolver.getIdentifier(rootPath, "src/main/resources/obr.xml")); 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"); XmlUtils.writeXml( fileManager.updateFile( pathResolver.getIdentifier(rootPath, folder + "/" + "src/main/resources/obr.xml")) .getOutputStream(), docXml); LogicalPath rootPath = LogicalPath.getInstance(Path.ROOT, ""); XmlUtils.writeXml( fileManager.updateFile( pathResolver.getIdentifier(rootPath, "src/main/resources/obr.xml")) .getOutputStream(), docXml);
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); }
@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; }
@Override public void deleteEntity(JavaType entity) { final String entityFilePathIdentifier = getPathResolver().getCanonicalPath(entity.getModule(), Path.SRC_MAIN_JAVA, entity); if (getFileManager().exists(entityFilePathIdentifier)) { getFileManager().delete(entityFilePathIdentifier); } }
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); }
private void addAddonsDependencies(Document pom, String folder, JavaPackage topLevelPackage) { projectOperations.getPathResolver().getIdentifier(Path.ROOT.getModulePathId(""), 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);
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"));
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); }
public void updateProjectType(final String moduleName, final ProjectType projectType) { Validate.notNull(projectType, "Project type required"); final Pom pom = getPomFromModuleName(moduleName); Validate.notNull(pom, "The pom is not available, so the project type cannot be changed"); final Document document = XmlUtils.readXml(fileManager.getInputStream(pom.getPath())); final Element packaging = DomUtils.createChildIfNotExists("packaging", document.getDocumentElement(), document); if (packaging.getTextContent().equals(projectType.getType())) { return; } packaging.setTextContent(projectType.getType()); final String descriptionOfChange = highlight(UPDATED + " project type") + " to " + projectType.getType(); fileManager.createOrUpdateTextFileIfRequired(pom.getPath(), XmlUtils.nodeToString(document), descriptionOfChange, false); }
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); 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(); }
public void removeProperty(final String moduleName, final Property property) { Validate .isTrue(isProjectAvailable(moduleName), "Property modification prohibited at this time"); Validate.notNull(property, "Property to remove required"); final Pom pom = getPomFromModuleName(moduleName); Validate.notNull(pom, "The pom is not available, so property removal cannot be performed"); if (!pom.isPropertyRegistered(property)) { return; } final Document document = XmlUtils.readXml(fileManager.getInputStream(pom.getPath())); final Element root = document.getDocumentElement(); final Element propertiesElement = XmlUtils.findFirstElement("/project/properties", root); String descriptionOfChange = ""; for (final Element candidate : XmlUtils.findElements("/project/properties/*", document.getDocumentElement())) { if (property.equals(new Property(candidate))) { propertiesElement.removeChild(candidate); descriptionOfChange = highlight(REMOVED + " property") + " " + property.getName(); // Stay in the loop just in case it was in the POM more than // once } } DomUtils.removeTextNodes(propertiesElement); fileManager.createOrUpdateTextFileIfRequired(pom.getPath(), XmlUtils.nodeToString(document), descriptionOfChange, false); }
private void removeRepository(final String moduleName, final Repository repository, final String path) { Validate.isTrue(isProjectAvailable(moduleName), "Repository modification prohibited at this time"); Validate.notNull(repository, "Repository required"); final Pom pom = getPomFromModuleName(moduleName); Validate.notNull(pom, "The pom is not available, so repository removal cannot be performed"); if ("pluginRepository".equals(path)) { if (!pom.isPluginRepositoryRegistered(repository)) { return; } } else { if (!pom.isRepositoryRegistered(repository)) { return; } } final Document document = XmlUtils.readXml(fileManager.getInputStream(pom.getPath())); final Element root = document.getDocumentElement(); String descriptionOfChange = ""; for (final Element candidate : XmlUtils.findElements(path, root)) { if (repository.equals(new Repository(candidate))) { candidate.getParentNode().removeChild(candidate); descriptionOfChange = highlight(REMOVED + " repository") + " " + repository.getUrl(); // We stay in the loop just in case it was in the POM more than // once } } fileManager.createOrUpdateTextFileIfRequired(pom.getPath(), XmlUtils.nodeToString(document), descriptionOfChange, false); }
public boolean isMessageMappingAvailable() { String webXmlPath = pathResolver.getIdentifier( LogicalPath.getInstance(Path.SRC_MAIN_WEBAPP, ""), WEB_MVC_CONFIG); if (!fileManager.exists(webXmlPath)) { return false; } 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(); Element exceptionResolver = XmlUtils.findFirstElement( RESOLVER_BEAN_MESSAGE + "/property[@name='exceptionMappings']/props/prop", root); boolean isExceptionAvailable = (exceptionResolver != null) ? true : false; return isExceptionAvailable; }
@Override public List<Dependency> addDependencies(final String moduleName, final Collection<? extends Dependency> newDependencies, boolean addToDependencyManagement, boolean checkFullDependency) { Validate.isTrue(isProjectAvailable(moduleName), "Dependency modification prohibited; no such module '%s'", moduleName); final Pom parentPom = getPomFromModuleName(""); boolean isSamePom = false; Pom pom = null; if ("".equals(moduleName)) { isSamePom = true; pom = parentPom; } else { pom = getPomFromModuleName(moduleName); } Validate.notNull(pom, "The pom is not available, so dependencies cannot be added"); final Document parentDocument = XmlUtils.readXml(fileManager.getInputStream(parentPom.getPath())); Document document = null; if (isSamePom) { document = parentDocument; } else { document = XmlUtils.readXml(fileManager.getInputStream(pom.getPath())); } return writeDependencyInPom(newDependencies, parentPom, pom, parentDocument, document, parentDocument.getDocumentElement(), document.getDocumentElement(), addToDependencyManagement, isSamePom, checkFullDependency); }
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); } } } }
private void resolveParentPom(final String pomPath, final Map<String, String> pomSet, final Element parentElement) { final String relativePath = XmlUtils.getTextContent("/relativePath", parentElement, DEFAULT_RELATIVE_PATH); final String parentPomPath = resolveRelativePath(pomPath, relativePath); final boolean alreadyDiscovered = pomSet.containsKey(parentPomPath); if (!alreadyDiscovered) { pomSet.put(parentPomPath, pomSet.get(parentPomPath)); if (new File(parentPomPath).isFile()) { final Document pomDocument = XmlUtils.readXml(getFileManager().getInputStream(parentPomPath)); final Element root = pomDocument.getDocumentElement(); resolvePoms(root, parentPomPath, pomSet); } } }
String docTagxPath = getPathResolver().getIdentifier(getWebappPath(), "WEB-INF/tags/util/load-scripts.tagx"); Validate.isTrue(fileManager.exists(docTagxPath), "load-script.tagx not found: ".concat(docTagxPath)); docTagxMutableFile = fileManager.updateFile(docTagxPath); docTagx = XmlUtils.getDocumentBuilder().parse( docTagxMutableFile.getInputStream()); throw new IllegalStateException(e); Element root = docTagx.getDocumentElement(); XmlUtils.writeXml(docTagxMutableFile.getOutputStream(), docTagx);
@Override public Map<String, String> getProperties(final LogicalPath propertyFilePath, final String propertyFilename) { Validate.notNull(propertyFilePath, "Property file path required"); Validate.notBlank(propertyFilename, "Property filename required"); final String filePath = getProjectOperations().getPathResolver().getIdentifier(propertyFilePath, propertyFilename); final Properties props = new Properties(); try { if (getFileManager().exists(filePath)) { loadProperties(props, new BufferedInputStream(new FileInputStream(filePath))); } else { throw new IllegalStateException(String.format( "ERROR: '%s' properties file doesn't exists.", filePath)); } } catch (final IOException ioe) { throw new IllegalStateException(ioe); } final Map<String, String> result = new HashMap<String, String>(); for (final Object key : props.keySet()) { result.put(key.toString(), props.getProperty(key.toString())); } return Collections.unmodifiableMap(result); }