Example usage for org.jdom2 Element getAttributeValue

List of usage examples for org.jdom2 Element getAttributeValue

Introduction

In this page you can find the example usage for org.jdom2 Element getAttributeValue.

Prototype

public String getAttributeValue(final String attname) 

Source Link

Document

This returns the attribute value for the attribute with the given name and within no namespace, null if there is no such attribute, and the empty string if the attribute value is empty.

Usage

From source file:br.com.sicoob.cro.cop.util.JobXMLLoader.java

/**
 * Obtem o Objeto Writer do XML./*from w  w  w .  j  a  va  2s  .c om*/
 *
 * @param chunk Elemento que contem os dados para o writer.
 * @return um {@link AbstractItemWriter}.
 * @throws Exception para algum erro.
 */
private AbstractItemWriter getWriter(Element chunk) throws Exception {
    return (AbstractItemWriter) Class.forName(chunk.getAttributeValue(WRITER)).newInstance();
}

From source file:br.com.sicoob.cro.cop.util.JobXMLLoader.java

/**
 * Obtem o Objeto Integer do XML./*from  w  ww  . j  a  v a  2  s  . c o m*/
 *
 * @param chunk Elemento que contem os dados para o intervalo de commit.
 * @return um {@link Integer}.
 * @throws Exception para algum erro.
 */
private Integer getCommitInterval(Element chunk) throws Exception {
    if (Validation.notNull(chunk.getAttributeValue(COMMIT_INTERVAL))) {
        return Integer.valueOf(chunk.getAttributeValue(COMMIT_INTERVAL));
    }
    return null;
}

From source file:br.com.sicoob.cro.cop.util.JobXMLLoader.java

/**
 * Obtem o Objeto Tasklet do XML.//from  www .  ja  v  a  2s  . co  m
 *
 * @param tasklet Elemento que contem os dados para o tasklet.
 * @return um {@link AbstractTasklet}.
 * @throws Exception para algum erro.
 */
private AbstractTasklet getTasklet(Element tasklet) throws Exception {
    return (AbstractTasklet) Class.forName(tasklet.getAttributeValue(REF)).newInstance();
}

From source file:bureau.Services.java

