Example usage for org.dom4j Element attributeValue

List of usage examples for org.dom4j Element attributeValue

Introduction

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

Prototype

String attributeValue(QName qName);

Source Link

Document

This returns the attribute value for the attribute with the given fully qualified name or null if there is no such attribute or the empty string if the attribute value is empty.

Usage

From source file:com.globalsight.terminology.ImportOptions.java

License:Apache License

/**
 * Reads and validates a ImportOptions XML string.
 *
 * Xml Format:/*w w  w .java 2  s .  c  o  m*/
 */
private void init(String p_options) throws TermbaseException {
    XmlParser parser = null;
    Document dom;

    try {
        parser = XmlParser.hire();
        dom = parser.parseXml(p_options);
    } finally {
        XmlParser.fire(parser);
    }

    try {
        Element root = dom.getRootElement();

        Element elem = (Element) root.selectSingleNode("/importOptions/fileOptions");

        m_fileOptions.m_name = elem.elementText("fileName");
        m_fileOptions.m_type = elem.elementText("fileType");
        m_fileOptions.m_encoding = elem.elementText("fileEncoding");
        m_fileOptions.m_separator = elem.elementText("separator");
        m_fileOptions.m_ignoreHeader = elem.elementText("ignoreHeader");
        m_fileOptions.m_entryCount = elem.elementText("entryCount");
        m_fileOptions.m_status = elem.elementText("status");
        m_fileOptions.m_errorMessage = elem.elementText("errorMessage");

        List columns = root.selectNodes("/importOptions/columnOptions/column");
        for (int i = 0; i < columns.size(); ++i) {
            Element col = (Element) columns.get(i);
            ColumnDescriptor desc = new ColumnDescriptor();

            desc.m_position = Integer.parseInt(col.attributeValue("id"));
            desc.m_name = col.elementText("name");
            desc.m_example = col.elementText("example");
            desc.m_type = col.elementText("type");
            desc.m_termLanguage = col.elementText("termLanguage");
            desc.m_encoding = col.elementText("encoding");
            desc.m_associatedColumn = col.elementText("associatedColumn");

            m_columns.add(desc);
        }

        elem = (Element) root.selectSingleNode("/importOptions/syncOptions");

        m_syncOptions.m_syncMode = elem.elementText("syncMode");
        m_syncOptions.m_syncLanguage = elem.elementText("syncLanguage");
        m_syncOptions.m_syncAction = elem.elementText("syncAction");
    } catch (Exception e) {
        // cast exception and throw
        error(e.getMessage(), e);
    }
}

From source file:com.globalsight.terminology.indexer.Writer.java

License:Apache License

private void getIndexableText(Element p_root, ArrayList p_result) {
    if (p_root == null || p_root.nodeCount() == 0) {
        return;//www.  j  ava 2  s .c o  m
    }

    List elements = p_root.elements();

    for (int i = 0, max = elements.size(); i < max; i++) {
        Element elem = (Element) elements.get(i);
        String name = elem.getName();

        Element field = null;
        String type = null;

        if (name.equals("descripGrp")) {
            getIndexableText(elem, p_result);
        } else if (name.equals("sourceGrp")) {
            getIndexableText(elem, p_result);
        } else if (name.equals("noteGrp")) {
            getIndexableText(elem, p_result);
        } else if (name.equals("descrip")) {
            field = elem;
            type = field.attributeValue("type");
        } else if (name.equals("source")) {
            field = elem;
            type = "source";
        } else if (name.equals("note")) {
            field = elem;
            type = "note";
        }

        if (field == null || type == null) {
            continue;
        }

        if (isIndexableField(type)) {
            p_result.add(EntryUtils.getInnerText(field));
        }
    }
}