List of usage examples for org.dom4j Element elementIterator
Iterator<Element> elementIterator();
From source file:hvv_admin4.HVV_Admin4Settings.java
public boolean ReadSettingsDbg() { boolean bResOk = true; try {//from ww w. j a v a 2 s.co m SAXReader reader = new SAXReader(); String strSettingsFilePathName = System.getenv("AMS_ROOT") + "/etc/settings.admin.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 ("debug.shorten.program.items".equals(name)) { m_bDebugShortenProgItems = "true".equals(value); } if ("debug.shorten.program.times".equals(name)) { m_bDebugShortenProgTimes = "true".equals(value); } if ("debug.shorten.thermoprocessing".equals(name)) { m_bDebugShortenThermoProcessing = "true".equals(value); } } } 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:hvv_admin4.HVV_AdminStepNames.java
private boolean ReadSettings() { boolean bResOk = true; try {//from w ww .j av a 2 s .com SAXReader reader = new SAXReader(); String strSettingsFilePathName = System.getenv("AMS_ROOT") + "/etc/hvv4.step.names.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 id = element.attributeValue("id"); String num = element.attributeValue("num"); String value = element.getText(); m_mapSteps.put(id, new ItemStepNames(num, value)); } } 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:hvv_constructor.FrmMainWindow.java
private void btnLoadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLoadActionPerformed final JFileChooser fc = new JFileChooser(); fc.setFileFilter(new MyXMLFilter()); fc.setCurrentDirectory(new File(theApp.GetAMSRoot() + "/ReadyPrograms")); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); //This is where a real application would open the file. logger.info("LoadProgram opening: " + file.getName()); TreeMap newProgram = new TreeMap(); boolean bResOk = true; try {// ww w. j a v a 2 s. com SAXReader reader = new SAXReader(); URL url = file.toURI().toURL(); Document document = reader.read(url); Element program = document.getRootElement(); if (program.getName().equals("Program")) { // iterate through child elements of root for (Iterator i = program.elementIterator(); i.hasNext();) { Element element = (Element) i.next(); String name = element.getName(); String strLineNumber = element.getTextTrim(); int nLineNumber = Integer.parseInt(strLineNumber); JProgAStatement statement = JProgAStatement.parse(element); if (statement != null) newProgram.put(nLineNumber, statement); logger.debug("Pairs: [" + name + " : " + strLineNumber + "]"); } theApp.m_program = newProgram; ShowProgram(); } else logger.error("There is no 'program' root-tag in pointed XML"); } 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; } } else { logger.info("LoadProgram cancelled."); } }
From source file:hvv_executor.comm.admin.from.HVV_Comm_srv_A2E.java
@Override public void processIncomingCommand(String strReqId, LinkedList lstIncomingParcel) throws Exception { String strCmd;//from www. j a v a2 s . c o m int nRetCode = 0; strCmd = (String) lstIncomingParcel.get(0); if (strCmd != null) { switch (strCmd) { case "START_PROGRAM": String strProgramToLoad = (String) lstIncomingParcel.get(1); logger.debug("INCOMING: [" + strReqId + ";START_PROGRAM;" + strProgramToLoad + "]"); File file = new File(theApp.GetAMSRoot() + "/ReadyPrograms/AdminSteps/" + strProgramToLoad); //This is where a real application would open the file. logger.info("LoadProgram opening: " + file.getName()); theApp.m_strCurrentProgram = file.getName(); TreeMap newProgram = new TreeMap(); boolean bResOk = true; try { SAXReader reader = new SAXReader(); URL url = file.toURI().toURL(); Document document = reader.read(url); Element program = document.getRootElement(); if (program.getName().equals("Program")) { // iterate through child elements of root for (Iterator i = program.elementIterator(); i.hasNext();) { Element element = (Element) i.next(); String name = element.getName(); String strLineNumber = element.getTextTrim(); int nLineNumber = Integer.parseInt(strLineNumber); JProgAStatement statement = JProgAStatement.parse(element); if (statement != null) newProgram.put(nLineNumber, statement); logger.debug("Pairs: [" + name + " : " + strLineNumber + "]"); } theApp.m_program = newProgram; theApp.m_pMainWnd.ShowProgram(); } else logger.error("There is no 'program' root-tag in pointed XML"); } 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; } theApp.m_pMainWnd.btnStart.setEnabled(false); logger.info("Starting Exec program"); new Thread(theApp.m_MainExeThread).start(); theApp.m_nRunningState = HVV_Executor.RUNNING_STATE_RUN; theApp.SetExProgramStartDateAsCurrent(); nRetCode = 0; break; case "PING": logger.debug("INCOMING: [" + strReqId + ";PING;" + "]"); nRetCode = 0; if (m_nStopRequested == 1) { nRetCode = 100; m_nStopRequested = 2; } break; case "QUIT": logger.info("'QUIT' processing"); SetState(STATE_DISCONNECTED); return; default: logger.error("" + strReqId + ": Unknown command '" + strCmd + "'. RetCode 3"); nRetCode = 3; break; } } else { logger.error("" + strReqId + ": Command is null. RetCode 2"); nRetCode = 2; } //RESPOND logger.debug("RESPOND [ " + strReqId + ";" + nRetCode + "]"); GetObjectOutputStream().writeObject(strReqId); GetObjectOutputStream().writeInt(1); GetObjectOutputStream().writeObject(nRetCode); GetObjectOutputStream().flush(); }
From source file:hvv_executor.FrmMainWindow.java
private void btnLoadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLoadActionPerformed final JFileChooser fc = new JFileChooser(); fc.setFileFilter(new MyXMLFilter()); String strCurrentProgram = theApp.GetAMSRoot() + "/ReadyPrograms"; fc.setCurrentDirectory(new File(strCurrentProgram)); int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); //This is where a real application would open the file. logger.info("LoadProgram opening: " + file.getName()); theApp.m_strCurrentProgram = file.getName(); TreeMap newProgram = new TreeMap(); boolean bResOk = true; try {/*from w w w . j ava 2 s .c o m*/ SAXReader reader = new SAXReader(); URL url = file.toURI().toURL(); Document document = reader.read(url); Element program = document.getRootElement(); if (program.getName().equals("Program")) { // iterate through child elements of root for (Iterator i = program.elementIterator(); i.hasNext();) { Element element = (Element) i.next(); String name = element.getName(); String strLineNumber = element.getTextTrim(); int nLineNumber = Integer.parseInt(strLineNumber); JProgAStatement statement = JProgAStatement.parse(element); if (statement != null) newProgram.put(nLineNumber, statement); logger.debug("Pairs: [" + name + " : " + strLineNumber + "]"); } theApp.m_program = newProgram; ShowProgram(); } else logger.error("There is no 'program' root-tag in pointed XML"); } 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; } } else { logger.info("LoadProgram cancelled."); } }
From source file:hvv_executor.HVV_ExecutorSettings.java
private boolean ReadSettings() { boolean bResOk = true; try {/*from w w w . ja va 2 s . com*/ SAXReader reader = new SAXReader(); String strSettingsFilePathName = System.getenv("AMS_ROOT") + "/etc/settings.executor.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 ("vacuum.host".equals(name)) m_strVacuumPartHost = value; if ("vacuum.port".equals(name)) m_nVacuumPartPort = Integer.parseInt(value); if ("hv.host".equals(name)) m_strHvPartHost = value; if ("hv.port".equals(name)) m_nHvPartPort = Integer.parseInt(value); if ("poller.host".equals(name)) m_strPollerPartHost = value; if ("poller.port".equals(name)) m_nPollerPartPort = Integer.parseInt(value); if ("admin.from.host".equals(name)) m_strAdminFromPartHost = value; if ("admin.from.port".equals(name)) m_nAdminFromPartPort = Integer.parseInt(value); if ("admin.to.host".equals(name)) m_strAdminToPartHost = value; if ("admin.to.port".equals(name)) m_nAdminToPartPort = Integer.parseInt(value); if ("timezone".equals(name)) m_nTimeZoneShift = Integer.parseInt(value); } } 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:it.jnrpe.utils.PluginRepositoryUtil.java
License:Apache License
/** * Loads the plugins definitions from the jnrpe_plugins.xml file. * /*from w w w . j ava 2s .co m*/ * @param cl * Classloader to be used to load classes * @param in * InputStream to the jnrpe_plugins.xml file * @return a collection of all the declared plugins * @throws PluginConfigurationException * on any error reading the plugin configuration */ @SuppressWarnings("unchecked") public static Collection<PluginDefinition> loadFromXmlPluginPackageDefinitions(final ClassLoader cl, final InputStream in) throws PluginConfigurationException { List<PluginDefinition> res = new ArrayList<PluginDefinition>(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document document; try { DocumentBuilder loader = factory.newDocumentBuilder(); DOMReader reader = new DOMReader(); document = reader.read(loader.parse(in)); } catch (Exception e) { throw new PluginConfigurationException(e.getMessage(), e); } Element plugins = document.getRootElement(); // TODO : validate against schema // iterate through child elements of root for (Iterator<Element> i = plugins.elementIterator(); i.hasNext();) { res.add(parsePluginDefinition(cl, i.next())); } return res; }
From source file:it.jnrpe.utils.PluginRepositoryUtil.java
License:Apache License
/** * Updates the plugin definition with the commandline read from the xml * file.//from w w w .j ava 2 s.com * * @param pluginDef * The plugin definition to be updated * @param xmlPluginElement * the xml element to be parsed */ @SuppressWarnings("rawtypes") private static void parseCommandLine(final PluginDefinition pluginDef, final Element xmlPluginElement) { Element commandLine = xmlPluginElement.element("command-line"); if (commandLine != null) { // The plugin has a command line... Element options = commandLine.element("options"); if (options == null) { // The command line is empty... return; } for (Iterator<Element> i = options.elementIterator(); i.hasNext();) { pluginDef.addOption(parsePluginOption(i.next())); } } }
From source file:itensil.workflow.model.FlowModel.java
License:Open Source License
/** * /*from w ww .j ava2s . c om*/ * @param stepSeqParent * @param idMap */ public static void collectIdChanges(Element stepSeqParent, Map<String, String> idMap, Collection<String> newIds) { Iterator itr = stepSeqParent.elementIterator(); while (itr.hasNext()) { Element elm = (Element) itr.next(); String oldid = elm.attributeValue("oldid"); if (!Check.isEmpty(oldid)) { if ("//N".equals(oldid)) newIds.add(elm.attributeValue("id")); else idMap.put(oldid, elm.attributeValue("id")); } if ("group".equals(elm.getName())) { collectIdChanges(elm, idMap, newIds); } } }
From source file:javaapplication3.DataXmlWorker.java
private ShortBuffer getXmlData(ShortBuffer mem_data) { ShortBuffer exitData = ShortBuffer.allocate(mem_data.limit()); exitData.put(mem_data.array());// ww w . ja v a2 s . c om SAXReader reader = new SAXReader(); File f = new File(file_name_to_unit_); if (!f.exists()) { System.out.println("no data file " + file_name_to_unit_); } try { Document document = reader.read(f); Element root = document.getRootElement().element("map"); // iterate through child elements of root for (Iterator i = root.elementIterator(); i.hasNext();) { Element element = (Element) i.next(); //System.out.println("addr[ " + element.attributeValue("addr") + "] = " + element.attributeValue("value")); // TODO put +2 into config int mem_adr = Integer.parseInt(element.attributeValue("addr")) - mem_shift_ + 2; // DEBUG +2 for fix webface bug if (mem_adr < mem_data.limit()) exitData.put(mem_adr, (short) Integer.parseInt(element.attributeValue("value"))); } return exitData; } catch (DocumentException ex) { System.out.println("Exeption: " + ex.getMessage()); Logger.getLogger(DataXmlWorker.class.getName()).log(Level.SEVERE, null, ex); } return exitData; }