List of usage examples for org.dom4j Document getRootElement
Element getRootElement();
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 *//*from w w w. j a 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 ww w .ja v a 2 s . c o m * @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.devices.AMSCalibration.java
public boolean LoadCalibration() { boolean bResOk = true; try {//from ww w .j a v a 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.license.License.java
License:Apache License
public static License fromXML(String xml) { try {//from w w w . j av a2 s . c o m 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: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 {// w ww.j a v a2 s .c om 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.com.centrumsystems.hudson.plugin.buildpipeline.BuildPipelineView.java
License:Open Source License
@JavaScriptMethod public Set<String> getAllFirstJobsName(String url) { Jenkins jk = Jenkins.getInstance();/* w w w .ja v a 2 s. c o m*/ Collection<View> views = jk.getViews(); Set<String> firstJobNameSet = new HashSet<String>(); String shortUrl = getViewShortUrlFromURL(url); StringBuilder sb = null; Document configXmlDoc = null; String viewName = null; for (View view : views) { sb = new StringBuilder(shortUrl); viewName = view.getViewName(); if ("ALL".equals(viewName)) { continue; } sb.append(viewName).append("/"); String viewConfigXml = fetchViewConfig(sb.toString()); try { configXmlDoc = DocumentHelper.parseText(viewConfigXml); } catch (DocumentException e) { e.printStackTrace(); } Iterator iter = configXmlDoc.getRootElement().elementIterator("gridBuilder"); while (iter.hasNext()) { Element elt = (Element) iter.next(); firstJobNameSet.add(elt.elementTextTrim("firstJob")); } } return firstJobNameSet; }
From source file:au.edu.usq.fascinator.harvester.fedora.FedoraDatastream.java
License:Open Source License
public Element getContentAsXml() throws IOException { Element elem = null;/*from ww w. ja va 2 s. c o m*/ SAXReader reader = new SAXReader(); try { Document doc = reader.read(getContentAsStream()); elem = doc.getRootElement(); } catch (Exception e) { throw new IOException(e.getMessage()); } return elem; }
From source file:au.edu.usq.fascinator.harvester.fedora.FedoraItem.java
License:Open Source License
public Element getMetadata() { Element elem = null;//from w w w. jav a 2s.c o m SAXReader reader = new SAXReader(); try { String metadata = getMetadataAsString(); Document doc = reader.read(new ByteArrayInputStream(metadata.getBytes("UTF-8"))); elem = doc.getRootElement(); } catch (UnsupportedEncodingException uee) { log.warn(uee); } catch (DocumentException de) { log.warn(de); } return elem; }
From source file:au.gov.ansto.bragg.cicada.core.internal.Algorithm_.java
License:Open Source License
public Document loadAlgorithmTitle(File algorithmFile) throws LoadAlgorithmFileFailedException { this.filename = algorithmFile.getPath(); Document file = null; try {/*from w ww . j a va 2 s.c o m*/ file = Parse.readFile(algorithmFile); } catch (DocumentException e) { throw new LoadAlgorithmFileFailedException("failed to load the algorithm from configuration file " + algorithmFile.getName() + ": " + e.getMessage(), e); } Element rootElement = file.getRootElement(); classID = rootElement.attributeValue("id"); try { setName(rootElement.attributeValue("name")); } catch (IllegalNameSetException e) { throw new LoadAlgorithmFileFailedException(e.getMessage() + ": illegal algorithm name"); } version = rootElement.attributeValue("version"); helpURL = rootElement.attributeValue("help_url"); shortDescription = rootElement.attributeValue("short_description"); icon = rootElement.attributeValue("icon"); try { algorithmType = AlgorithmType.valueOf(rootElement.attributeValue("type")); } catch (Exception e) { } String hiddenValue = rootElement.attributeValue("hidden"); if (hiddenValue != null) hidden = Boolean.valueOf(hiddenValue); if (classID == null) throw new LoadAlgorithmFileFailedException("classID not found in receipe file"); // if (icon == null) // throw new LoadAlgorithmFileFailedException("icon path not found in receipe file"); hasInPort = checkSourcePortExistence(rootElement); return file; }
From source file:au.gov.ansto.bragg.process.factory.ConfigurationFactory.java
License:Open Source License
/** * A static method to create a framework configuration from a given XML receipe file * @param file file handle as File instance * @return a handle of framework configuration object * @throws NullConfigurationPointerException can not create a configuration object * @throws DocumentException invalid recipe file *//* w w w.ja v a 2s .co m*/ public static FrameworkConfiguration createConfiguration(Document file) throws NullConfigurationPointerException, DocumentException { FrameworkConfiguration frameworkConfiguration = null; Element rootElement = file.getRootElement(); try { frameworkConfiguration = Parse.parseFile(rootElement); } catch (NullConfigurationPointerException ex) { throw new NullConfigurationPointerException("ConfigurationFactory "); } // System.out.println(frameworkConfiguration.toString()); return frameworkConfiguration; }