List of usage examples for org.dom4j Element elementTextTrim
String elementTextTrim(QName qname);
From source file:com.glaf.activiti.extension.xml.ExtensionReader.java
License:Apache License
public List<ExtensionEntity> readActions(java.io.InputStream inputStream) { List<ExtensionEntity> extensions = new java.util.ArrayList<ExtensionEntity>(); SAXReader xmlReader = new SAXReader(); try {/*ww w . j a va 2 s .com*/ Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); String x_type = root.attributeValue("type"); List<?> actions = root.elements("action"); Iterator<?> iter = actions.iterator(); while (iter.hasNext()) { Element element = (Element) iter.next(); ExtensionEntity extension = new ExtensionEntity(); extension.setProcessName(element.attributeValue("processName")); extension.setTaskName(element.attributeValue("taskName")); extension.setName(element.attributeValue("name")); extension.setType(x_type); extension.setDescription(element.elementTextTrim("description")); Iterator<?> it99 = element.elementIterator(); while (it99.hasNext()) { Element elem = (Element) it99.next(); String propertyName = elem.getName(); String propertyValue = elem.getTextTrim(); if (StringUtils.isNotEmpty(propertyValue)) { ExtensionFieldEntity extensionField = new ExtensionFieldEntity(); extensionField.setName(propertyName.trim()); extensionField.setValue(propertyValue.trim()); extension.addField(extensionField); } } if (element.elementText("sql") != null) { ExtensionFieldEntity extensionField = new ExtensionFieldEntity(); extensionField.setName("sql"); extensionField.setValue(element.elementTextTrim("sql")); extension.addField(extensionField); } if (element.elementText("handlers") != null) { ExtensionFieldEntity extensionField = new ExtensionFieldEntity(); extensionField.setName("handlers"); extensionField.setValue(element.elementTextTrim("handlers")); extension.addField(extensionField); } Element parametersE = element.element("parameters"); if (parametersE != null) { List<?> parameters = parametersE.elements("parameter"); Iterator<?> it = parameters.iterator(); while (it.hasNext()) { Element elem = (Element) it.next(); String propertyName = elem.attributeValue("name"); String type = elem.attributeValue("type"); String propertyValue = null; if (elem.attribute("value") != null) { propertyValue = elem.attributeValue("value"); } else { propertyValue = elem.getTextTrim(); } if (StringUtils.isNotEmpty(propertyName) && StringUtils.isNotEmpty(propertyValue)) { ExtensionParamEntity extensionParam = new ExtensionParamEntity(); extensionParam.setName(propertyName.trim()); extensionParam.setValue(propertyValue.trim()); extensionParam.setType(type); extension.addParam(extensionParam); } } } extensions.add(extension); } } catch (Exception ex) { throw new RuntimeException(ex); } return extensions; }
From source file:com.glaf.core.xml.MimeMappingReader.java
License:Apache License
public Map<String, String> read(InputStream inputStream) { Map<String, String> mapping = new HashMap<String, String>(); SAXReader xmlReader = new SAXReader(); try {//ww w . ja v a2s . c o m Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); List<?> elements = root.elements("mime-mapping"); for (int i = 0; i < elements.size(); i++) { Element element = (Element) elements.get(i); mapping.put(element.elementTextTrim("extension"), element.elementTextTrim("mime-type")); } } catch (Exception ex) { ex.printStackTrace(); throw new RuntimeException(ex); } return mapping; }
From source file:com.glaf.jbpm.config.JbpmExtensionReader.java
License:Apache License
public List<Extension> readTasks(java.io.InputStream inputStream) { List<Extension> extensions = new java.util.ArrayList<Extension>(); SAXReader xmlReader = new SAXReader(); try {// www.j a v a 2 s . c o m Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); String x_type = root.attributeValue("type"); List<?> rows = root.elements("taskmgr"); Iterator<?> iterator = rows.iterator(); while (iterator.hasNext()) { Element element = (Element) iterator.next(); Extension extension = new Extension(); extension.setProcessName(element.attributeValue("processName")); extension.setTaskName(element.attributeValue("taskName")); extension.setType(x_type); if (element.elementTextTrim("taskMgmtType") != null) { ExtensionField extensionField = new ExtensionField(); extensionField.setName("taskMgmtType"); extensionField.setValue(element.elementTextTrim("taskMgmtType")); extension.addField(extensionField); } Element propertiesE = element.element("properties"); if (propertiesE != null) { List<?> properties = propertiesE.elements("property"); Iterator<?> iter = properties.iterator(); while (iter.hasNext()) { Element elem = (Element) iter.next(); String propertyName = elem.attributeValue("key"); String propertyValue = null; if (elem.attribute("value") != null) { propertyValue = elem.attributeValue("value"); } else { propertyValue = elem.getTextTrim(); } if (StringUtils.isNotEmpty(propertyName) && StringUtils.isNotEmpty(propertyValue)) { ExtensionField extensionField = new ExtensionField(); extensionField.setName(propertyName.trim()); extensionField.setValue(propertyValue.trim()); extension.addField(extensionField); } } } if (element.elementText("handlers") != null) { ExtensionField extensionField = new ExtensionField(); extensionField.setName("handlers"); extensionField.setValue(element.elementTextTrim("handlers")); extension.addField(extensionField); } extensions.add(extension); } } catch (Exception ex) { throw new RuntimeException(ex); } return extensions; }
From source file:com.glaf.jbpm.config.JbpmExtensionReader.java
License:Apache License
public List<Extension> readActions(java.io.InputStream inputStream) { List<Extension> extensions = new java.util.ArrayList<Extension>(); SAXReader xmlReader = new SAXReader(); try {//from ww w . j a v a 2s .c o m Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); String x_type = root.attributeValue("type"); List<?> actions = root.elements("action"); Iterator<?> iter = actions.iterator(); while (iter.hasNext()) { Element element = (Element) iter.next(); Extension extension = new Extension(); extension.setProcessName(element.attributeValue("processName")); extension.setTaskName(element.attributeValue("taskName")); extension.setName(element.attributeValue("name")); extension.setType(x_type); extension.setDescription(element.elementTextTrim("description")); Iterator<?> it99 = element.elementIterator(); while (it99.hasNext()) { Element elem = (Element) it99.next(); String propertyName = elem.getName(); String propertyValue = elem.getTextTrim(); if (StringUtils.isNotEmpty(propertyValue)) { ExtensionField extensionField = new ExtensionField(); extensionField.setName(propertyName.trim()); extensionField.setValue(propertyValue.trim()); extension.addField(extensionField); } } if (element.elementText("sql") != null) { ExtensionField extensionField = new ExtensionField(); extensionField.setName("sql"); extensionField.setValue(element.elementTextTrim("sql")); extension.addField(extensionField); } if (element.elementText("handlers") != null) { ExtensionField extensionField = new ExtensionField(); extensionField.setName("handlers"); extensionField.setValue(element.elementTextTrim("handlers")); extension.addField(extensionField); } Element parametersE = element.element("parameters"); if (parametersE != null) { List<?> parameters = parametersE.elements("parameter"); Iterator<?> it = parameters.iterator(); while (it.hasNext()) { Element elem = (Element) it.next(); String propertyName = elem.attributeValue("name"); String type = elem.attributeValue("type"); String propertyValue = null; if (elem.attribute("value") != null) { propertyValue = elem.attributeValue("value"); } else { propertyValue = elem.getTextTrim(); } if (StringUtils.isNotEmpty(propertyName) && StringUtils.isNotEmpty(propertyValue)) { ExtensionParam extensionParam = new ExtensionParam(); extensionParam.setName(propertyName.trim()); extensionParam.setValue(propertyValue.trim()); extensionParam.setType(type); extension.addParam(extensionParam); } } } extensions.add(extension); } } catch (Exception ex) { throw new RuntimeException(ex); } return extensions; }
From source file:com.glaf.mail.xml.MailXmlReader.java
License:Apache License
public List<MailTemplate> read(java.io.InputStream inputStream) { List<MailTemplate> mailTemplates = new java.util.ArrayList<MailTemplate>(); SAXReader xmlReader = new SAXReader(); Document doc = null;/*w w w .ja v a 2s. c o m*/ try { doc = xmlReader.read(inputStream); } catch (Exception ex) { throw new RuntimeException(ex); } Element root = doc.getRootElement(); List<?> rows = root.elements(); Iterator<?> iterator = rows.iterator(); while (iterator.hasNext()) { Element element = (Element) iterator.next(); String mailId = element.attributeValue("id"); String title = element.attributeValue("title"); String templateId = element.elementText("templateId"); String templatePath = element.elementText("templatePath"); MailTemplate mt = new MailTemplate(); mt.setTitle(title); mt.setMailDefId(mailId); mt.setTemplateId(templateId); mt.setTemplatePath(templatePath); mt.setProperties(this.readProperties(element)); mt.setContent(element.elementText("content")); mt.setDescription(element.elementText("description")); List<?> datasets = element.elements("dataset"); Iterator<?> iter = datasets.iterator(); while (iter.hasNext()) { Element elem = (Element) iter.next(); MailDataSet mailDS = new MailDataSet(); mailDS.setProperties(this.readProperties(elem)); List<?> rowsets = elem.elements("rowset"); Iterator<?> it = rowsets.iterator(); while (it.hasNext()) { Element em = (Element) it.next(); MailRowSet rs = new MailRowSet(); rs.setQuery(em.elementTextTrim("query")); rs.setMapping(em.attributeValue("mapping")); rs.setMailMgr(em.attributeValue("mailMgr")); rs.setMailMgrClassName(em.attributeValue("mailMgrClassName")); rs.setMailMgrMapping(em.attributeValue("mailMgrMapping")); rs.setDataMgr(em.attributeValue("dataMgr")); rs.setDataMgrBeanId(em.attributeValue("dataMgrBeanId")); rs.setDataMgrClassName(em.attributeValue("dataMgrClassName")); rs.setProperties(this.readProperties(em)); String singleResult = em.attributeValue("singleResult"); if ("true".equals(singleResult)) { rs.setSingleResult(true); } mailDS.addRowSet(rs); } mt.addDataSet(mailDS); } mailTemplates.add(mt); } return mailTemplates; }
From source file:com.glaf.report.xml.ReportDefinitionReader.java
License:Apache License
public List<ReportDefinition> read(java.io.InputStream inputStream) { List<ReportDefinition> reports = new java.util.ArrayList<ReportDefinition>(); SAXReader xmlReader = new SAXReader(); Document doc = null;//from w ww.j a v a 2s. c o m try { doc = xmlReader.read(inputStream); } catch (Exception ex) { throw new RuntimeException(ex); } Element root = doc.getRootElement(); List<?> rows = root.elements(); Iterator<?> iterator = rows.iterator(); while (iterator.hasNext()) { Element element = (Element) iterator.next(); String reportId = element.attributeValue("id"); String templateId = element.elementText("templateId"); String templateFile = element.elementText("templateFile"); ReportDefinition rdf = new ReportDefinition(); rdf.setReportId(reportId); rdf.setTemplateId(templateId); rdf.setTemplateFile(templateFile); rdf.setProperties(this.readProperties(element)); List<?> datasets = element.elements("dataset"); Iterator<?> iter = datasets.iterator(); while (iter.hasNext()) { Element elem = (Element) iter.next(); ReportDataSet rds = new ReportDataSet(); rds.setDatasourceName(elem.attributeValue("datasourceName")); rds.setProperties(this.readProperties(elem)); List<?> rowsets = elem.elements("rowset"); Iterator<?> it = rowsets.iterator(); while (it.hasNext()) { Element em = (Element) it.next(); ReportRowSet rs = new ReportRowSet(); rs.setQuery(em.elementTextTrim("query")); rs.setMapping(em.attributeValue("mapping")); rs.setRptMgr(em.attributeValue("rptMgr")); rs.setRptMgrClassName(em.attributeValue("rptMgrClassName")); rs.setRptMgrMapping(em.attributeValue("rptMgrMapping")); rs.setDataMgr(em.attributeValue("dataMgr")); rs.setDataMgrBeanId(em.attributeValue("dataMgrBeanId")); rs.setDataMgrClassName(em.attributeValue("dataMgrClassName")); rs.setProperties(this.readProperties(em)); String singleResult = em.attributeValue("singleResult"); if ("true".equals(singleResult)) { rs.setSingleResult(true); } rds.addRowSet(rs); } rdf.addDataSet(rds); } reports.add(rdf); } return reports; }
From source file:com.globalsight.jobsAutoArchiver.AutoArchiver.java
License:Apache License
public void doWork() throws Exception { SAXReader saxReader = new SAXReader(); Document document = saxReader.read(new File(Constants.CONFIG_FILE_NAME)); Element rootElt = document.getRootElement(); runOnce = document.selectSingleNode("//runOnce").getText(); intervalTime = Integer.valueOf(document.selectSingleNode("//intervalTime").getText()); Iterator serverIter = rootElt.elementIterator("server"); while (serverIter.hasNext()) { final Element serverElement = (Element) serverIter.next(); Runnable runnable = new Runnable() { public void run() { try { String hostName = serverElement.elementTextTrim("host"); int port = Integer.valueOf(serverElement.elementTextTrim("port")); boolean isUseHTTPS = Boolean.valueOf(serverElement.elementTextTrim("https")); int intervalTimeForArchive = Integer .valueOf(serverElement.elementTextTrim("intervalTimeForArchive")); Iterator usersIter = serverElement.elementIterator("users"); while (usersIter.hasNext()) { Element usersElement = (Element) usersIter.next(); Iterator userIter = usersElement.elementIterator("user"); while (userIter.hasNext()) { Element userElement = (Element) userIter.next(); String userName = userElement.elementTextTrim("username"); String password = userElement.elementTextTrim("password"); autoArchive(hostName, port, isUseHTTPS, userName, password, intervalTimeForArchive); }/*from ww w . ja v a 2 s.com*/ } } catch (Throwable e) { LogUtil.info("error : " + e); } } }; Thread t = new Thread(runnable); t.start(); } }
From source file:com.globalsight.jobsAutoArchiver.AutoArchiver.java
License:Apache License
private void autoArchive(String hostName, int port, boolean isUseHTTPS, String userName, String password, int intervalTimeForArchive) { try {/*from w w w . j a va 2s.c om*/ Ambassador ambassador = WebServiceClientHelper.getClientAmbassador(hostName, port, userName, password, isUseHTTPS); String accessToken = ambassador.login(userName, password); String result = ambassador.fetchJobsByState(accessToken, Constants.JOB_STATE_EXPORTED, 0, 100, false); if (result == null) { LogUtil.info( "server " + hostName + " , user " + userName + " : no jobs that are in exported state."); } else { LogUtil.info("server " + hostName + " , user " + userName + " , returning of fetchJobsByState API:\n" + result); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy HH:mm:ss"); long diffInHours = 0; long now = (new Date()).getTime(); SAXReader saxReader = new SAXReader(); Document document2 = saxReader.read(new ByteArrayInputStream(result.getBytes("UTF-8"))); Element rootEltJob = document2.getRootElement(); Iterator iterJob = rootEltJob.elementIterator("Job"); Set<Long> jobIds = new HashSet<Long>(); while (iterJob.hasNext()) { String jobId = null; String completedDateStr = null; try { Element jobElement = (Element) iterJob.next(); jobId = jobElement.elementTextTrim("id"); completedDateStr = jobElement.elementTextTrim("completedDate"); Date completedDate = sdf.parse(completedDateStr.substring(0, 18).trim()); long completedDateLong = completedDate.getTime(); diffInHours = (now - completedDateLong) / 1000 / 60 / 60; if (diffInHours >= intervalTimeForArchive) { jobIds.add(Long.parseLong(jobId)); } } catch (Exception e) { LogUtil.info("Error to check job with jobID: " + jobId + " and completedDate '" + completedDateStr + "'.", e); } } StringBuffer jobs = new StringBuffer(); for (long id : jobIds) { jobs.append(id).append(","); } if (jobs.length() > 0 && jobs.toString().endsWith(",")) { String jobs2 = jobs.toString().substring(0, jobs.length() - 1); ambassador.archiveJob(accessToken, jobs2); String[] jobs2_array = jobs2.toString().split(","); for (String job : jobs2_array) { LogUtil.info("server " + hostName + ", user " + userName + " : the job " + job + " can be archived"); } } else { LogUtil.info("server " + hostName + ", user " + userName + " : no jobs that can be archived."); } } } catch (Exception e) { LogUtil.info("server " + hostName + ", user " + userName + ", error : " + e); } }
From source file:com.hwsoft.util.idcard.IDCardVerifyTools.java
/** * ?Nciicl?/*w ww. j a va2 s . c o m*/ * * @param backXMl? * @return */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static IdCardInfo parseXml(String backXMl, String userName, String idCard) { Document doc = null; String result_gmsfhm = null; String result_xm = null; String gmsfhm = null; String xm = null; String xp = null; String errormesage = null; IdCardInfo IdCardInfo = null; System.out.println("idcard bind Nciic backInfo:" + backXMl); try { //XML doc = DocumentHelper.parseText(backXMl); // ? Element rootElt = doc.getRootElement(); if ("RESPONSE".equalsIgnoreCase(rootElt.getName())) { //??? List<DefaultAttribute> list = rootElt.attributes(); for (DefaultAttribute e : list) { if ("errorcode".equals(e.getName())) { if ("-70".equalsIgnoreCase(e.getValue())) { throw new RuntimeException("?", null); } else if ("-71".equalsIgnoreCase(e.getValue())) { throw new RuntimeException("?", null); } else if ("-72".equalsIgnoreCase(e.getValue())) { throw new RuntimeException("IP ???", null); } else if ("-80".equalsIgnoreCase(e.getValue())) { throw new RuntimeException("??", null); } } } } else if ("ROWS".equalsIgnoreCase(rootElt.getName())) { Iterator iterForRow = rootElt.elementIterator("ROW"); while (iterForRow.hasNext()) { Element recordEleForRow = (Element) iterForRow.next(); //????? Iterator itersForInput = recordEleForRow.elementIterator("INPUT"); while (itersForInput.hasNext()) { Element recordEleForInput = (Element) itersForInput.next(); gmsfhm = recordEleForInput.elementTextTrim("gmsfhm"); if (!(idCard.equalsIgnoreCase(gmsfhm))) { throw new RuntimeException("?????", null); } xm = recordEleForInput.elementTextTrim("xm"); if (!(userName.equalsIgnoreCase(xm))) { throw new RuntimeException("?????", null); } } //?????? Iterator itersForOutput = recordEleForRow.elementIterator("OUTPUT"); while (itersForOutput.hasNext()) { Element recordEleForSubRow = (Element) itersForOutput.next(); Iterator itersForItem = recordEleForSubRow.elementIterator("ITEM"); while (itersForItem.hasNext()) { Element recordEleForItem = (Element) itersForItem.next(); gmsfhm = recordEleForItem.elementTextTrim("gmsfhm"); xm = recordEleForItem.elementTextTrim("xm"); xp = recordEleForItem.elementTextTrim("xp"); errormesage = recordEleForItem.elementTextTrim("errormesage"); if (gmsfhm != null) { result_gmsfhm = recordEleForItem.elementTextTrim("result_gmsfhm"); } if (xm != null) { result_xm = recordEleForItem.elementTextTrim("result_xm"); } if (xp != null) { xp = recordEleForItem.elementTextTrim("xp"); } if (errormesage != null) { errormesage = recordEleForItem.elementTextTrim("errormesage"); break; } } } if (null != errormesage) { throw new RuntimeException("??!", null); } else { if (!"".equalsIgnoreCase(result_xm)) { throw new RuntimeException("?????", null); } if (!"".equalsIgnoreCase(result_gmsfhm)) { throw new RuntimeException("?????", null); } IdCardInfo = new IdCardInfo(); IdCardInfo.setIdCardNumber(idCard); IdCardInfo.setRealName(userName); IdCardInfo.setAvatar(xp); } } } } catch (DocumentException e) { System.out.println("idcard bind erroinfo:XML??"); } catch (Exception e) { System.out.println("idcard bind erroinfo:XML??"); } return IdCardInfo; }
From source file:com.hyrt.cei.util.ColumnsUtil.java
public Table[] parsePDM_VO(InputStream ips) { Table[] tabs = new Table[] {}; List<Table> voS = new ArrayList<Table>(); Table vo = null;/*from w w w . j a va 2s. c o m*/ Column[] cols = null; SAXReader sr = new SAXReader(); Document doc = null; try { doc = sr.read(ips); } catch (DocumentException e) { e.printStackTrace(); } Iterator itr = doc.selectNodes("//c:Tables//o:Table").iterator(); while (itr.hasNext()) { vo = new Table(); cols = new Column[] {}; List<Column> list = new ArrayList<Column>(); Column col = null; Element e_table = (Element) itr.next(); vo.setTableName(e_table.elementTextTrim("Name")); vo.setTableCode(e_table.elementTextTrim("Code")); Iterator itr1 = e_table.element("Columns").elements("Column").iterator(); while (itr1.hasNext()) { try { col = new Column(); Element e_col = (Element) itr1.next(); String pkID = e_col.attributeValue("Id"); col.setDefaultValue(e_col.elementTextTrim("DefaultValue")); col.setName(e_col.elementTextTrim("Name")); if (e_col.elementTextTrim("DataType").indexOf("(") > 0) { col.setType(e_col.elementTextTrim("DataType").substring(0, e_col.elementTextTrim("DataType").indexOf("("))); } else { col.setType(e_col.elementTextTrim("DataType")); } col.setCode(e_col.elementTextTrim("Code")); col.setLength(e_col.elementTextTrim("Length") == null ? 0 : Integer.parseInt(e_col.elementTextTrim("Length"))); if (e_table.element("Keys") != null) { String keys_key_id = e_table.element("Keys").element("Key").attributeValue("Id"); String keys_column_ref = e_table.element("Keys").element("Key").element("Key.Columns") .element("Column").attributeValue("Ref"); String keys_primarykey_ref_id = e_table.element("PrimaryKey").element("Key") .attributeValue("Ref"); if (keys_primarykey_ref_id.equals(keys_key_id) && keys_column_ref.equals(pkID)) { col.setPkFlag(true); vo.setPkField(col.getCode()); } } list.add(col); //System.out.println(col); } catch (Exception ex) { // col.setType(e_col.elementTextTrim("DataType")); ex.printStackTrace(); } } vo.setCols(list.toArray(cols)); voS.add(vo); //System.out.println(vo); //System.out.println("======================"); //System.out.println(); } return voS.toArray(tabs); }