List of usage examples for org.dom4j Element add
void add(Namespace namespace);
Namespace
to this element. From source file:com.globalsight.everest.tm.util.ttx.TtxToTmx.java
License:Apache License
/** * Wraps textual content of TTX TUVs inside TMX <seg>. *///w w w .j a v a2 s .c o m private void addSegElement(Element p_tu) { ArrayList newTuvs = new ArrayList(); List tuvs = p_tu.selectNodes(".//tuv"); for (int i = 0, max = tuvs.size(); i < max; i++) { Element tuv = (Element) tuvs.get(i); Element seg = m_factory.createElement("seg"); seg.setContent(tuv.content()); tuv.content().clear(); tuv.add(seg); } }
From source file:com.globalsight.terminology.EntryUtils.java
License:Apache License
/** * Used to merge Tag ntig or tig of TBX files. * TBX files may contain several same languages in a single termentry, * when merging two new files, all the same languages should totally considered. * @param sameLangSetsInATermentry/*from ww w . j a v a 2 s . c o m*/ * @param p_one * @param p_two * @param p_comp */ private static void mergeTbxNtigsOrTigs(List sameLangSetsInATermentry, Element p_one, Element p_two, NodeComparator p_comp) { for (Iterator it = p_two.elementIterator(); it.hasNext();) { Element node = (Element) it.next(); it.remove(); node.detach(); String name = node.getName(); if (name.equals("ntig")) { String newTerm = node.element("termGrp").element("term").getText(); List<String> oldTerms = new ArrayList<String>(); for (int i = 0; i < sameLangSetsInATermentry.size(); i++) { Element tmp = (Element) sameLangSetsInATermentry.get(i); List<Element> ntigs = tmp.elements("ntig"); for (int j = 0; j < ntigs.size(); j++) { try { String oldTerm = ntigs.get(j).element("termGrp").element("term").getText(); oldTerms.add(oldTerm); } catch (Exception e) { //langSet or termGrp is empty } } } if (!oldTerms.contains(newTerm)) { p_one.add(node); } } if (name.equals("tig")) { String newTerm = node.element("term").getText(); List<String> oldTerms = new ArrayList<String>(); for (int i = 0; i < sameLangSetsInATermentry.size(); i++) { Element tmp = (Element) sameLangSetsInATermentry.get(i); List<Element> tigs = p_one.elements("tig"); for (int j = 0; j < tigs.size(); j++) { try { String oldTerm = tigs.get(j).element("term").getText(); oldTerms.add(oldTerm); } catch (Exception e) { //langSet or termGrp is empty } } } if (!oldTerms.contains(newTerm)) { p_one.add(node); } } } }
From source file:com.globalsight.terminology.EntryUtils.java
License:Apache License
static private void mergeNoteGrp(Element p_one, Element p_two, Element p_noteGrp, NodeComparator p_comp) { Element p_note = p_noteGrp.element("note"); if (p_note == null || !p_note.hasContent()) { return;/*from w ww . j a v a 2 s. c om*/ } // Find all noteGrps in 1. List matches = p_one.selectNodes("noteGrp"); if (matches == null || matches.size() == 0) { // No notes exist, add the new one to the end. p_one.add(p_noteGrp); return; } // Check if one of the matches is the same note. for (int i = 0, max = matches.size(); i < max; i++) { Element noteGrp = (Element) matches.get(i); Element note = noteGrp.element("note"); if (fieldEquals(note, p_note, p_comp)) { // could be a case/formatting-insensitive match note.detach(); noteGrp.content().add(0, p_note); return; } } // Note does not exist, add it to the end. p_one.add(p_noteGrp); }
From source file:com.globalsight.terminology.EntryUtils.java
License:Apache License
static private void mergeSourceGrp(Element p_one, Element p_two, Element p_sourceGrp, NodeComparator p_comp) { Element p_source = p_sourceGrp.element("source"); if (p_source == null || !p_source.hasContent()) { return;// w w w . ja v a 2s .co m } // Find all sourceGrps in 1. List matches = p_one.selectNodes("sourceGrp"); if (matches == null || matches.size() == 0) { // No sources exist, add the new one. p_one.add(p_sourceGrp); return; } // Check if one of the matches is the same source. for (int i = 0, max = matches.size(); i < max; i++) { Element sourceGrp = (Element) matches.get(i); Element source = sourceGrp.element("source"); if (fieldEquals(source, p_source, p_comp)) { // could be a case/formatting-insensitive match source.detach(); sourceGrp.content().add(0, p_source); mergeInnerGroups(sourceGrp, p_sourceGrp, p_comp); return; } } // Source does not exist, add it. p_one.add(p_sourceGrp); }
From source file:com.globalsight.terminology.EntryUtils.java
License:Apache License
private static void mergeLangSet(Element p_one, Element p_two, Element node, NodeComparator p_comp) { String languageName = node.attribute("lang").getText(); List langSets = p_one.elements("langSet"); List<Element> langSetsWithEqualLanguageName = new ArrayList<Element>(); for (int i = 0; i < langSets.size(); i++) { Element tmp = (Element) langSets.get(i); if (tmp.attribute("lang").getText().equals(languageName)) { langSetsWithEqualLanguageName.add(tmp); }//from w w w .j a va 2s.c o m } if (langSetsWithEqualLanguageName.size() == 0) { p_one.add(node); return; } mergeTbxNtigsOrTigs(langSetsWithEqualLanguageName, langSetsWithEqualLanguageName.get(0), node, p_comp); }
From source file:com.globalsight.terminology.EntryUtils.java
License:Apache License
static private void mergeLanguageGrp(Element p_one, Element p_two, Element p_languageGrp, NodeComparator p_comp) {//from w w w .j a va2 s. co m Element p_language = p_languageGrp.element("language"); // language element is an empty element. if (p_language == null) { return; } String name = p_language.attributeValue("name"); // Find language in entry 1. Element languageGrp = (Element) p_one.selectSingleNode("languageGrp[language/@name='" + name + "']"); if (languageGrp == null) { // languageGrp does not exist in entry 1, add to the end. p_one.add(p_languageGrp); return; } mergeInnerGroups(languageGrp, p_languageGrp, p_comp); }
From source file:com.globalsight.terminology.EntryUtils.java
License:Apache License
static private void mergeTermGrp(Element p_one, Element p_two, Element p_termGrp, NodeComparator p_comp) { Element p_term = p_termGrp.element("term"); if (p_term == null || !p_term.hasContent()) { return;/*w w w.jav a2 s . c o m*/ } // Find the term node in entry 1. List matches = p_one.selectNodes("termGrp"); for (int i = 0, max = matches.size(); i < max; i++) { Element termGrp = (Element) matches.get(i); Element term = termGrp.element("term"); if (fieldEquals(term, p_term, p_comp)) { mergeInnerGroups(termGrp, p_termGrp, p_comp); return; } } // termGrp does not exist in entry 1, add to the end. p_one.add(p_termGrp); }
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 w w w . j av a 2 s.c om*/ * * - 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; }
From source file:com.globalsight.terminology.importer.CsvReaderThread.java
License:Apache License
private void addTermGrp(Element p_root, Element p_term, String p_language) throws TermbaseException { Element langGrp = (Element) p_root.selectSingleNode("//languageGrp[language/@name='" + p_language + "']"); if (langGrp == null) { langGrp = buildLanguageGrp(p_language); p_root.add(langGrp); }/*w w w. j a v a2 s .co m*/ langGrp.add(p_term); }
From source file:com.globalsight.terminology.importer.CsvReaderThread.java
License:Apache License
private void addConceptDescripGrp(Element p_root, Element p_descrip) { p_root.add(p_descrip); }