public TableConfig readConfigXML( String fileLocation, FeatureType wantFeatureType, NetcdfDataset ds, Formatter errlog) throws IOException { org.jdom2.Document doc; try { SAXBuilder builder = new SAXBuilder(false); if (debugURL) System.out.println(" PointConfig URL = <" + fileLocation + ">"); doc = builder.build(fileLocation); } catch (JDOMException e) { throw new IOException(e.getMessage()); } if (debugXML) System.out.println(" SAXBuilder done"); if (showParsedXML) { XMLOutputter xmlOut = new XMLOutputter(); System.out.println( "*** PointConfig/showParsedXML = \n" + xmlOut.outputString(doc) + "\n*******"); } Element configElem = doc.getRootElement(); String featureType = configElem.getAttributeValue("featureType"); Element tableElem = configElem.getChild("table"); TableConfig tc = parseTableConfig(ds, tableElem, null); tc.featureType = FeatureType.valueOf(featureType); return tc; }
public static Question[] getQuestions(File xmlFile) { SAXBuilder builder = new SAXBuilder(); Question[] res = {}; try { Document document = (Document) builder.build(xmlFile); Element rootNode = document.getRootElement(); List topics = rootNode.getChildren("t"); String id, group, text, text_en, answer, q_type, q_ans, support, number; // , snippet; for (int i = 0; i < topics.size(); i++) { Element t = (Element) topics.get(i); List questions = t.getChildren("q"); for (int j = 0; j < questions.size(); j++) { Element q = (Element) questions.get(j); id = q.getAttributeValue("q_id").toString(); q_type = q.getAttributeValue("q_type").toString(); q_ans = q.getAttributeValue("q_exp_ans_type").toString(); support = q.getChild("answer").getAttributeValue("a_support"); // snippet = q.getChild("answer").getAttributeValue("a_support"); group = t.getAttributeValue("t_string").toString(); text = q.getChild("question").getText(); number = q.getChild("question").getAttributeValue("question_id"); answer = q.getChild("answer").getChildText("a_string"); text_en = q.getChild("q_translation").getText(); res = ArrayUtils.add( res, new Question( id, group, text, answer, text_en, new String[0], q_type, q_ans, support, number)); } } } catch (IOException io) { System.out.println(io.getMessage()); } catch (JDOMException jdomex) { System.out.println(jdomex.getMessage()); } return res; }
public static void read(InputStream is, StringBuilder errlog) throws IOException { Document doc; SAXBuilder saxBuilder = new SAXBuilder(); try { doc = saxBuilder.build(is); } catch (JDOMException e) { throw new IOException(e.getMessage()); } read(doc.getRootElement(), errlog); }
/** * Notifies the registered {@link ErrorHandler SAX error handler} (if any) of an input processing * error. The error handler can choose to absorb the error and let the processing continue. * * @param exception <code>JDOMException</code> containing the error information; will be wrapped * in a {@link SAXParseException} when reported to the SAX error handler. * @throws JDOMException if no error handler has been registered or if the error handler fired a * {@link SAXException}. */ private void handleError(JDOMException exception) throws JDOMException { if (errorHandler != null) { try { errorHandler.error(new SAXParseException(exception.getMessage(), null, exception)); } catch (SAXException se) { if (se.getException() instanceof JDOMException) { throw (JDOMException) (se.getException()); } throw new JDOMException(se.getMessage(), se); } } else { throw exception; } }
private void carregaConfig() { try { File file = new File("config.xml"); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(file); Element root = doc.getRootElement(); List list = root.getChildren(); Iterator i = list.iterator(); while (i.hasNext()) { Element xml = (Element) i.next(); Config c = new Config(); c.setPathRouterSnapshot(xml.getChildText("pathRouterSnapshot")); c.setPathDestSnapshot(xml.getChildText("pathDestSnapshot")); c.setSmtpHostEmail(xml.getChildText("smtpHostEmail")); c.setSmtpPortEmail(Integer.parseInt(xml.getChildText("smtpPortEmail"))); c.setUserEmail(xml.getChildText("userEmail")); c.setPassEmail(xml.getChildText("passEmail")); c.setHostFTP(xml.getChildText("hostFTP")); c.setPortaFTP(Integer.parseInt(xml.getChildText("portaFTP"))); c.setUserFTP(xml.getChildText("userFTP")); c.setPassFTP(xml.getChildText("passFTP")); c.setPathDestFTP(xml.getChildText("pathDestFTP")); txtPathAlarmeRouter.setText(c.getPathRouterSnapshot()); txtPathDestRouter.setText(c.getPathDestSnapshot()); txtSmtpHostEmail.setText(c.getSmtpHostEmail()); txtSmtpPortaEmail.setValue(c.getSmtpPortEmail()); txtUserEmail.setText(c.getUserEmail()); txtPassEmail.setText(c.getPassEmail()); txtHostFTP.setText(c.getHostFTP()); txtPortaFTP.setValue(c.getPortaFTP()); txtUserFTP.setText(c.getUserFTP()); txtPassFTP.setText(c.getPassFTP()); txtPathDestFTP.setText(c.getPathDestFTP()); } } catch (JDOMException ex) { System.out.println(ex.getMessage()); } catch (IOException ex) { System.out.println(ex.getMessage()); } }
public TableConfig readConfigXMLfromResource( String resourceLocation, FeatureType wantFeatureType, NetcdfDataset ds, Formatter errlog) throws IOException { ClassLoader cl = this.getClass().getClassLoader(); try (InputStream is = cl.getResourceAsStream(resourceLocation)) { if (is == null) throw new FileNotFoundException(resourceLocation); if (debugXML) { System.out.println(" PointConfig URL = <" + resourceLocation + ">"); try (InputStream is2 = cl.getResourceAsStream(resourceLocation)) { System.out.println(" contents=\n" + IO.readContents(is2)); } } org.jdom2.Document doc; try { SAXBuilder builder = new SAXBuilder(false); if (debugURL) System.out.println(" PointConfig URL = <" + resourceLocation + ">"); doc = builder.build(is); } catch (JDOMException e) { throw new IOException(e.getMessage()); } if (debugXML) System.out.println(" SAXBuilder done"); if (showParsedXML) { XMLOutputter xmlOut = new XMLOutputter(); System.out.println( "*** PointConfig/showParsedXML = \n" + xmlOut.outputString(doc) + "\n*******"); } Element configElem = doc.getRootElement(); String featureType = configElem.getAttributeValue("featureType"); Element tableElem = configElem.getChild("table"); assert tableElem != null; TableConfig tc = parseTableConfig(ds, tableElem, null); tc.featureType = FeatureType.valueOf(featureType); return tc; } }