List of usage examples for org.dom4j Node getText
String getText();
Returns the text of this node.
From source file:com.globalsight.cxe.adapter.serviceware.ServiceWareAPI.java
License:Apache License
/** * Returns a Hashtable containing all the Knowledge Object Ids and their * names/*from w w w . ja v a 2 s .com*/ * * @param p_sessionId * @return * @exception Exception */ public static Hashtable getKnowledgeObjects(String p_sessionId) throws Exception { Hashtable ht = new Hashtable(); StringBuffer url = new StringBuffer(s_apiUrl); url.append("?Action=GetKOs&SessionID="); url.append(p_sessionId); s_logger.debug("URL=" + url.toString()); String xml = readXml(url.toString()); s_logger.debug("XML is: " + xml); XmlParser xmlp = XmlParser.hire(); Document d = xmlp.parseXml(xml); Element root = d.getRootElement(); List idnodes = root.selectNodes("/GetKOsResponse/return/SessionKOs/KO/KOID"); List namenodes = root.selectNodes("/GetKOsResponse/return/SessionKOs/KO/Name"); for (int i = 0; i < idnodes.size(); i++) { Node id = (Node) idnodes.get(i); Node name = (Node) namenodes.get(i); s_logger.debug("Inserting: " + id.getText() + "," + name.getText()); ht.put(id.getText(), name.getText()); } XmlParser.fire(xmlp); return ht; }
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 ww w.ja v a2 s .com */ @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.page.pageexport.ExportEventObserverLocal.java
License:Apache License
/** * Notifies the person who initiated the job about the export being * complete. The job's first request's event flow xml is retrieved and the * importInitiatorId plucked from that.//from w w w . j a v a2 s . c o m * * @param p_batchEvent * @param p_args * @param p_subject * @param p_msgKey */ private void notifyImportInitiator(ExportBatchEvent p_batchEvent, String[] p_args, String p_subject, String p_msgKey) { XmlParser xmlParser = null; try { // first get back the event flow xml Job job = p_batchEvent.getJob(); Collection requests = job.getRequestList(); Iterator iter = requests.iterator(); Request firstRequest = (Request) iter.next(); String efxml = firstRequest.getEventFlowXml(); String companyIdStr = String.valueOf(job.getCompanyId()); // parse the efxml for the import initiator id xmlParser = XmlParser.hire(); Document document = xmlParser.parseXml(efxml); Element root = document.getRootElement(); Node node = root.selectSingleNode("/eventFlowXml/source/@importInitiatorId"); if (node != null) { String importInitatorId = node.getText(); if (importInitatorId != null && importInitatorId.length() > 0) { User user = ServerProxy.getUserManager().getUser(importInitatorId); s_logger.debug("Emailing import initator " + importInitatorId + " at email address " + user.getEmail()); ExportEventObserverHelper.sendEmail(user, p_args, p_subject, p_msgKey, companyIdStr); } } } catch (Exception ex) { s_logger.error( "Failed to send e-mail to the import initiator. The export process has completed but\r\n" + "the user will not receive e-mail notification due to the following exception:\r\n", ex); } finally { if (xmlParser != null) { XmlParser.fire(xmlParser); } } }
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 w w .jav a2 s.c o m*/ */ @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./*from w w w .j a va 2 s .c o 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.importer.ImportUtil.java
License:Apache License
/** * Returns the XML representation like Element.asXML() but without the * top-level tag.//from www . java 2s. c o m */ static public String getInnerXml(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(encodeXmlEntities(node.getText())); } else { // Element nodes write their text nodes correctly. result.append(node.asXML()); } } return result.toString(); }
From source file:com.globalsight.everest.tm.importer.TmxReaderThread.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 av a2 s . c om*/ private SegmentTmTu createTu(Element p_root) throws Exception { SegmentTmTu result = new SegmentTmTu(); // Optional TU attributes: // Original TU id, if known String id = p_root.attributeValue(Tmx.TUID); if (id != null && id.length() > 0) { try { long lid = Long.parseLong(id); result.setId(lid); } catch (Throwable ignore) { // <TU tuid> can be an alphanumeric token. // If it is not a simple number, we ignore it. } } // Datatype of the TU (html, javascript etc) String format = p_root.attributeValue(Tmx.DATATYPE); if (format == null || format.length() == 0) { format = m_tmx.getDatatype(); } result.setFormat(format); // Locale of Source TUV (use default from header) String lang = p_root.attributeValue(Tmx.SRCLANG); if (lang == null || lang.length() == 0) { lang = m_defaultSrcLang; } try { String locale = ImportUtil.normalizeLocale(lang); result.setSourceLocale(ImportUtil.getLocaleByName(locale)); } catch (Throwable ex) { CATEGORY.warn("invalid locale " + lang); throw new Exception("cannot handle locale " + lang); } // TODO: other optional attributes String usageCount = p_root.attributeValue(Tmx.USAGECOUNT); String usageDate = p_root.attributeValue(Tmx.LASTUSAGEDATE); //String tool = p_root.attributeValue(Tmx.CREATIONTOOL); //String toolversion = p_root.attributeValue(Tmx.CREATIONTOOLVERSION); // used in createTuv() //String creationDate = p_root.attributeValue(Tmx.CREATIONDATE); //String creationUser = p_root.attributeValue(Tmx.CREATIONID); //String changeDate = p_root.attributeValue(Tmx.CHANGEDATE); //String changeUser = p_root.attributeValue(Tmx.CHANGEID); // GlobalSight-defined properties: // 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(); } result.setType(segmentType); //Read SID node = p_root.selectSingleNode(".//prop[@type= '" + Tmx.PROP_TM_UDA_SID + "']"); if (node != null) { result.setSID(node.getText()); } // TU type (T or L) boolean isTranslatable = true; node = p_root.selectSingleNode(".//prop[@type = '" + Tmx.PROP_TUTYPE + "']"); if (node != null) { isTranslatable = node.getText().equals(Tmx.VAL_TU_TRANSLATABLE); } if (isTranslatable) { result.setTranslatable(); } else { result.setLocalizable(); } // prop with Att:: List propNodes = p_root.elements("prop"); for (int i = 0; i < propNodes.size(); i++) { Element elem = (Element) propNodes.get(i); ProjectTmTuTProp prop = createProp(result, elem); if (prop != null) result.addProp(prop); } // TUVs List nodes = p_root.elements("tuv"); for (int i = 0; i < nodes.size(); i++) { Element elem = (Element) nodes.get(i); SegmentTmTuv tuv = createTuv(result, elem); result.addTuv(tuv); } if (com.globalsight.everest.tm.importer.ImportOptions.TYPE_TMX_WORLD_SERVER .equals(m_options.getFileType())) { result.setFromWorldServer(true); } return result; }
From source file:com.globalsight.everest.tm.util.ttx.TtxClean.java
License:Apache License
/** * Returns the inner text like Element.getText() but for all * embedded text nodes.//from www . j a v a2 s . c om */ static public String getInnerText(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); if (node.getNodeType() == Node.TEXT_NODE) { result.append(node.getText()); } else if (node.getNodeType() == Node.ELEMENT_NODE) { result.append(getInnerText((Element) node)); } } return result.toString(); }
From source file:com.globalsight.everest.webapp.servlet.SnippetLibraryServlet.java
License:Apache License
/** * Extracts and executes a request for the SnippetLibrary to * create, modify, or delete snippets./*from w ww . j a v a 2 s . c o m*/ */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { try { String result = null; HttpSession session = request.getSession(); String userId = PageHandler.getUser(session).getUserId(); SessionManager sessionMgr = (SessionManager) session.getAttribute(WebAppConstants.SESSION_MANAGER); EditorState state = (EditorState) sessionMgr.getAttribute(WebAppConstants.EDITORSTATE); response.setContentType("text/xml; charset=UTF-8"); response.setHeader("Pragma", "No-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); Document dom = DocumentHelper.parseText(readBody(request)); Node commandNode = dom.selectSingleNode("/*/request"); if (commandNode == null) { returnBadRequest(response); } String command = commandNode.getText(); if (command == null || command.length() == 0) { returnBadRequest(response); } if (command.equals(SNIPPET_ACTION_GETPAGE)) { // retrieve page interpreted in a locale result = getPage(dom, state, request.getSession()); } else if (command.equals(SNIPPET_ACTION_GETSNIPPET)) { // retrieve the snippet for a specific position // (by name + locale + version) result = getSnippet(dom); } else if (command.equals(SNIPPET_ACTION_GETSNIPPETS)) { // retrieve the snippets for a position (by name + locale) result = getSnippets(dom); } else if (command.equals(SNIPPET_ACTION_CREATESNIPPET)) { result = createSnippet(userId, dom); } else if (command.equals(SNIPPET_ACTION_CREATESNIPPETGETSNIPPET)) { result = createSnippetGetSnippet(userId, dom); } else if (command.equals(SNIPPET_ACTION_MODIFYSNIPPET)) { result = modifySnippet(userId, dom); } else if (command.equals(SNIPPET_ACTION_MODIFYSNIPPETGETSNIPPET)) { result = modifySnippetGetSnippet(userId, dom); } else if (command.equals(SNIPPET_ACTION_REMOVESNIPPET)) { // deletes a snippet. result = removeSnippet(userId, dom); } else if (command.equals(SNIPPET_ACTION_ADDSNIPPETGETPAGE)) { // add a snippet and recompute the page result = addSnippetGetPage(userId, dom, state, request.getSession()); } else if (command.equals(SNIPPET_ACTION_MODIFYSNIPPETGETPAGE)) { // modify a snippet and recompute the page result = modifySnippetGetPage(userId, dom, state, request.getSession()); } else if (command.equals(SNIPPET_ACTION_REMOVESNIPPETGETPAGE)) { // remove a snippet and recompute the page result = removeSnippetGetPage(userId, dom, state, request.getSession()); } else if (command.equals(SNIPPET_ACTION_DELETECONTENTGETPAGE)) { // delete content and recompute the page result = deleteContentGetPage(userId, dom, state, request.getSession()); } else if (command.equals(SNIPPET_ACTION_UNDELETECONTENTGETPAGE)) { // un-delete content and recompute the page result = undeleteContentGetPage(userId, dom, state, request.getSession()); } // Mon Jul 11 21:32:17 2005 Amb6.6 source page editing additions else if (command.equals(SNIPPET_ACTION_GETGENERICNAMES)) { result = getGenericSnippetNames(); } else if (command.equals(SNIPPET_ACTION_GETSNIPPETSBYLOCALE)) { result = getSnippetsByLocale(dom); } else if (command.equals(SNIPPET_ACTION_GETGENERICSNIPPET)) { result = getGenericSnippet(dom); } if (CATEGORY.isDebugEnabled()) { CATEGORY.debug("action=" + command + " result=\n" + result); } if (result == null) { returnBadRequest(response); } else { returnXml(response, result); } } catch (SnippetException ex) { CATEGORY.warn(ex.getMessage(), ex); returnError(response, ex); } catch (Throwable ex) { CATEGORY.warn(ex.getMessage(), ex); returnError(response, ex); } }
From source file:com.globalsight.everest.webapp.servlet.SnippetLibraryServlet.java
License:Apache License
private String getPage(Document p_request, EditorState p_state, HttpSession p_session) throws Exception { long pageId = 0L; String locale = null;/*from w w w .j a va 2 s . co m*/ String role = null; int viewMode = 0; Node node; node = p_request.selectSingleNode("/*/arg[1]"); if (node != null) { pageId = Long.parseLong(node.getText()); } node = p_request.selectSingleNode("/*/arg[2]"); if (node != null) { locale = node.getText(); } node = p_request.selectSingleNode("/*/arg[3]"); if (node != null) { role = node.getText(); } node = p_request.selectSingleNode("/*/arg[4]"); if (node != null) { viewMode = Integer.parseInt(node.getText()); } if (pageId == 0L || locale == null || role == null || viewMode == 0) { CATEGORY.error("Invalid args, expected 4 - " + p_request.asXML()); throw new Exception("invalid argument"); } return getPage(p_session, p_state, viewMode, false); }