List of usage examples for org.dom4j Element getTextTrim
String getTextTrim();
From source file:org.hudsonci.plugins.team.cli.CopyTeamCommand.java
License:Open Source License
private void fixTeamName(Element element, String oldPrefix, String newPrefix) { String jobName = element.getTextTrim(); if (jobName.startsWith(oldPrefix)) { element.setText(newPrefix + jobName.substring(oldPrefix.length())); }//from w w w . j a v a 2 s . co m }
From source file:org.hudsonci.plugins.team.cli.CopyTeamCommand.java
License:Open Source License
private void fixTriggerProperty(Element origValue, String oldPrefix, String newPrefix) { Element cp = origValue.element("childProjects"); String childProjects = cp.getTextTrim(); List<String> children = new ArrayList<String>(); StringTokenizer st = new StringTokenizer(childProjects, ", "); boolean changed = false; while (st.hasMoreTokens()) { String child = st.nextToken(); if (child.startsWith(oldPrefix)) { changed = true;//from w w w . j av a 2 s. c o m child = newPrefix + child.substring(oldPrefix.length()); } children.add(child); } if (changed) { childProjects = StringUtils.join(children, ", "); cp.setText(childProjects); } }
From source file:org.hudsonci.utils.team.Team.java
License:Open Source License
public void read(Element parent, Find find, Map<String, Team> teamMap) { List<Element> elements = (List<Element>) parent.elements(); if (elements.isEmpty()) { find.warn("<team> with no name, members or jobs"); return;//from ww w . j a v a2 s.c om } String nameString = ""; for (Element child : elements) { String name = child.getName(); if ("name".equals(name)) { teamName = child.getTextTrim(); if (teamName.isEmpty()) { find.warn("Team with empty name"); return; } if (teamMap.containsKey(teamName)) { find.warn("Duplicate team " + teamName); return; } teamMap.put(teamName, this); nameString = " in team " + teamName + " "; if ("public".equals(teamName)) { isPublic = true; } } else if ("description".equals(name)) { description = child.getTextTrim(); if (description.isEmpty()) { find.fine("Empty description" + nameString); } } else if ("customFolderName".equals(name)) { customFolderName = child.getTextTrim(); if (customFolderName.isEmpty()) { find.fine("Empty customFolderName " + nameString); } } else if ("job".equals(name)) { TeamJob job = new TeamJob(); job.read(child, find, jobMap, nameString); } else if ("member".equals(name)) { TeamMember member = new TeamMember(); member.read(child, find, memberMap, nameString); } } if (teamName == null) { find.warn("Team with no name"); return; } if (description == null) { description = teamName; } }
From source file:org.hudsonci.utils.team.TeamJob.java
License:Open Source License
public void read(Element parent, Find find, Map<String, TeamJob> jobMap, String suffix) { List<Element> elements = (List<Element>) parent.elements(); if (elements.isEmpty()) { find.warn("Job with no id or visibility" + suffix); return;//ww w . ja v a 2 s . c om } boolean checkId = true; String nameString = ""; for (Element child : elements) { String name = child.getName(); if ("id".equals(name)) { String jobId = child.getTextTrim(); if (jobMap.containsKey(jobId)) { find.warn("Duplicate job " + jobId + suffix); checkId = false; } else { id = jobId; nameString = "in job " + id + " "; jobMap.put(id, this); } } else if ("visibility".equals(name)) { String rawVisibility = child.getTextTrim(); String[] teams = rawVisibility.split(","); for (String team : teams) { if (!visibilitySet.add(team.trim())) { find.warn("Duplicate visibility " + team + " " + nameString + suffix); } } } } if (checkId && id == null) { find.warn("Job with no id" + suffix); } }
From source file:org.hudsonci.utils.team.TeamManager.java
License:Open Source License
public boolean read(File file, Find find) { SAXReader reader = new SAXReader(); try {//from w w w.ja va 2 s. co m Document inDoc = reader.read(file); Element root = inDoc.getRootElement(); if (!"teamManager".equals(root.getName())) { find.error(file.getAbsolutePath() + " skipped; format error"); find.error("Root element must be teamManager"); return false; } find.verbose("Scanning " + file.getAbsolutePath()); for (Element child : (List<Element>) root.elements()) { String name = child.getName(); if ("sysAdmin".equals(name)) { String admin = child.getTextTrim(); if (!sysAdmins.add(admin)) { find.warn("Duplicate sysAdmin " + admin); } } else if ("team".equals(name)) { Team team = new Team(); team.read(child, find, teamMap); } } return true; } catch (DocumentException e) { find.exception(file, e, "Error reading teams.xml"); } return false; }
From source file:org.hudsonci.utils.team.TeamMember.java
License:Open Source License
public void read(Element parent, Find find, Map<String, TeamMember> memberMap, String suffix) { List<Element> elements = (List<Element>) parent.elements(); if (elements.isEmpty()) { find.warn("Team member with no name or permissions"); return;/*from w ww. j av a 2 s. c om*/ } String nameString = ""; for (Element child : elements) { String name = child.getName(); if ("name".equals(name)) { memberName = child.getTextTrim(); if (memberName.isEmpty()) { find.warn("Team member with empty name" + suffix); return; } else if (memberMap.containsKey(memberName)) { find.warn("Team member " + memberName + " is duplicate" + suffix); } else { memberMap.put(memberName, this); nameString = memberName + " "; } } else if ("permissions".equals(name)) { String permissions = child.getTextTrim(); if (permissions.isEmpty()) { find.info("Team member " + nameString + "has empty permissions" + suffix); continue; } for (String permission : permissions.split(",")) { permission = permission.trim(); if (this.permissions.contains(permission)) { find.warn("Team member " + nameString + "has duplicate permission " + permission + suffix); } this.permissions.add(permission); } } } if (permissions.isEmpty()) { find.info("Team member " + nameString + "has no permissions" + suffix); } }
From source file:org.intalio.tempo.workflow.fds.core.UserProcessMessageConvertor.java
License:Open Source License
/** * Converts a SOAP message from a user process to the WorkflowProcesses * format. <br>// ww w.j a v a 2s. c om * The conversion is done in-place. The passed <code>Document</code> * instance gets converted to the Workflow Processes format and its previous * format is lost. * * @param message * The SOAP message from a user process to convert to the * Workflow Processes format. * @throws MessageFormatException * If the specified message has an invalid format. Note that if * this exception is thrown, <code>message</code> may have * already been partly processed and therefore should be assumed * to be corrupted. */ @SuppressWarnings("unchecked") public void convertMessage(Document message) throws MessageFormatException, AxisFault { FormDispatcherConfiguration config = FormDispatcherConfiguration.getInstance(); XPath xpath = null; xpath = DocumentHelper.createXPath("/soapenv:Envelope/soapenv:Body/soapenv:Fault"); List<Node> fault = xpath.selectNodes(message); if (fault.size() != 0) throw new RuntimeException(fault.toString()); // Check SOAP action xpath = DocumentHelper.createXPath("/soapenv:Envelope/soapenv:Body"); xpath.setNamespaceURIs(MessageConstants.get_nsMap()); List<Node> bodyQueryResult = xpath.selectNodes(message); if (bodyQueryResult.size() != 0) { Element root = (Element) bodyQueryResult.get(0); if (root.asXML().indexOf("createTaskRequest") != -1) { _soapAction = "createTask"; xpath = DocumentHelper.createXPath("/soapenv:Envelope/soapenv:Header/addr:Action"); xpath.setNamespaceURIs(MessageConstants.get_nsMap()); List<Node> wsaActionQueryResult = xpath.selectNodes(message); if (wsaActionQueryResult.size() != 0) { Element wsaToElement = (Element) wsaActionQueryResult.get(0); wsaToElement.setText(_soapAction); } else _log.warn("Did not find addr:Action in SOAP header"); } } _log.debug("Converted SOAP Action: " + _soapAction); /* * Change the wsa:To endpoint to Workflow Processes, if a wsa:To header * is present. */ xpath = DocumentHelper.createXPath("/soapenv:Envelope/soapenv:Header/addr:To"); xpath.setNamespaceURIs(MessageConstants.get_nsMap()); List<Node> wsaToQueryResult = xpath.selectNodes(message); if (wsaToQueryResult.size() != 0) { Element wsaToElement = (Element) wsaToQueryResult.get(0); String workflowProcessesUrl = config.getPxeBaseUrl() + config.getWorkflowProcessesRelativeUrl(); wsaToElement.setText(workflowProcessesUrl); } else _log.debug("Did not find addr:To in SOAP header"); /* * Change the session address to be FDS endpoint and retrieve sender * endpoint */ xpath = DocumentHelper.createXPath("/soapenv:Envelope/soapenv:Header/intalio:callback/addr:Address"); xpath.setNamespaceURIs(MessageConstants.get_nsMap()); List<Node> callbackToQueryResult = xpath.selectNodes(message); if (callbackToQueryResult.size() != 0) { Element wsaToElement = (Element) callbackToQueryResult.get(0); _userProcessEndpoint = wsaToElement.getText(); wsaToElement.setText(config.getFdsUrl()); } else _log.debug("Did not find intalio:callback/addr:Address in SOAP header"); /* Next, fetch the user process namespace URI from the task metadata */ /* * 1. fetch the first element of SOAP envelope body. */ List<Node> allSoapBodyElements = DocumentHelper.createXPath("/soapenv:Envelope/soapenv:Body//*") .selectNodes(message); if (allSoapBodyElements.size() == 0) { throw new MessageFormatException("No elements found inside soapenv:Body."); } Element firstPayloadElement = (Element) allSoapBodyElements.get(0); /* * 2. fetch its namespace and use it to fetch the userProcessEndpoint * and userProcessNamespaceURI element (which should be in the same * namespace). If those elements are not found, nothing is reported. * This is necessary for converting responses, where this information is * not present. */ String messageNamespace = firstPayloadElement.getNamespaceURI(); _userProcessNamespaceUri = messageNamespace; Map<String, String> namespaceURIs = new HashMap<String, String>(MessageConstants.get_nsMap()); namespaceURIs.put(REQUEST_PREFIX, _userProcessNamespaceUri); /* * Add session in task meta data so that it can be retrieved when * workflow process needs to send a message to the user process */ xpath = DocumentHelper.createXPath("/soapenv:Envelope/soapenv:Header/intalio:callback/intalio:session"); xpath.setNamespaceURIs(namespaceURIs/* MessageConstants.get_nsMap() */); List<Node> sessionQueryResult = xpath.selectNodes(message); if (sessionQueryResult.size() != 0) { Element wsaToElement = (Element) sessionQueryResult.get(0); String session = wsaToElement.getText(); xpath = DocumentHelper.createXPath("//" + REQUEST_PREFIX + ":taskMetaData"); xpath.setNamespaceURIs(namespaceURIs/* MessageConstants.get_nsMap() */); List<Node> tmdQueryResult = xpath.selectNodes(message); Element tmdElement = (Element) tmdQueryResult.get(0); Element sessionElement = tmdElement.addElement("session", MessageConstants.IB4P_NS); sessionElement.setText(session); } // retrieve userProcessEndpoint from task meta data // or put sender endpoint in task meta data if not defined xpath = DocumentHelper .createXPath("//" + REQUEST_PREFIX + ":taskMetaData/" + REQUEST_PREFIX + ":userProcessEndpoint"); xpath.setNamespaceURIs(namespaceURIs/* MessageConstants.get_nsMap() */); List<Node> endpointQueryResult = xpath.selectNodes(message); if (endpointQueryResult.size() != 0) { Element userProcessEndpointElement = (Element) endpointQueryResult.get(0); String value = userProcessEndpointElement.getText(); if (value != null && value.length() > 0) _userProcessEndpoint = value; else if (_userProcessEndpoint != null) { _log.info("User process endpoint is empty in task metadata, adding " + _userProcessEndpoint); userProcessEndpointElement.setText(_userProcessEndpoint); } } else if (_userProcessEndpoint != null) { _log.info("User process endpoint is not defined in task metadata, adding " + _userProcessEndpoint); xpath = DocumentHelper.createXPath("//" + REQUEST_PREFIX + ":taskMetaData"); xpath.setNamespaceURIs(namespaceURIs/* MessageConstants.get_nsMap() */); List<Node> tmdQueryResult = xpath.selectNodes(message); if (tmdQueryResult.size() > 0) { Element wsaToElement = (Element) tmdQueryResult.get(0); Element nsElement = wsaToElement.addElement("userProcessEndpoint", MessageConstants.IB4P_NS); nsElement.setText(_userProcessEndpoint); } } // Add user process namespace to taskmetadata if not already defined xpath = DocumentHelper.createXPath( "//" + REQUEST_PREFIX + ":taskMetaData/" + REQUEST_PREFIX + ":userProcessNamespaceURI"); xpath.setNamespaceURIs(namespaceURIs/* MessageConstants.get_nsMap() */); List<Node> nsQueryResult = xpath.selectNodes(message); if (nsQueryResult.size() == 0 && _userProcessNamespaceUri != null) { xpath = DocumentHelper.createXPath("//" + REQUEST_PREFIX + ":taskMetaData"); xpath.setNamespaceURIs(namespaceURIs/* MessageConstants.get_nsMap() */); List<Node> tmdQueryResult = xpath.selectNodes(message); if (tmdQueryResult.size() > 0) { _log.info("User process namespace is not defined in task metadata, adding " + _userProcessNamespaceUri); Element wsaToElement = (Element) tmdQueryResult.get(0); Element nsElement = wsaToElement.addElement("userProcessNamespaceURI", MessageConstants.IB4P_NS); nsElement.setText(_userProcessNamespaceUri); } } else { Element wsaToElement = (Element) nsQueryResult.get(0); if (wsaToElement.getTextTrim().length() == 0) { _log.info("User process namespace is empty in task metadata, adding " + _userProcessNamespaceUri); wsaToElement.setText(_userProcessNamespaceUri); } } /* * Now, change the namespace of all soapenv:Body elements, except the * task input and the attachments, to ib4p. */ xpath = DocumentHelper.createXPath("//" + REQUEST_PREFIX + ":taskInput//*"); xpath.setNamespaceURIs(namespaceURIs/* MessageConstants.get_nsMap() */); List<Node> allTaskInputElements = xpath.selectNodes(message); xpath = DocumentHelper.createXPath("//" + REQUEST_PREFIX + ":attachments//*"); xpath.setNamespaceURIs(namespaceURIs/* MessageConstants.get_nsMap() */); List<Node> allAttachmentsElements = xpath.selectNodes(message); for (int i = 0; i < allSoapBodyElements.size(); ++i) { Node node = (Node) allSoapBodyElements.get(i); if (!allTaskInputElements.contains(node) && !allAttachmentsElements.contains(node)) { Element element = (Element) node; element.remove(element.getNamespace()); element.setQName(QName.get(element.getName(), "ib4p", MessageConstants.IB4P_NS)); } } }
From source file:org.jahia.utils.maven.plugin.osgi.ConvertToOSGiMojo.java
License:Open Source License
private void parsePom() throws DocumentException, IOException { SAXReader reader = new SAXReader(); File pom = new File(baseDir, "pom.xml"); Document pomDocument = reader.read(pom); Document bundleModuleDocument = reader .read(getClass().getClassLoader().getResourceAsStream("bundleModule.xml")); Element root = pomDocument.getRootElement(); // Set packaging Element packaging = root.element("packaging"); if (packaging == null) { root.addElement("packaging"); } else {//from w w w.j a v a 2s . com if (packaging.getTextTrim().toLowerCase().equals("war")) { packaging.setText("bundle"); } else { getLog().info("Non WAR packaging found : " + packaging.getTextTrim() + ", not modifying it to bundle, but you might want to double-check this."); } } // Copy template dependencies Element dependencies = root.element("dependencies"); if (dependencies == null) { dependencies = root.addElement("dependencies"); } List dependenciesTemplate = bundleModuleDocument.selectNodes("/project/*[local-name()='dependencies']/*"); for (Element dep : (Iterable<? extends Element>) dependenciesTemplate) { dependencies.add(dep.detach()); } // Generate plugin instructions Element plugins = (Element) pomDocument .selectSingleNode("/project/*[local-name()='build']/*[local-name()='plugins']"); if (plugins != null) { Element mavenWarPluginArtifactId = (Element) plugins .selectSingleNode("//*[local-name()='artifactId'][text()='maven-war-plugin']"); if (mavenWarPluginArtifactId != null) { Element previousPluginConfig = (Element) mavenWarPluginArtifactId.getParent().detach(); Element manifestEntries = previousPluginConfig.element("configuration").element("archive") .element("manifestEntries"); Element pluginTemplate = (Element) bundleModuleDocument.selectSingleNode( "/project/*[local-name()='build']/*[local-name()='plugins']/*[local-name()='plugin']"); if (pluginTemplate != null) { Element instructionsTemplate = (Element) pluginTemplate.element("configuration") .element("instructions").detach(); Element instructions = pluginTemplate.element("configuration").addElement("instructions"); generateBundlePlugin(manifestEntries, instructions, instructionsTemplate); if (!instructions.elements().isEmpty()) { plugins.add(pluginTemplate.detach()); } } } } // Export pom XMLWriter writer = new XMLWriter(new FileOutputStream(pom), OutputFormat.createPrettyPrint()); writer.write(pomDocument); writer.close(); }
From source file:org.jboss.as.quickstart.xml.DOM4JXMLParser.java
License:Apache License
private Book parseBook(Element n) { Book b = new Book(); Iterator children = n.elementIterator(); /*//from w ww .jav a 2 s .c o m * parse book element, we have to once more iterate over children. */ while (children.hasNext()) { Node child = (Node) children.next(); String childName = child.getName(); // empty/text nodes dont have name if (childName == null) continue; if (childName.equals("author")) { Element childElement = (Element) child; String textVal = childElement.getTextTrim(); b.setAuthor(textVal); } else if (childName.equals("title")) { Element childElement = (Element) child; String textVal = childElement.getTextTrim(); b.setTitle(textVal); } else if (childName.equals("genre")) { Element childElement = (Element) child; String textVal = childElement.getTextTrim(); b.setGenre(textVal); } else if (childName.equals("price")) { Element childElement = (Element) child; String textVal = childElement.getTextTrim(); b.setPrice(Float.parseFloat(textVal)); } else if (childName.equals("publish_date")) { Element childElement = (Element) child; String textVal = childElement.getTextTrim(); Date d; try { d = DATE_FORMATTER.parse(textVal); b.setPublishDate(d); } catch (ParseException e) { throw new RuntimeException(e); } } else if (childName.equals("description")) { Element childElement = (Element) child; String textVal = childElement.getTextTrim(); b.setDescription(textVal); } } return b; }
From source file:org.jboss.mx.metadata.JBossXMBean10.java
License:Open Source License
protected ModelMBeanNotificationInfo[] buildNotificationInfo(List notifications) throws NotCompliantMBeanException { List infos = new ArrayList(); for (Iterator it = notifications.iterator(); it.hasNext();) { Element notif = (Element) it.next(); String name = notif.elementTextTrim("name"); String description = notif.elementTextTrim("description"); List notifTypes = notif.elements("notification-type"); Descriptor descr = getDescriptor(notif, name, NOTIFICATION_DESCRIPTOR); List types = new ArrayList(); for (Iterator iterator = notifTypes.iterator(); iterator.hasNext();) { Element type = (Element) iterator.next(); types.add(type.getTextTrim()); }/*from w ww .j a va 2s. c o m*/ ModelMBeanNotificationInfo info = new ModelMBeanNotificationInfo( (String[]) types.toArray(new String[types.size()]), name, description, descr); infos.add(info); } return (ModelMBeanNotificationInfo[]) infos.toArray(new ModelMBeanNotificationInfo[infos.size()]); }