List of usage examples for org.dom4j Element attribute
Attribute attribute(QName qName);
From source file:com.globalsight.everest.edit.offline.ttx.TTXParser.java
License:Apache License
/** * Initialize toolSettings attributes' values. * /*w ww. j a v a2s. co m*/ * @param p_doc */ private void parseToolSettings(Element p_root) { if (p_root == null) { return; } try { Element ele = p_root.element(TTXConstants.FRONTMATTER).element(TTXConstants.TOOLSETTINGS); Attribute creationDateAtt = ele.attribute(TTXConstants.TOOLSETTINGS_ATT_CREATIONDATE); creationDate = (creationDateAtt == null ? "" : creationDateAtt.getValue()); Attribute creationToolAtt = ele.attribute(TTXConstants.TOOLSETTINGS_ATT_CREATIONTOOL); creationTool = (creationToolAtt == null ? "" : creationToolAtt.getValue()); Attribute creationToolVersionAtt = ele.attribute(TTXConstants.TOOLSETTINGS_ATT_CREATIONTOOLVERSION); creationToolVersion = (creationToolVersionAtt == null ? "" : creationToolVersionAtt.getValue()); } catch (Exception e) { s_logger.error("Error occurs during parsing toolSettings.", e); } }
From source file:com.globalsight.everest.edit.offline.ttx.TTXParser.java
License:Apache License
/** * Initialize userSettings attributes' values. * /* www . j av a 2 s . co m*/ * @param p_doc */ private void parseUserSettings(Element p_root) { if (p_root == null) { return; } try { Element ele = p_root.element(TTXConstants.FRONTMATTER).element(TTXConstants.USERSETTINGS); Attribute srcLangAtt = ele.attribute(TTXConstants.USERSETTINGS_SOURCE_lANGUAGE); sourceLanguage = (srcLangAtt == null ? "" : srcLangAtt.getValue()); Attribute dataTypeAtt = ele.attribute(TTXConstants.USERSETTINGS_DATA_TYPE); dataType = (dataTypeAtt == null ? "" : dataTypeAtt.getValue()); Attribute o_encodingAtt = ele.attribute(TTXConstants.USERSETTINGS_O_ENCODING); o_encoding = (o_encodingAtt == null ? "" : o_encodingAtt.getValue()); Attribute trgLangAtt = ele.attribute(TTXConstants.USERSETTINGS_TARGET_LANGUAGE); targetLanguage = (trgLangAtt == null ? "" : trgLangAtt.getValue()); Attribute srcDocumentPathAtt = ele.attribute(TTXConstants.USERSETTINGS_SOURCE_DOCUMENT_PATH); sourceDocumentPath = (srcDocumentPathAtt == null ? "" : srcDocumentPathAtt.getValue()); Attribute userIdAtt = ele.attribute(TTXConstants.USERSETTINGS_USERID); userId = (userIdAtt == null ? "" : userIdAtt.getValue()); Attribute dataTypeVersionAtt = ele.attribute(TTXConstants.USERSETTINGS_DATA_TYPE_VERSION); dataTypeVersion = (dataTypeVersionAtt == null ? "" : dataTypeVersionAtt.getValue()); Attribute settingsPathAtt = ele.attribute(TTXConstants.USERSETTINGS_SETTINGS_PATH); settingsPath = (settingsPathAtt == null ? "" : settingsPathAtt.getValue()); Attribute settingsNameAtt = ele.attribute(TTXConstants.USERSETTINGS_SETTINGS_NAME); settingsname = (settingsNameAtt == null ? "" : settingsNameAtt.getValue()); Attribute trgDefaultFontAtt = ele.attribute(TTXConstants.USERSETTINGS_TARGET_DEFAULT_FONT); targetDefaultFont = (trgDefaultFontAtt == null ? "" : trgDefaultFontAtt.getValue()); } catch (Exception e) { s_logger.error("Error occurs duing parsing userSettings.", e); } }
From source file:com.globalsight.everest.edit.offline.ttx.TTXParser.java
License:Apache License
/** * Parse extra info for uploading such as "pageId", "taskId" etc. * /*from ww w.j a v a 2 s . c om*/ * @param p_rawElement */ private void parseHeaderInfo(Element p_rawElement) { if (p_rawElement == null) { return; } Iterator utIt = p_rawElement.elementIterator(TTXConstants.UT); while (utIt.hasNext()) { Element utEle = (Element) utIt.next(); Attribute displayTextAtt = utEle.attribute(TTXConstants.UT_ATT_DISPLAYTEXT); if (displayTextAtt != null) { String attValue = displayTextAtt.getValue(); // ignore locked segment - UT gs:locked segment if (TTXConstants.GS_LOCKED_SEGMENT.equalsIgnoreCase(attValue)) { continue; } String utTextNodeValue = utEle.getStringValue(); int index = utTextNodeValue.lastIndexOf(":"); if (index == -1) { continue; } String utName = utTextNodeValue.substring(0, index).trim(); String utValue = utTextNodeValue.substring(index + 1).trim(); if (TTXConstants.GS_ENCODING.equalsIgnoreCase(attValue) || "Encoding".equalsIgnoreCase(utName)) { gs_Encoding = utValue; } else if (TTXConstants.GS_DOCUMENT_FORMAT.equalsIgnoreCase(attValue) || "Document Format".equalsIgnoreCase(utName)) { gs_DocumentFormat = utValue; } else if (TTXConstants.GS_PLACEHOLDER_FORMAT.equalsIgnoreCase(attValue) || "Placeholder Format".equalsIgnoreCase(utName)) { gs_PlaceholderFormat = utValue; } else if (TTXConstants.GS_SOURCE_LOCALE.equalsIgnoreCase(attValue) || "Source Locale".equalsIgnoreCase(utName)) { gs_SourceLocale = utValue; } else if (TTXConstants.GS_TARGET_LOCALE.equalsIgnoreCase(attValue) || "Target Locale".equalsIgnoreCase(utName)) { gs_TargetLocale = utValue; } else if (TTXConstants.GS_PAGEID.equalsIgnoreCase(attValue) || "Page ID".equalsIgnoreCase(utName)) { gs_PageID = utValue; } else if (TTXConstants.GS_WORKFLOW_ID.equalsIgnoreCase(attValue) || "Workflow ID".equalsIgnoreCase(utName)) { gs_WorkflowID = utValue; } else if (TTXConstants.GS_TASK_ID.equalsIgnoreCase(attValue) || "Task ID".equalsIgnoreCase(utName)) { gs_TaskID = utValue; } else if (TTXConstants.GS_EXACT_MATCH_WORD_COUNT.equalsIgnoreCase(attValue) || "Exact Match word count".equalsIgnoreCase(utName)) { gs_ExactMatchWordCount = utValue; } else if (TTXConstants.GS_FUZZY_MATCH_WORD_COUNT.equalsIgnoreCase(attValue) || "Fuzzy Match word count".equalsIgnoreCase(utName)) { gs_FuzzyMatchWordCount = utValue; } else if (TTXConstants.GS_EDIT_ALL.equalsIgnoreCase(attValue) || "Edit all".equalsIgnoreCase(utName)) { gs_EditAll = utValue; } else if (TTXConstants.GS_POPULATE_100_TARGET_SEGMENTS.equals(attValue) || "Populate 100% Target Segments".equalsIgnoreCase(utName)) { gs_Populate100TargetSegments = utValue; } } } }
From source file:com.globalsight.everest.edit.offline.ttx.TTXParser.java
License:Apache License
private void elementNodeProcessor(Node p_node, boolean p_isSource) { Element element = (Element) p_node; String eleStr = element.asXML(); String elementName = element.getName(); boolean isHeaderInfoUT = false; boolean isTuId = false; if (TTXConstants.TU.equalsIgnoreCase(elementName) || (element.getParent() != null && TTXConstants.TUV.equalsIgnoreCase(element.getParent().getName()))) { // latestPosition = TTXConstants.IN_TU; } else if (TTXConstants.UT.equalsIgnoreCase(elementName)) { Attribute att = element.attribute(TTXConstants.UT_ATT_DISPLAYTEXT); if (att != null) { String value = att.getValue(); // If header info,return as header info has been handled // separately. // This check is not required. isHeaderInfoUT = isHeaderInfo(value); if (isHeaderInfoUT) { return; }/* w w w . j ava2 s .co m*/ // If TuId,handle them here. isTuId = isTuId(value); if (isTuId) { // latestPosition = TTXConstants.TU_ID; String tuId = value.substring(value.indexOf(":") + 1).trim(); if (results != null && results.length() > 0) { results.append(TTXConstants.NEW_LINE).append(TTXConstants.NEW_LINE); } results.append(TTXConstants.HASH_MARK).append(tuId).append(TTXConstants.NEW_LINE); return; } } } if (element.nodeCount() > 0) { Iterator nodesIt = element.nodeIterator(); while (nodesIt.hasNext()) { Node node = (Node) nodesIt.next(); String nodeStr = node.asXML(); String nodeName = node.getName(); if (TTXConstants.TUV.equalsIgnoreCase(node.getName())) { Attribute langAtt = ((Element) node).attribute(TTXConstants.TUV_ATT_LANG); String lang = null; if (langAtt != null) { lang = langAtt.getValue(); } if (sourceLanguage != null && sourceLanguage.equals(lang)) { // latestPosition = TTXConstants.IN_SOURCE_TUV; // Not handle source TUV for TTX off-line uploading. // domNodehandler(node, true); } else { // latestPosition = TTXConstants.IN_TARGET_TUV; domNodehandler(node, false); } } else { domNodehandler(node, false); } } } else { if (TTXConstants.UT.equalsIgnoreCase(elementName)) { Attribute displayTextAtt = element.attribute(TTXConstants.UT_ATT_DISPLAYTEXT); if (displayTextAtt != null) { String attValue = displayTextAtt.getValue(); if (attValue != null && attValue.startsWith(TTXConstants.TU_ID)) { // latestPosition = TTXConstants.TU_ID; String tuId = attValue.substring(attValue.indexOf(":") + 1).trim(); if (results != null && results.length() > 0) { results.append(TTXConstants.NEW_LINE).append(TTXConstants.NEW_LINE); } results.append(TTXConstants.HASH_MARK).append(tuId).append(TTXConstants.NEW_LINE); } else if (attValue != null && attValue.startsWith(TTXConstants.GS)) { Attribute typeValueAtt = element.attribute(TTXConstants.UT_ATT_TYPE); String typeValue = null; if (typeValueAtt != null) { typeValue = typeValueAtt.getValue(); } String gsTag = attValue.substring(attValue.indexOf(":") + 1).trim(); if (typeValue != null && TTXConstants.UT_ATT_TYPE_START.equalsIgnoreCase(typeValue)) { results.append("[").append(gsTag).append("]"); } else if (typeValue != null && TTXConstants.UT_ATT_TYPE_END.equalsIgnoreCase(typeValue)) { results.append("[/").append(gsTag).append("]"); } else { results.append("[").append(gsTag).append("]"); results.append("[/").append(gsTag).append("]"); } } } } else if (TTXConstants.DF.equalsIgnoreCase(elementName)) { // do not handle this. } } }
From source file:com.globalsight.everest.edit.offline.ttx.TTXParser.java
License:Apache License
/** * Judge if current node is in target TUV element. * //from w w w.jav a 2 s.co m * @param p_node * @return */ private boolean isInTargetTuv(Node p_node) { boolean result = false; if (p_node == null) { return false; } Element parentNode = p_node.getParent(); while (parentNode != null) { // In Tuv. String nodeName = parentNode.getName(); if ("Tuv".equalsIgnoreCase(nodeName)) { Attribute langAtt = parentNode.attribute(TTXConstants.TUV_ATT_LANG); String attName = langAtt.getValue(); if (langAtt != null && targetLanguage.equalsIgnoreCase(attName)) { result = true; } break; } parentNode = parentNode.getParent(); } return result; }
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; }//from ww w .j a v a 2s . 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);/*from w w w . j ava 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/*from ww w. j a va2 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.util.Tmx.java
License:Apache License
private void init(Element p_element) { Attribute attr;// w ww. j a v a 2 s . c om 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 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 <tuv lang>. *//*w w w .ja va2 s . com*/ 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()); } }