List of usage examples for org.dom4j Element getTextTrim
String getTextTrim();
From source file:architecture.common.license.License.java
License:Apache License
public static License fromXML(String xml) { try {/*from w ww. j av a 2 s .com*/ Document d = DocumentHelper.parseText(xml); Element root = d.getRootElement(); License l = new License(); String id = root.attributeValue("id"); if (id == null) throw new LicenseException(L10NUtils.format("002105")); l.setID(Long.parseLong(id)); String name0 = root.attributeValue("name"); if (name0 == null) throw new LicenseException(L10NUtils.format("002106")); l.setName(name0); String edition = root.attributeValue("edition"); if (edition != null) l.setEdition(edition); String dateString = root.attributeValue("creationDate"); if (dateString == null) throw new LicenseException(L10NUtils.format("002107")); try { Date date = parseDate(dateString); l.setCreationDate(date); } catch (Exception e) { throw new LicenseException(L10NUtils.format("002108")); } String license = root.attributeValue("version"); if (license == null) throw new LicenseException(L10NUtils.format("002109")); l.setVersion(Version.parseVersion(license)); try { l.setType(Type.valueOf(root.attributeValue("type"))); } catch (IllegalArgumentException e) { throw new LicenseException(L10NUtils.format("002110")); } Element clientElement = root.element("client"); Client client = new Client(); client.setName(clientElement.attributeValue("name")); client.setCompany(clientElement.attributeValue("company")); l.setClient(client); for (Element e : (List<Element>) root.elements("module")) { Module m = new Module(); m.setName(e.attributeValue("name")); l.getModules().add(m); } Map<String, String> properties = new HashMap<String, String>(); for (Element e : (List<Element>) root.elements("property")) { String name = e.attributeValue("name"); String value = e.getTextTrim(); properties.put(name, value); } l.setProperties(properties); Element sig = root.element("signature"); l.setSignature(sig.getTextTrim()); return l; } catch (DocumentException e) { log.fatal(e.getMessage(), e); throw new LicenseException(L10NUtils.format("002111"), e); } }
From source file:architecture.common.xml.XmlProperties.java
License:Apache License
/** * Returns the value of the specified property. * * @param name/*from www .j a v a 2 s .co m*/ * the name of the property to get. * @return the value of the specified property. */ public synchronized String getProperty(String name) { String value = propertyCache.get(name); if (value != null) { return value; } String[] propName = parsePropertyName(name); // Search for this property by traversing down the XML heirarchy. Element element = document.getRootElement(); for (String aPropName : propName) { element = element.element(aPropName); if (element == null) { // This node doesn't match this part of the property name which // indicates this property doesn't exist so return null. return null; } } // At this point, we found a matching property, so return its value. // Empty strings are returned as null. value = element.getTextTrim(); if ("".equals(value)) { return null; } else { // Add to cache so that getting property next time is fast. propertyCache.put(name, value); return value; } }
From source file:architecture.ee.plugin.impl.PluginMetaDataImpl.java
protected String getElementValue(String xpath) { try {/*from w w w .java 2s . c o m*/ Element element = (Element) config.selectSingleNode(xpath); if (element != null) return element.getTextTrim(); } catch (Exception e) { log.error(e); } return null; }
From source file:batch.performance.visualizer.om.Result.java
License:Open Source License
public void parse(Document dom) throws IOException { List runs = dom.getRootElement().elements("run"); for (Iterator itr = runs.iterator(); itr.hasNext();) { Element run = (Element) itr.next(); final String date = run.attributeValue("date"); List groups = run.elements("group"); for (Iterator jtr = groups.iterator(); jtr.hasNext();) { Element group = (Element) jtr.next(); final URL testSpec = new URL(group.attributeValue("name")); List results = group.elements("result"); for (Iterator ktr = results.iterator(); ktr.hasNext();) { Element result = (Element) ktr.next(); URL instance = null; if (result.attribute("instance") != null) instance = new URL(result.attributeValue("instance")); DataSeries ds = createDataSeries(testSpec, result.attributeValue("scenario"), result.attributeValue("mode").equals("speed") ? Profiler.SPEED : Profiler.MEMORY, instance);/*from w ww .j a v a2s . co m*/ try { ds.addDataPoint(date, new BigInteger(result.getTextTrim())); } catch (NumberFormatException e) { ; // throw away this data point } } } } }
From source file:br.bookmark.db.util.XMLUtils.java
License:Open Source License
public static boolean parseElement(Object obj, Element element) throws Exception { // Pega o valor do elemento no xml e atribui ao campo correspondente do objeto String elementName = element.getName(); String elementValue = element.getTextTrim(); Field[] fields = obj.getClass().getDeclaredFields(); for (int i = 0; i < fields.length; i++) { if (fields[i].getName().equals(elementName)) { if (fields[i].getAnnotation(DBField.class) != null) { // Campo do tipo BD String tipoCampo = fields[i].getAnnotation(DBField.class).type().toUpperCase(); if (tipoCampo.startsWith("TEXT") || tipoCampo.startsWith("MEMO")) { Class[] parametro = { String.class }; Method met = ResultSetUtils.getMetodoSet(obj, fields[i].getName(), parametro); met.invoke(obj, elementValue); } else if (tipoCampo.startsWith("LONG")) { Class[] parametro = { Long.TYPE }; Method met = ResultSetUtils.getMetodoSet(obj, fields[i].getName(), parametro); met.invoke(obj, Long.parseLong(elementValue)); } else { throw new GenericDAOException("Tipo no previsto: " + tipoCampo); }//from ww w. j a v a2 s.c o m } else if (fields[i].getAnnotation(DBFK.class) != null) { // Campo do tipo FK Class[] parametro = { Long.TYPE }; Method met = ResultSetUtils.getMetodoSet(obj, fields[i].getName(), parametro); met.invoke(obj, Long.parseLong(elementValue)); } else { // Campo nao tem anotacao - tenta como string Class[] parametro = { String.class }; Method met = ResultSetUtils.getMetodoSet(obj, fields[i].getName(), parametro); met.invoke(obj, elementValue); } return true; } } return false; }
From source file:ca.upei.roblib.fedora.servletfilter.DrupalAuthModule.java
License:Apache License
protected Map<String, String> parseConnectionElement(Element connection) { Map<String, String> toReturn = new HashMap<String, String>(); toReturn.put("server", connection.attributeValue("server")); toReturn.put("database", connection.attributeValue("dbname")); toReturn.put("user", connection.attributeValue("user")); toReturn.put("pass", connection.attributeValue("password")); toReturn.put("port", connection.attributeValue("port")); toReturn.put("jdbcDriverClass", connection.attributeValue("jdbcDriverClass")); toReturn.put("jdbcURLProtocol", connection.attributeValue("jdbcURLProtocol")); Element sqlElement = connection.element("sql"); toReturn.put("sql", sqlElement.getTextTrim()); return toReturn; }
From source file:cbir.reader.XMLReader.java
License:Open Source License
public Descriptor readDescriptor(Element dataElement) { String descriptorType = dataElement.getName(); Descriptor descriptor = null; // EHD// w w w.j ava2 s .c o m if (descriptorType.equals("EHD")) { char[] ehdChars = new char[80]; dataElement.getTextTrim().getChars(0, 80, ehdChars, 0); double[] ehdValues = new double[ehdChars.length]; for (int i = 0; i < ehdChars.length; i++) ehdValues[i] = Integer.parseInt(Character.toString(ehdChars[i])); descriptor = new Descriptor(DescriptorType.MPEG_EHD, ehdValues, 9.d); // CEDD } else if (descriptorType.equals("CEDD")) { char[] ceddChars = new char[144]; dataElement.getTextTrim().getChars(0, 144, ceddChars, 0); double[] ceddValues = new double[ceddChars.length]; for (int i = 0; i < ceddChars.length; i++) ceddValues[i] = Integer.parseInt(Character.toString(ceddChars[i])); descriptor = new Descriptor(DescriptorType.CEDD, ceddValues, 9.d); } return descriptor; }
From source file:cc.warlock.core.client.logging.LoggingConfiguration.java
License:Open Source License
public void parseElement(Element element) { if (element.getName().equals("logging")) { enableLogging = Boolean.parseBoolean(element.attributeValue("enabled")); logFormat = element.attributeValue("format"); Element dir = element.element("dir"); if (dir != null) { logDirectory = new File(dir.getTextTrim()); }//from w w w. j a va2 s .c o m } }
From source file:cc.warlock.core.client.settings.internal.HighlightConfigurationProvider.java
License:Open Source License
protected IWarlockStyle createStyle(Element sElement) { WarlockStyle style = new WarlockStyle(); style.setBackgroundColor(colorValue(sElement, "background")); style.setForegroundColor(colorValue(sElement, "foreground")); if (sElement.attributeValue("name") != null) { style.setName(stringValue(sElement, "name")); }/*w w w .j ava2 s .c om*/ for (Element typeElement : (List<Element>) sElement.elements()) { String text = typeElement.getTextTrim(); style.addStyleType(IWarlockStyle.StyleType.valueOf(text)); } style.setFullLine(booleanValue(sElement, "full-line")); //System.out.println("Setting style sound to " + sElement.attributeValue("sound")); style.setSound(sElement.attributeValue("sound")); return style; }
From source file:cc.warlock.core.script.configuration.ScriptConfiguration.java
License:Open Source License
public void parseScriptConfig(Element scriptConfig) { // clear();//w w w .j a v a 2 s .c om for (Element element : (List<Element>) scriptConfig.elements()) { if ("dir".equals(element.getName())) { scriptDirectories.add(new File(element.getTextTrim())); } else if ("autoScan".equals(element.getName())) { scanTimeout.set(Long.parseLong(element.attributeValue("timeout"))); autoScan.set(Boolean.parseBoolean(element.getTextTrim())); } else if ("suppressExceptions".equals(element.getName())) { suppressExceptions.set(Boolean.parseBoolean(element.getTextTrim())); } else if ("script-prefix".equals(element.getName())) { scriptPrefix = element.getTextTrim(); } else if ("engine-file-extensions".equals(element.getName())) { for (Element extElement : (List<Element>) element.elements()) { addEngineExtension(element.attributeValue("engineId"), extElement.getTextTrim()); } } } }