List of usage examples for org.dom4j Element content
List<Node> content();
From source file:com.globalsight.cxe.adapter.msoffice.WordRepairer.java
License:Apache License
private static void forTextInWp(Element element) { @SuppressWarnings("unchecked") List<Node> ts = element.selectNodes("//w:p/text()"); for (Node t : ts) { String c = t.getText();//from w ww . ja va2s.c o m if (c.matches("[\n\r]*")) { continue; } Element wp = t.getParent(); Element wr = DocumentHelper.createElement("w:r"); wp.content().add(wp.indexOf(t), wr); Element wt = wr.addElement("w:t"); wt.setText(t.getText()); wp.remove(t); } }
From source file:com.globalsight.everest.edit.offline.OfflineEditManagerLocal.java
License:Apache License
/** * Adds all comments to database. The path is trans-unit/note. * // w w w. jav a 2s.c o m * @param doc * The document of the xliff file. * @param p_user * The user who uploaded the xliff file. */ private void addComment(Document doc, User p_user, HashSet<Long> jobIds) { XmlEntities entity = new XmlEntities(); Element root = doc.getRootElement(); Element file = root.element(XliffConstants.FILE); String target = file.attributeValue("target-language"); target = target.replace("-", "_"); org.dom4j.Element bodyElement = file.element(XliffConstants.BODY); for (Iterator i = bodyElement.elementIterator(XliffConstants.TRANS_UNIT); i.hasNext();) { Element foo = (Element) i.next(); // For GBS-3643: if resname="SID", do not add note value as comment. String resName = foo.attributeValue("resname"); if ("SID".equalsIgnoreCase(resName)) { continue; } for (Iterator notes = foo.elementIterator(XliffConstants.NOTE); notes.hasNext();) { Element note = (Element) notes.next(); List elements = note.elements(); String msg = m_resource.getString("msg_note_format_error"); if (elements == null || note.content().size() == 0) { continue; } for (Object obj : note.content()) { if (!(obj instanceof DefaultText)) { s_category.error(msg); s_category.error("Error note: " + note.asXML()); throw new IllegalArgumentException(msg); } } String textContent = note.getText(); if (textContent.startsWith("Match Type:")) { continue; } textContent = entity.decodeString(textContent, null); String tuId = foo.attributeValue("id"); try { // As we can not get to know the job ID only by the tuId, we // have to loop jobIds until we can get the TU object. long jobId = -1; TuImpl tu = null; for (long id : jobIds) { tu = SegmentTuUtil.getTuById(Long.parseLong(tuId), id); jobId = id; if (tu != null) { break; } } for (Object ob : tu.getTuvs(true, jobId)) { TuvImpl tuv = (TuvImpl) ob; TargetPage tPage = tuv.getTargetPage(jobId); if (tuv.getGlobalSightLocale().toString().equalsIgnoreCase(target)) { String title = String.valueOf(tu.getId()); String priority = "Medium"; String status = "open"; String category = "Type01"; IssueImpl issue = tuv.getComment(); if (issue == null) { String key = CommentHelper.makeLogicalKey(tPage.getId(), tu.getId(), tuv.getId(), 0); issue = new IssueImpl(Issue.TYPE_SEGMENT, tuv.getId(), title, priority, status, category, p_user.getUserId(), textContent, key); issue.setShare(false); issue.setOverwrite(false); } else { issue.setTitle(title); issue.setPriority(priority); issue.setStatus(status); issue.setCategory(category); issue.addHistory(p_user.getUserId(), textContent); issue.setShare(false); issue.setOverwrite(false); } HibernateUtil.saveOrUpdate(issue); break; } } } catch (Exception e) { s_category.error("Failed to add comments", e); } } } }
From source file:com.globalsight.everest.edit.offline.page.TmxUtil.java
License:Apache License
/** * Removes the given <sub> element from the segment. <sub> is special since * it does not only surround embedded tags but also text, which must be * pulled out of the <sub> and added to the parent tag. *///from w w w. j av a2 s. c o m public static void replaceNbsp(Element p_element) { Element parent = p_element.getParent(); int index = parent.indexOf(p_element); // We copy the current content, clear out the parent, and then // re-add the old content, inserting the <sub>'s textual // content instead of the <sub> (this clears any embedded TMX // tags in the subflow). ArrayList newContent = new ArrayList(); List content = parent.content(); for (int i = content.size() - 1; i >= 0; --i) { Node node = (Node) content.get(i); newContent.add(node.detach()); } Collections.reverse(newContent); parent.clearContent(); for (int i = 0, max = newContent.size(); i < max; ++i) { Node node = (Node) newContent.get(i); if (i == index) { parent.addText("\u00A0"); } else { parent.add(node); } } }
From source file:com.globalsight.everest.edit.offline.page.TmxUtil.java
License:Apache License
/** * Removes the given <sub> element from the segment. <sub> is special since * it does not only surround embedded tags but also text, which must be * pulled out of the <sub> and added to the parent tag. *//* ww w . j a v a 2s . com*/ public static void removeSubElement(Element p_element) { Element parent = p_element.getParent(); int index = parent.indexOf(p_element); // We copy the current content, clear out the parent, and then // re-add the old content, inserting the <sub>'s textual // content instead of the <sub> (this clears any embedded TMX // tags in the subflow). ArrayList newContent = new ArrayList(); List content = parent.content(); for (int i = content.size() - 1; i >= 0; --i) { Node node = (Node) content.get(i); newContent.add(node.detach()); } Collections.reverse(newContent); parent.clearContent(); for (int i = 0, max = newContent.size(); i < max; ++i) { Node node = (Node) newContent.get(i); if (i == index) { parent.addText(p_element.getText()); } else { parent.add(node); } } }
From source file:com.globalsight.everest.edit.offline.page.TmxUtil.java
License:Apache License
/** * Returns the XML representation like Element.asXML() but without the * top-level tag./*from www . j a v a2 s .c o m*/ */ @SuppressWarnings("unchecked") private static String getInnerXml(Element p_node) { StringBuffer result = new StringBuffer(); List<Node> content = p_node.content(); for (Node node : content) { if (node.getNodeType() == Node.TEXT_NODE) { result.append(EditUtil.encodeXmlEntities(node.getText())); } else { StringWriter out = new StringWriter(); result.append(out.toString()); } } return result.toString(); }
From source file:com.globalsight.everest.edit.offline.page.TmxUtil.java
License:Apache License
/** * Removes the given TMX 1.4 <hi> element from the segment. <hi> is special * since it does not surround embedded tags but text, which must be pulled * out of the <hi> and added to the parent segment. *///from ww w .j a va 2 s . c om private static void removeHiElement(Element p_element) { Element parent = p_element.getParent(); int index = parent.indexOf(p_element); // We copy the current content, clear out the parent, and then // re-add the old content, inserting the <hi>'s content // instead of the <hi>. ArrayList newContent = new ArrayList(); List content = parent.content(); for (int i = content.size() - 1; i >= 0; --i) { Node node = (Node) content.get(i); newContent.add(node.detach()); } Collections.reverse(newContent); parent.clearContent(); for (int i = 0, max = newContent.size(); i < max; ++i) { Node node = (Node) newContent.get(i); if (i == index) { parent.appendContent(p_element); } else { parent.add(node); } } }
From source file:com.globalsight.everest.projecthandler.ProjectTmTuvT.java
License:Apache License
/** * Removes the given TMX 1.4 <hi> element from the segment. <hi> is special * since it does not surround embedded tags but text, which must be pulled * out of the <hi> and added to the parent segment. *//* w ww.ja va 2 s. com*/ private void removeHiElement(Element p_element) { Element parent = p_element.getParent(); int index = parent.indexOf(p_element); // We copy the current content, clear out the parent, and then // re-add the old content, inserting the <hi>'s content // instead of the <hi>. ArrayList newContent = new ArrayList(); List content = parent.content(); for (int i = content.size() - 1; i >= 0; --i) { Node node = (Node) content.get(i); newContent.add(node.detach()); } Collections.reverse(newContent); parent.clearContent(); for (int i = 0, max = newContent.size(); i < max; ++i) { Node node = (Node) newContent.get(i); if (i == index) { parent.appendContent(p_element); } else { parent.add(node); } } }
From source file:com.globalsight.everest.projecthandler.ProjectTmTuvT.java
License:Apache License
/** * Returns the XML representation like Element.asXML() but without the * top-level tag./* w ww .j a v a2 s .com*/ */ @SuppressWarnings("unchecked") private String getInnerXml(Element p_node) { StringBuffer result = new StringBuffer(); List<Node> content = p_node.content(); for (Node node : content) { if (node.getNodeType() == Node.TEXT_NODE) { result.append(EditUtil.encodeXmlEntities(node.getText())); } else { StringWriter out = new StringWriter(); result.append(out.toString()); } } return result.toString(); }
From source file:com.globalsight.everest.tm.exporter.TmxWriter.java
License:Apache License
/** * Returns the XML representation like Element.asXML() but without the * top-level tag./* www .jav a 2s .co m*/ */ private static String getInnerXml(Element p_node, OutputFormat outputFormat) { 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.encodeXmlEntities(node.getText())); } else { // Note: DOM4J's node.asXML() constructs the same 2 objects. StringWriter out = new StringWriter(); XMLWriter writer = new XMLWriter(out, outputFormat); try { writer.write(node); } catch (IOException ignore) { } result.append(out.toString()); } } return result.toString(); }
From source file:com.globalsight.everest.tm.exporter.TmxWriter.java
License:Apache License
/** * Removes the given <sub> element from the segment. <sub> is special since * it does not only surround embedded tags but also text, which must be * pulled out of the <sub> and added to the parent tag. */// w ww . j a v a 2 s. c o m private static void removeSubElement(Element p_element) { Element parent = p_element.getParent(); int index = parent.indexOf(p_element); // We copy the current content, clear out the parent, and then // re-add the old content, inserting the <sub>'s textual // content instead of the <sub> (this clears any embedded TMX // tags in the subflow). ArrayList newContent = new ArrayList(); List content = parent.content(); for (int i = content.size() - 1; i >= 0; --i) { Node node = (Node) content.get(i); newContent.add(node.detach()); } Collections.reverse(newContent); parent.clearContent(); for (int i = 0, max = newContent.size(); i < max; ++i) { Node node = (Node) newContent.get(i); if (i == index) { parent.addText(p_element.getText()); } else { parent.add(node); } } }