List of usage examples for org.dom4j Element getStringValue
String getStringValue();
From source file:com.glaf.core.xml.XmlMappingReader.java
License:Apache License
public TableModel read(java.io.InputStream inputStream) { TableModel tableModel = new TableModel(); SAXReader xmlReader = new SAXReader(); try {//ww w.j av a 2s . c o m Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); Element element = root.element("entity"); if (element != null) { tableModel.setEntityName(element.attributeValue("name")); tableModel.setPrimaryKey(element.attributeValue("primaryKey")); tableModel.setTableName(element.attributeValue("table")); tableModel.setTitle(element.attributeValue("title")); tableModel.setStopWord(element.attributeValue("stopWord")); tableModel.setPackageName(element.attributeValue("package")); tableModel.setEnglishTitle(element.attributeValue("englishTitle")); tableModel.setFilePrefix(element.attributeValue("filePrefix")); tableModel.setParseType(element.attributeValue("parseType")); tableModel.setParseClass(element.attributeValue("parseClass")); tableModel.setAggregationKey(element.attributeValue("aggregationKeys")); tableModel.setSplit(element.attributeValue("split")); if (StringUtils.equals(element.attributeValue("insertOnly"), "true")) { tableModel.setInsertOnly(true); } String startRow = element.attributeValue("startRow"); if (StringUtils.isNumeric(startRow)) { tableModel.setStartRow(Integer.parseInt(startRow)); } String stopSkipRow = element.attributeValue("stopSkipRow"); if (StringUtils.isNumeric(stopSkipRow)) { tableModel.setStopSkipRow(Integer.parseInt(stopSkipRow)); } String minLength = element.attributeValue("minLength"); if (StringUtils.isNumeric(minLength)) { tableModel.setMinLength(Integer.parseInt(minLength)); } String batchSize = element.attributeValue("batchSize"); if (StringUtils.isNumeric(batchSize)) { tableModel.setBatchSize(Integer.parseInt(batchSize)); } List<?> excludes = element.elements("excludes"); if (excludes != null && excludes.size() > 0) { Iterator<?> iterator = excludes.iterator(); while (iterator.hasNext()) { Element elem = (Element) iterator.next(); tableModel.addExclude(elem.getStringValue()); } } List<?> rows = element.elements("property"); if (rows != null && rows.size() > 0) { Iterator<?> iterator = rows.iterator(); while (iterator.hasNext()) { Element elem = (Element) iterator.next(); ColumnModel field = new ColumnModel(); this.readField(elem, field); tableModel.addColumn(field); if (StringUtils.equals(tableModel.getPrimaryKey(), field.getColumnName())) { tableModel.setIdColumn(field); } } } Element idElem = element.element("id"); if (idElem != null) { ColumnModel idField = new ColumnModel(); this.readField(idElem, idField); tableModel.setIdColumn(idField); } } } catch (Exception ex) { ex.printStackTrace(); throw new RuntimeException(ex); } return tableModel; }
From source file:com.glaf.dts.util.XmlReader.java
License:Apache License
public DataTransfer read(java.io.InputStream inputStream) { DataTransfer tableModel = new DataTransfer(); SAXReader xmlReader = new SAXReader(); try {// w ww.j av a 2s. co m Document doc = xmlReader.read(inputStream); Element root = doc.getRootElement(); Element element = root.element("entity"); if (element != null) { List<?> attrs = element.attributes(); if (attrs != null && !attrs.isEmpty()) { Map<String, Object> dataMap = new java.util.HashMap<String, Object>(); Iterator<?> iter = attrs.iterator(); while (iter.hasNext()) { Attribute attr = (Attribute) iter.next(); dataMap.put(attr.getName(), attr.getStringValue()); tableModel.addProperty(attr.getName(), attr.getStringValue()); } Tools.populate(tableModel, dataMap); } tableModel.setEntityName(element.attributeValue("name")); tableModel.setPrimaryKey(element.attributeValue("primaryKey")); tableModel.setTableName(element.attributeValue("table")); tableModel.setTitle(element.attributeValue("title")); tableModel.setStopWord(element.attributeValue("stopWord")); tableModel.setPackageName(element.attributeValue("package")); tableModel.setEnglishTitle(element.attributeValue("englishTitle")); tableModel.setFilePrefix(element.attributeValue("filePrefix")); tableModel.setParseType(element.attributeValue("parseType")); tableModel.setParseClass(element.attributeValue("parseClass")); tableModel.setAggregationKeys(element.attributeValue("aggregationKeys")); tableModel.setSplit(element.attributeValue("split")); if (StringUtils.equals(element.attributeValue("insertOnly"), "true")) { tableModel.setInsertOnly("true"); } String startRow = element.attributeValue("startRow"); if (StringUtils.isNotEmpty(startRow) && StringUtils.isNumeric(startRow)) { tableModel.setStartRow(Integer.parseInt(startRow)); } String stopSkipRow = element.attributeValue("stopSkipRow"); if (StringUtils.isNotEmpty(stopSkipRow) && StringUtils.isNumeric(stopSkipRow)) { tableModel.setStopSkipRow(Integer.parseInt(stopSkipRow)); } String batchSize = element.attributeValue("batchSize"); if (StringUtils.isNotEmpty(batchSize) && StringUtils.isNumeric(batchSize)) { tableModel.setBatchSize(Integer.parseInt(batchSize)); } List<?> excludes = element.elements("excludes"); if (excludes != null && excludes.size() > 0) { Iterator<?> iterator = excludes.iterator(); while (iterator.hasNext()) { Element elem = (Element) iterator.next(); tableModel.addExclude(elem.getStringValue()); } } List<?> rows = element.elements("property"); if (rows != null && rows.size() > 0) { Iterator<?> iterator = rows.iterator(); while (iterator.hasNext()) { Element elem = (Element) iterator.next(); ColumnDefinition field = new ColumnDefinition(); this.readField(elem, field); tableModel.addColumn(field); if (StringUtils.equalsIgnoreCase(tableModel.getPrimaryKey(), field.getColumnName())) { tableModel.setIdColumn(field); } } } } } catch (Exception ex) { throw new RuntimeException(ex); } return tableModel; }
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 w w w .ja va2 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
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 w ww. java 2s. co m properties.put(name, value); } } return properties; }
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 .j av a 2 s . 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()); }/* ww w. ja v a 2 s . c om*/ 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.cxe.adapter.msoffice.ExcelRepairer.java
License:Apache License
private void repairWt() throws Exception { List<File> fs = getExcelRepairFiles(); for (File f : fs) { String content = FileUtil.readFile(f, "utf-8"); XmlParser parser = new XmlParser(); org.dom4j.Document document = parser.parseXml(content); Element element = document.getRootElement(); @SuppressWarnings("unchecked") List<Element> wts = element.selectNodes("//t"); for (Element wt : wts) { if (wt == null) continue; @SuppressWarnings("unchecked") List<Element> es = wt.elements(); if (!wt.isTextOnly()) { String text = wt.getStringValue(); for (Element e : es) { wt.remove(e);/*from w ww. j a va 2 s. com*/ } wt.setText(text); } } Writer fileWriter = new OutputStreamWriter(new FileOutputStream(f), "UTF-8"); XMLWriter xmlWriter = new XMLWriter(fileWriter); xmlWriter.write(document); xmlWriter.close(); } }
From source file:com.globalsight.cxe.adapter.msoffice.ExcelRepairer.java
License:Apache License
private void repairExcelSharedStrings() throws Exception { File f = new File(path + "/xl/sharedStrings.xml"); if (!f.exists()) return;//from w ww . j a v a2 s . c o m String content = FileUtil.readFile(f, "utf-8"); XmlParser parser = new XmlParser(); org.dom4j.Document document = parser.parseXml(content); Element element = document.getRootElement(); List<Element> rs = getElementByName(element, "r"); for (Element r : rs) { @SuppressWarnings("rawtypes") List els = r.content(); StringBuffer sb = new StringBuffer(); Element wt = null; List<DefaultText> texts = new ArrayList<DefaultText>(); for (Object el : els) { if (el instanceof DefaultText) { DefaultText text = (DefaultText) el; String s = text.getStringValue(); if ("\n".equals(s)) continue; texts.add(text); sb.append(text.getStringValue()); } else if (el instanceof Element) { Element elm = (Element) el; if ("t".equals(elm.getName())) { wt = elm; sb.append(elm.getStringValue()); } } } if (wt == null) { wt = r.addElement("t"); wt.addAttribute("xml:space", "preserve"); } if (sb.length() == 0) sb.append(" "); wt.clearContent(); wt.addText(sb.toString()); for (DefaultText text : texts) { r.remove(text); } } Writer fileWriter = new OutputStreamWriter(new FileOutputStream(f), "UTF-8"); XMLWriter xmlWriter = new XMLWriter(fileWriter); xmlWriter.write(document); xmlWriter.close(); }
From source file:com.globalsight.cxe.adapter.msoffice.WordRepairer.java
License:Apache License
private static void forNodesInWt(Element element) { @SuppressWarnings("unchecked") List<Element> wts = element.selectNodes("//w:t"); for (Element wt : wts) { @SuppressWarnings("unchecked") List<Element> es = wt.elements(); if (!wt.isTextOnly()) { String text = wt.getStringValue(); for (Element e : es) { wt.remove(e);/*from w w w. j a v a2 s. c o m*/ } wt.setText(text); } } }
From source file:com.globalsight.cxe.adapter.msoffice.WordRepairer.java
License:Apache License
private static void forWrInWr(Element element) { @SuppressWarnings("unchecked") List<Node> ts = element.selectNodes("//w:r/w:r"); for (Node t : ts) { Element wr = t.getParent(); if (wr == null) continue; List<?> els = wr.content(); StringBuffer sb = new StringBuffer(); Element wt = null;//from w w w . ja v a 2 s .co m List<Element> wrs = new ArrayList<Element>(); for (Object el : els) { if (el instanceof Element) { Element elm = (Element) el; if ("t".equals(elm.getName())) { wt = elm; sb.append(elm.getStringValue()); } else if ("r".equals(elm.getName())) { sb.append(elm.getStringValue()); wrs.add(elm); } } } if (wt == null) { wt = wr.addElement("w:t"); wt.addAttribute("xml:space", "preserve"); } wt.setText(sb.toString()); for (Element w : wrs) { wr.remove(w); } } }