Example usage for org.dom4j Attribute getValue

List of usage examples for org.dom4j Attribute getValue

Introduction

In this page you can find the example usage for org.dom4j Attribute getValue.

Prototype

String getValue();

Source Link

Document

Returns the value of the attribute.

Usage

From source file:com.globalsight.everest.edit.offline.ttx.TTXParser.java

License:Apache License

private boolean isLockedSegment(Node p_node) {
    boolean result = false;
    if (p_node == null) {
        return false;
    }//  w ww  . j av  a 2 s .c  o  m

    Element parentNode = p_node.getParent();
    if (parentNode != null) {
        // In Tuv.
        String nodeName = parentNode.getName();
        if ("ut".equalsIgnoreCase(nodeName)) {
            Attribute attt = parentNode.attribute(TTXConstants.UT_ATT_DISPLAYTEXT);
            if (attt != null) {
                String attValue = attt.getValue();
                result = TTXConstants.GS_LOCKED_SEGMENT.equalsIgnoreCase(attValue);
            }
        }
    }

    return result;
}

From source file:com.globalsight.everest.tm.exporter.TmxChecker.java

License:Apache License

@SuppressWarnings({ "unchecked", "rawtypes" })
public String fixSegment(String segment) {
    Document dom = getDom(segment);
    Element root = dom.getRootElement();

    Iterator ite = dtdMap.entrySet().iterator();
    while (ite.hasNext()) {
        Map.Entry entry = (Map.Entry) ite.next();
        String key = (String) entry.getKey();
        ArrayList array = (ArrayList) entry.getValue();

        String nodeName = "//" + key;
        List nodes = root.selectNodes(nodeName);

        for (int x = 0; x < nodes.size(); x++) {
            Element node = (Element) nodes.get(x);
            Attribute internalAttr = node.attribute("internal");
            Attribute typeAttr = node.attribute("type");
            ArrayList list = new ArrayList();
            list.addAll(node.attributes());
            resetXAttribute(key, list);// w ww . j a  v a 2s .c o m

            for (int y = 0; y < list.size(); y++) {
                Attribute temp = (Attribute) list.get(y);
                String name = temp.getName();

                if (!array.contains(name)) {
                    node.remove(temp);
                }
            }
            // GBS-3537 & GBS-3691
            if (internalAttr != null && "yes".equalsIgnoreCase(internalAttr.getValue())) {
                String exportedType = "x-internal";
                if (typeAttr != null) {
                    String type = typeAttr.getValue();
                    if (StringUtil.isNotEmpty(type)) {
                        exportedType += "-" + type.trim().toLowerCase();
                    }
                    typeAttr.setValue(exportedType);
                } else {
                    node.add(new DefaultAttribute("type", exportedType));
                }
            }
        }
    }

    return root.asXML();
}

From source file:com.globalsight.everest.tm.exporter.TmxChecker.java

License:Apache License

/**
* When export TM, "internal='yes' type='style'" will be merged to
* "type='x-internal-style'"; When import back, need revert back.
* 
* @param segment/*ww  w  . ja v a2  s. c om*/
* @return
*/
public String revertInternalTag(String segment) {
    Document dom = getDom(segment);
    Element root = dom.getRootElement();
    for (String tag : dtdMap.keySet()) {
        String nodeName = "//" + tag;
        List nodes = root.selectNodes(nodeName);
        for (int x = 0; x < nodes.size(); x++) {
            Element node = (Element) nodes.get(x);
            if (node.attribute("type") != null && node.attribute("type").getValue() != null) {
                Attribute typeAttr = node.attribute("type");
                String type = typeAttr.getValue();
                if ("x-internal".equalsIgnoreCase(type)) {
                    node.remove(typeAttr);
                    node.add(new DefaultAttribute("internal", "yes"));
                } else if (type.startsWith("x-internal")) {
                    String realTypeValue = type.substring("x-internal".length() + 1);
                    typeAttr.setValue(realTypeValue);
                    node.add(new DefaultAttribute("internal", "yes"));
                }
            }
        }
    }

    return root.asXML();
}

From source file:com.globalsight.everest.tm.exporter.TmxChecker.java

License:Apache License

private void resetXAttribute(String name, List list) {

    if (name == null || !needCheckXAttribute.contains(name)) {
        return;//from w ww. j av a2s  .  c om
    }

    Attribute idAttr = null;
    Attribute xAttr = null;

    for (int x = 0; x < list.size(); x++) {
        Attribute temp = (Attribute) list.get(x);
        if (temp.getName().equals("id")) {
            idAttr = temp;
        } else if (temp.getName().equals("x")) {
            xAttr = temp;
        }
    }

    if (idAttr != null && xAttr != null) {
        try {
            Integer.parseInt(xAttr.getValue());
        } catch (NumberFormatException nfe) {
            xAttr.setValue(idAttr.getValue());
        }
    }
}

From source file:com.globalsight.everest.tm.util.Tmx.java

License:Apache License

