List of usage examples for org.jdom2 Document getRootElement
public Element getRootElement()
Element
for this Document
From source file:br.com.sicoob.cro.cop.util.JobXMLLoader.java
/** * Le o arquivo {@code jobXMLName} e cria os objetos para o processamento. * * @throws BatchStartException para algum erro de leitura e inicializacao. *///w w w. j av a 2 s . c o m public void loadJSL() throws BatchStartException { try { ClassLoader tccl = Thread.currentThread().getContextClassLoader(); InputStream inputStream = tccl.getResourceAsStream(PREFIX.concat(this.jobXMlName.concat(XML_SUFFIX))); if (Validation.isNull(inputStream)) { throw new BatchStartException( BatchPropertiesUtil.getInstance().getMessage(FILENOTFOUND, this.jobXMlName)); } SAXBuilder builder = new SAXBuilder(); Document document = (Document) builder.build(inputStream); Element rootNode = document.getRootElement(); this.job = new Job(rootNode.getAttributeValue(ID), Job.Mode.ASYNC); loadSteps(rootNode); // valida se o job pode est completo if (Validation.notNull(this.job.getId()) && Validation.notNull(this.job.getSteps()) && this.job.getSteps().size() > 0) { LOG.info(BatchPropertiesUtil.getInstance().getMessage(BatchKeys.BATCH_LOADER_SUCCESS.getKey(), this.job.getId())); } else { throw new BatchStartException(BatchPropertiesUtil.getInstance() .getMessage(BatchKeys.BATCH_LOADER_FAIL.getKey(), this.job.getId())); } } catch (Exception excecao) { LOG.fatal(excecao); throw new BatchStartException(excecao); } }
From source file:bureau.Services.java
public void getAdmissionsFromFile() { SAXBuilder builder = new SAXBuilder(); try {/*from ww w . ja v a2s . com*/ //on liste et on parcours les fichiers pour trouver les .xml qui sont en ajout et en edit File repertoire = new File("\\\\172.18.8.70\\temp\\PP_PAT_IN");// \\\\178.18.8.70\\temp System.out.println("new file"); String[] listefichiers; int i; System.out.println("int i string liste fichier"); listefichiers = repertoire.list(); System.out.println("repertoire.list()"); for (i = 0; i < listefichiers.length; i++) { System.out.println("dans la boucle"); //si le fichier est en ajout if (listefichiers[i].startsWith("new")) { System.out.println("fichier new trouv"); Document doc = builder.build("" + repertoire + "\\" + listefichiers[i]); Element root = doc.getRootElement(); Element admissionXML = root; int type = 1; int ipp; int iep; ipp = parseInt(admissionXML.getChild("patient").getAttributeValue("ipp")); iep = parseInt(admissionXML.getAttributeValue("iep")); if (admissionXML.getChild("type").getText().startsWith("c")) type = 3; if (admissionXML.getChild("type").getText().startsWith("h")) type = 1; if (admissionXML.getChild("type").getText().startsWith("u")) type = 2; newAdmission(ipp, type, iep); System.out.println("nouvelle admission ajoute"); } if (listefichiers[i].startsWith("update")) { System.out.println("fichier en update trouv"); Document doc = builder.build("" + repertoire + "\\" + listefichiers[i]); Element root = doc.getRootElement(); Element admissionXML = root; int type = 1; int iep = parseInt(admissionXML.getAttributeValue("iep")); if (admissionXML.getChild("type").getText().startsWith("c")) type = 3; if (admissionXML.getChild("type").getText().startsWith("h")) type = 1; if (admissionXML.getChild("type").getText().startsWith("u")) type = 2; if (getAdmissionByIep(iep) == null) { System.out.println("Il n'y a pas d'admission avec cet IEP"); } else { Admission ad = getAdmissionByIep(iep); ad.setType(type); editAdmission(ad); System.out.println("admission modifie"); } String date_sortie = admissionXML.getChild("date_sortie").getValue(); DateFormat format = new SimpleDateFormat("YYYY-MM-DD", Locale.ENGLISH); Date date_s = format.parse(date_sortie); String date_entree = admissionXML.getChild("date_sortie").getValue(); Date date_e = format.parse(date_entree); List<Mouvement> listemouv = getMouvementByIep(iep); if (listemouv != null) { Mouvement mouv = listemouv.get(listemouv.size()); updateMouvement(mouv, mouv.getAdmission(), mouv.getLit(), mouv.getUf(), date_e, date_s); } else { System.out.println("pas de mouvement pour cette admission"); } } if (listefichiers[i].startsWith("mouv")) { System.out.println("fichier new trouv"); Document doc = builder.build("" + repertoire + "\\" + listefichiers[i]); Element root = doc.getRootElement(); Element mouvementXML = root; String service = "Cardiologie"; int ipp; int iep; Lit lit = new Lit(); String date_entree = mouvementXML.getChild("date_entree").getValue(); DateFormat format = new SimpleDateFormat("YYYY-MM-DD", Locale.ENGLISH); Date date = format.parse(date_entree); ipp = parseInt(mouvementXML.getChild("ipp").getValue()); iep = parseInt(mouvementXML.getChild("iep").getValue()); if (mouvementXML.getChild("service").getText().endsWith("2")) service = "Radio 2"; if (mouvementXML.getChild("service").getText().endsWith("1")) service = "Radio 1"; List<Lit> liste_lits = getLitByUF(service); for (Lit buff_lit : liste_lits) { if (!buff_lit.getOccupe()) { lit = buff_lit; } } newMouvement(getAdmissionByIep(iep), lit, getUniteFontionnelleByNom(service), date); System.out.println("nouvelle admission ajoute"); } } } catch (Exception e) { System.out.println("Erreur de lecture du fichier d'admission"); } }
From source file:ca.nrc.cadc.ac.json.JsonGroupReader.java
License:Open Source License
/** * Construct a Group from a Reader.// w w w.j a va2s. c o m * * @param reader Reader. * @return Group Group. * @throws ReaderException * @throws IOException */ @Override public Group read(Reader reader) throws ReaderException, IOException { if (reader == null) { throw new IllegalArgumentException("reader must not be null"); } Scanner s = new Scanner(reader).useDelimiter("\\A"); String json = s.hasNext() ? s.next() : ""; try { JsonInputter jsonInputter = new JsonInputter(); Document document = jsonInputter.input(json); return getGroup(document.getRootElement()); } catch (JSONException e) { String error = "Unable to parse JSON to Group because " + e.getMessage(); throw new ReaderException(error, e); } }
From source file:ca.nrc.cadc.ac.json.JsonUserListReader.java
License:Open Source License
/** * Construct a list of Users from a Reader. * * @param reader Reader./*from w w w. ja va 2 s. co m*/ * @return users List of Users. * @throws ReaderException */ @Override public List<User> read(Reader reader) throws ReaderException { if (reader == null) { throw new IllegalArgumentException("reader must not be null"); } Scanner s = new Scanner(reader).useDelimiter("\\A"); String json = s.hasNext() ? s.next() : ""; try { JsonInputter jsonInputter = new JsonInputter(); Document document = jsonInputter.input(json); return getUserList(document.getRootElement()); } catch (JSONException e) { String error = "Unable to parse JSON to list of Users because " + e.getMessage(); throw new ReaderException(error, e); } }
From source file:ca.nrc.cadc.ac.json.JsonUserReader.java
License:Open Source License
/** * Construct a User from a Reader./*from w ww . j a v a 2s . c o m*/ * * @param reader Reader. * @return User User. * @throws ReaderException * @throws IOException */ @Override public User read(Reader reader) throws ReaderException, IOException { if (reader == null) { throw new IllegalArgumentException("reader must not be null"); } Scanner s = new Scanner(reader).useDelimiter("\\A"); String json = s.hasNext() ? s.next() : ""; try { JsonInputter jsonInputter = new JsonInputter(); Document document = jsonInputter.input(json); return getUser(document.getRootElement()); } catch (JSONException e) { String error = "Unable to parse JSON to User because " + e.getMessage(); throw new ReaderException(error, e); } }
From source file:ca.nrc.cadc.ac.json.JsonUserRequestReader.java
License:Open Source License
/** * Construct a User from a Reader.//from ww w .j av a 2s. co m * * @param reader Reader. * @return User User. * @throws ReaderException * @throws IOException */ @Override public UserRequest read(Reader reader) throws ReaderException, IOException { if (reader == null) { throw new IllegalArgumentException("reader must not be null"); } Scanner s = new Scanner(reader).useDelimiter("\\A"); String json = s.hasNext() ? s.next() : ""; try { JsonInputter jsonInputter = new JsonInputter(); Document document = jsonInputter.input(json); return getUserRequest(document.getRootElement()); } catch (JSONException e) { String error = "Unable to parse JSON to User because " + e.getMessage(); throw new ReaderException(error, e); } }
From source file:ca.nrc.cadc.ac.xml.GroupListReader.java
License:Open Source License
/** * Construct a List of Group's from a Reader. * //from ww w .j a v a 2s . c o m * @param reader Reader. * @return Groups List of Group. * @throws ReaderException * @throws java.io.IOException * @throws java.net.URISyntaxException */ public List<Group> read(Reader reader) throws ReaderException, IOException, URISyntaxException { if (reader == null) { throw new IllegalArgumentException("reader must not be null"); } Document document; try { document = XmlUtil.buildDocument(reader); } catch (JDOMException jde) { String error = "XML failed validation: " + jde.getMessage(); throw new ReaderException(error, jde); } Element root = document.getRootElement(); String groupElemName = root.getName(); if (!groupElemName.equalsIgnoreCase(GROUPS)) { String error = "Expected groups element, found " + groupElemName; throw new ReaderException(error); } return getGroupList(root); }
From source file:ca.nrc.cadc.ac.xml.GroupReader.java
License:Open Source License
/** * Construct a Group from a Reader.// w w w . ja v a 2 s. co m * * @param reader Reader. * @return Group Group. * @throws ReaderException * @throws java.io.IOException */ public Group read(Reader reader) throws ReaderException, IOException { if (reader == null) { throw new IllegalArgumentException("reader must not be null"); } Document document; try { document = XmlUtil.buildDocument(reader); } catch (JDOMException jde) { String error = "XML failed validation: " + jde.getMessage(); throw new ReaderException(error, jde); } Element root = document.getRootElement(); String groupElemName = root.getName(); if (!groupElemName.equalsIgnoreCase(GROUP)) { String error = "Expected group element, found " + groupElemName; throw new ReaderException(error); } return getGroup(root); }
From source file:ca.nrc.cadc.ac.xml.UserListReader.java
License:Open Source License
/** * Construct a List of Users from a Reader. * * @param reader Reader./*from w ww . java 2s . c o m*/ * @return List of Users. * @throws ReaderException * @throws java.io.IOException */ public List<User> read(Reader reader) throws ReaderException, IOException { if (reader == null) { throw new IllegalArgumentException("reader must not be null"); } Document document; try { document = XmlUtil.buildDocument(reader); } catch (JDOMException jde) { String error = "XML failed validation: " + jde.getMessage(); throw new ReaderException(error, jde); } Element root = document.getRootElement(); String userElemName = root.getName(); if (!userElemName.equalsIgnoreCase(USERS)) { String error = "Expected users element, found " + userElemName; throw new ReaderException(error); } return getUserList(root); }
From source file:ca.nrc.cadc.ac.xml.UserReader.java
License:Open Source License
/** * Construct a User from a Reader.//from w w w . ja v a2s. c o m * * @param reader Reader. * @return User User. * @throws ReaderException * @throws java.io.IOException */ public User read(Reader reader) throws ReaderException, IOException { if (reader == null) { throw new IllegalArgumentException("reader must not be null"); } // Create a JDOM Document from the XML Document document; try { document = XmlUtil.buildDocument(reader); } catch (JDOMException jde) { String error = "XML failed validation: " + jde.getMessage(); throw new ReaderException(error, jde); } // Root element and namespace of the Document Element root = document.getRootElement(); return getUser(root); }