List of usage examples for org.dom4j Element setContent
void setContent(List<Node> content);
List
of Node
instances. From source file:revaligner.service.FileAligner.java
public ArrayList<String[]> populateSourceTxlf() throws Exception { System.out.println("populating source txlf with aligned segments...."); ArrayList<String[]> reportStates = new ArrayList(); ExtractionSupportImpl extractionSupportImpl = new ExtractionSupportImpl( Locale.makeLocale(this.sourcelanguage), Locale.makeLocale(this.targetlanguage)); Configuration config = new BaseConfiguration(); config.setProperty("extraction.tokens.extract", "all"); extractionSupportImpl.setConfiguration(config); Locale locale = Locale.makeLocale(this.sourcelanguage); TradosWordCounter wcounter = new TradosWordCounter(locale, config); org.dom4j.Document document_src = XmlParser.parseXmlFile(this.sourcetxlf_nonSeg); org.dom4j.Element root_src = document_src.getRootElement(); org.dom4j.Document document_src_ingt = XmlParser.parseXmlFile(this.sourcetxlf_nonSeg); org.dom4j.Element root_src_ingt = document_src_ingt.getRootElement(); org.dom4j.Document document_src_seg = XmlParser.parseXmlFile(this.sourcetxlf_seg); org.dom4j.Element root_src_seg = document_src_seg.getRootElement(); List<com.aspose.words.Node> list_source = root_src .selectNodes("//*[name() = 'group'][@restype = 'x-paragraph']"); List<com.aspose.words.Node> list_source_ingt = root_src_ingt .selectNodes("//*[name() = 'group'][@restype = 'x-paragraph']"); List<com.aspose.words.Node> list_source_seg = root_src_seg .selectNodes("//*[name() = 'group'][@restype = 'x-paragraph']"); int count = 0; int totalWC = 0; org.dom4j.Document document = XmlParser.parseXmlFile(this.alignedfile); List<org.dom4j.Element> groups = document.getRootElement().element("aligned").elements("group"); for (int i = 0; i < groups.size(); i++) { org.dom4j.Element group = (org.dom4j.Element) groups.get(i); List<org.dom4j.Element> units = group.elements("unit"); if (((org.dom4j.Element) units.get(0)).element("src_para") != null) { boolean isParaAllSegmented = true; for (int j = 0; j < units.size(); j++) { if (((org.dom4j.Element) units.get(j)).attributeValue("alignsegs").equals("false")) { isParaAllSegmented = false; break; }//from w w w . ja va2 s.c o m } String srcTextAccepted = group.elementText("text").replaceAll("(?s)<del>.*?</del>", "") .replaceAll("<(/)*ins>", ""); if (!extractionSupportImpl.isExtractable(srcTextAccepted)) { if (isParaAllSegmented) { for (int j = 0; j < units.size(); j++) { org.dom4j.Element unit = (org.dom4j.Element) units.get(j); List<org.dom4j.Element> srcsegs = unit.element("src_para").element("segments") .elements("src_seg"); List<org.dom4j.Element> trgsegs = unit.element("trg_para").element("segments") .elements("trg_seg"); for (int x = 0; x < srcsegs.size(); x++) { String[] s = new String[7]; s[0] = ((org.dom4j.Element) srcsegs.get(x)).getText(); if (x >= trgsegs.size()) { s[1] = ""; } else { org.dom4j.Element trgseg = (org.dom4j.Element) trgsegs.get(x); String id = trgseg.attributeValue("id"); if (id.startsWith("n - ")) { s[1] = trgseg.getText(); } else { List tmp_contents = new ArrayList(); if (id.contains(" - ")) { int start = Integer.parseInt(id.split(" - ")[0]); int end = Integer.parseInt(id.split(" - ")[1]); tmp_contents.addAll( (Collection) this.txlftrgsegmap.get(Integer.valueOf(start))); for (int su = start + 1; su <= end; su++) { boolean isprevendofpara = ((boolean[]) this.txlftrgsewsmap .get(Integer.valueOf(su - 1)))[1]; boolean iscurrentstartofpara = ((boolean[]) this.txlftrgsewsmap .get(Integer.valueOf(su)))[0]; if ((isprevendofpara) && (iscurrentstartofpara)) { List prevseg = (List) this.txlftrgsegmap .get(Integer.valueOf(su - 1)); int previdx = -1; for (int prev = 0; prev < prevseg.size(); prev++) { org.dom4j.Node prevnode = (org.dom4j.Node) prevseg .get(prev); if (prevnode.getNodeType() == 1) { org.dom4j.Element prevnode_e = (org.dom4j.Element) prevnode; if ((prevnode_e.getName().equals("ws")) && (prevnode_e .attributeValue("pos").equals("after"))) { previdx = prevseg.size() - prev; } } } if (previdx != -1) { tmp_contents.remove(tmp_contents.size() - previdx); } List currseg = (List) this.txlftrgsegmap .get(Integer.valueOf(su)); int curridx = -1; for (int curr = 0; curr < currseg.size(); curr++) { org.dom4j.Node currnode = (org.dom4j.Node) currseg .get(curr); if (currnode.getNodeType() == 1) { org.dom4j.Element currnode_e = (org.dom4j.Element) currnode; if ((currnode_e.getName().equals("ws")) && (currnode_e .attributeValue("pos").equals("before"))) { curridx = curr; } } } if (curridx != -1) { currseg.remove(curridx); } if (Locale.makeLocale(this.targetlanguage).isFarEast()) { tmp_contents.addAll(currseg); } else { tmp_contents.add(DocumentHelper.createText(" ")); tmp_contents.addAll(currseg); } } else { tmp_contents.addAll((Collection) this.txlftrgsegmap .get(Integer.valueOf(su))); } } } else { tmp_contents.addAll((Collection) this.txlftrgsegmap .get(Integer.valueOf(Integer.parseInt(id)))); } s[1] = trimText(assembleText(tmp_contents).replace("<br> ", "↵<br>"), false)[0]; } } s[2] = "N/A"; s[3] = "N/A"; s[4] = ((org.dom4j.Element) srcsegs.get(x)).attributeValue("tctype"); s[5] = "0"; s[6] = ""; reportStates.add(s); } } } else { String[] s = new String[7]; for (int j = 0; j < units.size(); j++) { s[0] = ((org.dom4j.Element) units.get(j)).element("src_para").elementText("text"); if (((org.dom4j.Element) units.get(j)).element("trg_para") != null) { s[1] = ((org.dom4j.Element) units.get(j)).element("trg_para").elementText("text"); } else { s[1] = ""; } s[2] = "N/A"; s[3] = "N/A"; s[4] = ((org.dom4j.Element) units.get(j)).element("src_para").attributeValue("tctype"); s[5] = "0"; s[6] = ""; reportStates.add(s); } } } else { if (isParaAllSegmented) { org.dom4j.Element txlf_group = (org.dom4j.Element) list_source.get(count); org.dom4j.Element txlf_group_ingt = (org.dom4j.Element) list_source_ingt.get(count); org.dom4j.Element txlf_group_seg = (org.dom4j.Element) list_source_seg.get(count); txlf_group.setContent(txlf_group_seg.content()); List transunits = txlf_group.elements("trans-unit"); txlf_group_ingt.setContent(txlf_group_seg.content()); List transunits_ingt = txlf_group_ingt.elements("trans-unit"); ArrayList<String> mergedsegtext = new ArrayList(); ArrayList<List> merged_trg_contents = new ArrayList(); ArrayList<String> mergedsegtctypes = new ArrayList(); ArrayList<String> keys = new ArrayList(); ArrayList<String> key_left = new ArrayList(); ArrayList<String> key_right = new ArrayList(); ArrayList<String> org_keys = new ArrayList(); ArrayList<String> trg_keys = new ArrayList(); ArrayList<List> trg_contents = new ArrayList(); ArrayList<String> src_tctypes = new ArrayList(); ArrayList<String> src_review_stats = new ArrayList(); ArrayList<String> src_ignore_stats = new ArrayList(); ArrayList<Integer> edited_idx = new ArrayList(); for (int j = 0; j < units.size(); j++) { org.dom4j.Element unit = (org.dom4j.Element) units.get(j); org.dom4j.Element src_para = unit.element("src_para"); org.dom4j.Element trg_para = unit.element("trg_para"); List src_segs = src_para.element("segments").elements("src_seg"); for (int z = 0; z < src_segs.size(); z++) { org.dom4j.Element src_seg = (org.dom4j.Element) src_segs.get(z); src_tctypes.add(src_seg.attributeValue("tctype")); src_review_stats.add(src_seg.attributeValue("needreview")); src_ignore_stats.add(src_seg.attributeValue("ignored")); keys.add(src_seg.getText().replaceAll("(?s)<del>.*?</del>", "") .replaceAll("<(/)*ins>", "").replace("<br>", "").trim()); org_keys.add(src_seg.getText()); if (trg_para != null) { List trg_segs = trg_para.element("segments").elements("trg_seg"); if (((org.dom4j.Element) trg_segs.get(z)).attributeValue("edited") .equals("true")) { edited_idx.add(Integer.valueOf(trg_contents.size())); } if (trg_segs.size() > z) { trg_keys.add(((org.dom4j.Element) trg_segs.get(z)).getText()); String id = ((org.dom4j.Element) trg_segs.get(z)).attributeValue("id"); if (id.startsWith("n - ")) { trg_contents.add(new ArrayList()); } else { List tmp_contents = new ArrayList(); if (id.contains(" - ")) { int start = Integer.parseInt(id.split(" - ")[0]); int end = Integer.parseInt(id.split(" - ")[1]); tmp_contents.addAll((Collection) this.txlftrgsegmap .get(Integer.valueOf(start))); for (int su = start + 1; su <= end; su++) { boolean isprevendofpara = ((boolean[]) this.txlftrgsewsmap .get(Integer.valueOf(su - 1)))[1]; boolean iscurrentstartofpara = ((boolean[]) this.txlftrgsewsmap .get(Integer.valueOf(su)))[0]; if ((isprevendofpara) && (iscurrentstartofpara)) { List prevseg = (List) this.txlftrgsegmap .get(Integer.valueOf(su - 1)); int previdx = -1; for (int prev = 0; prev < prevseg.size(); prev++) { org.dom4j.Node prevnode = (org.dom4j.Node) prevseg .get(prev); if (prevnode.getNodeType() == 1) { org.dom4j.Element prevnode_e = (org.dom4j.Element) prevnode; if ((prevnode_e.getName().equals("ws")) && (prevnode_e.attributeValue("pos") .equals("after"))) { previdx = prevseg.size() - prev; } } } if (previdx != -1) { tmp_contents.remove(tmp_contents.size() - previdx); } List currseg = (List) this.txlftrgsegmap .get(Integer.valueOf(su)); int curridx = -1; for (int curr = 0; curr < currseg.size(); curr++) { org.dom4j.Node currnode = (org.dom4j.Node) currseg .get(curr); if (currnode.getNodeType() == 1) { org.dom4j.Element currnode_e = (org.dom4j.Element) currnode; if ((currnode_e.getName().equals("ws")) && (currnode_e.attributeValue("pos") .equals("before"))) { curridx = curr; } } } if (curridx != -1) { currseg.remove(curridx); } if (Locale.makeLocale(this.targetlanguage).isFarEast()) { tmp_contents.addAll(currseg); } else { tmp_contents.add(DocumentHelper.createText(" ")); tmp_contents.addAll(currseg); } } else { tmp_contents.addAll((Collection) this.txlftrgsegmap .get(Integer.valueOf(su))); } } } else { tmp_contents.addAll((Collection) this.txlftrgsegmap .get(Integer.valueOf(Integer.parseInt(id)))); } trg_contents.add(tmp_contents); } } else { trg_keys.add(""); trg_contents.add(new ArrayList()); } } else { trg_keys.add(""); trg_contents.add(new ArrayList()); } if ((z == 0) && (z == src_segs.size() - 1)) { key_left.add(src_para.attributeValue("lefttrim")); key_right.add(src_para.attributeValue("righttrim")); } else if (z == 0) { key_left.add(src_para.attributeValue("lefttrim")); key_right.add("true"); } else if (z == src_segs.size() - 1) { key_left.add("true"); key_right.add(src_para.attributeValue("righttrim")); } else { key_left.add("true"); key_right.add("true"); } } } SegmenterFactory factory = new SegmenterFactory(); Configuration segconfig = createConfigForSegmenter(false, this.sourcelanguage); Segmenter segmenter = factory.getSegmenter("trados", Locale.makeLocale(this.sourcelanguage), segconfig); List<String> finsegs = segmenter .segment(group.elementText("text").replaceAll("(?s)<del>.*?</del>", "") .replaceAll("<(/)*ins>", "").replace("<br>", "").replace("<", "<") .replace(">", ">").replace("&", "&")); ArrayList<ArrayList<Integer>> indices = new ArrayList(); int key_start_index = 0; for (int k = 0; k < finsegs.size(); k++) { String finsegtext = ((String) finsegs.get(k)).replace("&", "&").replace("<", "<") .replace(">", ">"); String combined_key = ""; ArrayList<Integer> indice = new ArrayList(); for (int x = key_start_index; x < keys.size(); x++) { combined_key = combined_key + (String) keys.get(x); indice.add(Integer.valueOf(x)); if (combined_key.replace("", " ").trim().replaceAll("(\\s)+", "") .equals(finsegtext.replace("", " ").trim().replaceAll("(\\s)+", ""))) { indices.add(indice); key_start_index = x + 1; break; } } } ArrayList<Integer> merged_edited_idx = new ArrayList(); ArrayList<String[]> statss = new ArrayList(); for (int m = 0; m < indices.size(); m++) { boolean iscontentsuseable = true; ArrayList<Integer> temp_indice = (ArrayList) indices.get(m); String temp_src = ""; String temp_org_src = ""; String temp_trg = ""; List temp_trg_content = new ArrayList(); int id = 1; int rid = 1; int bxrid = 1; int bptrid = 1; int bxid = 1; int bptid = 1; HashMap<String, String> map_rid = new HashMap(); String temp_tctype = (String) src_tctypes .get(((Integer) temp_indice.get(0)).intValue()); String temp_review_stats = (String) src_review_stats .get(((Integer) temp_indice.get(0)).intValue()); for (Iterator localIterator = temp_indice.iterator(); localIterator.hasNext();) { int it = ((Integer) localIterator.next()).intValue(); temp_tctype = temp_tctype.equals(src_tctypes.get(it)) ? temp_tctype : "MIX"; temp_review_stats = ((String) src_review_stats.get(it)).equals("true") ? "true" : temp_review_stats.equals("true") ? "true" : "false"; String temp_ignore_stats = (String) src_ignore_stats.get(it); if (edited_idx.contains(Integer.valueOf(it))) { iscontentsuseable = false; } temp_src = temp_src + (String) keys.get(it); temp_org_src = temp_org_src + (String) org_keys.get(it); if (temp_ignore_stats.equals("true")) { temp_trg = temp_trg + "[skipseg]"; temp_trg_content.add(DocumentHelper.createText("[skipseg]")); } else { temp_trg = temp_trg + (String) trg_keys.get(it); List trg_content = (List) trg_contents.get(it); for (int nc = 0; nc < trg_content.size(); nc++) { org.dom4j.Node raw = (org.dom4j.Node) trg_content.get(nc); if (raw.getNodeType() == 3) { temp_trg_content.add(raw); } else if (raw.getNodeType() == 1) { org.dom4j.Element rawe = (org.dom4j.Element) raw; if (rawe.getName().equals("source")) { for (int ncc = 0; ncc < rawe.content().size(); ncc++) { org.dom4j.Node node = (org.dom4j.Node) rawe.content().get(ncc); if (node.getNodeType() == 3) { temp_trg_content.add(node); } else if (node.getNodeType() == 1) { org.dom4j.Element e = (org.dom4j.Element) node; if (!e.getName().equals("x")) { if (!e.getName().equals("ph")) { if (e.getName().equals("bx")) { if ((e.attribute("fake") != null) && (e.attributeValue("fake") .equals("true")) && (temp_indice.indexOf( Integer.valueOf(it)) != 0)) { continue; } if ((e.attribute("fake") == null) || (!e.attributeValue("fake") .equals("true"))) { } } else if (e.getName().equals("ex")) { if ((e.attribute("fake") != null) && (e.attributeValue("fake") .equals("true")) && (temp_indice.indexOf(Integer.valueOf( it)) != temp_indice.size() - 1)) { continue; } if ((e.attribute("fake") == null) || (!e.attributeValue("fake") .equals("true"))) { } } else if (e.getName().equals("bpt")) { if ((e.attribute("fake") != null) && (e.attributeValue("fake") .equals("true")) && (temp_indice.indexOf( Integer.valueOf(it)) != 0)) { continue; } if ((e.attribute("fake") == null) || (!e.attributeValue("fake") .equals("true"))) { } } else if (e.getName().equals("ept")) { if ((e.attribute("fake") != null) && (e.attributeValue("fake") .equals("true")) && (temp_indice.indexOf(Integer.valueOf( it)) != temp_indice.size() - 1)) { continue; } if ((e.attribute("fake") == null) || (!e.attributeValue("fake") .equals("true"))) { } } } } if (e.attribute("fake") != null) { e.remove(e.attribute("fake")); } temp_trg_content.add(e); } } } else if (rawe.getName().equals("ws")) { String pos = rawe.attributeValue("pos"); if (pos.equals("before")) { for (int ncc = 0; ncc < rawe.content().size(); ncc++) { org.dom4j.Node node = (org.dom4j.Node) rawe.content() .get(ncc); if (node.getNodeType() == 3) { temp_trg_content.add(0, node); } else if (node.getNodeType() == 1) { org.dom4j.Element e = (org.dom4j.Element) node; if ((!e.getName().equals("x")) && (e.getName().equals("it"))) { if (e.attributeValue("pos").equals("open")) { if ((e.attribute("fake") != null) && (e.attributeValue("fake") .equals("true")) && (temp_indice.indexOf( Integer.valueOf(it)) != 0)) { continue; } if (e.getText().equals("")) { e.setName("bx"); } else { e.setName("bpt"); } if ((e.attribute("fake") == null) || (!e.attributeValue("fake") .equals("true"))) { } } else if (e.attributeValue("pos") .equals("close")) { if ((e.attribute("fake") != null) && (e.attributeValue("fake") .equals("true")) && (temp_indice.indexOf(Integer.valueOf( it)) != temp_indice.size() - 1)) { continue; } if (e.getText().equals("")) { e.setName("ex"); } else { e.setName("ept"); } e.remove(e.attribute("ctype")); if ((e.attribute("fake") == null) || (!e.attributeValue("fake") .equals("true"))) { } } e.remove(e.attribute("pos")); } else { if (e.attribute("fake") != null) { e.remove(e.attribute("fake")); } temp_trg_content.add(0, e); } } } } else if (pos.equals("after")) { for (int ncc = 0; ncc < rawe.content().size(); ncc++) { org.dom4j.Node node = (org.dom4j.Node) rawe.content() .get(ncc); if (node.getNodeType() == 3) { temp_trg_content.add(node); } else if (node.getNodeType() == 1) { org.dom4j.Element e = (org.dom4j.Element) node; if ((!e.getName().equals("x")) && (e.getName().equals("it"))) { if (e.attributeValue("pos").equals("open")) { if ((e.attribute("fake") != null) && (e.attributeValue("fake") .equals("true")) && (temp_indice.indexOf( Integer.valueOf(it)) != 0)) { continue; } if (e.getText().equals("")) { e.setName("bx"); } else { e.setName("bpt"); } if ((e.attribute("fake") == null) || (!e.attributeValue("fake") .equals("true"))) { } } else if (e.attributeValue("pos") .equals("close")) { if ((e.attribute("fake") != null) && (e.attributeValue("fake") .equals("true")) && (temp_indice.indexOf(Integer.valueOf( it)) != temp_indice.size() - 1)) { continue; } if (e.getText().equals("")) { e.setName("ex"); } else { e.setName("ept"); } e.remove(e.attribute("ctype")); if ((e.attribute("fake") == null) || (!e.attributeValue("fake") .equals("true"))) { } } e.remove(e.attribute("pos")); } else { if (e.attribute("fake") != null) { e.remove(e.attribute("fake")); } temp_trg_content.add(e); } } } } } } } } } String[] stats = TrackChangeHelper.getTxlfTrgStatsFromTCType(temp_tctype, temp_trg); if ((stats[0].equals("1")) && (temp_review_stats.equals("true"))) { stats[2] = "fuzzy-match"; } String[] s = new String[7]; s[0] = temp_org_src.replace("<br> ", "↵<br>"); if (iscontentsuseable) { s[1] = trimText(assembleText(temp_trg_content).replace("<br> ", "↵<br>"), false)[0]; } else { s[1] = temp_trg.replace("<br> ", "↵<br>"); } if (s[1].contains("[skipseg]")) { if (s[1].replace("[skipseg]", "").trim().equals("")) { s[1] = ""; temp_trg_content = new ArrayList(); temp_trg_content.add(DocumentHelper.createText("")); temp_trg = ""; stats[0] = "1"; stats[1] = "translated"; stats[2] = "exact-match"; } else { s[1] = s[1].replace("[skipseg]", ""); temp_trg_content = replacetextinDomObj(temp_trg_content); temp_trg = temp_trg.replace("[skipseg]", ""); } } s[2] = stats[0]; s[3] = stats[2]; s[4] = temp_tctype; wcounter = new TradosWordCounter(locale, config); wcounter.countText(((org.dom4j.Element) transunits.get(m)).element("source").getText()); s[5] = Integer.toString(wcounter.getWordCount()); s[6] = ""; totalWC += wcounter.getWordCount(); reportStates.add(s); if (extractionSupportImpl.isExtractable(temp_src)) { mergedsegtext.add(temp_trg); if (!iscontentsuseable) { merged_edited_idx.add(Integer.valueOf(merged_trg_contents.size())); } merged_trg_contents.add(temp_trg_content); mergedsegtctypes.add(temp_tctype); statss.add(stats); } } for (int t = 0; t < transunits.size(); t++) { org.dom4j.Element trans_unit = (org.dom4j.Element) transunits.get(t); org.dom4j.Element trans_unit_ignt = (org.dom4j.Element) transunits_ingt.get(t); trans_unit.addAttribute("gs4tr:editStatus", "leveraged"); org.dom4j.Element source = trans_unit.element("source"); org.dom4j.Element target = trans_unit.addElement("target"); trans_unit.elements().add(source.indexOf(source.getParent()) + 2, target.clone()); trans_unit.remove(target); target = trans_unit.element("target"); org.dom4j.Element target_ignt = trans_unit_ignt.addElement("target"); trans_unit_ignt.elements().add(source.indexOf(source.getParent()) + 2, target_ignt.clone()); trans_unit_ignt.remove(target_ignt); target_ignt = trans_unit_ignt.element("target"); if (merged_edited_idx.contains(Integer.valueOf(t))) { target.setText(((String) mergedsegtext.get(t)).replace("<", "<") .replace(">", ">").replace("&", "&").trim()); target_ignt.setText(((String) mergedsegtext.get(t)).replace("<", "<") .replace(">", ">").replace("&", "&").trim()); } else { target.setContent(trimContents((List) merged_trg_contents.get(t))); target_ignt.setContent(trimContents((List) merged_trg_contents.get(t))); if (!((String[]) statss.get(t))[0].equals("75")) { org.dom4j.Element source_ingt = trans_unit_ignt.element("source"); source_ingt.setContent(trimContents((List) merged_trg_contents.get(t))); } } String[] stats = (String[]) statss.get(t); if (stats[0].equals("1")) { trans_unit.addAttribute("gs4tr:locked", "true"); } target.addAttribute("gs4tr:score", stats[0]); target.addAttribute("state", stats[1]); target.addAttribute("state-qualifier", stats[2]); if (stats[0].equals("0")) { trans_unit.remove(target); } } } else { String trgtext = ""; if (((org.dom4j.Element) units.get(0)).element("trg_para") != null) { trgtext = ((org.dom4j.Element) units.get(0)).element("trg_para").elementText("text"); } String temp_tctype = ((org.dom4j.Element) units.get(0)).element("src_para") .attributeValue("tctype"); for (int j = 1; j < units.size(); j++) { org.dom4j.Element prev_unit = (org.dom4j.Element) units.get(j - 1); org.dom4j.Element unit = (org.dom4j.Element) units.get(j); String src_tctype = unit.element("src_para").attributeValue("tctype"); temp_tctype = temp_tctype.equals(src_tctype) ? temp_tctype : "MIX"; if (unit.element("trg_para") != null) { String Rtrim = prev_unit.element("src_para").attributeValue("righttrim"); String Ltrim = unit.element("src_para").attributeValue("lefttrim"); if ((Rtrim.equals("true")) || (Ltrim.equals("true"))) { trgtext = trgtext + " " + unit.element("trg_para").elementText("text"); } else { trgtext = trgtext + unit.element("trg_para").elementText("text"); } } } org.dom4j.Element txlf_group = (org.dom4j.Element) list_source.get(count); org.dom4j.Element trans_unit = txlf_group.element("trans-unit"); trans_unit.addAttribute("gs4tr:editStatus", "leveraged"); org.dom4j.Element source = trans_unit.element("source"); org.dom4j.Element target = trans_unit.addElement("target"); trans_unit.elements().add(source.indexOf(source.getParent()) + 2, target.clone()); trans_unit.remove(target); target = trans_unit.element("target"); int lb_cnt = 0; String surfix = trgtext; while (surfix.indexOf("<br> ") != -1) { lb_cnt++; int pos = surfix.indexOf("<br> "); String prefix = surfix.substring(0, pos); target.addText(prefix.replace("<", "<").replace(">", ">").replace("&", "&")); org.dom4j.Element x = target.addElement("x"); x.addAttribute("ctype", "lb"); x.addAttribute("id", Integer.toString(lb_cnt)); x.addAttribute("equiv-text", " "); surfix = surfix.substring(pos + 5, surfix.length()); } target.addText(surfix.replace("<", "<").replace(">", ">").replace("&", "&")); String[] stats = TrackChangeHelper.getTxlfTrgStatsFromTCType(temp_tctype, trgtext); target.addAttribute("gs4tr:score", stats[0]); target.addAttribute("state", stats[1]); target.addAttribute("state-qualifier", stats[2]); String[] s = new String[7]; s[0] = group.elementText("text").replace("<br> ", "↵<br>"); s[1] = trgtext.replace("<br> ", "↵<br>"); s[2] = stats[0]; s[3] = stats[2]; s[4] = temp_tctype; wcounter = new TradosWordCounter(locale, config); wcounter.countText(source.getText()); s[5] = Integer.toString(wcounter.getWordCount()); s[6] = ""; totalWC += wcounter.getWordCount(); reportStates.add(s); } count++; } } } root_src.element("file").addAttribute("gs4tr:wordcount", Integer.toString(totalWC)); fixTxlfTrgTags(document_src); this.populatedsourcetxlf = (this.sourcefile + ".txlf"); if (new File(this.populatedsourcetxlf).exists()) { new File(this.populatedsourcetxlf).delete(); } OutputStreamWriter writer = new OutputStreamWriter( new BufferedOutputStream(new FileOutputStream(this.populatedsourcetxlf)), "UTF8"); document_src.write(writer); writer.close(); removeBlankLinesAndNameSpace(this.populatedsourcetxlf); root_src_ingt.element("file").addAttribute("gs4tr:wordcount", Integer.toString(totalWC)); fixTxlfTrgTags(document_src_ingt); String ingtfile = this.sourcefile + ".ingt.txlf"; if (new File(ingtfile).exists()) { new File(ingtfile).delete(); } OutputStreamWriter writer_ingt = new OutputStreamWriter( new BufferedOutputStream(new FileOutputStream(ingtfile)), "UTF8"); document_src_ingt.write(writer_ingt); writer_ingt.close(); removeBlankLinesAndNameSpace(ingtfile); return reportStates; }
From source file:revaligner.service.FileAligner.java
public void fixTxlfTrgTags(org.dom4j.Document doc) throws Exception { org.dom4j.Element root = doc.getRootElement(); List<org.dom4j.Element> list_transunit = root.selectNodes("//*[name() = 'trans-unit']"); for (org.dom4j.Element e : list_transunit) { org.dom4j.Element source = e.element("source"); org.dom4j.Element target = e.element("target"); if ((target != null) && (!target.getText().equals(""))) { HashMap<String, List<Object>> src_map = new HashMap(); boolean tagnodeappear = false; boolean textnodeappear = false; boolean sourcetagsurroundtext = true; int maxid = 1; for (int i = 0; i < source.content().size(); i++) { org.dom4j.Node node = (org.dom4j.Node) source.content().get(i); if (node.getNodeType() == 1) { org.dom4j.Element tag = (org.dom4j.Element) node; maxid = Math.max(maxid, Integer.parseInt(tag.attributeValue("id"))); }/*from w ww . j a v a2 s.c o m*/ } maxid++; for (int i = 0; i < source.content().size(); i++) { org.dom4j.Node node = (org.dom4j.Node) source.content().get(i); if (node.getNodeType() == 1) { if (textnodeappear) { tagnodeappear = true; } org.dom4j.Element tag = (org.dom4j.Element) node; String key = ""; if ((tag.getName().equals("ex")) || (tag.getName().equals("ept"))) { key = tag.getName() + "#" + tag.attributeValue("rid"); } else if (tag.getName().equals("x")) { key = tag.getName() + "#" + tag.attributeValue("ctype"); } else { key = tag.getName(); } if (src_map.containsKey(key)) { ((List) src_map.get(key)).add(node.clone()); } else { List<Object> list = new ArrayList(); list.add(node.clone()); src_map.put(key, list); } } else { if (tagnodeappear) { sourcetagsurroundtext = false; } textnodeappear = true; } } HashMap<String, String> rid_map = new HashMap(); List trg_contents = new ArrayList(); boolean targetnotag = true; for (int i = 0; i < target.content().size(); i++) { org.dom4j.Node node = (org.dom4j.Node) target.content().get(i); if (node.getNodeType() == 1) { org.dom4j.Element tag = (org.dom4j.Element) node; String rid = tag.attributeValue("rid"); String key = ""; if ((tag.getName().equals("ph")) || (tag.getName().equals("bpt")) || (tag.getName().equals("bx"))) { key = tag.getName(); if (src_map.containsKey(key)) { List list = (List) src_map.get(key); trg_contents.add(list.get(0)); targetnotag = false; rid_map.put(rid, ((org.dom4j.Element) list.get(0)).attributeValue("rid")); list.remove(0); if (list.size() == 0) { src_map.remove(key); } } } else if (tag.getName().equals("x")) { key = tag.getName() + "#" + tag.attributeValue("ctype"); if (src_map.containsKey(key)) { List list = (List) src_map.get(key); trg_contents.add(list.get(0)); targetnotag = false; list.remove(0); if (list.size() == 0) { src_map.remove(key); } } else if ((tag.getName().equals("x")) && (tag.attributeValue("ctype").equals("x-tab"))) { org.dom4j.Element tab = DocumentHelper.createElement("x"); tab.addAttribute("ctype", "x-tab"); tab.addAttribute("id", Integer.toString(maxid)); maxid++; tab.addAttribute("equiv-text", " "); trg_contents.add(tab); } else if ((tag.getName().equals("x")) && (tag.attributeValue("ctype").equals("lb"))) { org.dom4j.Element lb = DocumentHelper.createElement("x"); lb.addAttribute("ctype", "lb"); lb.addAttribute("id", Integer.toString(maxid)); maxid++; lb.addAttribute("equiv-text", " "); trg_contents.add(lb); } } else if ((tag.getName().equals("ex")) || (tag.getName().equals("ept"))) { String mapped_rid = (String) rid_map.get(tag.attributeValue("rid")); key = tag.getName() + "#" + mapped_rid; if (src_map.containsKey(key)) { List list = (List) src_map.get(key); trg_contents.add(list.get(0)); rid_map.put(rid, ((org.dom4j.Element) list.get(0)).attributeValue("rid")); list.remove(0); if (list.size() == 0) { src_map.remove(key); } } } } else if (node.getNodeType() == 3) { String text = node.getText(); if (text.contains("<br> ")) { String key = "x#lb"; String[] ss = text.split("<br> "); for (int s = 0; s < ss.length; s++) { trg_contents.add(DocumentHelper.createText(ss[s])); if (s < ss.length - 1) { if (src_map.containsKey(key)) { List list = (List) src_map.get(key); trg_contents.add(list.get(0)); targetnotag = false; list.remove(0); if (list.size() == 0) { src_map.remove(key); } } else { org.dom4j.Element lb = DocumentHelper.createElement("x"); lb.addAttribute("ctype", "lb"); lb.addAttribute("id", Integer.toString(maxid)); maxid++; lb.addAttribute("equiv-text", " "); trg_contents.add(lb); } } } } else if (text.contains("<br>")) { String key = "x#lb"; String[] ss = text.split("<br> "); for (int s = 0; s < ss.length; s++) { trg_contents.add(DocumentHelper.createText(ss[s])); if (s < ss.length - 1) { if (src_map.containsKey(key)) { List list = (List) src_map.get(key); trg_contents.add(list.get(0)); targetnotag = false; list.remove(0); if (list.size() == 0) { src_map.remove(key); } } else { org.dom4j.Element lb = DocumentHelper.createElement("x"); lb.addAttribute("ctype", "lb"); lb.addAttribute("id", Integer.toString(maxid)); maxid++; lb.addAttribute("equiv-text", " "); trg_contents.add(lb); } } } } else { trg_contents.add(node); } } else { trg_contents.add(node); } } while (trg_contents.size() > 0) { org.dom4j.Node nd = (org.dom4j.Node) trg_contents.get(0); if (nd.getNodeType() == 3) { if (nd.getText().trim().equals("")) { trg_contents.remove(0); } else { nd.setText(nd.getText().replaceAll("^(\\s)+", "")); break; } } else if ((nd.getNodeType() == 1) && (nd.getName().equals("x")) && (((org.dom4j.Element) nd).attributeValue("ctype").equals("lb"))) { trg_contents.remove(0); } else { if ((nd.getNodeType() != 1) || (!nd.getName().equals("x")) || (!((org.dom4j.Element) nd).attributeValue("ctype").equals("x-tab"))) { break; } trg_contents.remove(0); } } while (trg_contents.size() > 0) { org.dom4j.Node nd = (org.dom4j.Node) trg_contents.get(trg_contents.size() - 1); if (nd.getNodeType() == 3) { if (nd.getText().trim().equals("")) { trg_contents.remove(trg_contents.size() - 1); } else { nd.setText(nd.getText().replaceAll("(\\s)+$", "")); break; } } else if ((nd.getNodeType() == 1) && (nd.getName().equals("x")) && (((org.dom4j.Element) nd).attributeValue("ctype").equals("lb"))) { trg_contents.remove(trg_contents.size() - 1); } else { if ((nd.getNodeType() != 1) || (!nd.getName().equals("x")) || (!((org.dom4j.Element) nd).attributeValue("ctype").equals("x-tab"))) { break; } trg_contents.remove(trg_contents.size() - 1); } } boolean isnotignoredsegment = true; if (trg_contents.size() == 1) { org.dom4j.Node node = (org.dom4j.Node) trg_contents.get(0); if ((node.getNodeType() == 3) && (node.getText().replaceFirst("", "").equals(""))) { isnotignoredsegment = false; } } if ((targetnotag) && (sourcetagsurroundtext) && (isnotignoredsegment)) { boolean isleadingtag = true; int index = 0; for (int i = 0; i < source.content().size(); i++) { org.dom4j.Node node = (org.dom4j.Node) source.content().get(i); if (node.getNodeType() == 1) { if (isleadingtag) { trg_contents.add(index, node); index++; } else { trg_contents.add(node); } } else { isleadingtag = false; index++; } } } target.setContent(trg_contents); } } }
From source file:revaligner.service.FileAligner.java
private List<String[]> integrateNotesIntoSegments(String file) throws Exception { System.out.println("integrating comments...."); List<String[]> notesinfo = new ArrayList<String[]>(); int id = 0;// www . java 2 s .co m org.dom4j.Document doc = XmlParser.parseXmlFile(file); org.dom4j.Element root = doc.getRootElement(); List transunits = root.selectNodes("//*[name() = 'trans-unit']"); for (Object transunit_obj : transunits) { Element transunit = (Element) transunit_obj; Element target = transunit.element("target"); if (target != null && !target.content().isEmpty()) { List<Element> notes = transunit.elements("note"); for (int i = notes.size() - 1; i >= 0; i--) { Element note = notes.get(i); List content = target.content(); content.add(0, DocumentHelper.createText("[%cmt_" + id + "_s%]")); content.add(DocumentHelper.createText("[%cmt_" + id + "_e%]")); target.setContent(content); String[] noteinfo = new String[3]; noteinfo[0] = note.attribute("from") != null ? note.attributeValue("from") : "Unknown"; noteinfo[1] = note.attribute("timestamp") != null ? note.attributeValue("timestamp") : "Unknown"; noteinfo[2] = note.getText(); notesinfo.add(noteinfo); id++; } } } OutputStreamWriter writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file)), "UTF8"); doc.write(writer); writer.close(); return notesinfo; }
From source file:routines.system.NestXMLTool.java
License:Open Source License
public static void parseAndAdd(org.dom4j.Element nestRoot, String value) { try {//from w w w.j a v a2 s . com org.dom4j.Document doc4Str = org.dom4j.DocumentHelper.parseText("<root>" + value + "</root>"); nestRoot.setContent(doc4Str.getRootElement().content()); } catch (java.lang.Exception e) { e.printStackTrace(); nestRoot.setText(value); } }
From source file:zuora.ots_login_0_1.OTS_Login.java
License:Apache License
public void tFileInputXML_1Process(final java.util.Map<String, Object> globalMap) throws TalendException { globalMap.put("tFileInputXML_1_SUBPROCESS_STATE", 0); final boolean execStat = this.execStat; String currentVirtualComponent = null; String iterateId = ""; String currentComponent = ""; java.util.Map<String, Object> resourceMap = new java.util.HashMap<String, Object>(); try {/*from w w w. jav a 2 s. com*/ String currentMethodName = new java.lang.Exception().getStackTrace()[0].getMethodName(); boolean resumeIt = currentMethodName.equals(resumeEntryMethodName); if (resumeEntryMethodName == null || resumeIt || globalResumeTicket) {// start // the // resume globalResumeTicket = true; row5Struct row5 = new row5Struct(); /** * [tWriteJSONField_2_Out begin ] start */ ok_Hash.put("tWriteJSONField_2_Out", false); start_Hash.put("tWriteJSONField_2_Out", System.currentTimeMillis()); currentVirtualComponent = "tWriteJSONField_2"; currentComponent = "tWriteJSONField_2_Out"; int tos_count_tWriteJSONField_2_Out = 0; // tWriteXMLFieldOut_begin int nb_line_tWriteJSONField_2_Out = 0; boolean needRoot_tWriteJSONField_2_Out = true; String strCompCache_tWriteJSONField_2_Out = null; java.util.Queue<row3Struct> listGroupby_tWriteJSONField_2_Out = new java.util.concurrent.ConcurrentLinkedQueue<row3Struct>(); class ThreadXMLField_tWriteJSONField_2_Out extends Thread { java.util.Queue<row3Struct> queue; java.util.List<java.util.Map<String, String>> flows; java.lang.Exception lastException; String currentComponent; ThreadXMLField_tWriteJSONField_2_Out(java.util.Queue q) { this.queue = q; globalMap.put("queue_tWriteJSONField_2_In", queue); lastException = null; } ThreadXMLField_tWriteJSONField_2_Out(java.util.Queue q, java.util.List<java.util.Map<String, String>> l) { this.queue = q; this.flows = l; lastException = null; globalMap.put("queue_tWriteJSONField_2_In", queue); globalMap.put("flows_tWriteJSONField_2_In", flows); } public java.lang.Exception getLastException() { return this.lastException; } public String getCurrentComponent() { return this.currentComponent; } @Override public void run() { try { tWriteJSONField_2_InProcess(globalMap); } catch (TalendException te) { this.lastException = te.getException(); this.currentComponent = te.getCurrentComponent(); } } } ThreadXMLField_tWriteJSONField_2_Out txf_tWriteJSONField_2_Out = new ThreadXMLField_tWriteJSONField_2_Out( listGroupby_tWriteJSONField_2_Out); txf_tWriteJSONField_2_Out.start(); java.util.List<java.util.List<String>> groupbyList_tWriteJSONField_2_Out = new java.util.ArrayList<java.util.List<String>>(); java.util.Map<String, String> valueMap_tWriteJSONField_2_Out = new java.util.HashMap<String, String>(); class NestXMLTool_tWriteJSONField_2_Out { public void parseAndAdd(org.dom4j.Element nestRoot, String value) { try { org.dom4j.Document doc4Str = org.dom4j.DocumentHelper .parseText("<root>" + value + "</root>"); nestRoot.setContent(doc4Str.getRootElement().content()); } catch (java.lang.Exception e) { e.printStackTrace(); nestRoot.setText(value); } } public void setText(org.dom4j.Element element, String value) { if (value.startsWith("<![CDATA[") && value.endsWith("]]>")) { String text = value.substring(9, value.length() - 3); element.addCDATA(text); } else { element.setText(value); } } public void replaceDefaultNameSpace(org.dom4j.Element nestRoot) { if (nestRoot != null) { for (org.dom4j.Element tmp : (java.util.List<org.dom4j.Element>) nestRoot.elements()) { if (("").equals(tmp.getQName().getNamespace().getURI()) && ("").equals(tmp.getQName().getNamespace().getPrefix())) { tmp.setQName(org.dom4j.DocumentHelper.createQName(tmp.getName(), nestRoot.getQName().getNamespace())); } replaceDefaultNameSpace(tmp); } } } public void removeEmptyElement(org.dom4j.Element root) { if (root != null) { for (org.dom4j.Element tmp : (java.util.List<org.dom4j.Element>) root.elements()) { removeEmptyElement(tmp); } if (root.content().size() == 0 && root.attributes().size() == 0 && root.declaredNamespaces().size() == 0) { if (root.getParent() != null) { root.getParent().remove(root); } } } } } NestXMLTool_tWriteJSONField_2_Out nestXMLTool_tWriteJSONField_2_Out = new NestXMLTool_tWriteJSONField_2_Out(); row5Struct rowStructOutput_tWriteJSONField_2_Out = null; // sort group root element for judgement of group java.util.List<org.dom4j.Element> groupElementList_tWriteJSONField_2_Out = new java.util.ArrayList<org.dom4j.Element>(); org.dom4j.Element root4Group_tWriteJSONField_2_Out = null; org.dom4j.Document doc_tWriteJSONField_2_Out = org.dom4j.DocumentHelper.createDocument(); org.dom4j.io.OutputFormat format_tWriteJSONField_2_Out = org.dom4j.io.OutputFormat .createCompactFormat(); format_tWriteJSONField_2_Out.setNewLineAfterDeclaration(false); format_tWriteJSONField_2_Out.setTrimText(false); format_tWriteJSONField_2_Out.setEncoding("ISO-8859-15"); int[] orders_tWriteJSONField_2_Out = new int[1]; /** * [tWriteJSONField_2_Out begin ] stop */ /** * [tFileInputXML_1 begin ] start */ ok_Hash.put("tFileInputXML_1", false); start_Hash.put("tFileInputXML_1", System.currentTimeMillis()); currentComponent = "tFileInputXML_1"; int tos_count_tFileInputXML_1 = 0; int nb_line_tFileInputXML_1 = 0; String os_tFileInputXML_1 = System.getProperty("os.name").toLowerCase(); boolean isWindows_tFileInputXML_1 = false; if (os_tFileInputXML_1.indexOf("windows") > -1 || os_tFileInputXML_1.indexOf("nt") > -1) { isWindows_tFileInputXML_1 = true; } class NameSpaceTool_tFileInputXML_1 { public java.util.HashMap<String, String> xmlNameSpaceMap = new java.util.HashMap<String, String>(); private java.util.List<String> defualtNSPath = new java.util.ArrayList<String>(); public void countNSMap(org.dom4j.Element el) { for (org.dom4j.Namespace ns : (java.util.List<org.dom4j.Namespace>) el .declaredNamespaces()) { if (ns.getPrefix().trim().length() == 0) { xmlNameSpaceMap.put("pre" + defualtNSPath.size(), ns.getURI()); String path = ""; org.dom4j.Element elTmp = el; while (elTmp != null) { if (elTmp.getNamespacePrefix() != null && elTmp.getNamespacePrefix().length() > 0) { path = "/" + elTmp.getNamespacePrefix() + ":" + elTmp.getName() + path; } else { path = "/" + elTmp.getName() + path; } elTmp = elTmp.getParent(); } defualtNSPath.add(path); } else { xmlNameSpaceMap.put(ns.getPrefix(), ns.getURI()); } } for (org.dom4j.Element e : (java.util.List<org.dom4j.Element>) el.elements()) { countNSMap(e); } } private final org.talend.xpath.XPathUtil util = new org.talend.xpath.XPathUtil(); { util.setDefaultNSPath(defualtNSPath); } public String addDefaultNSPrefix(String path) { return util.addDefaultNSPrefix(path); } public String addDefaultNSPrefix(String relativeXpression, String basePath) { return util.addDefaultNSPrefix(relativeXpression, basePath); } } class XML_API_tFileInputXML_1 { public boolean isDefNull(org.dom4j.Node node) throws javax.xml.transform.TransformerException { if (node != null && node instanceof org.dom4j.Element) { org.dom4j.Attribute attri = ((org.dom4j.Element) node).attribute("nil"); if (attri != null && ("true").equals(attri.getText())) { return true; } } return false; } public boolean isMissing(org.dom4j.Node node) throws javax.xml.transform.TransformerException { return node == null ? true : false; } public boolean isEmpty(org.dom4j.Node node) throws javax.xml.transform.TransformerException { if (node != null) { return node.getText().length() == 0; } return false; } } org.dom4j.io.SAXReader reader_tFileInputXML_1 = new org.dom4j.io.SAXReader(); Object filename_tFileInputXML_1 = null; try { filename_tFileInputXML_1 = "C:/ETL_FASTWEB/ZUORA/data/responses/ots/login.xml"; } catch (java.lang.Exception e) { System.err.println(e.getMessage()); } if (filename_tFileInputXML_1 != null && filename_tFileInputXML_1 instanceof String && filename_tFileInputXML_1.toString().startsWith("//")) { if (!isWindows_tFileInputXML_1) { filename_tFileInputXML_1 = filename_tFileInputXML_1.toString().replaceFirst("//", "/"); } } boolean isValidFile_tFileInputXML_1 = true; org.dom4j.Document doc_tFileInputXML_1 = null; java.io.Closeable toClose_tFileInputXML_1 = null; try { if (filename_tFileInputXML_1 instanceof java.io.InputStream) { java.io.InputStream inputStream_tFileInputXML_1 = (java.io.InputStream) filename_tFileInputXML_1; toClose_tFileInputXML_1 = inputStream_tFileInputXML_1; doc_tFileInputXML_1 = reader_tFileInputXML_1.read(inputStream_tFileInputXML_1); } else { java.io.Reader unicodeReader_tFileInputXML_1 = new UnicodeReader( new java.io.FileInputStream(String.valueOf(filename_tFileInputXML_1)), "ISO-8859-15"); toClose_tFileInputXML_1 = unicodeReader_tFileInputXML_1; org.xml.sax.InputSource in_tFileInputXML_1 = new org.xml.sax.InputSource( unicodeReader_tFileInputXML_1); doc_tFileInputXML_1 = reader_tFileInputXML_1.read(in_tFileInputXML_1); } } catch (java.lang.Exception e) { System.err.println(e.getMessage()); isValidFile_tFileInputXML_1 = false; } finally { if (toClose_tFileInputXML_1 != null) { toClose_tFileInputXML_1.close(); } } if (isValidFile_tFileInputXML_1) { NameSpaceTool_tFileInputXML_1 nsTool_tFileInputXML_1 = new NameSpaceTool_tFileInputXML_1(); nsTool_tFileInputXML_1.countNSMap(doc_tFileInputXML_1.getRootElement()); java.util.HashMap<String, String> xmlNameSpaceMap_tFileInputXML_1 = nsTool_tFileInputXML_1.xmlNameSpaceMap; org.dom4j.XPath x_tFileInputXML_1 = doc_tFileInputXML_1.createXPath(nsTool_tFileInputXML_1 .addDefaultNSPrefix("/soapenv:Envelope/soapenv:Body/soapenv:Fault")); x_tFileInputXML_1.setNamespaceURIs(xmlNameSpaceMap_tFileInputXML_1); java.util.List<org.dom4j.tree.AbstractNode> nodeList_tFileInputXML_1 = (java.util.List<org.dom4j.tree.AbstractNode>) x_tFileInputXML_1 .selectNodes(doc_tFileInputXML_1); XML_API_tFileInputXML_1 xml_api_tFileInputXML_1 = new XML_API_tFileInputXML_1(); String str_tFileInputXML_1 = ""; org.dom4j.Node node_tFileInputXML_1 = null; // init all mapping xpaths for (org.dom4j.tree.AbstractNode temp_tFileInputXML_1 : nodeList_tFileInputXML_1) { nb_line_tFileInputXML_1++; row5 = null; boolean whetherReject_tFileInputXML_1 = false; row5 = new row5Struct(); try { org.dom4j.XPath xTmp0_tFileInputXML_1 = org.dom4j.DocumentHelper .createXPath(nsTool_tFileInputXML_1.addDefaultNSPrefix("faultcode", "/soapenv:Envelope/soapenv:Body/soapenv:Fault")); xTmp0_tFileInputXML_1.setNamespaceURIs(xmlNameSpaceMap_tFileInputXML_1); Object obj0_tFileInputXML_1 = xTmp0_tFileInputXML_1.evaluate(temp_tFileInputXML_1); if (obj0_tFileInputXML_1 == null) { node_tFileInputXML_1 = null; str_tFileInputXML_1 = ""; } else if (obj0_tFileInputXML_1 instanceof org.dom4j.Node) { node_tFileInputXML_1 = (org.dom4j.Node) obj0_tFileInputXML_1; str_tFileInputXML_1 = org.jaxen.function.StringFunction.evaluate( node_tFileInputXML_1, org.jaxen.dom4j.DocumentNavigator.getInstance()); } else if (obj0_tFileInputXML_1 instanceof String || obj0_tFileInputXML_1 instanceof Number) { node_tFileInputXML_1 = temp_tFileInputXML_1; str_tFileInputXML_1 = String.valueOf(obj0_tFileInputXML_1); } else if (obj0_tFileInputXML_1 instanceof java.util.List) { java.util.List<org.dom4j.Node> nodes_tFileInputXML_1 = (java.util.List<org.dom4j.Node>) obj0_tFileInputXML_1; node_tFileInputXML_1 = nodes_tFileInputXML_1.size() > 0 ? nodes_tFileInputXML_1.get(0) : null; str_tFileInputXML_1 = node_tFileInputXML_1 == null ? "" : org.jaxen.function.StringFunction.evaluate(node_tFileInputXML_1, org.jaxen.dom4j.DocumentNavigator.getInstance()); } if (xml_api_tFileInputXML_1.isDefNull(node_tFileInputXML_1)) { row5.faultcode = null; } else if (xml_api_tFileInputXML_1.isEmpty(node_tFileInputXML_1)) { row5.faultcode = ""; } else if (xml_api_tFileInputXML_1.isMissing(node_tFileInputXML_1)) { row5.faultcode = null; } else { row5.faultcode = str_tFileInputXML_1; } org.dom4j.XPath xTmp1_tFileInputXML_1 = org.dom4j.DocumentHelper .createXPath(nsTool_tFileInputXML_1.addDefaultNSPrefix("faultstring", "/soapenv:Envelope/soapenv:Body/soapenv:Fault")); xTmp1_tFileInputXML_1.setNamespaceURIs(xmlNameSpaceMap_tFileInputXML_1); Object obj1_tFileInputXML_1 = xTmp1_tFileInputXML_1.evaluate(temp_tFileInputXML_1); if (obj1_tFileInputXML_1 == null) { node_tFileInputXML_1 = null; str_tFileInputXML_1 = ""; } else if (obj1_tFileInputXML_1 instanceof org.dom4j.Node) { node_tFileInputXML_1 = (org.dom4j.Node) obj1_tFileInputXML_1; str_tFileInputXML_1 = org.jaxen.function.StringFunction.evaluate( node_tFileInputXML_1, org.jaxen.dom4j.DocumentNavigator.getInstance()); } else if (obj1_tFileInputXML_1 instanceof String || obj1_tFileInputXML_1 instanceof Number) { node_tFileInputXML_1 = temp_tFileInputXML_1; str_tFileInputXML_1 = String.valueOf(obj1_tFileInputXML_1); } else if (obj1_tFileInputXML_1 instanceof java.util.List) { java.util.List<org.dom4j.Node> nodes_tFileInputXML_1 = (java.util.List<org.dom4j.Node>) obj1_tFileInputXML_1; node_tFileInputXML_1 = nodes_tFileInputXML_1.size() > 0 ? nodes_tFileInputXML_1.get(0) : null; str_tFileInputXML_1 = node_tFileInputXML_1 == null ? "" : org.jaxen.function.StringFunction.evaluate(node_tFileInputXML_1, org.jaxen.dom4j.DocumentNavigator.getInstance()); } if (xml_api_tFileInputXML_1.isDefNull(node_tFileInputXML_1)) { row5.faultstring = null; } else if (xml_api_tFileInputXML_1.isEmpty(node_tFileInputXML_1)) { row5.faultstring = ""; } else if (xml_api_tFileInputXML_1.isMissing(node_tFileInputXML_1)) { row5.faultstring = null; } else { row5.faultstring = str_tFileInputXML_1; } } catch (java.lang.Exception e) { whetherReject_tFileInputXML_1 = true; System.err.println(e.getMessage()); row5 = null; } if (nb_line_tFileInputXML_1 > 50) { break; } /** * [tFileInputXML_1 begin ] stop */ /** * [tFileInputXML_1 main ] start */ currentComponent = "tFileInputXML_1"; tos_count_tFileInputXML_1++; /** * [tFileInputXML_1 main ] stop */ // Start of branch "row5" if (row5 != null) { /** * [tWriteJSONField_2_Out main ] start */ currentVirtualComponent = "tWriteJSONField_2"; currentComponent = "tWriteJSONField_2_Out"; if (txf_tWriteJSONField_2_Out.getLastException() != null) { currentComponent = txf_tWriteJSONField_2_Out.getCurrentComponent(); throw txf_tWriteJSONField_2_Out.getLastException(); } nb_line_tWriteJSONField_2_Out++; valueMap_tWriteJSONField_2_Out.clear(); valueMap_tWriteJSONField_2_Out.put("faultcode", (row5.faultcode != null ? row5.faultcode.toString() : null)); valueMap_tWriteJSONField_2_Out.put("faultstring", (row5.faultstring != null ? row5.faultstring.toString() : null)); String strTemp_tWriteJSONField_2_Out = ""; strTemp_tWriteJSONField_2_Out = strTemp_tWriteJSONField_2_Out + valueMap_tWriteJSONField_2_Out.get("faultcode") + valueMap_tWriteJSONField_2_Out.get("faultcode").length(); strTemp_tWriteJSONField_2_Out = strTemp_tWriteJSONField_2_Out + valueMap_tWriteJSONField_2_Out.get("faultstring") + valueMap_tWriteJSONField_2_Out.get("faultstring").length(); if (strCompCache_tWriteJSONField_2_Out == null) { strCompCache_tWriteJSONField_2_Out = strTemp_tWriteJSONField_2_Out; rowStructOutput_tWriteJSONField_2_Out = row5; } else { // the data read is different from the data read // last time. if (strCompCache_tWriteJSONField_2_Out .equals(strTemp_tWriteJSONField_2_Out) == false) { nestXMLTool_tWriteJSONField_2_Out .replaceDefaultNameSpace(doc_tWriteJSONField_2_Out.getRootElement()); java.io.StringWriter strWriter_tWriteJSONField_2_Out = new java.io.StringWriter(); org.dom4j.io.XMLWriter output_tWriteJSONField_2_Out = new org.dom4j.io.XMLWriter( strWriter_tWriteJSONField_2_Out, format_tWriteJSONField_2_Out); output_tWriteJSONField_2_Out.write(doc_tWriteJSONField_2_Out); output_tWriteJSONField_2_Out.close(); row3Struct row_tWriteJSONField_2_Out = new row3Struct(); row_tWriteJSONField_2_Out.result = strWriter_tWriteJSONField_2_Out.toString(); listGroupby_tWriteJSONField_2_Out.add(row_tWriteJSONField_2_Out); doc_tWriteJSONField_2_Out.clearContent(); needRoot_tWriteJSONField_2_Out = true; for (int i_tWriteJSONField_2_Out = 0; i_tWriteJSONField_2_Out < orders_tWriteJSONField_2_Out.length; i_tWriteJSONField_2_Out++) { orders_tWriteJSONField_2_Out[i_tWriteJSONField_2_Out] = 0; } if (groupbyList_tWriteJSONField_2_Out != null && groupbyList_tWriteJSONField_2_Out.size() >= 0) { groupbyList_tWriteJSONField_2_Out.clear(); } strCompCache_tWriteJSONField_2_Out = strTemp_tWriteJSONField_2_Out; rowStructOutput_tWriteJSONField_2_Out = row5; } } org.dom4j.Element subTreeRootParent_tWriteJSONField_2_Out = null; // build root xml tree if (needRoot_tWriteJSONField_2_Out) { needRoot_tWriteJSONField_2_Out = false; org.dom4j.Element root_tWriteJSONField_2_Out = doc_tWriteJSONField_2_Out .addElement("result"); subTreeRootParent_tWriteJSONField_2_Out = root_tWriteJSONField_2_Out; org.dom4j.Element root_0_tWriteJSONField_2_Out = root_tWriteJSONField_2_Out .addElement("faultstring"); if (valueMap_tWriteJSONField_2_Out.get("faultstring") != null) { nestXMLTool_tWriteJSONField_2_Out.setText(root_0_tWriteJSONField_2_Out, valueMap_tWriteJSONField_2_Out.get("faultstring")); } root4Group_tWriteJSONField_2_Out = subTreeRootParent_tWriteJSONField_2_Out; } else { subTreeRootParent_tWriteJSONField_2_Out = root4Group_tWriteJSONField_2_Out; } // build group xml tree // build loop xml tree org.dom4j.Element loop_tWriteJSONField_2_Out = org.dom4j.DocumentHelper .createElement("faultcode"); if (orders_tWriteJSONField_2_Out[0] == 0) { orders_tWriteJSONField_2_Out[0] = 0; } if (1 < orders_tWriteJSONField_2_Out.length) { orders_tWriteJSONField_2_Out[1] = 0; } subTreeRootParent_tWriteJSONField_2_Out.elements() .add(orders_tWriteJSONField_2_Out[0]++, loop_tWriteJSONField_2_Out); if (valueMap_tWriteJSONField_2_Out.get("faultcode") != null) { nestXMLTool_tWriteJSONField_2_Out.setText(loop_tWriteJSONField_2_Out, valueMap_tWriteJSONField_2_Out.get("faultcode")); } tos_count_tWriteJSONField_2_Out++; /** * [tWriteJSONField_2_Out main ] stop */ } // End of branch "row5" /** * [tFileInputXML_1 end ] start */ currentComponent = "tFileInputXML_1"; } } globalMap.put("tFileInputXML_1_NB_LINE", nb_line_tFileInputXML_1); ok_Hash.put("tFileInputXML_1", true); end_Hash.put("tFileInputXML_1", System.currentTimeMillis()); /** * [tFileInputXML_1 end ] stop */ /** * [tWriteJSONField_2_Out end ] start */ currentVirtualComponent = "tWriteJSONField_2"; currentComponent = "tWriteJSONField_2_Out"; if (nb_line_tWriteJSONField_2_Out > 0) { nestXMLTool_tWriteJSONField_2_Out .replaceDefaultNameSpace(doc_tWriteJSONField_2_Out.getRootElement()); java.io.StringWriter strWriter_tWriteJSONField_2_Out = new java.io.StringWriter(); org.dom4j.io.XMLWriter output_tWriteJSONField_2_Out = new org.dom4j.io.XMLWriter( strWriter_tWriteJSONField_2_Out, format_tWriteJSONField_2_Out); output_tWriteJSONField_2_Out.write(doc_tWriteJSONField_2_Out); output_tWriteJSONField_2_Out.close(); row3Struct row_tWriteJSONField_2_Out = new row3Struct(); row_tWriteJSONField_2_Out.result = strWriter_tWriteJSONField_2_Out.toString(); listGroupby_tWriteJSONField_2_Out.add(row_tWriteJSONField_2_Out); } globalMap.put("tWriteJSONField_2_Out_NB_LINE", nb_line_tWriteJSONField_2_Out); globalMap.put("tWriteJSONField_2_In_FINISH" + (listGroupby_tWriteJSONField_2_Out == null ? "" : listGroupby_tWriteJSONField_2_Out.hashCode()), "true"); txf_tWriteJSONField_2_Out.join(); if (txf_tWriteJSONField_2_Out.getLastException() != null) { currentComponent = txf_tWriteJSONField_2_Out.getCurrentComponent(); throw txf_tWriteJSONField_2_Out.getLastException(); } resourceMap.put("finish_tWriteJSONField_2_Out", true); ok_Hash.put("tWriteJSONField_2_Out", true); end_Hash.put("tWriteJSONField_2_Out", System.currentTimeMillis()); /** * [tWriteJSONField_2_Out end ] stop */ } // end the resume } catch (java.lang.Exception e) { TalendException te = new TalendException(e, currentComponent, globalMap); te.setVirtualComponentName(currentVirtualComponent); throw te; } catch (java.lang.Error error) { throw error; } finally { try { /** * [tFileInputXML_1 finally ] start */ currentComponent = "tFileInputXML_1"; /** * [tFileInputXML_1 finally ] stop */ /** * [tWriteJSONField_2_Out finally ] start */ currentVirtualComponent = "tWriteJSONField_2"; currentComponent = "tWriteJSONField_2_Out"; java.util.Queue listGroupby_tWriteJSONField_2_Out = (java.util.Queue) globalMap .get("queue_tWriteJSONField_2_In"); if (resourceMap.get("finish_tWriteJSONField_2_Out") == null) { globalMap.put("tWriteJSONField_2_In_FINISH_WITH_EXCEPTION" + (listGroupby_tWriteJSONField_2_Out == null ? "" : listGroupby_tWriteJSONField_2_Out.hashCode()), "true"); } if (listGroupby_tWriteJSONField_2_Out != null) { globalMap.put("tWriteJSONField_2_In_FINISH" + (listGroupby_tWriteJSONField_2_Out == null ? "" : listGroupby_tWriteJSONField_2_Out.hashCode()), "true"); } /** * [tWriteJSONField_2_Out finally ] stop */ } catch (java.lang.Exception e) { // ignore } catch (java.lang.Error error) { // ignore } resourceMap = null; } globalMap.put("tFileInputXML_1_SUBPROCESS_STATE", 1); }
From source file:zuora.ots_subscription_0_1.OTS_Subscription.java
License:Apache License
public void tLogCatcher_1Process(final java.util.Map<String, Object> globalMap) throws TalendException { globalMap.put("tLogCatcher_1_SUBPROCESS_STATE", 0); final boolean execStat = this.execStat; String currentVirtualComponent = null; String iterateId = ""; String currentComponent = ""; java.util.Map<String, Object> resourceMap = new java.util.HashMap<String, Object>(); try {//from w w w . j a va 2 s . c om String currentMethodName = new java.lang.Exception().getStackTrace()[0].getMethodName(); boolean resumeIt = currentMethodName.equals(resumeEntryMethodName); if (resumeEntryMethodName == null || resumeIt || globalResumeTicket) {// start // the // resume globalResumeTicket = true; row3Struct row3 = new row3Struct(); /** * [tWriteJSONField_1_Out begin ] start */ ok_Hash.put("tWriteJSONField_1_Out", false); start_Hash.put("tWriteJSONField_1_Out", System.currentTimeMillis()); currentVirtualComponent = "tWriteJSONField_1"; currentComponent = "tWriteJSONField_1_Out"; int tos_count_tWriteJSONField_1_Out = 0; // tWriteXMLFieldOut_begin int nb_line_tWriteJSONField_1_Out = 0; boolean needRoot_tWriteJSONField_1_Out = true; String strCompCache_tWriteJSONField_1_Out = null; java.util.Queue<row6Struct> listGroupby_tWriteJSONField_1_Out = new java.util.concurrent.ConcurrentLinkedQueue<row6Struct>(); class ThreadXMLField_tWriteJSONField_1_Out extends Thread { java.util.Queue<row6Struct> queue; java.util.List<java.util.Map<String, String>> flows; java.lang.Exception lastException; String currentComponent; ThreadXMLField_tWriteJSONField_1_Out(java.util.Queue q) { this.queue = q; globalMap.put("queue_tWriteJSONField_1_In", queue); lastException = null; } ThreadXMLField_tWriteJSONField_1_Out(java.util.Queue q, java.util.List<java.util.Map<String, String>> l) { this.queue = q; this.flows = l; lastException = null; globalMap.put("queue_tWriteJSONField_1_In", queue); globalMap.put("flows_tWriteJSONField_1_In", flows); } public java.lang.Exception getLastException() { return this.lastException; } public String getCurrentComponent() { return this.currentComponent; } @Override public void run() { try { tWriteJSONField_1_InProcess(globalMap); } catch (TalendException te) { this.lastException = te.getException(); this.currentComponent = te.getCurrentComponent(); } } } ThreadXMLField_tWriteJSONField_1_Out txf_tWriteJSONField_1_Out = new ThreadXMLField_tWriteJSONField_1_Out( listGroupby_tWriteJSONField_1_Out); txf_tWriteJSONField_1_Out.start(); java.util.List<java.util.List<String>> groupbyList_tWriteJSONField_1_Out = new java.util.ArrayList<java.util.List<String>>(); java.util.Map<String, String> valueMap_tWriteJSONField_1_Out = new java.util.HashMap<String, String>(); class NestXMLTool_tWriteJSONField_1_Out { public void parseAndAdd(org.dom4j.Element nestRoot, String value) { try { org.dom4j.Document doc4Str = org.dom4j.DocumentHelper .parseText("<root>" + value + "</root>"); nestRoot.setContent(doc4Str.getRootElement().content()); } catch (java.lang.Exception e) { e.printStackTrace(); nestRoot.setText(value); } } public void setText(org.dom4j.Element element, String value) { if (value.startsWith("<![CDATA[") && value.endsWith("]]>")) { String text = value.substring(9, value.length() - 3); element.addCDATA(text); } else { element.setText(value); } } public void replaceDefaultNameSpace(org.dom4j.Element nestRoot) { if (nestRoot != null) { for (org.dom4j.Element tmp : (java.util.List<org.dom4j.Element>) nestRoot.elements()) { if (("").equals(tmp.getQName().getNamespace().getURI()) && ("").equals(tmp.getQName().getNamespace().getPrefix())) { tmp.setQName(org.dom4j.DocumentHelper.createQName(tmp.getName(), nestRoot.getQName().getNamespace())); } replaceDefaultNameSpace(tmp); } } } public void removeEmptyElement(org.dom4j.Element root) { if (root != null) { for (org.dom4j.Element tmp : (java.util.List<org.dom4j.Element>) root.elements()) { removeEmptyElement(tmp); } if (root.content().size() == 0 && root.attributes().size() == 0 && root.declaredNamespaces().size() == 0) { if (root.getParent() != null) { root.getParent().remove(root); } } } } } NestXMLTool_tWriteJSONField_1_Out nestXMLTool_tWriteJSONField_1_Out = new NestXMLTool_tWriteJSONField_1_Out(); row3Struct rowStructOutput_tWriteJSONField_1_Out = null; // sort group root element for judgement of group java.util.List<org.dom4j.Element> groupElementList_tWriteJSONField_1_Out = new java.util.ArrayList<org.dom4j.Element>(); org.dom4j.Element root4Group_tWriteJSONField_1_Out = null; org.dom4j.Document doc_tWriteJSONField_1_Out = org.dom4j.DocumentHelper.createDocument(); org.dom4j.io.OutputFormat format_tWriteJSONField_1_Out = org.dom4j.io.OutputFormat .createCompactFormat(); format_tWriteJSONField_1_Out.setNewLineAfterDeclaration(false); format_tWriteJSONField_1_Out.setTrimText(false); format_tWriteJSONField_1_Out.setEncoding("ISO-8859-15"); int[] orders_tWriteJSONField_1_Out = new int[1]; /** * [tWriteJSONField_1_Out begin ] stop */ /** * [tLogCatcher_1 begin ] start */ ok_Hash.put("tLogCatcher_1", false); start_Hash.put("tLogCatcher_1", System.currentTimeMillis()); currentComponent = "tLogCatcher_1"; int tos_count_tLogCatcher_1 = 0; for (LogCatcherUtils.LogCatcherMessage lcm : tLogCatcher_1.getMessages()) { row3.type = lcm.getType(); row3.origin = (lcm.getOrigin() == null || lcm.getOrigin().length() < 1 ? null : lcm.getOrigin()); row3.priority = lcm.getPriority(); row3.message = lcm.getMessage(); row3.code = lcm.getCode(); row3.moment = java.util.Calendar.getInstance().getTime(); row3.pid = pid; row3.root_pid = rootPid; row3.father_pid = fatherPid; row3.project = projectName; row3.job = jobName; row3.context = contextStr; /** * [tLogCatcher_1 begin ] stop */ /** * [tLogCatcher_1 main ] start */ currentComponent = "tLogCatcher_1"; tos_count_tLogCatcher_1++; /** * [tLogCatcher_1 main ] stop */ /** * [tWriteJSONField_1_Out main ] start */ currentVirtualComponent = "tWriteJSONField_1"; currentComponent = "tWriteJSONField_1_Out"; if (txf_tWriteJSONField_1_Out.getLastException() != null) { currentComponent = txf_tWriteJSONField_1_Out.getCurrentComponent(); throw txf_tWriteJSONField_1_Out.getLastException(); } nb_line_tWriteJSONField_1_Out++; valueMap_tWriteJSONField_1_Out.clear(); valueMap_tWriteJSONField_1_Out.put("moment", (row3.moment != null ? FormatterUtils.format_Date(row3.moment, "yyyy-MM-dd HH:mm:ss") : null)); valueMap_tWriteJSONField_1_Out.put("pid", (row3.pid != null ? row3.pid.toString() : null)); valueMap_tWriteJSONField_1_Out.put("root_pid", (row3.root_pid != null ? row3.root_pid.toString() : null)); valueMap_tWriteJSONField_1_Out.put("father_pid", (row3.father_pid != null ? row3.father_pid.toString() : null)); valueMap_tWriteJSONField_1_Out.put("project", (row3.project != null ? row3.project.toString() : null)); valueMap_tWriteJSONField_1_Out.put("job", (row3.job != null ? row3.job.toString() : null)); valueMap_tWriteJSONField_1_Out.put("context", (row3.context != null ? row3.context.toString() : null)); valueMap_tWriteJSONField_1_Out.put("priority", (row3.priority != null ? row3.priority.toString() : null)); valueMap_tWriteJSONField_1_Out.put("type", (row3.type != null ? row3.type.toString() : null)); valueMap_tWriteJSONField_1_Out.put("origin", (row3.origin != null ? row3.origin.toString() : null)); valueMap_tWriteJSONField_1_Out.put("message", (row3.message != null ? row3.message.toString() : null)); valueMap_tWriteJSONField_1_Out.put("code", (row3.code != null ? row3.code.toString() : null)); String strTemp_tWriteJSONField_1_Out = ""; strTemp_tWriteJSONField_1_Out = strTemp_tWriteJSONField_1_Out + valueMap_tWriteJSONField_1_Out.get("moment") + valueMap_tWriteJSONField_1_Out.get("moment").length(); strTemp_tWriteJSONField_1_Out = strTemp_tWriteJSONField_1_Out + valueMap_tWriteJSONField_1_Out.get("project") + valueMap_tWriteJSONField_1_Out.get("project").length(); strTemp_tWriteJSONField_1_Out = strTemp_tWriteJSONField_1_Out + valueMap_tWriteJSONField_1_Out.get("job") + valueMap_tWriteJSONField_1_Out.get("job").length(); strTemp_tWriteJSONField_1_Out = strTemp_tWriteJSONField_1_Out + valueMap_tWriteJSONField_1_Out.get("type") + valueMap_tWriteJSONField_1_Out.get("type").length(); strTemp_tWriteJSONField_1_Out = strTemp_tWriteJSONField_1_Out + valueMap_tWriteJSONField_1_Out.get("origin") + valueMap_tWriteJSONField_1_Out.get("origin").length(); strTemp_tWriteJSONField_1_Out = strTemp_tWriteJSONField_1_Out + valueMap_tWriteJSONField_1_Out.get("message") + valueMap_tWriteJSONField_1_Out.get("message").length(); strTemp_tWriteJSONField_1_Out = strTemp_tWriteJSONField_1_Out + valueMap_tWriteJSONField_1_Out.get("code") + valueMap_tWriteJSONField_1_Out.get("code").length(); if (strCompCache_tWriteJSONField_1_Out == null) { strCompCache_tWriteJSONField_1_Out = strTemp_tWriteJSONField_1_Out; rowStructOutput_tWriteJSONField_1_Out = row3; } else { // the data read is different from the data read last // time. if (strCompCache_tWriteJSONField_1_Out.equals(strTemp_tWriteJSONField_1_Out) == false) { nestXMLTool_tWriteJSONField_1_Out .replaceDefaultNameSpace(doc_tWriteJSONField_1_Out.getRootElement()); java.io.StringWriter strWriter_tWriteJSONField_1_Out = new java.io.StringWriter(); org.dom4j.io.XMLWriter output_tWriteJSONField_1_Out = new org.dom4j.io.XMLWriter( strWriter_tWriteJSONField_1_Out, format_tWriteJSONField_1_Out); output_tWriteJSONField_1_Out.write(doc_tWriteJSONField_1_Out); output_tWriteJSONField_1_Out.close(); row6Struct row_tWriteJSONField_1_Out = new row6Struct(); row_tWriteJSONField_1_Out.result = strWriter_tWriteJSONField_1_Out.toString(); listGroupby_tWriteJSONField_1_Out.add(row_tWriteJSONField_1_Out); doc_tWriteJSONField_1_Out.clearContent(); needRoot_tWriteJSONField_1_Out = true; for (int i_tWriteJSONField_1_Out = 0; i_tWriteJSONField_1_Out < orders_tWriteJSONField_1_Out.length; i_tWriteJSONField_1_Out++) { orders_tWriteJSONField_1_Out[i_tWriteJSONField_1_Out] = 0; } if (groupbyList_tWriteJSONField_1_Out != null && groupbyList_tWriteJSONField_1_Out.size() >= 0) { groupbyList_tWriteJSONField_1_Out.clear(); } strCompCache_tWriteJSONField_1_Out = strTemp_tWriteJSONField_1_Out; rowStructOutput_tWriteJSONField_1_Out = row3; } } org.dom4j.Element subTreeRootParent_tWriteJSONField_1_Out = null; // build root xml tree if (needRoot_tWriteJSONField_1_Out) { needRoot_tWriteJSONField_1_Out = false; org.dom4j.Element root_tWriteJSONField_1_Out = doc_tWriteJSONField_1_Out .addElement("result"); subTreeRootParent_tWriteJSONField_1_Out = root_tWriteJSONField_1_Out; org.dom4j.Element root_0_tWriteJSONField_1_Out = root_tWriteJSONField_1_Out .addElement("project"); if (valueMap_tWriteJSONField_1_Out.get("project") != null) { nestXMLTool_tWriteJSONField_1_Out.setText(root_0_tWriteJSONField_1_Out, valueMap_tWriteJSONField_1_Out.get("project")); } org.dom4j.Element root_1_tWriteJSONField_1_Out = root_tWriteJSONField_1_Out .addElement("job"); if (valueMap_tWriteJSONField_1_Out.get("job") != null) { nestXMLTool_tWriteJSONField_1_Out.setText(root_1_tWriteJSONField_1_Out, valueMap_tWriteJSONField_1_Out.get("job")); } org.dom4j.Element root_2_tWriteJSONField_1_Out = root_tWriteJSONField_1_Out .addElement("type"); if (valueMap_tWriteJSONField_1_Out.get("type") != null) { nestXMLTool_tWriteJSONField_1_Out.setText(root_2_tWriteJSONField_1_Out, valueMap_tWriteJSONField_1_Out.get("type")); } org.dom4j.Element root_3_tWriteJSONField_1_Out = root_tWriteJSONField_1_Out .addElement("origin"); if (valueMap_tWriteJSONField_1_Out.get("origin") != null) { nestXMLTool_tWriteJSONField_1_Out.setText(root_3_tWriteJSONField_1_Out, valueMap_tWriteJSONField_1_Out.get("origin")); } org.dom4j.Element root_4_tWriteJSONField_1_Out = root_tWriteJSONField_1_Out .addElement("message"); if (valueMap_tWriteJSONField_1_Out.get("message") != null) { nestXMLTool_tWriteJSONField_1_Out.setText(root_4_tWriteJSONField_1_Out, valueMap_tWriteJSONField_1_Out.get("message")); } org.dom4j.Element root_5_tWriteJSONField_1_Out = root_tWriteJSONField_1_Out .addElement("code"); if (valueMap_tWriteJSONField_1_Out.get("code") != null) { nestXMLTool_tWriteJSONField_1_Out.setText(root_5_tWriteJSONField_1_Out, valueMap_tWriteJSONField_1_Out.get("code")); } root4Group_tWriteJSONField_1_Out = subTreeRootParent_tWriteJSONField_1_Out; } else { subTreeRootParent_tWriteJSONField_1_Out = root4Group_tWriteJSONField_1_Out; } // build group xml tree // build loop xml tree org.dom4j.Element loop_tWriteJSONField_1_Out = org.dom4j.DocumentHelper.createElement("moment"); if (orders_tWriteJSONField_1_Out[0] == 0) { orders_tWriteJSONField_1_Out[0] = 0; } if (1 < orders_tWriteJSONField_1_Out.length) { orders_tWriteJSONField_1_Out[1] = 0; } subTreeRootParent_tWriteJSONField_1_Out.elements().add(orders_tWriteJSONField_1_Out[0]++, loop_tWriteJSONField_1_Out); if (valueMap_tWriteJSONField_1_Out.get("moment") != null) { nestXMLTool_tWriteJSONField_1_Out.setText(loop_tWriteJSONField_1_Out, valueMap_tWriteJSONField_1_Out.get("moment")); } tos_count_tWriteJSONField_1_Out++; /** * [tWriteJSONField_1_Out main ] stop */ /** * [tLogCatcher_1 end ] start */ currentComponent = "tLogCatcher_1"; } ok_Hash.put("tLogCatcher_1", true); end_Hash.put("tLogCatcher_1", System.currentTimeMillis()); /** * [tLogCatcher_1 end ] stop */ /** * [tWriteJSONField_1_Out end ] start */ currentVirtualComponent = "tWriteJSONField_1"; currentComponent = "tWriteJSONField_1_Out"; if (nb_line_tWriteJSONField_1_Out > 0) { nestXMLTool_tWriteJSONField_1_Out .replaceDefaultNameSpace(doc_tWriteJSONField_1_Out.getRootElement()); java.io.StringWriter strWriter_tWriteJSONField_1_Out = new java.io.StringWriter(); org.dom4j.io.XMLWriter output_tWriteJSONField_1_Out = new org.dom4j.io.XMLWriter( strWriter_tWriteJSONField_1_Out, format_tWriteJSONField_1_Out); output_tWriteJSONField_1_Out.write(doc_tWriteJSONField_1_Out); output_tWriteJSONField_1_Out.close(); row6Struct row_tWriteJSONField_1_Out = new row6Struct(); row_tWriteJSONField_1_Out.result = strWriter_tWriteJSONField_1_Out.toString(); listGroupby_tWriteJSONField_1_Out.add(row_tWriteJSONField_1_Out); } globalMap.put("tWriteJSONField_1_Out_NB_LINE", nb_line_tWriteJSONField_1_Out); globalMap.put("tWriteJSONField_1_In_FINISH" + (listGroupby_tWriteJSONField_1_Out == null ? "" : listGroupby_tWriteJSONField_1_Out.hashCode()), "true"); txf_tWriteJSONField_1_Out.join(); if (txf_tWriteJSONField_1_Out.getLastException() != null) { currentComponent = txf_tWriteJSONField_1_Out.getCurrentComponent(); throw txf_tWriteJSONField_1_Out.getLastException(); } resourceMap.put("finish_tWriteJSONField_1_Out", true); ok_Hash.put("tWriteJSONField_1_Out", true); end_Hash.put("tWriteJSONField_1_Out", System.currentTimeMillis()); /** * [tWriteJSONField_1_Out end ] stop */ } // end the resume } catch (java.lang.Exception e) { TalendException te = new TalendException(e, currentComponent, globalMap); te.setVirtualComponentName(currentVirtualComponent); throw te; } catch (java.lang.Error error) { throw error; } finally { try { /** * [tLogCatcher_1 finally ] start */ currentComponent = "tLogCatcher_1"; /** * [tLogCatcher_1 finally ] stop */ /** * [tWriteJSONField_1_Out finally ] start */ currentVirtualComponent = "tWriteJSONField_1"; currentComponent = "tWriteJSONField_1_Out"; java.util.Queue listGroupby_tWriteJSONField_1_Out = (java.util.Queue) globalMap .get("queue_tWriteJSONField_1_In"); if (resourceMap.get("finish_tWriteJSONField_1_Out") == null) { globalMap.put("tWriteJSONField_1_In_FINISH_WITH_EXCEPTION" + (listGroupby_tWriteJSONField_1_Out == null ? "" : listGroupby_tWriteJSONField_1_Out.hashCode()), "true"); } if (listGroupby_tWriteJSONField_1_Out != null) { globalMap.put("tWriteJSONField_1_In_FINISH" + (listGroupby_tWriteJSONField_1_Out == null ? "" : listGroupby_tWriteJSONField_1_Out.hashCode()), "true"); } /** * [tWriteJSONField_1_Out finally ] stop */ } catch (java.lang.Exception e) { // ignore } catch (java.lang.Error error) { // ignore } resourceMap = null; } globalMap.put("tLogCatcher_1_SUBPROCESS_STATE", 1); }