List of usage examples for org.dom4j Element getTextTrim
String getTextTrim();
From source file:org.jboss.pnc.pvt.execution.ParamJenkinsJob.java
License:Apache License
private JenkinsArchiver readJobArchiver() { List<Node> nodes = doc.selectNodes("//hudson.tasks.ArtifactArchiver"); if (null == nodes || 0 == nodes.size()) { return null; }/*from w ww . j a v a 2s . c o m*/ Element ele = (Element) nodes.get(0); Element subEle = ele.element("artifacts"); String artifacts = subEle == null ? "" : subEle.getTextTrim(); subEle = ele.element("excludes"); String excludes = subEle == null ? "" : subEle.getTextTrim(); subEle = ele.element("allowEmptyArchive"); boolean allowEmptyArchive = subEle == null ? true : Boolean.valueOf(subEle.getTextTrim()); subEle = ele.element("onlyIfSuccessful"); boolean onlyIfSuccessful = subEle == null ? false : Boolean.valueOf(subEle.getTextTrim()); subEle = ele.element("fingerprint"); boolean fingerprint = subEle == null ? false : Boolean.valueOf(subEle.getTextTrim()); subEle = ele.element("defaultExcludes"); boolean defaultExcludes = subEle == null ? true : Boolean.valueOf(subEle.getTextTrim()); JenkinsArchiver jar = new JenkinsArchiver(); jar.setAllowEmptyArchive(allowEmptyArchive); jar.setArtifacts(artifacts); jar.setDefaultExcludes(defaultExcludes); jar.setExcludes(excludes); jar.setFingerprint(fingerprint); jar.setOnlyIfSuccessful(onlyIfSuccessful); return jar; }
From source file:org.jboss.seam.init.Initialization.java
License:LGPL
@SuppressWarnings("unchecked") private void installComponentsFromXmlElements(Element rootElement, Properties replacements) throws DocumentException, ClassNotFoundException { /*List<Element> importJavaElements = rootElement.elements("import-java-package"); for (Element importElement : importJavaElements) {//from ww w . j av a 2 s .c om String pkgName = importElement.getTextTrim(); importedPackages.add(pkgName); addNamespace( Package.getPackage(pkgName) ); }*/ for (Element importElement : elements(rootElement, "import")) { globalImports.add(importElement.getTextTrim()); } for (Element component : elements(rootElement, "component")) { installComponentFromXmlElement(component, component.attributeValue("name"), component.attributeValue("class"), replacements); } for (Element factory : elements(rootElement, "factory")) { installFactoryFromXmlElement(factory); } for (Element event : elements(rootElement, "event")) { installEventListenerFromXmlElement(event); } for (Element elem : (List<Element>) rootElement.elements()) { String ns = elem.getNamespace().getURI(); NamespaceDescriptor nsInfo = resolveNamespace(ns); if (nsInfo == null) { if (!ns.equals(COMPONENT_NAMESPACE)) { log.warn("namespace declared in components.xml does not resolve to a package: " + ns); } } else { String name = elem.attributeValue("name"); String elemName = toCamelCase(elem.getName(), true); String className = elem.attributeValue("class"); if (className == null) { for (String packageName : nsInfo.getPackageNames()) { try { // Try each of the packages in the namespace descriptor for a matching class className = packageName + '.' + elemName; Reflections.classForName(className); break; } catch (ClassNotFoundException ex) { className = null; } } } try { //get the class implied by the namespaced XML element name Class<Object> clazz = Reflections.classForName(className); Name nameAnnotation = clazz.getAnnotation(Name.class); //if the name attribute is not explicitly specified in the XML, //imply the name from the @Name annotation on the class implied //by the XML element name if (name == null && nameAnnotation != null) { name = nameAnnotation.value(); } //if this class already has the @Name annotation, the XML element //is just adding configuration to the existing component, don't //add another ComponentDescriptor (this is super-important to //allow overriding!) if (nameAnnotation != null && nameAnnotation.value().equals(name)) { Install install = clazz.getAnnotation(Install.class); if (install == null || install.value()) { className = null; } } } catch (ClassNotFoundException cnfe) { //there is no class implied by the XML element name so the //component must be defined some other way, assume that we are //just adding configuration, don't add a ComponentDescriptor //TODO: this is problematic, it results in elements getting // ignored when mis-spelled or given the wrong namespace!! className = null; } catch (Exception e) { throw new RuntimeException("Error loading element " + elemName + " with component name " + name + " and component class " + className); } //finally, if we could not get the name from the XML name attribute, //or from an @Name annotation on the class, imply it if (name == null) { String prefix = nsInfo.getComponentPrefix(); String componentName = toCamelCase(elem.getName(), false); name = Strings.isEmpty(prefix) ? componentName : prefix + '.' + componentName; } installComponentFromXmlElement(elem, name, className, replacements); } } }
From source file:org.jboss.seam.init.Initialization.java
License:LGPL
private String trimmedText(Element element, String propName, Properties replacements) { String text = element.getTextTrim(); if (text == null) { throw new IllegalArgumentException("property value must be specified in element body: " + propName); }/*from w ww . java 2s . c om*/ return replace(text, replacements); }
From source file:org.jboss.tools.windup.runtime.options.Help.java
License:Open Source License
public static Help load(File windupHome) { final Help result = new Help(); try {/*from w w w. j a v a2 s .c om*/ Document doc = new SAXReader().read(getFile(windupHome)); Iterator optionElementIterator = doc.getRootElement().elementIterator(OPTION); while (optionElementIterator.hasNext()) { Element optionElement = (Element) optionElementIterator.next(); String name = optionElement.attributeValue(NAME); String description = optionElement.element(DESCRIPTION).getTextTrim(); String type = optionElement.element(TYPE).getTextTrim(); String uiType = optionElement.element(UI_TYPE).getTextTrim(); boolean required = Boolean.valueOf(optionElement.element(REQUIRED).getTextTrim()); List<String> availableOptions = null; if (optionElement.element(AVAILABLE_OPTIONS) != null) { availableOptions = new ArrayList<>(); for (Element availableOption : (List<Element>) optionElement.element(AVAILABLE_OPTIONS) .elements(AVAILABLE_OPTION)) { availableOptions.add(availableOption.getTextTrim()); } } OptionDescription option = new OptionDescription(name, description, type, uiType, availableOptions, required); result.addOption(option); } } catch (DocumentException | IOException e) { System.err.println("WARNING: Failed to load detailed help information!"); } return result; }
From source file:org.jbpm.instantiation.FieldInstantiator.java
License:Open Source License
public static Object getValue(Class type, Element propertyElement) { // parse the value Object value = null;/*from ww w . j ava 2 s.c om*/ try { if (type == String.class) { value = propertyElement.getText(); } else if ((type == Integer.class) || (type == int.class)) { value = new Integer(propertyElement.getTextTrim()); } else if ((type == Long.class) || (type == long.class)) { value = new Long(propertyElement.getTextTrim()); } else if ((type == Float.class) || (type == float.class)) { value = new Float(propertyElement.getTextTrim()); } else if ((type == Double.class) || (type == double.class)) { value = new Double(propertyElement.getTextTrim()); } else if ((type == Boolean.class) || (type == boolean.class)) { value = Boolean.valueOf(propertyElement.getTextTrim()); } else if ((type == Character.class) || (type == char.class)) { value = new Character(propertyElement.getTextTrim().charAt(0)); } else if ((type == Short.class) || (type == short.class)) { value = new Short(propertyElement.getTextTrim()); } else if ((type == Byte.class) || (type == byte.class)) { value = new Byte(propertyElement.getTextTrim()); } else if (List.class.isAssignableFrom(type)) { value = getCollection(propertyElement, new ArrayList()); } else if (Set.class.isAssignableFrom(type)) { value = getCollection(propertyElement, new HashSet()); } else if (Collection.class.isAssignableFrom(type)) { value = getCollection(propertyElement, new ArrayList()); } else if (Map.class.isAssignableFrom(type)) { value = getMap(propertyElement, new HashMap()); } else if (Element.class.isAssignableFrom(type)) { value = propertyElement; } else { Constructor constructor = type.getConstructor(new Class[] { String.class }); if ((propertyElement.isTextOnly()) && (constructor != null)) { value = constructor.newInstance(new Object[] { propertyElement.getTextTrim() }); } } } catch (Exception e) { log.error("couldn't parse the bean property value '" + propertyElement.asXML() + "' to a '" + type.getName() + "'"); throw new JbpmException(e); } return value; }
From source file:org.jbpm.jpdl.internal.convert.Jpdl3Converter.java
License:Open Source License
public void resolveTransitionDestination(Element transitionElement, Element jpdl4Element) { Element transition4 = jpdl4Element.addElement("transition"); transition4.addAttribute("name", transitionElement.attributeValue("name")); if (transitionElement.elementTextTrim("description") != null) { transition4.addComment(transitionElement.elementTextTrim("description")); }/*from w w w . ja va 2s.c om*/ //Get condition from jpdl3 element String condition = transitionElement.attributeValue("condition"); if (condition == null) { Element conditionElement = transitionElement.element("condition"); if (conditionElement != null) { condition = conditionElement.getTextTrim(); // for backwards compatibility if ((condition == null) || (condition.length() == 0)) { condition = conditionElement.attributeValue("expression"); } } } if (condition != null && condition.length() > 0) { Element condition4 = transition4.addElement("condition"); condition4.addAttribute("expr", condition); } // set destinationNode of the transition String toName = transitionElement.attributeValue("to"); if (toName == null) { addWarning("node '" + transitionElement.getPath() + "' has a transition without a 'to'-attribute to specify its destinationNode"); } else { Element to = this.findNode(toName); if (to == null) { addWarning("transition to='" + toName + "' on node '" + transitionElement.getName() + "' cannot be resolved"); } transition4.addAttribute("to", toName); } // read the actions convertActions(transitionElement, transition4, ""); convertExceptionHandlers(transitionElement, transition4); }
From source file:org.jbpm.jpdl.xml.JpdlXmlReader.java
License:Open Source License
/** * creates the transition object and configures it by the read attributes * @return the created <code>org.jbpm.graph.def.Transition</code> object * (useful, if you want to override this method * to read additional configuration properties) *///w w w . j av a 2s. c o m public Transition resolveTransitionDestination(Element transitionElement, Node node) { Transition transition = new Transition(); transition.setProcessDefinition(processDefinition); transition.setName(transitionElement.attributeValue("name")); transition.setDescription(transitionElement.elementTextTrim("description")); String condition = transitionElement.attributeValue("condition"); if (condition == null) { Element conditionElement = transitionElement.element("condition"); if (conditionElement != null) { condition = conditionElement.getTextTrim(); // for backwards compatibility if ((condition == null) || (condition.length() == 0)) { condition = conditionElement.attributeValue("expression"); } } } transition.setCondition(condition); // add the transition to the node node.addLeavingTransition(transition); // set destinationNode of the transition String toName = transitionElement.attributeValue("to"); if (toName == null) { addWarning("node '" + node.getFullyQualifiedName() + "' has a transition without a 'to'-attribute to specify its destinationNode"); } else { Node to = ((NodeCollection) node.getParent()).findNode(toName); if (to == null) { addWarning("transition to='" + toName + "' on node '" + node.getFullyQualifiedName() + "' cannot be resolved"); } else { to.addArrivingTransition(transition); } } // read the actions readActions(transitionElement, transition, Event.EVENTTYPE_TRANSITION); readExceptionHandlers(transitionElement, transition); return transition; }
From source file:org.jcommon.com.jsip.utils.SipUtil.java
License:Apache License
public static String getPresences(String str) throws IOException { String presence = ""; try {/*from w w w . j a v a 2 s . com*/ if (str == null) return presence; Document doc = DocumentHelper.parseText(str); Element root = doc.getRootElement(); if (root != null) { root = root.element("person"); if (root != null) { root = root.element("note"); if (root != null) { presence = root.getTextTrim(); } } } } catch (Throwable t) { logger.error("parse to doc error :\n" + str, t); t.printStackTrace(); } return presence; }
From source file:org.jcommon.com.util.config.ConfigLoader.java
License:Apache License
@SuppressWarnings("unchecked") private static String getTextFromElement(Element e) { Element element = e; if (element != null) { List<Attribute> l = element.attributes(); if (l != null && l.size() != 0) { String[] keys = new String[l.size()]; String[] values = new String[l.size()]; for (int i = 0; i < l.size(); i++) { Attribute a = l.get(i); keys[i] = a.getName();//from w ww .j av a 2 s. c o m values[i] = a.getValue(); } return JsonUtils.toJson(keys, values, false); } return element.getTextTrim(); } return null; }
From source file:org.jenkins.tools.test.model.MavenPom.java
License:Open Source License
public void addDependencies(Map<String, VersionNumber> toAdd, Map<String, VersionNumber> toReplace, VersionNumber coreDep, Map<String, String> pluginGroupIds) throws IOException { File pom = new File(rootDir.getAbsolutePath() + "/" + pomFileName); Document doc;// w ww. ja va 2 s . c o m try { doc = new SAXReader().read(pom); } catch (DocumentException x) { throw new IOException(x); } Element dependencies = doc.getRootElement().element("dependencies"); if (dependencies == null) { dependencies = doc.getRootElement().addElement("dependencies"); } for (Element mavenDependency : (List<Element>) dependencies.elements("dependency")) { Element artifactId = mavenDependency.element("artifactId"); if (artifactId == null || !"maven-plugin".equals(artifactId.getTextTrim())) { continue; } Element version = mavenDependency.element("version"); if (version == null || version.getTextTrim().startsWith("${")) { // Prior to 1.532, plugins sometimes assumed they could pick up the Maven plugin version from their parent POM. if (version != null) { mavenDependency.remove(version); } version = mavenDependency.addElement("version"); version.addText(coreDep.toString()); } } for (Element mavenDependency : (List<Element>) dependencies.elements("dependency")) { Element artifactId = mavenDependency.element("artifactId"); if (artifactId == null) { continue; } excludeSecurity144Compat(mavenDependency); VersionNumber replacement = toReplace.get(artifactId.getTextTrim()); if (replacement == null) { continue; } Element version = mavenDependency.element("version"); if (version != null) { mavenDependency.remove(version); } version = mavenDependency.addElement("version"); version.addText(replacement.toString()); } dependencies.addComment("SYNTHETIC"); for (Map.Entry<String, VersionNumber> dep : toAdd.entrySet()) { Element dependency = dependencies.addElement("dependency"); String group = pluginGroupIds.get(dep.getKey()); // Handle cases where plugin isn't under default groupId if (group != null && !group.isEmpty()) { dependency.addElement("groupId").addText(group); } else { dependency.addElement("groupId").addText("org.jenkins-ci.plugins"); } dependency.addElement("artifactId").addText(dep.getKey()); dependency.addElement("version").addText(dep.getValue().toString()); excludeSecurity144Compat(dependency); } FileWriter w = new FileWriter(pom); try { doc.write(w); } finally { w.close(); } }