List of usage examples for org.dom4j Document getRootElement
Element getRootElement();
From source file:com.globalsight.webservices.Ambassador.java
License:Apache License
private String joinXml(String xml, String startDate, String finishDate, String fileType, String languages, String exportedFileName, String projectNames) throws WebServiceException { Document doc = null; try {//from w ww . j ava2s. com doc = DocumentHelper.parseText(xml); Element rootElt = doc.getRootElement(); Iterator fileIter = rootElt.elementIterator("fileOptions"); while (fileIter.hasNext()) { Element fileEle = (Element) fileIter.next(); if (exportedFileName != null) { Element fileNameElem = fileEle.element("fileName"); if (fileType.equals("xml")) { fileNameElem.setText(exportedFileName + ".xml"); } else if (fileType.equals("tmx2")) { fileNameElem.setText(exportedFileName + ".tmx"); } } Element fileTypeElem = fileEle.element("fileType"); fileTypeElem.setText(fileType); Element fileEncodingElem = fileEle.element("fileEncoding"); fileEncodingElem.setText("UTF-8"); } Iterator selectIter = rootElt.elementIterator("selectOptions"); while (selectIter.hasNext()) { Element selectEle = (Element) selectIter.next(); Element selectModeElem = selectEle.element("selectMode"); // Element selectLanguage = selectEle.element("selectLanguage"); selectModeElem.setText(com.globalsight.everest.tm.exporter.ExportOptions.SELECT_ALL); // if (StringUtil.isEmpty(languages)) // { // } // else // { // selectModeElem // .setText(com.globalsight.everest.tm.exporter.ExportOptions.SELECT_FILTERED); // selectLanguage.setText(languages); // } } Iterator filterIter = rootElt.elementIterator("filterOptions"); while (filterIter.hasNext()) { Element filterEle = (Element) filterIter.next(); Element createdafterElem = filterEle.element("createdafter"); createdafterElem.setText(startDate); Element createdbeforeElem = filterEle.element("createdbefore"); Element language = filterEle.element("language"); Element projectName = filterEle.element("projectName"); if (finishDate == null) { Date nowDate = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); String nowDateStr = sdf.format(nowDate); createdbeforeElem.setText(nowDateStr); } else { createdbeforeElem.setText(finishDate); } if (StringUtil.isNotEmpty(languages)) { language.setText(languages); } if (StringUtil.isNotEmpty(projectNames)) { projectName.setText(projectNames); } } Iterator outputIter = rootElt.elementIterator("outputOptions"); while (outputIter.hasNext()) { Element outputEle = (Element) outputIter.next(); Element systemFields = outputEle.element("systemFields"); systemFields.setText("true"); } String xmlDoc = doc.asXML(); return xmlDoc.substring(xmlDoc.indexOf("<exportOptions>")); } catch (DocumentException e) { throw new WebServiceException(e.getMessage()); } }
From source file:com.globalsight.webservices.AmbassadorHelper.java
License:Apache License
/** * Parse roles information from XML format string. * The XML format string is like below:/*from w ww . j a va 2 s .c om*/ * <?xml version=\"1.0\"?> * <roles> * <role> * <sourceLocale>en_US</sourceLocale> * <targetLocale>de_DE</targetLocale> * <activities> * <activity> * <name>Dtp1</name> * </activity> * <activity> * <name>Dtp2</name> * </activity> * </activities> * </role> * </roles> * * @param p_user -- User * @param p_xml -- Roles information * @return List<UserRole> */ @SuppressWarnings({ "unused", "rawtypes" }) private List<UserRole> parseRoles(User p_user, String p_xml) { if (StringUtil.isEmpty(p_xml)) return null; ArrayList<UserRole> roles = new ArrayList<UserRole>(); try { XmlParser parser = new XmlParser(); Document doc = parser.parseXml(p_xml); Element root = doc.getRootElement(); List rolesList = root.elements(); if (rolesList == null || rolesList.size() == 0) return null; String sourceLocale, targetLocale, activityId, activityName, activityDisplayName, activityUserType, activityType; Activity activity = null; UserRole role = null; LocalePair localePair = null; UserManagerWLRemote userManager = ServerProxy.getUserManager(); JobHandlerWLRemote jobManager = ServerProxy.getJobHandler(); Company loggedCompany = CompanyWrapper.getCompanyByName(p_user.getCompanyName()); for (Iterator iter = rolesList.iterator(); iter.hasNext();) { Element roleElement = (Element) iter.next(); sourceLocale = roleElement.element("sourceLocale").getText(); targetLocale = roleElement.element("targetLocale").getText(); String localeCompanyName = null; Company localeCompany = null; Element node = (Element) roleElement.selectSingleNode("companyName"); if (CompanyWrapper.SUPER_COMPANY_ID.equals(String.valueOf(loggedCompany.getId()))) { if (node == null) return null; localeCompanyName = roleElement.element("companyName").getText(); localeCompany = CompanyWrapper.getCompanyByName(localeCompanyName.trim()); if (localeCompany == null) return null; } else { if (node != null) return null; } if (localeCompany == null) localePair = getLocalePairBySourceTargetAndCompanyStrings(sourceLocale, targetLocale, loggedCompany.getId()); else localePair = getLocalePairBySourceTargetAndCompanyStrings(sourceLocale, targetLocale, localeCompany.getId()); if (localePair == null) return null; List activitiesList = roleElement.elements("activities"); if (activitiesList == null || activitiesList.size() == 0) return null; for (Iterator iter1 = activitiesList.iterator(); iter1.hasNext();) { Element activitiesElement = (Element) iter1.next(); List activityList = activitiesElement.elements(); for (Iterator iter2 = activityList.iterator(); iter2.hasNext();) { Element activityElement = (Element) iter2.next(); activityName = activityElement.element("name").getText(); if (localeCompany != null) { activity = jobManager.getActivityByCompanyId(activityName + "_" + localeCompany.getId(), String.valueOf(localeCompany.getId())); } else { activity = jobManager.getActivityByCompanyId(activityName + "_" + loggedCompany.getId(), String.valueOf(loggedCompany.getId())); } if (activity == null) return null; role = userManager.createUserRole(); ((Role) role).setActivity(activity); ((Role) role).setSourceLocale(sourceLocale); ((Role) role).setTargetLocale(targetLocale); // role.setUser(p_user.getUserId()); roles.add(role); } } } } catch (Exception e) { logger.error(e.getMessage(), e); return null; } return roles; }
From source file:com.google.gdt.util.HttpTranslator.java
License:Open Source License
/** * parse the response from google server and extracts the desired translated Text * @param response/*ww w. j a v a 2 s.c o m*/ * @return translatedText */ private String parseResponse(String response) { // System.out.println(response); String translatedText = ""; InputSource is = new InputSource(new StringReader(response)); SAXReader reader = new SAXReader(); Document doc = null; try { doc = reader.read(is); } catch (DocumentException e) { logger.log(Level.SEVERE, "Not able to parse response : " + response, e); return ""; } Element root = doc.getRootElement(); for (Iterator i = root.elementIterator(); i.hasNext();) { Element element = (Element) i.next(); translatedText += element.getText(); } return translatedText; }
From source file:com.google.jenkins.flakyTestHandler.junit.FlakySuiteResult.java
License:Open Source License
/** * Parses the JUnit XML file into {@link FlakySuiteResult}s. * This method returns a collection, as a single XML may have multiple <testsuite> * elements wrapped into the top-level <testsuites>. *//* w w w. jav a 2 s. c om*/ static List<FlakySuiteResult> parse(File xmlReport, boolean keepLongStdio) throws DocumentException, IOException, InterruptedException { List<FlakySuiteResult> r = new ArrayList<FlakySuiteResult>(); // parse into DOM SAXReader saxReader = new SAXReader(); ParserConfigurator.applyConfiguration(saxReader, new SuiteResultParserConfigurationContext(xmlReport)); Document result = saxReader.read(xmlReport); Element root = result.getRootElement(); parseSuite(xmlReport, keepLongStdio, r, root); return r; }
From source file:com.googlecode.starflow.engine.xml.Dom4jProcDefParser.java
License:Apache License
/** * ???// ww w.ja va2 s . c o m * * @param processDefine * @return */ public static ProcessDefine parserProcessInfo(ProcessDefine processDefine) { SAXReader reader = new SAXReader(); Document document = null; try { document = reader.read(new StringReader(processDefine.getProcessDefContent())); Element rootElement = document.getRootElement(); String _name = rootElement.attributeValue(StarFlowNames.FLOW_ATTR_NAME); String _chname = rootElement.attributeValue(StarFlowNames.FLOW_ATTR_CHNAME); String _version = rootElement.attributeValue(StarFlowNames.FLOW_ATTR_VERSION); String _xpath = "/ProcessDefine/ProcessProperty/".concat(StarFlowNames.FLOW_CHILD_DESC); String _description = rootElement.selectSingleNode(_xpath).getText(); _xpath = "/ProcessDefine/ProcessProperty/".concat(StarFlowNames.FLOW_CHILD_LIMITTIME); String _limitTime = rootElement.selectSingleNode(_xpath).getText(); processDefine.setProcessDefName(_name); if (_chname != null) processDefine.setProcessCHName(_chname); else processDefine.setProcessCHName(_name); processDefine.setVersionSign(_version); processDefine.setDescription(_description); processDefine.setLimitTime(Long.parseLong(_limitTime)); } catch (Exception e) { throw new StarFlowParserException("???", e); } return processDefine; }
From source file:com.googlecode.starflow.engine.xml.ProcessDefineParser.java
License:Apache License
private static void queryProcessXmlInfo(ProcessElement processXml, Document document) { Element rootElement = document.getRootElement(); String name = rootElement.attributeValue(StarFlowNames.FLOW_ATTR_NAME); String chname = rootElement.attributeValue(StarFlowNames.FLOW_ATTR_CHNAME); String version = rootElement.attributeValue(StarFlowNames.FLOW_ATTR_VERSION); String xpath = "/ProcessDefine/ProcessProperty/".concat(StarFlowNames.FLOW_CHILD_DESC); String description = rootElement.selectSingleNode(xpath).getText(); xpath = "/ProcessDefine/ProcessProperty/".concat(StarFlowNames.FLOW_CHILD_LIMITTIME); String limitTime = rootElement.selectSingleNode(xpath).getText(); processXml.setName(name);/*w w w . j av a 2s. c o m*/ if (chname != null) processXml.setChname(chname); else processXml.setChname(name); processXml.setVersion(version); processXml.setDescription(description); processXml.setLimitTime(Long.parseLong(limitTime)); Element node = (Element) rootElement.selectSingleNode("/ProcessDefine/ProcessProperty"); processXml.setEvents(NodeUtil.getTriggerEvents(node)); processXml.setProperties(NodeUtil.getExtProperties(node)); }
From source file:com.gote.importexport.ExportTournamentForOpenGotha.java
License:Apache License
/** * Update a document according to Tournament state * /*from w ww .j av a2 s .c om*/ * @param pDocument Document * @param pTournament Tournament */ private void updateDocument(Document pDocument, Tournament pTournament) { Element pElementTournament = pDocument.getRootElement(); Element elementGames = pElementTournament.element(TournamentOpenGothaUtil.TAG_GAMES); @SuppressWarnings("unchecked") List<Element> listOfGames = (List<Element>) elementGames.elements(TournamentOpenGothaUtil.TAG_GAME); for (Element game : listOfGames) { // Check if there is no result for the game before checking games if (game.attribute(TournamentOpenGothaUtil.ATTRIBUTE_GAME_RESULT) != null && !TournamentOpenGothaUtil.VALUE_GAME_RESULT_UNKNOWN .equals(game.attribute(TournamentOpenGothaUtil.ATTRIBUTE_GAME_RESULT).getValue())) { if (game.attribute(TournamentOpenGothaUtil.ATTRIBUTE_GAME_ROUND) != null && game.attribute(TournamentOpenGothaUtil.ATTRIBUTE_GAME_BLACK_PLAYER) != null && game.attribute(TournamentOpenGothaUtil.ATTRIBUTE_GAME_WHITE_PLAYER) != null) { game.addAttribute(TournamentOpenGothaUtil.ATTRIBUTE_GAME_RESULT, pTournament.getGameResultWithCompleteName( Integer.parseInt(game.attribute(TournamentOpenGothaUtil.ATTRIBUTE_GAME_ROUND) .getValue()), game.attribute(TournamentOpenGothaUtil.ATTRIBUTE_GAME_BLACK_PLAYER).getValue(), game.attribute(TournamentOpenGothaUtil.ATTRIBUTE_GAME_WHITE_PLAYER) .getValue())); } else { LOGGER.log(Level.SEVERE, "Either the round number, black player name or white player name has not been found for game : " + game + ". Update impossible"); } } } }
From source file:com.gote.importexport.ImportTournamentFromGOTE.java
License:Apache License
@Override public Tournament createTournamentFromConfig(File pFile) { LOGGER.log(Level.INFO, "Loading tournament from file " + pFile); Tournament tournament = new Tournament(); String content = ImportExportUtil.getFileContent(pFile); if (content == null) { LOGGER.log(Level.SEVERE, "File \"" + pFile.getPath() + "\" content is null"); return null; }//from ww w . ja v a2 s . com SAXReader reader = new SAXReader(); Document document; try { document = reader.read(new StringReader(content)); } catch (DocumentException e) { LOGGER.log(Level.SEVERE, "DocumentException, creation stopped : " + e); return null; } Element pElementTournament = document.getRootElement(); boolean initSuccess = initTournament(tournament, pElementTournament); if (initSuccess) { return tournament; } else { return null; } }
From source file:com.gote.importexport.ImportTournamentFromOpenGotha.java
License:Apache License
@Override public Tournament createTournamentFromConfig(File pFile) { LOGGER.log(Level.INFO, "A new tournament is going to be created from the file : " + pFile.getPath()); Tournament tournament = new Tournament(); String content = ImportExportUtil.getFileContent(pFile); if (content == null) { LOGGER.log(Level.SEVERE, "File \"" + pFile.getPath() + "\" content is null"); return null; }//from w ww.j a v a 2 s .com SAXReader reader = new SAXReader(); Document document; try { document = reader.read(new StringReader(content)); } catch (DocumentException e) { LOGGER.log(Level.SEVERE, "DocumentException, creation stopped : " + e); return null; } Element pElementTournament = document.getRootElement(); boolean initSuccess = initTournament(tournament, pElementTournament); if (initSuccess) { return tournament; } else { return null; } }
From source file:com.gtrj.docdeal.ui.GalleryFileActivity.java
License:Open Source License
private String parseXml(String xml) { try {//from w ww . j av a 2 s. co m File file = new File(ContextString.FilePath + File.separator + "xml.txt"); FileOutputStream fileOutputStream = new FileOutputStream(file); fileOutputStream.write(xml.getBytes()); Document document = DocumentHelper.parseText(xml); Element root = document.getRootElement(); Element totalPageElement = root.element(""); Element currentPageElement = root.element("?"); Element pictureElement = root.element(""); totalPage = Integer.parseInt(totalPageElement.getText()); String pageNum = currentPageElement.getText(); String path = Base64Util.decoderBase64FileWithFileName(pictureElement.getText(), pageNum + ".jpg", this); return path; } catch (DocumentException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }