Example usage for org.dom4j Element attribute

List of usage examples for org.dom4j Element attribute

Introduction

In this page you can find the example usage for org.dom4j Element attribute.

Prototype

Attribute attribute(QName qName);

Source Link

Document

DOCUMENT ME!

Usage

From source file:edu.wustl.cab2b.server.multimodelcategory.MultiModelCategoryXmlParser.java

License:BSD License

Collection<MultiModelAttributeBean> populateMMCAttribs(List<Element> attributes) {
    Collection<MultiModelAttributeBean> mmcAttribs = new ArrayList<MultiModelAttributeBean>();
    for (Element a : attributes) {
        MultiModelAttributeBean multiModelCategoryAttribute = new MultiModelAttributeBean();

        String mmcAttribName = a.attribute("name").getValue();
        multiModelCategoryAttribute.setName(mmcAttribName);

        String mmcAttribDesc = a.attribute("description").getValue();
        multiModelCategoryAttribute.setDescription(mmcAttribDesc);

        Collection<AttributeInterface> mappedClassAttributes = new ArrayList<AttributeInterface>();
        List<Element> mappedClasseAttribs = a.elements();
        for (Element mappedClassAttrib : mappedClasseAttribs) {
            String entityGroupName = mappedClassAttrib.attribute("model").getValue();
            EntityGroupInterface entityGroup = EntityCache.getInstance().getEntityGroupByName(entityGroupName);

            String entityName = mappedClassAttrib.attribute("class").getValue();
            EntityInterface entity = entityGroup.getEntityByName(entityName);

            Collection<AttributeInterface> attribs = entity.getAllAttributes();

            String attribName = mappedClassAttrib.attribute("name").getValue();
            for (AttributeInterface ai : attribs) {
                if (attribName.equals(ai.getName())) {
                    mappedClassAttributes.add(ai);
                    break;
                }/*from   w w w. jav a 2s . co  m*/
            }
        }
        multiModelCategoryAttribute.setSelectedAttributes(mappedClassAttributes);
        mmcAttribs.add(multiModelCategoryAttribute);
    }
    return mmcAttribs;
}

From source file:edu.wustl.cab2b.server.multimodelcategory.MultiModelCategoryXmlParser.java

License:BSD License

Collection<IPath> populateMMCPaths(List<Element> paths) {
    Collection<IPath> iPaths = new ArrayList<IPath>();
    for (Element path : paths) {
        IPath iPath = PathFinder.getInstance().getPathById(Long.parseLong(path.attribute("id").getValue()));
        iPaths.add(iPath);/*from   w ww.  j a v  a2 s. c  om*/
    }
    return iPaths;
}

From source file:eu.sisob.uma.crawler.ResearchersCrawlers.Reporting.ReportingUtils.java

License:Open Source License

public static void extractExpressionFromCSVID(String xmlfile, String csvfile, String outfile) throws Exception {
    org.dom4j.io.SAXReader reader = new org.dom4j.io.SAXReader();
    org.dom4j.Document document = reader.read(xmlfile);
    org.dom4j.Element root = document.getRootElement();

    CSVReader csvreader = new CSVReader(new FileReader(csvfile), ';');
    HashMap<String, List<String>> hm = new HashMap<String, List<String>>();
    String[] nextLine;/* w  w  w  .j av  a2 s .c om*/
    while ((nextLine = csvreader.readNext()) != null) {
        hm.put(nextLine[0], new ArrayList<String>());
    }

    for (Iterator i1 = root.elementIterator("blockinfo"); i1.hasNext();) {
        org.dom4j.Element e1 = (org.dom4j.Element) i1.next();

        String id = e1.attribute("id_entity").getValue();
        //if(!id.equals("786643")) continue;
        List<String> al = hm.get(id);
        if (al == null)
            continue;
        int PA = 0, AS = 0;
        if (al.size() != 0) {
            int last = al.size() - 1;
            String[] ss = al.get(last).split("\t");
            PA = Integer.parseInt(ss[0]);
            AS = Integer.parseInt(ss[1]);
            al.remove(last);
        }

        for (Object obj : e1.elements()) {
            org.dom4j.Element exp = (org.dom4j.Element) obj;

            String aux_content = exp.element("Content").getText().replace("\n", " ").replace("\r\n", " ");
            if (!al.contains(exp.getName() + "\t\t" + aux_content + "\r\n")) {
                if (exp.getName().contains("Activity"))
                    PA++;
                if (exp.getName().contains("Studies"))
                    AS++;
                al.add(exp.getName() + "\t\t" + aux_content + "\r\n");
            }

        }
        //content += "\tPA: " + PA + " AS: " + AS + "\r\n";
        al.add(PA + "\t" + AS);
        hm.put(id, al);
    }

    csvreader = new CSVReader(new FileReader(csvfile), ';');

    while ((nextLine = csvreader.readNext()) != null) {
        String key = nextLine[0];
        //System.out.println("ID: " + key + " " + hm.get(key));
        List<String> al = hm.get(key);
        int size = al.size();
        System.out.println(key + "\t" + (size != 0 ? al.get(size - 1) : ""));
        //for(String s : hm.get(key))
        //  System.out.println(s);
    }

}

From source file:eu.sisob.uma.crawler.ResearchersCrawlers.Reporting.ReportingUtils.java

License:Open Source License

public static void extractExpressions(String xmlfile, String csvfile, String outfile) throws Exception {
    org.dom4j.io.SAXReader reader = new org.dom4j.io.SAXReader();
    org.dom4j.Document document = reader.read(xmlfile);
    org.dom4j.Element root = document.getRootElement();

    CSVReader csvreader = new CSVReader(new FileReader(csvfile), ';');
    HashMap<String, String> hm = new HashMap<String, String>();
    String[] nextLine;//from  w  ww . j  av a 2  s  .  c om
    while ((nextLine = csvreader.readNext()) != null) {
        //hm.put(nextLine[0], "");
    }

    for (Iterator i1 = root.elementIterator("blockinfo"); i1.hasNext();) {
        org.dom4j.Element e1 = (org.dom4j.Element) i1.next();

        String id = e1.attribute("id_entity").getValue();
        //if(!id.equals("786643")) continue;

        int PA = 0, AS = 0;

        for (Object obj : e1.elements()) {
            org.dom4j.Element exp = (org.dom4j.Element) obj;

            if (exp.getName().contains("Activity")) {
                hm.put(exp.element("Title_name").getText(), "");
            }
        }

    }

    csvreader = new CSVReader(new FileReader(csvfile), ';');

    for (String key : hm.keySet()) {
        System.out.println(key);
    }

}

From source file:fr.gouv.culture.vitam.command.VitamCommand.java

License:Open Source License

public static void checkFilesType() {
    File fic = new File(FILEarg);
    if (!fic.exists()) {
        System.err.println(StaticValues.LBL.error_filenotfile.get() + ": " + FILEarg);
        return;/*from   ww w. j a va2  s.c o  m*/
    } else {
        System.out.println("\n" + StaticValues.LBL.tools_dir_format_output.get() + "\n");
        Document global = null;
        Element root = null;
        XMLWriter writer = null;
        try {
            writer = new XMLWriter(outputStream, StaticValues.defaultOutputFormat);
        } catch (UnsupportedEncodingException e1) {
            System.err.println(StaticValues.LBL.error_writer.get() + ": " + e1.toString());
            return;
        }
        if (StaticValues.config.argument.outputModel == VitamOutputModel.OneXML) {
            root = XmlDom.factory.createElement("checkfiles");
            root.addAttribute("source", FILEarg);
            global = XmlDom.factory.createDocument(root);
            EmlExtract.filEmls.clear();
        }
        if (showFormat) {
            if (StaticValues.config.droidHandler == null && StaticValues.config.exif == null
                    && StaticValues.config.jhove == null) {
                System.err.println(StaticValues.LBL.error_initfits.get());
                return;
            }
            try {
                List<File> files = DroidHandler.matchedFiled(new File[] { fic }, extensions,
                        StaticValues.config.argument.recursive);
                for (File file : files) {
                    String shortname;
                    if (fic.isDirectory()) {
                        shortname = StaticValues.getSubPath(file, fic);
                    } else {
                        shortname = FILEarg;
                    }
                    Element result = Commands.showFormat(shortname, null, null, file, StaticValues.config,
                            StaticValues.config.argument);
                    XmlDom.addDate(StaticValues.config.argument, StaticValues.config, result);
                    if (root != null) {
                        root.add(result);
                    } else {
                        writer.write(result);
                        System.out.println("\n========================================================");
                    }
                }
            } catch (CommandExecutionException e) {
                System.err.println(StaticValues.LBL.error_analysis.get() + e);
                e.printStackTrace();
            } catch (IOException e) {
                System.err.println(StaticValues.LBL.error_analysis.get() + e);
            }
        } else {
            if (StaticValues.config.droidHandler == null) {
                System.err.println(StaticValues.LBL.error_initdroid.get());
                return;
            }
            if (root != null) {
                Element newElt = XmlDom.factory.createElement("toolsversion");
                if (StaticValues.config.droidHandler != null) {
                    newElt.addAttribute("pronom", StaticValues.config.droidHandler.getVersionSignature());
                }
                if (StaticValues.config.droidHandler != null) {
                    newElt.addAttribute("droid", "6.1");
                }
                root.add(newElt);
            }
            List<DroidFileFormat> list;
            try {
                VitamArgument argument = new VitamArgument(StaticValues.config.argument.archive,
                        StaticValues.config.argument.recursive, true, true, true,
                        StaticValues.config.argument.outputModel, StaticValues.config.argument.checkSubFormat,
                        StaticValues.config.argument.extractKeyword);
                List<File> files = DroidHandler.matchedFiled(new File[] { fic }, extensions,
                        argument.recursive);
                list = StaticValues.config.droidHandler.checkFilesFormat(files, argument, null);
                String pathBeforeArg = fic.getCanonicalPath();
                pathBeforeArg = pathBeforeArg.substring(0, pathBeforeArg.indexOf(FILEarg));
                for (DroidFileFormat droidFileFormat : list) {
                    Element fileformat = droidFileFormat.toElement(true);
                    Attribute filename = fileformat.attribute("filename");
                    if (filename != null) {
                        String value = filename.getText();
                        filename.setText(value.replace(pathBeforeArg, ""));
                    }
                    XmlDom.addDate(StaticValues.config.argument, StaticValues.config, fileformat);
                    if (root != null) {
                        root.add(fileformat);
                    } else {
                        writer.write(fileformat);
                        System.out.println("\n========================================================");
                    }
                }
            } catch (CommandExecutionException e) {
                System.err.println(StaticValues.LBL.error_analysis.get() + e);
                e.printStackTrace();
            } catch (UnsupportedEncodingException e) {
                System.err.println(StaticValues.LBL.error_analysis.get() + e);
            } catch (IOException e) {
                System.err.println(StaticValues.LBL.error_analysis.get() + e);
            }
        }
        if (global != null) {
            XmlDom.addDate(StaticValues.config.argument, StaticValues.config, root);
            if (!EmlExtract.filEmls.isEmpty()) {
                Element sortEml = XmlDom.factory.createElement("emlsort");
                for (String parent : EmlExtract.filEmls.keySet()) {
                    Element eparent = XmlDom.factory.createElement("parent");
                    String fil = EmlExtract.filEmls.get(parent);
                    eparent.addAttribute("messageId", parent);
                    String[] fils = fil.split(",");
                    for (String mesg : fils) {
                        if (mesg != null && mesg.length() > 1) {
                            Element elt = XmlDom.factory.createElement("descendant");
                            elt.addAttribute("messageId", mesg);
                            eparent.add(elt);
                        }
                    }
                    sortEml.add(eparent);
                }
                root.add(sortEml);
            }
            try {
                writer.write(global);
            } catch (IOException e) {
                System.err.println(StaticValues.LBL.error_analysis.get() + e);
            }
        }
    }
}

From source file:fr.gouv.culture.vitam.gui.VitamGui.java

License:Open Source License

/**
 * Check a directory only against type/*from  w w w.  j  a v  a 2  s  . c o m*/
 * 
 * @param task
 */
private void oneDirOrFileCheck(RunnerLongTask task) {
    List<File> files = filesToScan;
    filesToScan = null;
    try {
        config.initDroid();
        vitamResult = null;
    } catch (CommandExecutionException e) {
        System.err.println(StaticValues.LBL.error_initdroid.get() + e.toString());
        vitamResult = null;
        return;
    }
    System.out.println("Check File Type");
    Element root = null;
    vitamResult = new VitamResult();
    if (config.argument.outputModel == VitamOutputModel.OneXML) {
        root = XmlDom.factory.createElement("checkfiles");
        root.addAttribute("source", config.lastScannedDirectory.getAbsolutePath());
        vitamResult.unique = XmlDom.factory.createDocument(root);
        Element newElt = XmlDom.factory.createElement("toolsversion");
        if (StaticValues.config.droidHandler != null) {
            newElt.addAttribute("pronom", StaticValues.config.droidHandler.getVersionSignature());
        }
        if (StaticValues.config.droidHandler != null) {
            newElt.addAttribute("droid", "6.1");
        }
        root.add(newElt);
    } else {
        // force multiple
        vitamResult.multiples = new ArrayList<Document>();
    }
    List<DroidFileFormat> list = null;
    int warning = 0;
    try {
        list = config.droidHandler.checkFilesFormat(files, config.argument, task);
        String pathBeforeArg = config.lastScannedDirectory.getCanonicalPath();
        pathBeforeArg = pathBeforeArg.substring(0,
                pathBeforeArg.indexOf(config.lastScannedDirectory.getName()));
        for (DroidFileFormat droidFileFormat : list) {
            boolean warn = false;
            Element fileformat = droidFileFormat.toElement(true);
            if (config.preventXfmt && droidFileFormat.getPUID().startsWith(StaticValues.FORMAT_XFMT)) {
                warning++;
                warn = true;
            }
            Attribute filename = fileformat.attribute("filename");
            if (filename != null) {
                String value = filename.getText();
                filename.setText(value.replace(pathBeforeArg, ""));
            }
            XmlDom.addDate(config.argument, config, fileformat);
            if (root != null) {
                root.add(fileformat);
            } else {
                // multiple
                root = XmlDom.factory.createElement("checkfiles");
                root.addAttribute("source", config.lastScannedDirectory.getAbsolutePath());
                Document document = XmlDom.factory.createDocument(root);
                root.add(fileformat);
                if (warn) {
                    root.addAttribute("status", "warning");
                } else {
                    root.addAttribute("status", "ok");
                }
                vitamResult.multiples.add(document);
                root = null;
            }
        }
    } catch (CommandExecutionException e) {
        System.err.println(StaticValues.LBL.error_analysis.get() + e);
        e.printStackTrace();
        vitamResult = null;
    } catch (IOException e) {
        System.err.println(StaticValues.LBL.error_analysis.get() + e);
        vitamResult = null;
    }
    if (root != null) {
        XmlDom.addDate(config.argument, config, root);
        if (warning > 0) {
            root.addAttribute("status", "warning");
        } else {
            root.addAttribute("status", "ok");
        }
    }
    if (list != null) {
        texteOut.insertIcon(new ImageIcon(getClass().getResource(RESOURCES_IMG_VALID_PNG)));
        System.out.println(StaticValues.LBL.action_format.get() + " [ " + list.size() + " / " + files.size()
                + (warning > 0 ? " (" + StaticValues.LBL.error_warning.get() + warning + " )" : "") + " ]");
    }
}

From source file:freemarker.ext.xml._Dom4jNavigator.java

License:Apache License

void getAttributes(Object node, String localName, String namespaceUri, List result) {
    if (node instanceof Element) {
        Element e = (Element) node;
        if (localName == null) {
            result.addAll(e.attributes());
        } else {//from ww w  .j  a  v  a  2  s  .  c o  m
            Attribute attr = e
                    .attribute(e.getQName().getDocumentFactory().createQName(localName, "", namespaceUri));
            if (attr != null) {
                result.add(attr);
            }
        }
    } else if (node instanceof ProcessingInstruction) {
        ProcessingInstruction pi = (ProcessingInstruction) node;
        if ("target".equals(localName)) {
            result.add(new DefaultAttribute("target", pi.getTarget()));
        } else if ("data".equals(localName)) {
            result.add(new DefaultAttribute("data", pi.getText()));
        } else {
            result.add(new DefaultAttribute(localName, pi.getValue(localName)));
        }
    } else if (node instanceof DocumentType) {
        DocumentType doctype = (DocumentType) node;
        if ("publicId".equals(localName)) {
            result.add(new DefaultAttribute("publicId", doctype.getPublicID()));
        } else if ("systemId".equals(localName)) {
            result.add(new DefaultAttribute("systemId", doctype.getSystemID()));
        } else if ("elementName".equals(localName)) {
            result.add(new DefaultAttribute("elementName", doctype.getElementName()));
        }
    }
}

From source file:galign.helpers.tmx.TmxHeader.java

License:Apache License

private void init(Element p_element) {
    Attribute attr;//w  w w  . j  av  a  2  s .  com
    List nodes;
    Date date;

    // mandatory

    m_creationtoolversion = p_element.attributeValue(CREATIONTOOLVERSION);
    m_creationtool = p_element.attributeValue(CREATIONTOOL);
    m_segtype = p_element.attributeValue(SEGTYPE);
    m_o_tmf = p_element.attributeValue(O_TMF);
    m_adminlang = p_element.attributeValue(ADMINLANG);
    m_srclang = p_element.attributeValue(SRCLANG);
    m_datatype = p_element.attributeValue(DATATYPE);

    // optional

    m_o_encoding = p_element.attributeValue(O_ENCODING);
    m_creationid = p_element.attributeValue(CREATIONID);
    m_changeid = p_element.attributeValue(CHANGEID);

    attr = p_element.attribute(CREATIONDATE);
    if (attr == null) {
        date = null;
    } else {
        date = UTC.parseNoSeparators(attr.getValue());
        if (date == null) {
            date = UTC.parse(attr.getValue());
        }
    }
    m_creationdate = date;

    attr = p_element.attribute(CHANGEDATE);
    if (attr == null) {
        date = null;
    } else {
        date = UTC.parseNoSeparators(attr.getValue());
        if (date == null) {
            date = UTC.parse(attr.getValue());
        }
    }
    m_changedate = date;

    // elements

    for (Iterator i = p_element.elementIterator("note"); i.hasNext();) {
        Element node = (Element) i.next();

        m_notes.add(new Note(node));
    }

    for (Iterator i = p_element.elementIterator("prop"); i.hasNext();) {
        Element node = (Element) i.next();

        m_props.add(new Prop(node));
    }

    // TODO: UDE
}

From source file:gestionecassa.backends.XmlDataBackend.java

License:Open Source License

@Override
public Collection<ArticleGroup> loadArticlesList() throws IOException {
    Collection<ArticleGroup> output = new LinkedList<ArticleGroup>();

    SAXReader reader = new SAXReader();
    Document document;//w w w.  j ava 2s.c  o  m
    try {
        document = reader.read(ArtListFile);
    } catch (DocumentException ex) {
        logger.warn("Error while reading/parsing the file", ex);
        throw new IOException("I was not able to read/parse the file", ex);
    }

    Element root = document.getRootElement();

    for (Object gr : root.elements("group")) {
        Element tempRefGroup = (Element) gr;

        String g_name = tempRefGroup.element("name").getText();
        int g_id = new Integer(tempRefGroup.element("id").getText()).intValue();

        Collection<Article> tempList = new LinkedList<Article>();
        for (Object art : tempRefGroup.elements("article")) {
            Element tempRefArt = (Element) art;

            String name = tempRefArt.element("name").getText();
            double price = new Double(tempRefArt.element("price").getText()).doubleValue();
            int id = new Integer(tempRefArt.element("id").getText()).intValue();

            Article article;
            if (tempRefArt.attribute("options").getValue().equals("true")) {

                List<ArticleOption> opts = new LinkedList<ArticleOption>();
                int idOpt = 0;
                for (Object opt : tempRefArt.element("options").elements("option")) {
                    opts.add(new ArticleOption(idOpt++, ((Element) opt).getText(), true));
                }

                article = new Article(id, name, price, true, opts);
            } else {
                article = new Article(id, name, price);
            }
            tempList.add(article);
        }
        output.add(new ArticleGroup(g_id, g_name, true, tempList));
    }

    return output;
}

From source file:gov.abrs.etms.tag.ProcessImageTag.java

License:Open Source License

private int[] extractBoxConstraint(Element root) {
    int[] result = new int[4];
    try {//from w ww  . j av a2s. com
        String nodeName = currentToken.getNode().getName();
        XPath xPath = new DefaultXPath("//node[@name='" + nodeName + "']");
        Element node = (Element) xPath.selectSingleNode(root);
        result[0] = Integer.valueOf(node.attribute("x").getValue()).intValue();
        result[1] = Integer.valueOf(node.attribute("y").getValue()).intValue();
        result[2] = Integer.valueOf(node.attribute("width").getValue()).intValue();
        result[3] = Integer.valueOf(node.attribute("height").getValue()).intValue();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}