List of usage examples for org.dom4j Document getRootElement
Element getRootElement();
From source file:com.globalsight.ling.docproc.worldserver.WsSkeletonDispose.java
License:Apache License
@Override public String dealSkeleton(String skeleton, String localizedBy) { boolean localizedByUser = false; boolean localizedByMT = false; boolean localizedByLocalTM = false; if (localizedBy != null && localizedBy.equals(PageTemplate.byUser)) { localizedByUser = true;// w w w.jav a2 s .c o m } else if (localizedBy != null && localizedBy.equals(PageTemplate.byMT)) { localizedByMT = true; } else if (localizedBy != null && localizedBy.equals(PageTemplate.byLocalTM)) { localizedByLocalTM = true; } int begin = skeleton.indexOf("<" + IWS_SEGMENT_DATA); int end = skeleton.indexOf("</" + IWS_SEGMENT_DATA) + ("</" + IWS_SEGMENT_DATA + ">").length(); String iwsStr = skeleton.substring(begin, end); iwsStr = "<segmentdata " + "xmlns:iws=\"http://www.idiominc.com/ws/asset\">" + iwsStr + "</segmentdata>"; Document dom = getDom(iwsStr); Element root = dom.getRootElement(); List iwsStatusList = root.selectNodes("//iws:status"); for (int x = 0; x < iwsStatusList.size(); x++) { Element status = (Element) iwsStatusList.get(x); if (localizedByUser || localizedByLocalTM || localizedByMT) { /* * if (status.attribute("match-quality") != null) * status.remove(status.attribute("match-quality")); * * if (status.attribute("source_content") != null) * status.remove(status.attribute("source_content")); * * if (status.attribute("target_content") != null) * status.remove(status.attribute("target_content")); */ List<Attribute> attrList = new ArrayList(); attrList.addAll(status.attributes()); for (int i = 0; i < attrList.size(); i++) { String name = attrList.get(i).getName(); if (!name.equals(IWS_TRANSLATION_STATUS) && !name.equals(IWS_TRANSLATION_TYPE) && !name.equals(IWS_SOURCE_CONTENT)) { status.remove(attrList.get(i)); } } } if (status.attribute(IWS_TRANSLATION_STATUS) != null) { if (localizedByUser) { status.attribute(IWS_TRANSLATION_STATUS).setValue("finished"); } else if (localizedByLocalTM) { status.attribute(IWS_TRANSLATION_STATUS).setValue("pending"); } } else { if (localizedByUser) { status.addAttribute(IWS_TRANSLATION_STATUS, "finished"); } else if (localizedByLocalTM) { status.addAttribute(IWS_TRANSLATION_STATUS, "pending"); } } if (status.attribute(IWS_TRANSLATION_TYPE) != null) { if (localizedByMT) { status.attribute(IWS_TRANSLATION_TYPE).setValue("machine_translation_mt"); } else if (localizedByUser || localizedByLocalTM) { status.attribute(IWS_TRANSLATION_TYPE).setValue("manual_translation"); } } else { if (localizedBy != null) { if (localizedByMT) { status.addAttribute(IWS_TRANSLATION_TYPE, "machine_translation_mt"); } else if (localizedByUser || localizedByLocalTM) { status.addAttribute(IWS_TRANSLATION_TYPE, "manual_translation"); } } } } iwsStr = dom.selectSingleNode("//iws:segment-metadata").asXML(); String str = "xmlns:iws=\"http://www.idiominc.com/ws/asset\""; iwsStr = iwsStr.replace(str, ""); skeleton = skeleton.substring(0, begin) + iwsStr + skeleton.substring(end); return skeleton; }
From source file:com.globalsight.reports.handler.MissingTermsReportHandler.java
License:Apache License
/** * Figures out what languages are in the Termbase. These are the user * specified language names.//from w w w . jav a 2s . c o m * * @param p_xmlDefinition * termbase def xml */ private void setTermbaseLangs(String p_xmlDefinition) throws Exception { XmlParser parser = XmlParser.hire(); Document dom = parser.parseXml(p_xmlDefinition); Element root = dom.getRootElement(); List langGrps = root.selectNodes(LANGUAGEDEFINITION); m_termbaseLangs = new ArrayList(); for (int i = 0; i < langGrps.size(); i++) { Element e = (Element) langGrps.get(i); String lang = e.getText(); m_termbaseLangs.add(lang); } XmlParser.fire(parser); }
From source file:com.globalsight.reports.handler.MissingTermsReportHandler.java
License:Apache License
/** * Returns the term's text in some language (most likely English). This * really just grabs the first language out of the entryXml <br> * // www .java2 s.co m * @param p_tb * termbase * @param p_entryId * entry (concept) id * @return term text */ private String getTerm(ITermbase p_tb, long p_entryId) throws Exception { String entryXml = p_tb.getEntry(p_entryId); XmlParser parser = XmlParser.hire(); Document dom = parser.parseXml(entryXml); Element root = dom.getRootElement(); List langGrps = root.selectNodes(TERMBASEXML); Element firstTerm = (Element) langGrps.get(0); String termText = firstTerm.getText(); XmlParser.fire(parser); return termText; }
From source file:com.globalsight.reports.MissingTermsReplet.java
License:Apache License
/** * Figures out what languages are in the Termbase. These are the user * specified language names.//from w w w . j a va2 s .co m * * @param p_xmlDefinition * termbase def xml */ private void setTermbaseLangs(String p_xmlDefinition) throws Exception { XmlParser parser = XmlParser.hire(); Document dom = parser.parseXml(p_xmlDefinition); Element root = dom.getRootElement(); List langGrps = root.selectNodes("/definition/languages/language/name"); m_termbaseLangs = new ArrayList(); for (int i = 0; i < langGrps.size(); i++) { Element e = (Element) langGrps.get(i); String lang = e.getText(); m_termbaseLangs.add(lang); } XmlParser.fire(parser); }
From source file:com.globalsight.reports.MissingTermsReplet.java
License:Apache License
/** * Returns the term's text in some language (most likely English). This * really just grabs the first language out of the entryXml * /* w ww .j a v a 2 s . com*/ * @param p_tb * termbase * @param p_entryId * entry (concept) id * @return term text */ private String getTerm(ITermbase p_tb, long p_entryId) throws Exception { String entryXml = p_tb.getEntry(p_entryId); XmlParser parser = XmlParser.hire(); Document dom = parser.parseXml(entryXml); Element root = dom.getRootElement(); List langGrps = root.selectNodes("/conceptGrp/languageGrp/termGrp/term"); Element firstTerm = (Element) langGrps.get(0); String termText = firstTerm.getText(); XmlParser.fire(parser); return termText; }
From source file:com.globalsight.selenium.testcases.util.DownloadUtil.java
License:Apache License
public static String download(String jobName) throws Exception { String wsdlUrl = ConfigUtil.getConfigData("serverUrl") + "/globalsight/services/AmbassadorWebService?wsdl"; AmbassadorServiceLocator loc = new AmbassadorServiceLocator(); Ambassador service = loc.getAmbassadorWebService(new URL(wsdlUrl)); String token = service.login(ConfigUtil.getConfigData("adminName"), ConfigUtil.getConfigData("adminPassword")); String fileXml = null;//from w w w . j a va 2s.co m String waitTimeStr = ConfigUtil.getConfigData("middleWait"); String checkTimesStr = ConfigUtil.getConfigData("checkTimes"); int checkTimes = 30, times = 0; long waitTime = 60000; try { checkTimes = Integer.parseInt(checkTimesStr); waitTime = Long.parseLong(waitTimeStr); } catch (Exception e) { checkTimes = 30; waitTime = 60000; } while (times < checkTimes) { fileXml = service.getJobExportFiles(token, jobName); if (fileXml != null) break; else { Thread.sleep(waitTime); times++; } } SAXReader saxReader = new SAXReader(); Document document = saxReader.read(new StringReader(fileXml)); Element rootElement = document.getRootElement(); String root = rootElement.elementText("root"); ArrayList<Element> paths = (ArrayList<Element>) rootElement.elements("paths"); for (Element element : paths) { String filePath = element.getText(); File outputFile = downloadHttp(root + File.separator + filePath); } return null; }
From source file:com.globalsight.smartbox.bussiness.process.Usecase02PostProcess.java
License:Apache License
/** * Convert xml to csv or txt file//from w ww . j a v a2s . co m * * @param format * @param originFile * @return * @throws Exception */ private File convertXMLToCSVTXT(String format, String targetFile, String outputFilePath) throws Exception { File xmlFile = new File(targetFile); File outputFile = new File(outputFilePath); SAXReader saxReader = new SAXReader(); Document document = saxReader.read(xmlFile); Element aElement = document.getRootElement(); String encoding = aElement.attributeValue("BomInfo"); FileOutputStream fos = new FileOutputStream(outputFilePath); FileUtil.writeBom(fos, encoding); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos, encoding)); List<Element> rows = aElement.elements("row"); for (Element row : rows) { List<String> rowStr = new ArrayList<String>(); rowStr.add(row.elementText("sid")); rowStr.add(row.elementText("sourceLocaleName")); rowStr.add(row.elementText("sourceLocaleCode")); rowStr.add(row.elementText("unknown")); rowStr.add(row.elementText("translationSource")); rowStr.add(row.elementText("targetLocale")); rowStr.add(row.elementText("creationDate")); List<Element> segments = row.elements("segment"); for (Element element : segments) { rowStr.add(element.getText()); } StringBuffer sb = new StringBuffer(); if ("csv".equals(format)) { for (String str : rowStr) { sb.append("\"").append(str).append("\"").append(","); } } else { for (String str : rowStr) { sb.append(str).append("|"); } } sb.deleteCharAt(sb.length() - 1); bw.write(sb.toString()); bw.newLine(); } bw.close(); fos.close(); return outputFile; }
From source file:com.globalsight.smartbox.util.WebClientHelper.java
License:Apache License
/** * Check if importing/exporting is happening on server. * // ww w .j ava 2 s. c om * @return boolean */ public static boolean isServerImportingOrExporting() { try { String status = ambassador.getImportExportStatus(accessToken); Document dom = DocumentHelper.parseText(status); Element root = dom.getRootElement(); String creatingNum = root.element("jobsCreating").getText(); String exportingNum = root.element("localesExporting").getText(); int cNum = Integer.valueOf(creatingNum); int eNum = Integer.valueOf(exportingNum); if (cNum > 0 || eNum > 0) return true; } catch (Exception e) { LogUtil.info("Exception when try to detect server importing/exporting status:" + e.getMessage()); } return false; }
From source file:com.globalsight.terminology.Definition.java
License:Apache License
/** * Reads and validates a Termbase Definition given in an XML string. */// w ww .j ava2 s . c o m private void init(String p_definition) throws TermbaseException { XmlParser parser = null; Document dom; try { parser = XmlParser.hire(); dom = parser.parseXml(p_definition); } finally { XmlParser.fire(parser); } try { Element root = dom.getRootElement(); Node nameNode = root.selectSingleNode("/definition/name"); Node descNode = root.selectSingleNode("/definition/description"); if (nameNode != null) { m_name = nameNode.getText(); } if (descNode != null) { m_description = descNode.getText(); } List langs = root.selectNodes("/definition/languages/language"); if (langs.size() == 0) { error("no languages defined", null); } for (int i = 0, max = langs.size(); i < max; ++i) { Element lang = (Element) langs.get(i); String name = lang.valueOf("name"); String locale = lang.valueOf("locale"); String hasTerms = lang.valueOf("hasterms"); if (name == null || locale == null || hasTerms == null) { error("incomplete language definition", null); } m_languages.add(new Language(name, locale, hasTerms)); } List fields = root.selectNodes("/definition/fields/field"); for (int i = 0, max = fields.size(); i < max; ++i) { Element field = (Element) fields.get(i); String name = field.valueOf("name"); String type = field.valueOf("type"); String system = field.valueOf("system"); String indexed = field.valueOf("indexed"); String values = field.valueOf("values"); if (name == null || type == null || system == null || indexed == null || values == null) { error("incomplete field definition", null); } m_fields.add(new Field(name, type, system, indexed, values)); } List indexes = root.selectNodes("/definition/indexes/index"); for (int i = 0, max = indexes.size(); i < max; ++i) { Element index = (Element) indexes.get(i); String languageName = index.valueOf("languagename"); String locale = index.valueOf("locale"); String type = index.valueOf("type"); if (languageName == null || locale == null || type == null) { error("incomplete index definition", null); } m_indexes.add(new Index(languageName, locale, type)); } } catch (TermbaseException e) { throw e; } catch (Exception e) { // cast exception and throw error(e.getMessage(), e); } }
From source file:com.globalsight.terminology.EntryUtils.java
License:Apache License
/** * Sets the entry's concept ID./* w w w.jav a 2 s .com*/ */ static public void setConceptId(Entry p_entry, long p_cid) throws TermbaseException { Document dom = p_entry.getDom(); Element root = dom.getRootElement(); Element concept = root.element("concept"); if (concept == null) { // create new <concept> element and add to tree root.addElement("concept").addText(String.valueOf(p_cid)); } else { concept.setText(String.valueOf(p_cid)); } // let entry know its dom is dirty p_entry.setDom(dom); }