List of usage examples for org.dom4j Node getText
String getText();
Returns the text of this node.
From source file:com.globalsight.terminology.EntryUtils.java
License:Apache License
/** * Returns the HTML representation of an element's text. This is * like getInnerXml() but doesn't encode apostrophes. */// w ww.j a v a 2s .co m static public String getInnerHtml(Element p_node) { StringBuffer result = new StringBuffer(); List content = p_node.content(); for (int i = 0, max = content.size(); i < max; i++) { Node node = (Node) content.get(i); // Work around a specific behaviour of DOM4J text nodes: // The text node asXML() returns the plain Unicode string, // so we need to encode entities manually. if (node.getNodeType() == Node.TEXT_NODE) { result.append(EditUtil.encodeHtmlEntities(node.getText())); } else { // Element nodes write their text nodes correctly. result.append(node.asXML()); } } return result.toString(); }
From source file:com.globalsight.terminology.Validator.java
License:Apache License
/** * Validates an entry. Caller must lock Termbase object with * Termbase.addReader().//from ww w .ja v a 2s . c om */ static public ValidationInfo validate(Entry p_entry, Definition m_definition, long tb_id) throws TermbaseException { long cid = EntryUtils.getConceptId(p_entry); ValidationInfo result = new ValidationInfo(cid); if (CATEGORY.isDebugEnabled()) { CATEGORY.debug("Validating entry " + cid + "..."); } List langGrps = EntryUtils.getLanguageGrps(p_entry); for (int i = 0, max = langGrps.size(); i < max; i++) { Node langGrp = (Node) langGrps.get(i); String langName = langGrp.valueOf("language/@name"); Definition.Language language = m_definition.getLanguage(langName); List terms = EntryUtils.getTerms(langGrp); for (int j = 0, max2 = terms.size(); j < max2; j++) { Node termNode = (Node) terms.get(j); Node termAttribute = termNode.selectSingleNode("//term/@termId"); String termId = null; if (termAttribute != null) { termId = termAttribute.getText(); } String term = termNode.getText(); // Collect exact matches from the same language. Hitlist hits = getDuplicateTerm(tb_id, langName, term, termId); addHits(result, langName, term, hits); // Should look for fuzzy matches too. } } if (CATEGORY.isDebugEnabled()) { CATEGORY.debug("Validating entry " + cid + "... done."); } return result; }
From source file:com.globalsight.webservices.Ambassador.java
License:Apache License
/** * Converts a DOM TU to a GS SegmentTmTu, thereby converting any TMX format * specialities as best as possible./* w w w . j a v a2s . c o m*/ * * @param p_root * Element * @param ptm * @throws Exception */ private void editTm2Tu(Element p_root) throws Exception { // Original TU id, if known String id = p_root.attributeValue(Tmx.TUID); ProjectTmTuT tu = null; try { if (id != null && id.length() > 0) { long lid = Long.parseLong(id); tu = HibernateUtil.get(ProjectTmTuT.class, lid); if (tu == null) { throw new Exception("Can not find tu with id: " + lid); } } else { throw new Exception("Can not find tu id"); } // Datatype of the TU (html, javascript etc) String format = p_root.attributeValue(Tmx.DATATYPE); if (format == null || format.length() == 0) { format = "html"; } tu.setFormat(format.trim()); // Locale of Source TUV (use default from header) String lang = p_root.attributeValue(Tmx.SRCLANG); if (lang == null || lang.length() == 0) { lang = "en_US"; } String locale = ImportUtil.normalizeLocale(lang); LocaleManagerLocal manager = new LocaleManagerLocal(); tu.setSourceLocale(manager.getLocaleByString(locale)); // Segment type (text, css-color, etc) String segmentType = "text"; Node node = p_root.selectSingleNode(".//prop[@type = '" + Tmx.PROP_SEGMENTTYPE + "']"); if (node != null) { segmentType = node.getText(); } tu.setType(segmentType); // Sid node = p_root.selectSingleNode(".//prop[@type= '" + Tmx.PROP_TM_UDA_SID + "']"); if (node != null) { tu.setSid(node.getText()); } // TUVs List nodes = p_root.elements("tuv"); for (int i = 0; i < nodes.size(); i++) { Element elem = (Element) nodes.get(i); ProjectTmTuvT tuv = new ProjectTmTuvT(); tuv.reconvertFromTmx(elem, tu); // Check the locale List<ProjectTmTuvT> savedTuvs = new ArrayList<ProjectTmTuvT>(); for (ProjectTmTuvT savedTuv : tu.getTuvs()) { if (savedTuv.getLocale().equals(tuv.getLocale())) { savedTuvs.add(savedTuv); } } if (savedTuvs.size() == 0) { throw new WebServiceException( "Can not find tuv with tu id: " + tu.getId() + ", locale: " + tuv.getLocale()); } // More than one tuv have the locale, than go to check the // create // date. if (savedTuvs.size() > 1) { boolean find = false; for (ProjectTmTuvT savedTuv : savedTuvs) { if (savedTuv.getCreationDate().getTime() == tuv.getCreationDate().getTime()) { find = true; savedTuv.merge(tuv); HibernateUtil.save(savedTuv); } } if (!find) { throw new WebServiceException("Can not find tuv with tu id: " + tu.getId() + ", locale: " + tuv.getLocale() + ", creation date:" + tuv.getCreationDate()); } } else { ProjectTmTuvT savedTuv = savedTuvs.get(0); savedTuv.merge(tuv); HibernateUtil.save(savedTuv); } } HibernateUtil.save(tu); } finally { HibernateUtil.closeSession(); } }
From source file:com.globalsight.webservices.Ambassador.java
License:Apache License
private void editTm3Tu(Element p_root, ProjectTM ptm) throws Exception { String tuId = p_root.attributeValue(Tmx.TUID); BaseTm tm = TM3Util.getBaseTm(ptm.getTm3Id()); TM3Tu tm3Tu = tm.getTu(Long.parseLong(tuId)); TM3Attribute typeAttr = TM3Util.getAttr(tm, TYPE); TM3Attribute formatAttr = TM3Util.getAttr(tm, FORMAT); TM3Attribute sidAttr = TM3Util.getAttr(tm, SID); TM3Attribute translatableAttr = TM3Util.getAttr(tm, TRANSLATABLE); TM3Attribute fromWsAttr = TM3Util.getAttr(tm, FROM_WORLDSERVER); TM3Attribute projectAttr = TM3Util.getAttr(tm, UPDATED_BY_PROJECT); SegmentTmTu tu = TM3Util.toSegmentTmTu(tm3Tu, ptm.getId(), formatAttr, typeAttr, sidAttr, fromWsAttr, translatableAttr, projectAttr); // Datatype of the TU (html, javascript etc) String format = p_root.attributeValue(Tmx.DATATYPE); if (format == null || format.length() == 0) { format = "html"; }/*from w w w . j a v a 2 s .c om*/ tu.setFormat(format.trim()); // Locale of Source TUV (use default from header) String lang = p_root.attributeValue(Tmx.SRCLANG); if (lang == null || lang.length() == 0) { lang = "en_US"; } String locale = ImportUtil.normalizeLocale(lang); LocaleManagerLocal manager = new LocaleManagerLocal(); tu.setSourceLocale(manager.getLocaleByString(locale)); // Segment type (text, css-color, etc) String segmentType = "text"; Node node = p_root.selectSingleNode(".//prop[@type = '" + Tmx.PROP_SEGMENTTYPE + "']"); if (node != null) { segmentType = node.getText(); } tu.setType(segmentType); // Sid String sid = null; node = p_root.selectSingleNode(".//prop[@type= '" + Tmx.PROP_TM_UDA_SID + "']"); if (node != null) { sid = node.getText(); tu.setSID(sid); } // TUVs List nodes = p_root.elements("tuv"); List<SegmentTmTuv> tuvsToBeUpdated = new ArrayList<SegmentTmTuv>(); for (int i = 0; i < nodes.size(); i++) { Element elem = (Element) nodes.get(i); SegmentTmTuv tuv = new SegmentTmTuv(); PageTmTu pageTmTu = new PageTmTu(-1, -1, "plaintext", "text", true); tuv.setTu(pageTmTu); tuv.setSid(sid); TmxUtil.convertFromTmx(elem, tuv); Collection splitSegments = tuv.prepareForSegmentTm(); Iterator itSplit = splitSegments.iterator(); while (itSplit.hasNext()) { AbstractTmTuv.SegmentAttributes segAtt = (AbstractTmTuv.SegmentAttributes) itSplit.next(); String segmentString = segAtt.getText(); tuv.setSegment(segmentString); } // Check the locale List<SegmentTmTuv> savedTuvs = new ArrayList<SegmentTmTuv>(); for (BaseTmTuv savedTuv : tu.getTuvs()) { if (savedTuv.getLocale().equals(tuv.getLocale())) { savedTuvs.add((SegmentTmTuv) savedTuv); } } if (savedTuvs.size() > 1) { boolean find = false; for (SegmentTmTuv savedTuv : savedTuvs) { if (savedTuv.getCreationDate().getTime() == tuv.getCreationDate().getTime()) { find = true; savedTuv.merge(tuv); tuvsToBeUpdated.add(savedTuv); } } if (!find) { throw new WebServiceException("Can not find tuv with tu id: " + tu.getId() + ", locale: " + tuv.getLocale() + ", creation date:" + tuv.getCreationDate()); } } else { SegmentTmTuv savedTuv = savedTuvs.get(0); savedTuv.merge(tuv); tuvsToBeUpdated.add(savedTuv); } } ptm.getSegmentTmInfo().updateSegmentTmTuvs(ptm, tuvsToBeUpdated); }
From source file:com.google.code.pentahoflashcharts.charts.AbstractChartFactory.java
License:Open Source License
public static String getValue(Node n) { if (n != null && n.getText() != null && n.getText().length() > 0) { return n.getText().trim(); } else {// w ww . j a v a 2s .c o m return null; } }
From source file:com.google.code.pentahoflashcharts.charts.pfcxml.BarLineChartBuilder.java
License:Open Source License
protected void setupLineElements(Chart c, Node root, IPentahoResultSet data, int rowCount) { Style lineStyle = setupLineStyle(root); LineChart e = new LineChart(lineStyle); Node colIndexNode = root.selectSingleNode("/chart/line/sql-column-index"); Node linetooltipNode = root.selectSingleNode("/chart/line/tooltip"); if (getValue(linetooltipNode) != null) { e.setTooltip(getValue(linetooltipNode)); }//w w w . j a v a 2 s . co m if (colIndexNode != null && colIndexNode.getText().length() > 0) { int index = Integer.parseInt(colIndexNode.getText().trim()); for (int j = 0; j < rowCount; j++) { double value = ((Number) data.getValueAt(j, index - 1)).doubleValue(); e.addValues(value); } } else { for (int j = 0; j < rowCount; j++) { double value = ((Number) data.getValueAt(j, data.getColumnCount() - 1)).doubleValue(); e.addValues(value); } } Node colorNode = root.selectSingleNode("/chart/line/color"); if (colorNode != null && colorNode.getText().length() > 0) { e.setColour(colorNode.getText().trim()); } Node textNode = root.selectSingleNode("/chart/line/text"); if (textNode != null && textNode.getText().length() > 0) { e.setText(textNode.getText().trim()); } e.setRightYAxis(); c.addElements(e); }
From source file:com.google.code.pentahoflashcharts.charts.pfcxml.BarLineChartBuilder.java
License:Open Source License
protected void setupBarElements(Chart c, Node root, IPentahoResultSet data) { List bars = root.selectNodes("/chart/bars/bar"); Node is_3DNode = root.selectSingleNode("/chart/is-3D"); Node is_glassNode = root.selectSingleNode("/chart/is-glass"); // Node is_sketchNode = root.selectSingleNode("/chart/is-sketch"); BarChart.Style style = null;//ww w . j av a 2s .c o m if (getValue(is_3DNode) != null) { String str = is_3DNode.getText().trim(); if (str.equalsIgnoreCase("true")) { style = BarChart.Style.THREED; } } if (getValue(is_glassNode) != null) { String str = is_glassNode.getText().trim(); if (str.equalsIgnoreCase("true")) { style = BarChart.Style.GLASS; } } if (style == null) style = BarChart.Style.NORMAL; BarChart[] values = null; int rowCount = data.getRowCount(); int barNum = bars.size(); values = new BarChart[barNum]; for (int i = 0; i < barNum; i++) { Node bar = (Node) bars.get(i); Node colorNode = bar.selectSingleNode("color"); Node textNode = bar.selectSingleNode("text"); BarChart e = new BarChart(style); Number[] datas = new Number[rowCount]; if (colorNode != null && colorNode.getText().length() > 2) { String str = colorNode.getText().trim(); e.setColour(str); } if (textNode != null && textNode.getText().length() > 0) { e.setText(textNode.getText().trim()); } Node colIndexNode = bar.selectSingleNode("sql-column-index"); if (colIndexNode != null && colIndexNode.getText().length() > 0) { int index = Integer.parseInt(colIndexNode.getText().trim()); for (int j = 0; j < rowCount; j++) { datas[j] = (Number) data.getValueAt(j, index - 1); e.addBars(new BarChart.Bar(datas[j].doubleValue())); // e.addValues(datas[j].doubleValue()); } } values[i] = e; } c.addElements(values); }
From source file:com.google.code.pentahoflashcharts.charts.pfcxml.ChartBuilder.java
License:Open Source License
public static String getValue(Node n) { if (n != null && n.getText() != null && n.getText().length() > 0) { return n.getText().trim(); } else {// ww w . j av a2s. c om return null; } }
From source file:com.google.code.pentahoflashcharts.charts.pfcxml.ChartBuilder.java
License:Open Source License
public static String getNodeValue(Node n) { return n.getText().trim(); }
From source file:com.google.code.pentahoflashcharts.charts.pfcxml.ChartBuilder.java
License:Open Source License
public static void setYAxisRange(Chart c, Node stepsNode, Node yMaxNode) { YAxis yaxis = new YAxis(); int y_max = 10000; int y_step = 10; if (stepsNode != null && stepsNode.getText().length() > 0) { y_step = Integer.parseInt(stepsNode.getText().trim()); }//from w w w .ja va 2 s .c om if (yMaxNode != null && yMaxNode.getText().length() > 0) { y_max = Integer.parseInt(yMaxNode.getText().trim()); } yaxis.setRange(0, y_max, y_step); c.setYAxis(yaxis); }