public void getAdmissionsFromFile() {
    SAXBuilder builder = new SAXBuilder();
    try {//www . ja  va2  s .  c o  m
        //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.xml.AbstractReaderWriter.java

License:Open Source License

/**
 * Get a Principal object from a JDOM element.
 *
 * @param element The Principal JDOM element.
 * @return A Principal object.// ww  w .jav  a2 s  .  c  om
 * @throws ReaderException
 */
protected final Principal getPrincipal(Element element) throws ReaderException {
    if (element == null) {
        String error = "null identity element";
        throw new ReaderException(error);
    }

    if (!element.getName().equals(IDENTITY)) {
        String error = "expected identity element name, found " + element.getName();
        throw new ReaderException(error);
    }

    String type = element.getAttributeValue(TYPE);
    if (type == null) {
        String error = "type attribute not found in identity element" + element.getName();
        throw new ReaderException(error);
    }

    String identity = element.getText();
    Principal principal;
    if (type.equals(IdentityType.OPENID.getValue())) {
        principal = new OpenIdPrincipal(identity);
    } else if (type.equals(IdentityType.CADC.getValue())) {
        principal = new NumericPrincipal(UUID.fromString(identity));
    } else if (type.equals(IdentityType.USERNAME.getValue())) {
        principal = new HttpPrincipal(identity);
    } else if (type.equals(IdentityType.X500.getValue())) {
        principal = new X500Principal(identity);
    } else if (type.equals(IdentityType.ENTRY_DN.getValue())) {
        principal = new DNPrincipal(identity);
    } else {
        String error = "Unknown type attribute: " + type;
        throw new ReaderException(error);
    }

    return principal;
}

From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java

License:Open Source License

/**
 * Get a UserRequest object from a JDOM element.
 *
 * @param element The UserRequest JDOM element.
 * @return A UserRequest object.// ww w  .j  a v  a 2 s .c  om
 * @throws ReaderException
 */
protected final Group getGroup(Element element) throws ReaderException {
    String uri = element.getAttributeValue(URI);
    if (uri == null) {
        String error = "group missing required uri attribute";
        throw new ReaderException(error);
    }

    // Group owner
    User user = null;
    Element ownerElement = element.getChild(OWNER);
    if (ownerElement != null) {
        // Owner user
        Element userElement = ownerElement.getChild(USER);
        if (userElement == null) {
            String error = "owner missing required user element";
            throw new ReaderException(error);
        }
        user = getUser(userElement);
    }

    GroupURI groupURI = new GroupURI(uri);
    Group group = new Group(groupURI);

    // set owner field
    setField(group, user, OWNER);

    // description
    Element descriptionElement = element.getChild(DESCRIPTION);
    if (descriptionElement != null) {
        group.description = descriptionElement.getText();
    }

    // lastModified
    Element lastModifiedElement = element.getChild(LAST_MODIFIED);
    if (lastModifiedElement != null) {
        try {
            DateFormat df = DateUtil.getDateFormat(DateUtil.IVOA_DATE_FORMAT, DateUtil.UTC);
            group.lastModified = df.parse(lastModifiedElement.getText());
        } catch (ParseException e) {
            String error = "Unable to parse group lastModified because " + e.getMessage();

            throw new ReaderException(error);
        }
    }

    // properties
    Element propertiesElement = element.getChild(PROPERTIES);
    if (propertiesElement != null) {
        List<Element> propertyElements = propertiesElement.getChildren(PROPERTY);
        for (Element propertyElement : propertyElements) {
            group.getProperties().add(getGroupProperty(propertyElement));
        }
    }

    // groupMembers
    Element groupMembersElement = element.getChild(GROUP_MEMBERS);
    if (groupMembersElement != null) {
        List<Element> groupElements = groupMembersElement.getChildren(GROUP);
        for (Element groupMember : groupElements) {
            group.getGroupMembers().add(getGroup(groupMember));
        }
    }

    // userMembers
    Element userMembersElement = element.getChild(USER_MEMBERS);
    if (userMembersElement != null) {
        List<Element> userElements = userMembersElement.getChildren(USER);
        for (Element userMember : userElements) {
            group.getUserMembers().add(getUser(userMember));
        }
    }

    // groupAdmins
    Element groupAdminsElement = element.getChild(GROUP_ADMINS);
    if (groupAdminsElement != null) {
        List<Element> groupElements = groupAdminsElement.getChildren(GROUP);
        for (Element groupMember : groupElements) {
            group.getGroupAdmins().add(getGroup(groupMember));
        }
    }

    // userAdmins
    Element userAdminsElement = element.getChild(USER_ADMINS);
    if (userAdminsElement != null) {
        List<Element> userElements = userAdminsElement.getChildren(USER);
        for (Element userMember : userElements) {
            group.getUserAdmins().add(getUser(userMember));
        }
    }

    return group;
}

From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java

License:Open Source License

/**
 * Get a GroupProperty object from a JDOM element.
 *
 * @param element The GroupProperty JDOM element.
 * @return A GroupProperty object.//from   www.ja  v  a  2 s. c o  m
 * @throws ReaderException
 */
protected final GroupProperty getGroupProperty(Element element) throws ReaderException {
    if (element == null) {
        String error = "null property element";
        throw new ReaderException(error);
    }

    if (!element.getName().equals(PROPERTY)) {
        String error = "expected property element name, found " + element.getName();
        throw new ReaderException(error);
    }

    String key = element.getAttributeValue(KEY);
    if (key == null) {
        String error = "required key attribute not found";
        throw new ReaderException(error);
    }

    String type = element.getAttributeValue(TYPE);
    if (type == null) {
        String error = "required type attribute not found";
        throw new ReaderException(error);
    }
    Object value;
    if (type.equals(STRING)) {
        value = String.valueOf(element.getText());
    } else {
        if (type.equals(INTEGER)) {
            value = Integer.valueOf(element.getText());
        } else {
            String error = "Unsupported GroupProperty type: " + type;
            throw new ReaderException(error);
        }
    }
    Boolean readOnly = Boolean.valueOf(element.getAttributeValue(READ_ONLY));

    return new GroupProperty(key, value, readOnly);
}

From source file:ca.nrc.cadc.dali.tables.votable.VOTableReader.java

License:Open Source License

/**
 * Builds a List of Info objects from a List of INFO Elements.
 *
 * @param elements List of INFO Elements.
 * @param namespace document namespace.//from www  .  j  av a  2 s  . co  m
 * @return List of Info objects.
 */
protected List<Info> getInfos(List<Element> elements, Namespace namespace) {
    ArrayList<Info> infos = new ArrayList<Info>();
    for (Element element : elements) {
        String name = element.getAttributeValue("name");
        String value = element.getAttributeValue("value");
        if (name != null && !name.trim().isEmpty() && value != null && !value.trim().isEmpty()) {
            infos.add(new Info(name, value));
        }
    }
    return infos;
}

From source file:ca.nrc.cadc.dali.tables.votable.VOTableReader.java

License:Open Source License

/**
 * Build a List of TableParam objects from a List of PARAM Elements.
 *
 * @param elements List of PARAM Elements.
 * @param namespace document namespace./*from w ww  .  j av  a 2s  .com*/
 * @return List of TableParam objects.
 */
protected List<TableParam> getParams(List<Element> elements, Namespace namespace) {
    ArrayList<TableParam> params = new ArrayList<TableParam>();
    for (Element element : elements) {
        String datatype = element.getAttributeValue("datatype");
        if (datatype == null) {
            datatype = element.getAttributeValue("xtype");
        }
        String name = element.getAttributeValue("name");
        String value = element.getAttributeValue("value");
        TableParam tableParam = new TableParam(name, datatype, value);
        updateTableField(tableParam, element, namespace);
        params.add(tableParam);
    }
    return params;
}

From source file:ca.nrc.cadc.dali.tables.votable.VOTableReader.java

License:Open Source License

/**
 * Build a List of TableField objects from a List of FIELD Elements.
 *
 * @param elements List of FIELD Elements.
 * @param namespace document namespace.// w  w w  .java2 s  .c o m
 * @return List of TableField objects.
 */
protected List<TableField> getFields(List<Element> elements, Namespace namespace) {
    ArrayList<TableField> fields = new ArrayList<TableField>();
    for (Element element : elements) {
        String datatype = element.getAttributeValue("datatype");
        if (datatype == null) {
            datatype = element.getAttributeValue("xtype");
        }
        String name = element.getAttributeValue("name");
        TableField tableField = new TableField(name, datatype);
        updateTableField(tableField, element, namespace);
        fields.add(tableField);
    }
    return fields;
}