List of usage examples for org.dom4j Element attributeValue
String attributeValue(QName qName);
From source file:com.glaf.jbpm.xml.JpdlXmlReader.java
License:Apache License
public List<String> getTaskNames(InputStream inputStream) { List<String> taskNames = new ArrayList<String>(); SAXReader xmlReader = new SAXReader(); Document doc = null;/* w w w .j a v a 2 s .com*/ try { doc = xmlReader.read(inputStream); } catch (Exception ex) { throw new RuntimeException(ex); } Element root = doc.getRootElement(); List<?> rows = root.elements("task-node"); Iterator<?> iterator = rows.iterator(); while (iterator.hasNext()) { Element element = (Element) iterator.next(); List<?> tasks = element.elements("task"); Iterator<?> iter = tasks.iterator(); while (iter.hasNext()) { Element elem = (Element) iter.next(); String taskName = elem.attributeValue("name"); if (taskNames.contains(taskName)) { throw new RuntimeException("task name '" + taskName + "' is exists."); } taskNames.add(taskName); } } return taskNames; }
From source file:com.glaf.jbpm.xml.JpdlXmlReader.java
License:Apache License
public void checkTaskNames(Document doc) { List<String> taskNames = new ArrayList<String>(); Element root = doc.getRootElement(); List<?> rows = root.elements("task-node"); Iterator<?> iterator = rows.iterator(); while (iterator.hasNext()) { Element element = (Element) iterator.next(); List<?> tasks = element.elements("task"); Iterator<?> iter = tasks.iterator(); while (iter.hasNext()) { Element elem = (Element) iter.next(); String taskName = elem.attributeValue("name"); if (taskNames.contains(taskName)) { throw new RuntimeException("task name '" + taskName + "' is exists."); }/*from ww w.j a v a 2 s . c om*/ taskNames.add(taskName); } } }
From source file:com.glaf.jbpm.xml.JpdlXmlReader.java
License:Apache License
public List<Todo> read(InputStream inputStream) { List<Todo> todoList = new java.util.ArrayList<Todo>(); SAXReader xmlReader = new SAXReader(); int sortNo = 1; try {// w w w .j a va 2 s.co m Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); String processName = root.attributeValue("name"); String moduleName = root.elementText("description"); List<?> rows = root.elements("task-node"); Iterator<?> iterator = rows.iterator(); while (iterator.hasNext()) { Element element = (Element) iterator.next(); List<?> tasks = element.elements("task"); Iterator<?> iter = tasks.iterator(); while (iter.hasNext()) { Element elem = (Element) iter.next(); String taskName = elem.attributeValue("name"); if (taskName.startsWith("task55")) { continue; } Todo model = new Todo(); model.setSortNo(sortNo++); model.setProcessName(processName); model.setModuleName(moduleName); model.setTitle(moduleName + " " + elem.attributeValue("description") + "??"); model.setContent(moduleName + " " + elem.attributeValue("description") + "??"); model.setCode(processName + "_" + taskName); model.setTaskName(taskName); model.setProvider("jbpm"); model.setLinkType(processName + "_" + taskName); String detail_url = conf.get("jbpm_task_detail_url"); String list_url = conf.get("jbpm_task_url"); model.setLink(detail_url + "&rowId=#{rowId}&x_method=view&app_name=" + processName); model.setListLink(list_url + "&taskType=running&app_name=" + processName); model.setLimitDay(2); model.setXa(6); model.setXb(6); todoList.add(model); } } } catch (Exception ex) { throw new RuntimeException(ex); } return todoList; }
From source file:com.glaf.mail.MxMailHelper.java
License:Apache License
public Map<String, String> getAttributes(String attribute) { Map<String, String> dataMap = new java.util.HashMap<String, String>(); StringReader stringReader = new StringReader(attribute); SAXReader xmlReader = new SAXReader(); try {//from www. j a v a 2 s . c o m Document doc = xmlReader.read(stringReader); Element root = doc.getRootElement(); List<?> elements = root.elements("element"); if (elements != null && elements.size() > 0) { Iterator<?> iterator = elements.iterator(); while (iterator.hasNext()) { Element element = (Element) iterator.next(); String name = element.attributeValue("name"); String value = element.attributeValue("value"); if (StringUtils.isEmpty(value)) { value = element.getStringValue(); } dataMap.put(name, value); } } } catch (Exception ex) { ex.printStackTrace(); } return dataMap; }
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;//ww w .j av a2 s .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.mail.xml.MailXmlReader.java
License:Apache License
protected Map<String, Object> readProperties(Element element) { Map<String, Object> properties = new java.util.HashMap<String, Object>(); Element propsElement = element.element("properties"); if (propsElement != null) { List<?> rows = propsElement.elements("property"); Iterator<?> iter = rows.iterator(); while (iter.hasNext()) { Element elem = (Element) iter.next(); String name = elem.attributeValue("name"); String value = elem.attributeValue("value"); if (StringUtils.isEmpty(value)) { value = elem.getStringValue(); }//from www.j a v a 2s .co m properties.put(name, value); } } return properties; }
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;// w w w . j av a 2 s .com 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.glaf.template.TemplateReader.java
License:Apache License
@SuppressWarnings("unchecked") public Map<String, Template> getTemplates(InputStream inputStream) { Map<String, Template> dataMap = new java.util.HashMap<String, Template>(); Element root = this.getRootElement(inputStream); List<?> templates = root.elements("template"); if (templates != null && templates.size() > 0) { Iterator<?> iterator = templates.iterator(); while (iterator.hasNext()) { Element element = (Element) iterator.next(); Template template = new Template(); List<Element> elems = element.elements(); if (elems != null && !elems.isEmpty()) { Map<String, Object> rowMap = new java.util.HashMap<String, Object>(); for (Element em : elems) { rowMap.put(em.getName(), em.getStringValue()); }/* ww w .ja va2s . c o m*/ Tools.populate(template, rowMap); } String text = element.elementText("text"); String name = element.elementText("name"); String title = element.elementText("title"); String templateId = element.attributeValue("id"); String dataFile = element.elementText("dataFile"); String moduleId = element.elementText("moduleId"); String moduleName = element.elementText("moduleName"); String callbackUrl = element.elementText("callbackUrl"); String description = element.elementText("description"); String language = element.elementText("language"); String objectId = element.elementText("objectId"); String objectValue = element.elementText("objectValue"); String _fileType = element.elementText("fileType"); template.setLanguage(language); int fileType = 0; if (StringUtils.isNumeric(_fileType)) { fileType = Integer.parseInt(_fileType); } if (dataFile.endsWith(".java")) { fileType = 50; } else if (dataFile.endsWith(".jsp")) { fileType = 51; } else if (dataFile.endsWith(".ftl")) { fileType = 52; template.setLanguage("freemarker"); } else if (dataFile.endsWith(".vm")) { fileType = 54; template.setLanguage("velocity"); } else if (dataFile.endsWith(".xml")) { fileType = 60; } else if (dataFile.endsWith(".htm") || dataFile.endsWith(".html")) { fileType = 80; } template.setTemplateType(FileUtils.getFileExt(dataFile)); if (StringUtils.isEmpty(text)) { String filename = SystemProperties.getConfigRootPath() + dataFile; File file = new File(filename); template.setLastModified(file.lastModified()); template.setFileSize(file.length()); byte[] data = FileUtils.getBytes(file); template.setData(data); } if (template.getData() == null || template.getFileSize() == 0) { throw new RuntimeException(" template content is null "); } template.setContent(text); template.setDataFile(dataFile); template.setTitle(title); template.setName(name); if (StringUtils.isNotEmpty(name)) { template.setName(name); } else { template.setName(title); } template.setFileType(fileType); template.setCallbackUrl(callbackUrl); template.setDescription(description); template.setTemplateId(templateId); template.setModuleId(moduleId); template.setModuleName(moduleName); template.setObjectId(objectId); template.setObjectValue(objectValue); dataMap.put(templateId, template); } } return dataMap; }
From source file:com.glaf.template.TemplateReader.java
License:Apache License
@SuppressWarnings("unchecked") public List<Template> readTemplates(InputStream inputStream) { List<Template> templates = new java.util.ArrayList<Template>(); Element root = this.getRootElement(inputStream); List<Element> elements = root.elements("template"); if (elements != null && !elements.isEmpty()) { for (Element element : elements) { Template tpl = new Template(); tpl.setTemplateId(element.attributeValue("id")); tpl.setName(element.attributeValue("name")); tpl.setDescription(element.attributeValue("description")); List<Element> elems = element.elements(); if (elems != null && !elems.isEmpty()) { Map<String, Object> dataMap = new java.util.HashMap<String, Object>(); for (Element em : elems) { dataMap.put(em.getName(), em.getStringValue()); }/*from w w w.j av a 2s. c o m*/ Tools.populate(tpl, dataMap); } if (StringUtils.isEmpty(tpl.getContent())) { if (StringUtils.isNotEmpty(tpl.getDataFile())) { String filename = SystemProperties.getConfigRootPath() + "/" + tpl.getDataFile(); try { tpl.setContent(FileUtils.readFile(filename)); } catch (Exception ex) { ex.printStackTrace(); } } } templates.add(tpl); } } return templates; }
From source file:com.globalsight.connector.mindtouch.util.MindTouchHelper.java
License:Apache License
/** * Parse tree xml from "getTreeXml(pageId)" method to form a tree. * /* w ww.jav a2 s. c o m*/ * @param treeXml * -- the tree information in XML format. * @return MindTouchPage */ @SuppressWarnings("rawtypes") public MindTouchPage parseTreeXml(String treeXml) throws Exception { MindTouchPage rootMtp = null; Document doc = getDocument(treeXml); String id = null; String href = null; List pageNodes = doc.selectNodes("//page"); List<MindTouchPage> allPages = new ArrayList<MindTouchPage>(); Iterator it = pageNodes.iterator(); while (it.hasNext()) { MindTouchPage mtp = new MindTouchPage(); Element pageNode = (Element) it.next(); // page id id = pageNode.attributeValue("id"); mtp.setId(Long.parseLong(id)); // href href = pageNode.attributeValue("href"); mtp.setHref(href); // parent page id String parentName = null; if (pageNode.getParent() != null) { parentName = pageNode.getParent().getName(); } if ("subpages".equals(parentName)) { String parentId = pageNode.getParent().getParent().attributeValue("id"); mtp.setParentId(Long.parseLong(parentId)); } else if ("pages".equals(parentName)) { rootMtp = mtp; } Iterator subNodeIt = pageNode.nodeIterator(); while (subNodeIt.hasNext()) { Element node = (Element) subNodeIt.next(); String name = node.getName(); String text = node.getText(); if ("uri.ui".equals(name)) { mtp.setUriUi(text); } else if ("title".equals(name)) { // title cannot have "<" and ">" text = text.replace("<", "<").replace(">", ">"); // as json does not allow "\" and "/", remove them for displaying. text = text.replace("\\", "").replace("/", ""); text = text.replace("%22", "\""); text = text.replace("%3F", "?"); text = text.replace("%23", "#"); text = text.replace("%3D", "="); text = text.replace("%26", "&"); text = text.replace("%25", "%"); mtp.setTitle(text); } else if ("path".equals(name)) { mtp.setPath(text); } else if ("date.created".equals(name)) { mtp.setDateCreated(text); } } allPages.add(mtp); } HashMap<Long, MindTouchPage> map = new HashMap<Long, MindTouchPage>(); for (MindTouchPage mtp : allPages) { map.put(mtp.getId(), mtp); } for (MindTouchPage mtp : allPages) { long parentId = mtp.getParentId(); MindTouchPage parent = map.get(parentId); if (parent != null) { parent.addSubPage(mtp); } } return rootMtp; }