private void init(Element p_element) {
    Attribute attr;
    List nodes;/* ww w.j  ava  2 s  .  co  m*/
    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

    nodes = p_element.selectNodes("note");
    for (int i = 0; i < nodes.size(); i++) {
        Element node = (Element) nodes.get(i);

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

    nodes = p_element.selectNodes("prop");
    for (int i = 0; i < nodes.size(); i++) {
        Element node = (Element) nodes.get(i);

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

    // TODO: UDE
}

From source file:com.globalsight.everest.tm.util.ttx.TtxToTmx.java

License:Apache License

/**
 * Lowercases relevant TMX attributes like &lt;tuv lang&gt;.
 *///from w w w.jav  a2  s.c om
private void lowercaseAttributes(Element p_tu) {
    // TUVs have been lowercased already (need `.')
    List tuvs = p_tu.selectNodes(".//tuv");

    // Rename uppercase <tuv Lang> to lowercase lang.
    for (int i = 0, max = tuvs.size(); i < max; i++) {
        Element tuv = (Element) tuvs.get(i);

        Attribute attr = tuv.attribute(Ttx.LANG);
        tuv.remove(attr);

        tuv.addAttribute("xml:lang", attr.getValue());
    }
}

From source file:com.globalsight.everest.tm.util.Ttx.java

License:Apache License

private void init(Element p_element) {
    Element elem;/*from w w  w .  j  av  a  2 s  .  c  om*/
    Attribute attr;
    List nodes;
    Date date;

    elem = (Element) p_element.selectSingleNode("//ToolSettings");

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

    m_creationtool = elem.attributeValue(CREATIONTOOL);
    m_creationtoolversion = elem.attributeValue(CREATIONTOOLVERSION);

    elem = (Element) p_element.selectSingleNode("//UserSettings");

    m_datatype = elem.attributeValue(DATATYPE);
    m_o_encoding = elem.attributeValue(O_ENCODING);
    m_settingsname = elem.attributeValue(SETTINGSNAME);
    m_settingspath = elem.attributeValue(SETTINGSPATH);
    m_sourcelanguage = elem.attributeValue(SOURCELANGUAGE);
    m_targetlanguage = elem.attributeValue(TARGETLANGUAGE);
    m_targetdefaultfont = elem.attributeValue(TARGETDEFAULTFONT);
    m_sourcedocumentpath = elem.attributeValue(SOURCEDOCUMENTPATH);
}

From source file:com.globalsight.ling.docproc.DiplomatWordCounter.java

License:Apache License

private boolean isSkipElement(Element element) {
    Attribute attribute = element.attribute("isSkip");
    if (attribute != null) {
        return "true".equals(attribute.getValue());
    }// www .j  ava2s. c o  m
    return false;
}

From source file:com.globalsight.reports.util.ReportHandlerFactory.java

License:Apache License

/**
 * Reads in the Report handler mapping from an XML file, parses it
 * and populates this data structure//from  w ww . ja  v  a  2s  .co  m
 *
 * @param reportConfigXML the name of the XML file that
 * holds the report mapping.
 * @return <code>true</code> if successful, <code>false</code>
 * otherwise.
 */
public static boolean createReportHandlerMap(String reportConfigXML) {
    boolean retVal = false;
    SAXReader reader = new SAXReader();
    Document document = null;

    try {
        InputStream is = ReportHandlerFactory.class.getResourceAsStream(reportConfigXML);
        document = reader.read(new InputSource(is));

        // parse XML file in order to get className counterpart to pagename
        List<?> moduleList = document.selectNodes(Constants.REPORTMODULE_NODE_XPATH);
        for (Iterator<?> iter = moduleList.iterator(); iter.hasNext();) {
            Element element = (Element) iter.next();
            Attribute attribute = element.attribute(Constants.REPORTNAME_ATTRIBUTE);
            Element elementNode = element.element(Constants.REPORTHANDLER_NODE);

            Attribute attributeNode = elementNode.attribute(Constants.CLASS_ATTRIBUTE);

            if (CATEGORY.isDebugEnabled()) {
                CATEGORY.debug("CreateReportHandlerMap key: " + attribute.getValue() + " value: "
                        + attributeNode.getValue());
            }

            reportHandlerMap.put(attribute.getValue(), attributeNode.getValue());
        }

        // parse XML file in order to get target Url counterpart to pagename 
        List<?> urlList = document.selectNodes(Constants.REPORTURL_NODE_XPATH);
        for (Iterator<?> iterUrl = urlList.iterator(); iterUrl.hasNext();) {
            Element urlElement = (Element) iterUrl.next();
            Attribute jspNameAttribute = urlElement.attribute(Constants.JSPNAME_ATTRIBUTE);
            Attribute urlAttribute = urlElement.attribute(Constants.TARGETURL_ATTRIBUTE);
            reportTargetUrlMap.put(jspNameAttribute.getValue(), urlAttribute.getValue());
        }

        if (instance == null) {
            instance = new ReportHandlerFactory();
            retVal = true;
        }

    } catch (DocumentException e) {
        CATEGORY.error("Cannot read the ReportConfig.xml", e);
    }

    return retVal;
}

From source file:com.globalsight.terminology.exporter.MtfWriter.java

License:Apache License

/**
 * Converts a GlobalSight concept group to a MultiTerm iX concept
 * group. Differences:/*from  www  .j av a2s. c o  m*/
 *
 *  - concept level <descrip type="entryClass|status"> -->
 *    <system type="entryClass|status">
 *
 *  - <language name="English" locale="en_US" /> -->
 *    <language type="English" lang="EN" />
 *
 *  - <noteGrp><note> -->
 *    <descripGrp><descrip type="note"></descripGrp>
 *
 *  - <note> -->  (should not be produced but could be in old data)
 *    <descripGrp><descrip type="note"></descripGrp>
 *
 *  - <sourceGrp><source></sourceGrp> -->
 *    <descripGrp><descrip type="source"></descripGrp>
 *
 *  - descripGrp is not recursive
 */
private Document convertToMtf(Document p_elem) {
    List nodes;
    Node node;
    Element root = p_elem.getRootElement();
    Element elem;
    Iterator it;
    ListIterator lit;

    if (false && CATEGORY.isDebugEnabled()) {
        CATEGORY.debug("gt2mtf init: " + p_elem.asXML());
    }

    // rewrite <descrip type=entryClass> (only one on concept level)
    nodes = root.selectNodes("descrip[@type='entryClass']");
    for (it = nodes.iterator(); it.hasNext();) {
        elem = (Element) it.next();
        Element parent = elem.getParent();
        parent.remove(elem);
        parent.addElement("system").addAttribute("type", "entryClass").addText(elem.getText());
    }

    // rewrite <descrip type=status> (?? used in MTF?)
    nodes = root.selectNodes("descrip[@type='status']");
    for (it = nodes.iterator(); it.hasNext();) {
        elem = (Element) it.next();
        Element parent = elem.getParent();
        parent.remove(elem);
        parent.addElement("system").addAttribute("type", "status").addText(elem.getText());
    }

    // rewrite <noteGrp>
    while (true) {
        // refresh the node list, we're rewriting the structure
        node = root.selectSingleNode("//noteGrp");
        if (node == null) {
            break;
        }

        elem = (Element) node;

        Element parent = elem.getParent();
        parent.remove(elem);

        Element newNote = parent.addElement("descripGrp");
        Element note = null;

        // copy all child nodes but remember the <note>
        for (lit = elem.elements().listIterator(); lit.hasNext();) {
            Element child = (Element) lit.next();

            if (child.getName().equals("note")) {
                note = child;
            } else {
                lit.remove();
                newNote.add(child);
            }
        }

        // create new <descrip type="note"> with note's value
        newNote.addElement("descrip").addAttribute("type", "note").addText(note.getText());
    }

    // rewrite single <note>, if any are left in the entry
    while (true) {
        // refresh the node list, we're rewriting the structure
        node = root.selectSingleNode("//note");
        if (node == null) {
            break;
        }

        Element note = (Element) node;

        Element parent = note.getParent();
        parent.remove(note);

        Element newNote = parent.addElement("descripGrp");
        newNote.addElement("descrip").addAttribute("type", "note").addText(note.getText());
    }

    // rewrite <sourceGrp>
    while (true) {
        // refresh the node list, we're rewriting the structure
        node = root.selectSingleNode("//sourceGrp");
        if (node == null) {
            break;
        }

        elem = (Element) node;

        Element parent = elem.getParent();
        parent.remove(elem);

        Element newSource = parent.addElement("descripGrp");
        Element source = null;

        // copy all child nodes but remember the <source>
        for (lit = elem.elements().listIterator(); lit.hasNext();) {
            Element child = (Element) lit.next();

            if (child.getName().equals("source")) {
                source = child;
            } else {
                lit.remove();
                newSource.add(child);
            }
        }

        // create new <descrip type="source"> with source's value
        newSource.addElement("descrip").addAttribute("type", "source").addText(source.getText());
    }

    // rewrite <language>
    nodes = root.selectNodes("//languageGrp/language");

    for (it = nodes.iterator(); it.hasNext();) {
        elem = (Element) it.next();

        Attribute nameAttr = elem.attribute("name");
        Attribute langAttr = elem.attribute("locale");

        String langName = nameAttr.getValue();
        String langLocale = langAttr.getValue();

        // locales in MTF consist of 2 letter codes (uppercase).
        langLocale = langLocale.substring(0, 2).toUpperCase();

        elem.remove(nameAttr);
        elem.remove(langAttr);

        elem.addAttribute("type", langName);
        elem.addAttribute("lang", langLocale);
    }

    if (false && CATEGORY.isDebugEnabled()) {
        CATEGORY.debug("gt2mtf done: " + p_elem.asXML());
    }

    return p_elem;
}