List of usage examples for org.dom4j Element getText
String getText();
From source file:ams.devices.AMSCalibration.java
public boolean LoadCalibration() { boolean bResOk = true; try {/*w ww .java 2 s. c o m*/ SAXReader reader = new SAXReader(); String strCalibrationFilePathName = System.getenv("AMS_ROOT") + "/calibration.xml"; URL url = (new java.io.File(strCalibrationFilePathName)).toURI().toURL(); Document document = reader.read(url); Element root = document.getRootElement(); // iterate through child elements of root for (Iterator i = root.elementIterator(); i.hasNext();) { Element element = (Element) i.next(); String name = element.getName(); String value = element.getText(); //logger.debug( "LoadCalibration(): Pairs: [" + name + " : " + value + "]"); if ("ADC1".equals(name)) { for (Iterator andevsparams = element.elementIterator(); andevsparams.hasNext();) { Element elementAnDev = (Element) andevsparams.next(); name = elementAnDev.getName(); value = elementAnDev.getText(); logger.debug("LoadCalibration(): Pairs: ADC1: [" + name + " : " + value + "]"); String strKind = name.substring(7, 8); String strChannel = name.substring(5, 6); int nChannel = -1; boolean bOk = true; try { nChannel = Integer.parseInt(strChannel, 10); } catch (NumberFormatException e) { logger.error("LoadCalibration(): Strange channel number '" + strChannel + "' has been extracted from name " + name); bOk = false; bResOk = false; } Double dblValue = null; try { value = value.replace(',', '.'); dblValue = new Double(value); } catch (NumberFormatException ex) { logger.error("LoadCalibration(): NumberFormatException caught while parsing value '" + value + "'"); bOk = false; bResOk = false; } if (bOk) { AMSCalibrationUnit unit = (AMSCalibrationUnit) m_mapCalibrationUnits .get(AMSConstants.ADC1); if (unit != null) { if (strKind.equals("A")) unit.SetSlope(nChannel, dblValue); else if (strKind.equals("B")) unit.SetShift(nChannel, dblValue); else { logger.warn("Unknown Kind of param'" + strKind + "' from name '" + name + "' in calibration.xml! Pay attention!"); bResOk = false; } } else { logger.error( "Unit ? ADC1 m_mapCalibrationUnits null!"); bResOk = false; } } } } if ("ADC2".equals(name)) { for (Iterator andevsparams = element.elementIterator(); andevsparams.hasNext();) { Element elementAnDev = (Element) andevsparams.next(); name = elementAnDev.getName(); value = elementAnDev.getText(); logger.debug("LoadCalibration(): Pairs: ADC2: [" + name + " : " + value + "]"); String strKind = name.substring(7, 8); String strChannel = name.substring(5, 6); int nChannel = -1; boolean bOk = true; try { nChannel = Integer.parseInt(strChannel, 10); } catch (NumberFormatException e) { logger.error("LoadCalibration(): Strange channel number '" + strChannel + "' has been extracted from name " + name); bOk = false; bResOk = false; } Double dblValue = null; try { value = value.replace(',', '.'); dblValue = new Double(value); } catch (NumberFormatException ex) { logger.error("LoadCalibration(): NumberFormatException caught while parsing value '" + value + "'"); bOk = false; bResOk = false; } if (bOk) { AMSCalibrationUnit unit = (AMSCalibrationUnit) m_mapCalibrationUnits .get(AMSConstants.ADC2); if (unit != null) { if (strKind.equals("A")) unit.SetSlope(nChannel, dblValue); else if (strKind.equals("B")) unit.SetShift(nChannel, dblValue); else { logger.warn("Unknown Kind of param'" + strKind + "' from name '" + name + "' in calibration.xml! Pay attention!"); bResOk = false; } } else { logger.error( "Unit ? ADC2 m_mapCalibrationUnits null!"); bResOk = false; } } } } if ("ADC3".equals(name)) { for (Iterator andevsparams = element.elementIterator(); andevsparams.hasNext();) { Element elementAnDev = (Element) andevsparams.next(); name = elementAnDev.getName(); value = elementAnDev.getText(); logger.debug("LoadCalibration(): Pairs: ADC3. [" + name + " : " + value + "]"); String strKind = name.substring(7, 8); String strChannel = name.substring(5, 6); int nChannel = -1; boolean bOk = true; try { nChannel = Integer.parseInt(strChannel, 10); } catch (NumberFormatException e) { logger.error("LoadCalibration(): Strange channel number '" + strChannel + "' has been extracted from name " + name); bOk = false; bResOk = false; } Double dblValue = null; try { value = value.replace(',', '.'); dblValue = new Double(value); } catch (NumberFormatException ex) { logger.error("LoadCalibration(): NumberFormatException caught while parsing value '" + value + "'"); bOk = false; bResOk = false; } if (bOk) { AMSCalibrationUnit unit = (AMSCalibrationUnit) m_mapCalibrationUnits .get(AMSConstants.ADC3); if (unit != null) { if (strKind.equals("A")) unit.SetSlope(nChannel, dblValue); else if (strKind.equals("B")) unit.SetShift(nChannel, dblValue); else { logger.warn("Unknown Kind of param'" + strKind + "' from name '" + name + "' in calibration.xml! Pay attention!"); bResOk = false; } } else { logger.error( "Unit ? ADC3 m_mapCalibrationUnits null!"); bResOk = false; } } } } if ("ADC4".equals(name)) { for (Iterator andevsparams = element.elementIterator(); andevsparams.hasNext();) { Element elementAnDev = (Element) andevsparams.next(); name = elementAnDev.getName(); value = elementAnDev.getText(); logger.debug("LoadCalibration(): Pairs: ADC4: [" + name + " : " + value + "]"); String strKind = name.substring(7, 8); String strChannel = name.substring(5, 6); int nChannel = -1; boolean bOk = true; try { nChannel = Integer.parseInt(strChannel, 10); } catch (NumberFormatException e) { logger.error("LoadCalibration(): Strange channel number '" + strChannel + "' has been extracted from name " + name); bOk = false; bResOk = false; } Double dblValue = null; try { value = value.replace(',', '.'); dblValue = new Double(value); } catch (NumberFormatException ex) { logger.error("LoadCalibration(): NumberFormatException caught while parsing value '" + value + "'"); bOk = false; bResOk = false; } if (bOk) { AMSCalibrationUnit unit = (AMSCalibrationUnit) m_mapCalibrationUnits .get(AMSConstants.ADC4); if (unit != null) { if (strKind.equals("A")) unit.SetSlope(nChannel, dblValue); else if (strKind.equals("B")) unit.SetShift(nChannel, dblValue); else { logger.warn("Unknown Kind of param'" + strKind + "' from name '" + name + "' in calibration.xml! Pay attention!"); bResOk = false; } } else { logger.error( "Unit ? ADC4 m_mapCalibrationUnits null!"); bResOk = false; } } } } } } catch (MalformedURLException ex) { logger.error("MalformedURLException caught while loading settings!", ex); bResOk = false; } catch (DocumentException ex) { logger.error("DocumentException caught while loading settings!", ex); bResOk = false; } return bResOk; }
From source file:architecture.common.lifecycle.internal.XmlApplicationPropertiesOld.java
License:Apache License
public String get(Object o) { String name = (String) o; String value = propertyCache.get(name); if (value != null) return value; String propName[] = parsePropertyName(name); Element element = doc.getRootElement(); for (int i = 0; i < propName.length; i++) { element = element.element(propName[i]); if (element == null) return null; }/*from w w w. j a v a 2 s. c o m*/ lock.lock(); try { value = element.getText(); if ("".equals(value)) return null; value = value.trim(); propertyCache.put(name, value); return value; } finally { lock.unlock(); } }
From source file:architecture.common.lifecycle.internal.XmlApplicationPropertiesOld.java
License:Apache License
public synchronized String remove(Object key) { String name = (String) key; propertyCache.remove(name);/* ww w. j a v a2 s. co m*/ String propName[] = parsePropertyName(name); Element element = doc.getRootElement(); for (int i = 0; i < propName.length - 1; i++) { element = element.element(propName[i]); if (element == null) return null; } String value = element.getText(); element.remove(element.element(propName[propName.length - 1])); saveProperties(); return value; }
From source file:architecture.ee.plugin.impl.PluginManagerImpl.java
protected void isValidVersion(String pluginName, Document pluginXML, File pluginDir) throws PluginException { architecture.common.license.License.Version version = licenseManager.getLicense().getVersion(); Element maxServerVersionElement = (Element) pluginXML.selectSingleNode("/plugin/maxServerVersion"); if (maxServerVersionElement != null) { String maxServerVersionString = maxServerVersionElement.getText(); if (maxServerVersionString != null) { maxServerVersionString = maxServerVersionString.trim(); License.Version maxServerVersion = License.Version.parseVersion(maxServerVersionString); if (version.compareTo(maxServerVersion) == 1) { String msg = String.format("Plugin %s requires a version less than or equal to %s", new Object[] { pluginName, maxServerVersionString }); log.error(msg);/* ww w.ja v a 2 s .c o m*/ throw new PluginException(msg); } } } Element minServerVersionElement = (Element) pluginXML.selectSingleNode("/plugin/minServerVersion"); if (minServerVersionElement != null) { String minServerVersionString = minServerVersionElement.getText(); if (minServerVersionString != null) { minServerVersionString = minServerVersionString.trim(); architecture.common.license.License.Version minServerVersion = architecture.common.license.License.Version .parseVersion(minServerVersionString); if (version.compareTo(minServerVersion) == -1) { String msg = String.format("Plugins %s requires a version of at least %s", new Object[] { pluginName, minServerVersionString }); log.error(msg); throw new PluginException(msg); } } else { log.warn(String.format("Empty minServerVersion element has no value in plugin %s", new Object[] { pluginName })); } } }
From source file:at.kc.tugraz.ss.serv.dataimport.impl.fct.op.SSDataImportAchsoFct.java
License:Apache License
private static List<String> getAnnotations(final Iterator annotationsIterator) throws Exception { final List<String> annotations = new ArrayList<>(); Iterator annotContentIterator; Element annotation; while (annotationsIterator.hasNext()) { annotContentIterator = ((Element) annotationsIterator.next()).nodeIterator(); while (annotContentIterator.hasNext()) { annotation = (Element) annotContentIterator.next(); try { switch (SSI5CloudAchsoVideoMetaDataE.get(annotation.getName())) { case semanticRefId: annotations.add(annotation.getText()); break; }/* w ww .jav a2 s . com*/ } catch (Exception error) { } } } return SSStrU.distinctWithoutEmptyAndNull(SSServCaller .i5CloudAchsoSemanticAnnotationsSetGet(SSStrU.distinctWithoutEmptyAndNull(annotations))); }
From source file:br.com.atus.util.CEPWebService.java
@SuppressWarnings("rawtypes") public CEPWebService(String cep) { try {//from w w w. j ava2 s . c o m URL url = new URL("http://cep.republicavirtual.com.br/web_cep.php?cep=" + cep + "&formato=xml"); Document document = getDocumento(url); Element root = document.getRootElement(); for (Iterator i = root.elementIterator(); i.hasNext();) { Element element = (Element) i.next(); if (element.getQualifiedName().equals("uf")) setEstado(element.getText()); if (element.getQualifiedName().equals("cidade")) setCidade(element.getText()); if (element.getQualifiedName().equals("bairro")) setBairro(element.getText()); if (element.getQualifiedName().equals("tipo_logradouro")) setTipoLogradouro(element.getText()); if (element.getQualifiedName().equals("logradouro")) setLogradouro(element.getText()); if (element.getQualifiedName().equals("resultado")) setResultado(Integer.parseInt(element.getText())); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:br.com.cgcop.utilitarios.CEPWebService.java
public void consultar(String cep) throws MalformedURLException, DocumentException { URL url = new URL("http://cep.republicavirtual.com.br/web_cep.php?cep=" + cep + "&formato=xml"); Document document = getDocumento(url); Element root = document.getRootElement(); for (Iterator i = root.elementIterator(); i.hasNext();) { Element element = (Element) i.next(); if (element.getQualifiedName().equals("uf")) { setEstado(element.getText()); }//from w w w . j a v a 2s .com if (element.getQualifiedName().equals("cidade")) { setCidade(element.getText()); } if (element.getQualifiedName().equals("bairro")) { setBairro(element.getText()); } if (element.getQualifiedName().equals("tipo_logradouro")) { setTipoLogradouro(element.getText()); } if (element.getQualifiedName().equals("logradouro")) { setLogradouro(element.getText()); } if (element.getQualifiedName().equals("resultado")) { setResultado(Integer.parseInt(element.getText())); } } }
From source file:br.com.sistemapetshop.util.CepWebService.java
@SuppressWarnings("rawtypes") public CepWebService(String cep) { try {//from w w w . j ava 2 s . c o m URL url = new URL("http://cep.republicavirtual.com.br/web_cep.php?cep=" + cep + "&formato=xml"); Document document = getDocumento(url); Element root = document.getRootElement(); for (Iterator i = root.elementIterator(); i.hasNext();) { Element element = (Element) i.next(); if (element.getQualifiedName().equals("uf")) { setEstado(element.getText()); } if (element.getQualifiedName().equals("cidade")) { setCidade(element.getText()); } if (element.getQualifiedName().equals("bairro")) { setBairro(element.getText()); } if (element.getQualifiedName().equals("tipo_logradouro")) { setTipoLogradouro(element.getText()); } if (element.getQualifiedName().equals("logradouro")) { setLogradouro(element.getText()); } if (element.getQualifiedName().equals("resultado")) { setResultado(Integer.parseInt(element.getText())); } } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:br.com.sistemapetshop.util.WebServiceCep.java
/** * Faz uma busca a partir do cep enviado, no site * <a href="http://www.republicavirtual.com.br" * target="_blank">republicavirtual.com.br</a>, retornando o resultado em um * objeto {@link WebServiceCep}.//from w w w .j a va2 s . c o m * <BR> * <BR>No se faz necessrio formataes, a string pode ser enviada em * qualquer formatao, pois s sero consideradas os primeiros 8 numeros da * string. * <BR>Por Exemplo: * <BR>Uma <tt>{@link String} "14.568-910"</tt> automaticamente passada * para * <tt>"14568910"</tt>. * <BR>Uma <tt>{@link String} "1%4#5?55%16a8&910"</tt> automaticamente * passada para * <tt>"14555168"</tt>, s levando em conta os primeiros 8 nmeros. * * @param cep Nmero do cep a ser carregado. S sero considerados os * primeiros 8 nmeros da {@link String} enviada. Todos os caracters no * numricos sero removidos, e a string ser truncada caso seja maior que 8 * caracters. * @return {@link WebServiceCep} contendo as informaes da pesquisa. */ public static WebServiceCep searchCep(String cep) { cep = cep.replaceAll("\\D*", ""); //To numeric digits only if (cep.length() > 8) { cep = cep.substring(0, 8); } WebServiceCep loadCep = new WebServiceCep(cep); try { XmlEnums enums = new XmlEnums(); for (Element e : getElements(cep)) { enums.getXml(e.getQualifiedName()).setCep(e.getText(), loadCep); } } catch (DocumentException ex) { if (ex.getNestedException() != null && ex.getNestedException() instanceof java.net.UnknownHostException) { loadCep.setResultText("Site no encontrado."); loadCep.setResulCode(-14); } else { loadCep.setResultText("No foi possivel ler o documento xml."); loadCep.setResulCode(-15); } loadCep.setExceptio(ex); } catch (MalformedURLException ex) { loadCep.setExceptio(ex); loadCep.setResultText("Erro na formao da url."); loadCep.setResulCode(-16); } catch (Exception ex) { loadCep.setExceptio(ex); loadCep.setResultText("Erro inesperado."); loadCep.setResulCode(-17); } return loadCep; }
From source file:br.com.ufra.cep.service.CepWebService.java
public CepWebService(String cep) { try {/*ww w . ja v a 2 s.c o m*/ URL url = new URL("http://cep.republicavirtual.com.br/web_cep.php?cep=" + cep + "&formato=xml"); Document document = getDocumento(url); Element root = document.getRootElement(); for (Iterator i = root.elementIterator(); i.hasNext();) { Element element = (Element) i.next(); if (element.getQualifiedName().equals("estado")) { setEstado(element.getText()); } if (element.getQualifiedName().equals("cidade")) { setCidade(element.getText()); } if (element.getQualifiedName().equals("bairro")) { setBairro(element.getText()); } if (element.getQualifiedName().equals("tipo_logradouro")) { setTipo_logradouro(element.getText()); } if (element.getQualifiedName().equals("logradouro")) { setLogradouro(element.getText()); } if (element.getQualifiedName().equals("resultado")) { setResultado(Integer.parseInt(element.getText())); } if (element.getQualifiedName().equals("resultado_txt")) { setResultado_txt(element.getText()); } } } catch (Exception ex) { ex.printStackTrace(); } }