List of usage examples for org.dom4j Element elementIterator
Iterator<Element> elementIterator();
From source file:InitializeDB.java
License:Open Source License
public static void setupDB(int year) { try {/* w ww . j a va 2 s . c om*/ //String filename = "nvdcve-2008.xml"; Connection con = getConnection(); Statement sql = con.createStatement(); sql.execute("drop table if exists nvd"); //,primary key(id) sql.execute( "create table nvd(id varchar(20) not null,soft varchar(160) not null default 'ndefined',rng varchar(100) not null default 'undefined',lose_types varchar(100) not null default 'undefind',severity varchar(20) not null default 'unefined',access varchar(20) not null default 'unefined');"); SAXReader saxReader = new SAXReader(); for (int ct = 2002; ct <= year; ct++) { //String fname="/transient/mulval/oval/nvd/nvdcve-"+Integer.toString(ct)+".xml"; String fname = "nvd_old/nvdcve-" + Integer.toString(ct) + ".xml"; Document document = saxReader.read(fname); List entry = document.selectNodes("/*[local-name(.)='nvd']/*[local-name(.)='entry']"); Iterator ent = entry.iterator(); int act = 0; while (ent.hasNext()) { // varchar(20) not null default 'name', Element id = (Element) ent.next(); String cveid = id.attributeValue("name"); String cvss = ""; String access = ""; // System.out.println(cveid + access); String sev = ""; String host = "localhost"; String sftw = ""; String rge = ""; String rge_tmp = ""; String lose_tmp = ""; String lose_types = ""; ArrayList<String> subele = new ArrayList<String>(); ArrayList<String> attr = new ArrayList<String>(); Iterator ei = id.elementIterator(); while (ei.hasNext()) { // put all of the subelements' // names(subelement of entry) to the // array list Element sube = (Element) ei.next(); subele.add(sube.getName()); } //System.out.println(id.getText()); Iterator i = id.attributeIterator(); while (i.hasNext()) { // put the attributes of the entries to // the arraylist Attribute att = (Attribute) i.next(); attr.add(att.getName()); } if (subele.contains("vuln_soft")) { Element vs = (Element) id.element("vuln_soft"); Iterator itr = vs.elementIterator("prod"); while (itr.hasNext()) { // record all of the softwares Element n = (Element) itr.next(); //sftw = sftw + n.attributeValue("name") + ","; sftw = n.attributeValue("name"); if (sftw.contains("'")) { sftw = sftw.replace("'", "''"); } break; } //int lsf = sftw.length(); //sftw = sftw.substring(0, lsf - 1);// delete the last comma } if (attr.contains("severity")) { sev = id.attributeValue("severity"); } if (attr.contains("CVSS_vector")) { cvss = id.attributeValue("CVSS_vector"); char ac = cvss.charAt(9); if (ac == 'L') access = "l"; else if (ac == 'M') access = "m"; else if (ac == 'H') access = "h"; else ; } if (subele.contains("range")) { // to get the range as a array Element vs = (Element) id.element("range"); Iterator rgi = vs.elementIterator(); while (rgi.hasNext()) { // record all of the softwares Element rg = (Element) rgi.next(); if (rg.getName().equals("user_init")) rge_tmp = "user_action_req"; else if (rg.getName().equals("local_network")) rge_tmp = "lan"; else if (rg.getName().equals("network")) rge_tmp = "remoteExploit"; else if (rg.getName().equals("local")) rge_tmp = "local"; else rge_tmp = "other"; rge = rge + "''" + rge_tmp + "'',"; } int lr = rge.length(); rge = rge.substring(0, lr - 1);// delete the last comma } if (subele.contains("loss_types")) { Element lt = (Element) id.element("loss_types"); Iterator lti = lt.elementIterator(); while (lti.hasNext()) { ArrayList<String> isecat = new ArrayList<String>(); Element ls = (Element) lti.next(); if (ls.getName().equals("avail")) lose_tmp = "availability_loss"; else if (ls.getName().equals("conf")) lose_tmp = "data_loss"; else if (ls.getName().equals("int")) lose_tmp = "data_modification"; else lose_tmp = "other"; lose_types = lose_types + "''" + lose_tmp + "'',"; } int ltp = lose_types.length(); lose_types = lose_types.substring(0, ltp - 1);// delete the // last // comma } //System.out.println(cveid + lose_types + rge + sftw + sev + access); String insert = "insert nvd values('" + cveid + "','" + sftw + "','" + rge + "','" + lose_types + "','" + sev + "','" + access + "')"; sql.execute(insert); } } sql.close(); con.close(); } catch (java.lang.ClassNotFoundException e) { System.err.println("ClassNotFoundException:" + e.getMessage()); } catch (SQLException ex) { System.err.println("SQLException:" + ex.getMessage()); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:NessusXMLParser.java
License:Open Source License
public static void parseNessus(String nessusReport) { try {// w w w. j a va 2 s . c o m SAXReader saxReader = new SAXReader(); FileWriter fr = new FileWriter("vulInfo.txt"); Document document = saxReader.read(nessusReport); // each entry is indexed by one cve_id List reportHost = document.selectNodes( "/*[local-name(.)='NessusClientData_v2']/*[local-name(.)='Report']/*[local-name(.)='ReportHost']"); Iterator reportHostItrt = reportHost.iterator(); while (reportHostItrt.hasNext()) { Element host = (Element) reportHostItrt.next(); // System.out.println("host name is: "+host.attribute(0).getText()); // element iterator of each entry Iterator ei = host.elementIterator(); // put all of the subelements' names(subelement of entry) to // an array list(subele) while (ei.hasNext()) { Element sube = (Element) ei.next(); // System.out.println("attribute count is: "+sube.attributeCount()); if (!sube.getName().equals("ReportItem")) continue; // a list of elements for each entry ArrayList<String> subele = new ArrayList<String>(); Iterator reportItemItrt = sube.elementIterator(); while (reportItemItrt.hasNext()) { Element reportItemElement = (Element) reportItemItrt.next(); // System.out.println(reportItemElement.getName()); subele.add(reportItemElement.getName()); } if (subele.size() == 0 || (!subele.contains("cve"))) continue; Iterator itr = sube.elementIterator("cve"); while (itr.hasNext()) { System.out.println("host name is: " + host.attribute(0).getText()); fr.write(host.attribute(0).getText() + "\n"); Element cve = (Element) itr.next(); System.out.println(cve.getText()); fr.write(cve.getText() + "\n"); System.out.println("port number is: " + sube.attribute(0).getText()); fr.write(sube.attribute(0).getText() + "\n"); System.out.println("protocol is: " + sube.attribute(2).getText()); fr.write(sube.attribute(2).getText() + "\n"); System.out.println(); // fr.write("\n"); } } } // end of each entry's processing fr.close(); // print out the stack trace for each exception(either documentation // exception or IO exception). } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Addons.CepWebService.java
private static void criarEndereco(Endereco endereco) { try {/*from w ww. j a v a 2 s . co m*/ URL url = new URL( "http://cep.republicavirtual.com.br/web_cep.php?cep=" + endereco.getCep() + "&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")) endereco.setUf(element.getText()); if (element.getQualifiedName().equals("cidade")) endereco.setCidade(element.getText()); if (element.getQualifiedName().equals("bairro")) endereco.setBairro(element.getText()); if (element.getQualifiedName().equals("tipo_logradouro")) endereco.setTipo_logradouro(element.getText()); if (element.getQualifiedName().equals("logradouro")) endereco.setLogradouro(element.getText()); if (element.getQualifiedName().equals("resultado")) endereco.setResultado(Integer.parseInt(element.getText())); if (element.getQualifiedName().equals("resultado_txt")) endereco.setResultado_txt(element.getText()); } endereco.setError(false); } catch (MalformedURLException | DocumentException | NumberFormatException ex) { endereco.setError(true); endereco.setMessage(ex.getMessage()); } }
From source file:adr.main.AlcorAdrSettings.java
/** * ? ? .xml //from w w w .jav a 2s . c o m * @return * true - ? * false - ? */ public boolean LoadSettings() { boolean bResOk = true; try { SAXReader reader = new SAXReader(); String strSettingsFilePathName = "alcor.adr.settings.xml";//System.getenv( "AMS_ROOT") + "/etc/settings.ams.xml"; URL url = (new java.io.File(strSettingsFilePathName)).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( "Pairs: [" + name + " : " + value + "]"); if ("COM_Port".equals(name)) m_pCOMPortSettings.SetPort(value); if ("COM_Baudrate".equals(name)) m_pCOMPortSettings.SetBaudRate(Integer.parseInt(value)); if ("COM_DataBits".equals(name)) { switch (value) { case "5": m_pCOMPortSettings.SetDataBits(SerialPort.DATABITS_5); break; case "6": m_pCOMPortSettings.SetDataBits(SerialPort.DATABITS_6); break; case "7": m_pCOMPortSettings.SetDataBits(SerialPort.DATABITS_7); break; case "8": m_pCOMPortSettings.SetDataBits(SerialPort.DATABITS_8); break; default: logger.warn("Unknown COM_DataBits value '" + value + "' in settings.xml! Using default!"); bResOk = false; break; } } if ("COM_Parity".equals(name)) { switch (value) { case "None": m_pCOMPortSettings.SetParity(SerialPort.PARITY_NONE); break; case "Odd": m_pCOMPortSettings.SetParity(SerialPort.PARITY_ODD); break; case "Even": m_pCOMPortSettings.SetParity(SerialPort.PARITY_EVEN); break; case "Mark": m_pCOMPortSettings.SetParity(SerialPort.PARITY_MARK); break; case "Space": m_pCOMPortSettings.SetParity(SerialPort.PARITY_SPACE); break; default: logger.warn("Unknown COM_Parity value '" + value + "' in settings.xml! Using default!"); bResOk = false; break; } } if ("COM_StopBits".equals(name)) { switch (value) { case "1": m_pCOMPortSettings.SetStopBits(SerialPort.STOPBITS_1); break; case "2": m_pCOMPortSettings.SetParity(SerialPort.STOPBITS_2); break; default: logger.warn("Unknown COM_StopBits value '" + value + "' in settings.xml! Using default!"); bResOk = false; break; } } } } 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:ams.AMSDevSerialNumbers.java
/** * Loads tested laser devices numbers from XML<br> * So user don't need to enter them one more time *//*www . ja v a 2 s. c o m*/ private void LoadDevNumsFromXML() { try { SAXReader reader = new SAXReader(); String strSerialsFileName = System.getenv("AMS_ROOT") + "/serials.xml"; URL url = (new java.io.File(strSerialsFileName)).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("Pairs: [" + name + " : " + value + "]"); switch (name) { case "Device1": m_strDev1SerialNumber = value; break; case "Device2": m_strDev2SerialNumber = value; break; case "Device3": m_strDev3SerialNumber = value; break; case "Device4": m_strDev4SerialNumber = value; break; case "Device5": m_strDev5SerialNumber = value; break; case "Device6": m_strDev6SerialNumber = value; break; case "Device7": m_strDev7SerialNumber = value; break; case "Device8": m_strDev8SerialNumber = value; break; default: } } } catch (MalformedURLException ex) { logger.error("MalformedURLException caught while loading serials!", ex); } catch (DocumentException ex) { logger.error("DocumentException caught while loading serials!", ex); } }
From source file:ams.AMSSettings.java
/** * ? ? .xml /*from w w w .j av a2 s. com*/ * @return * true - ? * false - ? */ public boolean LoadSettings() { boolean bResOk = true; try { SAXReader reader = new SAXReader(); String strSettingsFilePathName = System.getenv("AMS_ROOT") + "/settings.xml"; URL url = (new java.io.File(strSettingsFilePathName)).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( "Pairs: [" + name + " : " + value + "]"); if ("COM_Port".equals(name)) m_pCOMPortSettings.SetPort(value); if ("COM_Baudrate".equals(name)) m_pCOMPortSettings.SetBaudRate(Integer.parseInt(value)); if ("COM_DataBits".equals(name)) { switch (value) { case "5": m_pCOMPortSettings.SetDataBits(SerialPort.DATABITS_5); break; case "6": m_pCOMPortSettings.SetDataBits(SerialPort.DATABITS_6); break; case "7": m_pCOMPortSettings.SetDataBits(SerialPort.DATABITS_7); break; case "8": m_pCOMPortSettings.SetDataBits(SerialPort.DATABITS_8); break; default: logger.warn("Unknown COM_DataBits value '" + value + "' in settings.xml! Using default!"); bResOk = false; break; } } if ("COM_Parity".equals(name)) { switch (value) { case "None": m_pCOMPortSettings.SetParity(SerialPort.PARITY_NONE); break; case "Odd": m_pCOMPortSettings.SetParity(SerialPort.PARITY_ODD); break; case "Even": m_pCOMPortSettings.SetParity(SerialPort.PARITY_EVEN); break; case "Mark": m_pCOMPortSettings.SetParity(SerialPort.PARITY_MARK); break; case "Space": m_pCOMPortSettings.SetParity(SerialPort.PARITY_SPACE); break; default: logger.warn("Unknown COM_Parity value '" + value + "' in settings.xml! Using default!"); bResOk = false; break; } } if ("COM_StopBits".equals(name)) { switch (value) { case "1": m_pCOMPortSettings.SetStopBits(SerialPort.STOPBITS_1); break; case "2": m_pCOMPortSettings.SetParity(SerialPort.STOPBITS_2); break; default: logger.warn("Unknown COM_StopBits value '" + value + "' in settings.xml! Using default!"); bResOk = false; break; } } if ("Devices".equals(name)) { for (Iterator andevsparams = element.elementIterator(); andevsparams.hasNext();) { Element elementAnDev = (Element) andevsparams.next(); name = elementAnDev.getName(); value = elementAnDev.getText(); //logger.debug( "Pairs: Devices.[" + name + " : " + value + "]"); boolean bOk = true; try { Integer.parseInt(value, 16); } catch (NumberFormatException e) { logger.error("Param Anode_devices." + name + " is not a valid hex-number [" + value + "]! using default!"); bOk = false; bResOk = false; } if (bOk) { switch (name) { case "ADC1": m_strADC1Address = value; break; case "ADC2": m_strADC2Address = value; break; case "DAC1": m_strDAC1Address = value; break; case "DAC2": m_strDAC2Address = value; break; case "REL1": m_strREL1Address = value; break; case "ADC3": m_strADC3Address = value; break; case "ADC4": m_strADC4Address = value; break; case "DAC3": m_strDAC3Address = value; break; case "DAC4": m_strDAC4Address = value; break; case "REL2": m_strREL2Address = value; break; default: logger.warn("Unknown param Device.'" + name + "' in settings.xml! Pay attention!"); bResOk = false; } } } } if ("Device0_channels".equals(name)) bResOk = ParseDeviceBlock(AMSConstants.T_DEVICE1, element) & bResOk; if ("Device1_channels".equals(name)) bResOk = ParseDeviceBlock(AMSConstants.T_DEVICE2, element) & bResOk; if ("Device2_channels".equals(name)) bResOk = ParseDeviceBlock(AMSConstants.T_DEVICE3, element) & bResOk; if ("Device3_channels".equals(name)) bResOk = ParseDeviceBlock(AMSConstants.T_DEVICE4, element) & bResOk; if ("Device4_channels".equals(name)) bResOk = ParseDeviceBlock(AMSConstants.T_DEVICE5, element) & bResOk; if ("Device5_channels".equals(name)) bResOk = ParseDeviceBlock(AMSConstants.T_DEVICE6, element) & bResOk; if ("Device6_channels".equals(name)) bResOk = ParseDeviceBlock(AMSConstants.T_DEVICE7, element) & bResOk; if ("Device7_channels".equals(name)) bResOk = ParseDeviceBlock(AMSConstants.T_DEVICE8, element) & bResOk; } /* // iterate through child elements of root with element name "foo" for ( Iterator i = root.elementIterator( "foo" ); i.hasNext(); ) { Element foo = (Element) i.next(); // do something } // iterate through attributes of root for ( Iterator i = root.attributeIterator(); i.hasNext(); ) { Attribute attribute = (Attribute) i.next(); // do something } */ } 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:ams.AMSSettings.java
/** * ?? ? ? ? .xml // www . j a va2s .c o m * ? DeviceX_channels ( ) * @param nDevice ? * @param deviceRoot .xml-root ? ? * @return * true - ?; * false - ? */ private boolean ParseDeviceBlock(int nDevice, Element deviceRoot) { boolean bResOk = true; for (Iterator dev = deviceRoot.elementIterator(); dev.hasNext();) { Element devElem = (Element) dev.next(); String name = devElem.getName(); if (name.equals("anode")) { for (Iterator dev_an_chans = devElem.elementIterator(); dev_an_chans.hasNext();) { Element elementAnDev = (Element) dev_an_chans.next(); name = elementAnDev.getName(); String value = elementAnDev.getText(); Integer test = new Integer(value); logger.debug("Pairs: Device" + nDevice + ".anode.[" + name + " : " + value + "]"); boolean bOk = true; if (name.contains("DAC") == true) { if (test.shortValue() < 1 && test.shortValue() > 4) { logger.warn("Bad value for Device" + nDevice + ".anode.[" + name + "] = '" + value + "'. Using default!"); bOk = false; bResOk = false; } } else { if (test.shortValue() < 1 && test.shortValue() > 9) { logger.warn("Bad value for Device" + nDevice + ".anode.[" + name + "] = '" + value + "'. Using default!"); bOk = false; bResOk = false; } } if (bOk) { switch (name) { case "ADC_V_DEV": ((AMSSettingsTDev) m_mapDevs.get(nDevice)).SetAnoAdcVoltDev(Integer.parseInt(value)); break; case "ADC_V_CHAN": ((AMSSettingsTDev) m_mapDevs.get(nDevice)).SetAnoAdcVoltChan(Integer.parseInt(value)); break; case "ADC_C_DEV": ((AMSSettingsTDev) m_mapDevs.get(nDevice)).SetAnoAdcCurrDev(Integer.parseInt(value)); break; case "ADC_C_CHAN": ((AMSSettingsTDev) m_mapDevs.get(nDevice)).SetAnoAdcCurrChan(Integer.parseInt(value)); break; case "DAC_DEV": ((AMSSettingsTDev) m_mapDevs.get(nDevice)).SetAnoDacDev(Integer.parseInt(value)); break; case "DAC_CHAN": ((AMSSettingsTDev) m_mapDevs.get(nDevice)).SetAnoDacChan(Integer.parseInt(value)); break; case "REL_DEV": ((AMSSettingsTDev) m_mapDevs.get(nDevice)).SetAnoRelDev(Integer.parseInt(value)); break; case "REL_CHAN": ((AMSSettingsTDev) m_mapDevs.get(nDevice)).SetAnoRelChan(Integer.parseInt(value)); break; } } } } else if (name.equals("tubulation")) { for (Iterator dev_an_chans = devElem.elementIterator(); dev_an_chans.hasNext();) { Element elementAnDev = (Element) dev_an_chans.next(); name = elementAnDev.getName(); String value = elementAnDev.getText(); Integer test = new Integer(value); logger.debug("Pairs: Device" + nDevice + ".tubulation.[" + name + " : " + value + "]"); boolean bOk = true; if (name.contains("DAC") == true) { if (test.shortValue() < 1 && test.shortValue() > 4) { logger.warn("Bad value for Device" + nDevice + ".tubulation.[" + name + "] = '" + value + "'. Using default!"); bOk = false; bResOk = false; } } else { if (test.shortValue() < 1 && test.shortValue() > 9) { logger.warn("Bad value for Device" + nDevice + ".tubulation.[" + name + "] = '" + value + "'. Using default!"); bOk = false; bResOk = false; } } if (bOk) { switch (name) { case "ADC_V_DEV": ((AMSSettingsTDev) m_mapDevs.get(nDevice)).SetTubAdcVoltDev(Integer.parseInt(value)); break; case "ADC_V_CHAN": ((AMSSettingsTDev) m_mapDevs.get(nDevice)).SetTubAdcVoltChan(Integer.parseInt(value)); break; case "ADC_C_DEV": ((AMSSettingsTDev) m_mapDevs.get(nDevice)).SetTubAdcCurrDev(Integer.parseInt(value)); break; case "ADC_C_CHAN": ((AMSSettingsTDev) m_mapDevs.get(nDevice)).SetTubAdcCurrChan(Integer.parseInt(value)); break; case "DAC_DEV": ((AMSSettingsTDev) m_mapDevs.get(nDevice)).SetTubDacDev(Integer.parseInt(value)); break; case "DAC_CHAN": ((AMSSettingsTDev) m_mapDevs.get(nDevice)).SetTubDacChan(Integer.parseInt(value)); break; case "REL_DEV": ((AMSSettingsTDev) m_mapDevs.get(nDevice)).SetTubRelDev(Integer.parseInt(value)); break; case "REL_CHAN": ((AMSSettingsTDev) m_mapDevs.get(nDevice)).SetTubRelChan(Integer.parseInt(value)); break; } } } } } return bResOk; }
From source file:ams.devices.AMSCalibration.java
public boolean LoadCalibration() { boolean bResOk = true; try {// www . jav a 2s . 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:at.kc.tugraz.ss.serv.dataimport.impl.fct.op.SSDataImportAchsoFct.java
License:Apache License
public static List<SSi5CloudAchsoVideo> getVideoObjs(final SSUri userUri, final String vidXML) throws Exception { try {/* www . j a va 2s . co m*/ final Document document = DocumentHelper.parseText(vidXML); final Element rootElement = document.getRootElement(); final Iterator vidIterator = rootElement.elementIterator(); final List<SSi5CloudAchsoVideo> videos = new ArrayList<>(); Iterator vidContentIterator; Element vid; Element vidContent; String title; String video_uri; String creator; Long created_at; List<String> annotations; List<String> keywords; SSi5CloudAchsoVideo videoObj; while (vidIterator.hasNext()) { vid = (Element) vidIterator.next(); vidContentIterator = vid.elementIterator(); title = null; video_uri = null; creator = null; created_at = null; annotations = new ArrayList<>(); keywords = new ArrayList<>(); while (vidContentIterator.hasNext()) { vidContent = (Element) vidContentIterator.next(); switch (SSI5CloudAchsoVideoMetaDataE.get(vidContent.getName())) { case title: title = (String) vidContent.getData(); break; case video_uri: video_uri = (String) vidContent.getData(); break; case creator: creator = (String) vidContent.getData(); break; case created_at: created_at = getCreationTime((String) vidContent.getData()); break; case keywords: keywords = getKeywords(vidContent.nodeIterator()); break; case annotations: annotations = getAnnotations(vidContent.nodeIterator()); break; } } try { videoObj = SSi5CloudAchsoVideo.get(SSUri.get(video_uri), SSLabel.get(title), SSLabel.get(creator), keywords, annotations); videoObj.creationTime = created_at; videos.add(videoObj); } catch (Exception error) { SSLogU.warn("couldnt add vid: " + video_uri); } } return videos; } catch (Exception error) { SSServErrReg.regErrThrow(error); return null; } }
From source file:au.gov.ansto.bragg.process.parse.Parse.java
License:Open Source License
protected static List<InConfiguration> getInConfigurationList(final Element element, final String parentName) throws DocumentException { // List<?> list = element.selectNodes("*"); List<InConfiguration> portList = new LinkedList<InConfiguration>(); for (Iterator<?> iter = element.elementIterator(); iter.hasNext();) { Element item = (Element) iter.next(); portList.add((InConfiguration) getPortConfiguration(item, "in", parentName)); }//w w w . j a v a 2 s. co m return portList; }