List of usage examples for org.dom4j DocumentHelper createDocument
public static Document createDocument()
From source file:com.glaf.jbpm.xml.JpdlXmlReader.java
License:Apache License
public void convert(File dir) { if (!(dir.exists() || dir.isDirectory())) { return;//from w w w . ja v a2 s. co m } String[] filelist = dir.list(); for (int i = 0; i < filelist.length; i++) { String filename = dir.getAbsolutePath() + "/" + filelist[i]; java.io.File file = new java.io.File(filename); if (file.isDirectory()) { this.convert(file); } else if (file.isFile() && file.getName().equals("processdefinition.xml")) { List<Todo> todoList = null; try { todoList = this.read(new FileInputStream(file)); } catch (FileNotFoundException ex) { ex.printStackTrace(); } if (todoList != null && todoList.size() > 0) { index = index + 100; Document doc = DocumentHelper.createDocument(); doc.setXMLEncoding("GBK"); Element root = doc.addElement("rows"); Iterator<Todo> iter = todoList.iterator(); while (iter.hasNext()) { Todo todo = (Todo) iter.next(); Map<String, Object> dataMap = Tools.getDataMap(todo); dataMap.remove("id"); dataMap.remove("locked"); dataMap.remove("configFlag"); dataMap.remove("versionNo"); Element row = root.addElement("row"); row.addAttribute("id", String.valueOf(index++)); Set<Entry<String, Object>> entrySet = dataMap.entrySet(); for (Entry<String, Object> entry : entrySet) { String key = entry.getKey(); Object value = entry.getValue(); if (value != null && !(value instanceof Map<?, ?>) && !(value instanceof Set<?>) && !(value instanceof Collection<?>)) { Element elem = row.addElement("property"); elem.addAttribute("name", key); if (key.equals("link") || key.equals("listLink")) { elem.addCDATA(sp + " " + value.toString()); } else { elem.addAttribute("value", value.toString()); } } } } filename = dir.getAbsolutePath() + "/" + "todo.xml"; Dom4jUtils.savePrettyDoument(doc, filename, "GBK"); doc = null; root = null; } } } }
From source file:com.globalsight.everest.workflow.WorkflowTemplateAdapter.java
License:Apache License
/** * Creates a new workflow template.//from w w w .ja v a 2 s.com * <p> * o * * @param p_workflowTemplate * - The template to be created. * @param p_ctx * - The JbpmContext object used for template ownership. * @param p_worklfowOwners * - The owner(s) of the workflow instances. */ public WorkflowTemplate createWorkflowTemplate(WorkflowTemplate p_workflowTemplate, WorkflowOwners p_workflowOwners) throws Exception { JbpmContext ctx = null; try { ctx = WorkflowConfiguration.getInstance().getJbpmContext(); Document document = DocumentHelper.createDocument(); setTemplateName(document, p_workflowTemplate.getName()); setNodeNames(p_workflowTemplate.getWorkflowTasks()); createTemplateNodes(document, p_workflowTemplate, p_workflowOwners); ProcessDefinition pd = ProcessDefinition.parseXmlString(Dom4jUtil.formatXML(document, Dom4jUtil.UTF8)); ctx.deployProcessDefinition(pd); p_workflowTemplate.setId(pd.getId()); saveXmlToFileStore(document, p_workflowTemplate.getName()); } catch (Exception e) { throw e; } finally { ctx.close(); } return p_workflowTemplate; }
From source file:com.globalsight.smartbox.bussiness.process.Usecase02PreProcess.java
License:Apache License
/** * Convert csv/txt file to xml file/*from ww w .j ava2s .co m*/ * * @param format * @param originFile * @return */ private String convertToXML(String format, File originFile) { String fileName = originFile.getName(); // Save the converted file to temp directory String xmlFilePath = jobInfo.getTempFile() + File.separator + fileName.substring(0, fileName.lastIndexOf(".")) + ".xml"; File xmlFile = new File(xmlFilePath); FileReader fr = null; FileInputStream fis = null; InputStreamReader isr = null; BufferedReader br = null; XMLWriter output = null; try { String encoding = FileUtil.guessEncoding(originFile); Document document = DocumentHelper.createDocument(); Element aElement = document.addElement("root"); aElement.addAttribute("BomInfo", encoding == null ? "" : encoding); if (encoding == null) { fr = new FileReader(originFile); br = new BufferedReader(fr); } else { fis = new FileInputStream(originFile); isr = new InputStreamReader(fis, encoding); br = new BufferedReader(isr); } String str; if ("csv".equals(format)) { while ((str = br.readLine()) != null) { String[] values = str.split("\",\""); values[0] = values[0].substring(1); values[10] = values[10].substring(0, values[10].length() - 1); writeRow(aElement, values); } } else { while ((str = br.readLine()) != null) { str = str + "*"; String[] values = str.split("\\|"); values[10] = values[10].substring(0, values[10].lastIndexOf("*")); writeRow(aElement, values); } } output = new XMLWriter(new FileOutputStream(xmlFile)); output.write(document); } catch (Exception e) { String message = "Failed to convert to XML, File Name: " + originFile.getName(); LogUtil.fail(message, e); return null; } finally { try { if (output != null) { output.close(); } if (br != null) { br.close(); } if (isr != null) { isr.close(); } if (fis != null) { fis.close(); } if (fr != null) { fr.close(); } } catch (IOException e) { e.printStackTrace(); } } return xmlFile.getPath(); }
From source file:com.gote.pojo.Tournament.java
License:Apache License
/** * Transform Tournament in a formatted XML * /*from w w w . j av a2 s.c om*/ * @return XML to write as a String */ public String toXML() { // Create document Document doc = DocumentHelper.createDocument(); // Create tournament element Element root = doc.addElement(TournamentGOTEUtil.TAG_TOURNAMENT); // Add attributes root.addAttribute(TournamentGOTEUtil.ATT_TOURNAMENT_NAME, getTitle()); root.addAttribute(TournamentGOTEUtil.ATT_TOURNAMENT_SERVER, getServerType()); root.addAttribute(TournamentGOTEUtil.ATT_TOURNAMENT_DATESTART, getStartDate().toString()); root.addAttribute(TournamentGOTEUtil.ATT_TOURNAMENT_DATEEND, getEndDate().toString()); // Add rules getTournamentRules().toXML(root); // Add players Element players = root.addElement(TournamentGOTEUtil.TAG_PLAYERS); for (Player player : getParticipantsList()) { player.toXML(players); } // Add rounds Element rounds = root.addElement(TournamentGOTEUtil.TAG_ROUNDS); for (Round round : getRounds()) { round.toXML(rounds); } StringWriter out = new StringWriter(1024); XMLWriter writer; try { writer = new XMLWriter(OutputFormat.createPrettyPrint()); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return null; } writer.setWriter(out); try { writer.write(doc); } catch (IOException e) { e.printStackTrace(); } // Return the friendly XML return out.toString(); }
From source file:com.gst.mix.service.XBRLBuilder.java
License:Apache License
public String build(final Map<MixTaxonomyData, BigDecimal> map, final Date startDate, final Date endDate, final String currency) { this.instantScenarioCounter = 1; this.durationScenarioCounter = 1; this.contextMap = new HashMap<>(); final Document doc = DocumentHelper.createDocument(); this.root = doc.addElement("xbrl"); this.root.addElement("schemaRef").addNamespace("link", "http://www.themix.org/sites/default/files/Taxonomy2010/dct/dc-all_2010-08-31.xsd"); this.startDate = startDate; this.endDate = endDate; for (final Entry<MixTaxonomyData, BigDecimal> entry : map.entrySet()) { final MixTaxonomyData taxonomy = entry.getKey(); final BigDecimal value = entry.getValue(); addTaxonomy(this.root, taxonomy, value); }// w w w . j a v a 2s . co m addContexts(); addCurrencyUnit(currency); addNumberUnit(); doc.setXMLEncoding("UTF-8"); return doc.asXML(); }
From source file:com.haulmont.cuba.core.entity.ScheduledTask.java
License:Apache License
public void updateMethodParameters(List<MethodParameterInfo> params) { Document doc = DocumentHelper.createDocument(); Element paramsEl = doc.addElement("params"); for (MethodParameterInfo param : params) { Element paramEl = paramsEl.addElement("param"); paramEl.addAttribute("type", param.getType().getName()); paramEl.addAttribute("name", param.getName()); paramEl.setText(param.getValue() != null ? param.getValue().toString() : ""); }//from w ww. j a v a2 s .c o m setMethodParamsXml(Dom4j.writeDocument(doc, true)); }
From source file:com.haulmont.cuba.core.sys.AbstractViewRepository.java
License:Apache License
protected void init() { StopWatch initTiming = new Slf4JStopWatch("ViewRepository.init." + getClass().getSimpleName()); storage.clear();/* w w w . ja va 2 s.c o m*/ readFileNames.clear(); String configName = AppContext.getProperty("cuba.viewsConfig"); if (!StringUtils.isBlank(configName)) { Element rootElem = DocumentHelper.createDocument().addElement("views"); StrTokenizer tokenizer = new StrTokenizer(configName); for (String fileName : tokenizer.getTokenArray()) { addFile(rootElem, fileName); } checkDuplicates(rootElem); for (Element viewElem : Dom4j.elements(rootElem, "view")) { deployView(rootElem, viewElem, new HashSet<>()); } } initTiming.stop(); }
From source file:com.haulmont.cuba.core.sys.AbstractViewRepository.java
License:Apache License
public void deployViews(String resourceUrl) { lock.readLock().lock();//from ww w . ja va2s. co m try { checkInitialized(); } finally { lock.readLock().unlock(); } Element rootElem = DocumentHelper.createDocument().addElement("views"); lock.writeLock().lock(); try { addFile(rootElem, resourceUrl); for (Element viewElem : Dom4j.elements(rootElem, "view")) { deployView(rootElem, viewElem, new HashSet<>()); } } finally { lock.writeLock().unlock(); } }
From source file:com.haulmont.cuba.core.sys.persistence.MappingFileCreator.java
License:Apache License
private Document createDocument(Map<Class<?>, List<Attr>> mappings) { Document doc = DocumentHelper.createDocument(); Element rootEl = doc.addElement("entity-mappings", XMLNS); Namespace xsi = new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); rootEl.add(xsi);/*w w w .j av a 2 s . com*/ rootEl.addAttribute(new QName("schemaLocation", xsi), SCHEMA_LOCATION); rootEl.addAttribute("version", PERSISTENCE_VER); for (Map.Entry<Class<?>, List<Attr>> entry : mappings.entrySet()) { if (entry.getKey().getAnnotation(MappedSuperclass.class) != null) { Element entityEl = rootEl.addElement("mapped-superclass", XMLNS); entityEl.addAttribute("class", entry.getKey().getName()); createAttributes(entry, entityEl); } } for (Map.Entry<Class<?>, List<Attr>> entry : mappings.entrySet()) { if (entry.getKey().getAnnotation(Entity.class) != null) { Element entityEl = rootEl.addElement("entity", XMLNS); entityEl.addAttribute("class", entry.getKey().getName()); entityEl.addAttribute("name", entry.getKey().getAnnotation(Entity.class).name()); createAttributes(entry, entityEl); } } for (Map.Entry<Class<?>, List<Attr>> entry : mappings.entrySet()) { if (entry.getKey().getAnnotation(Embeddable.class) != null) { Element entityEl = rootEl.addElement("embeddable", XMLNS); entityEl.addAttribute("class", entry.getKey().getName()); createAttributes(entry, entityEl); } } return doc; }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopAbstractTable.java
License:Apache License
@Override public void applySettings(Element element) { if (!isSettingsEnabled()) { return;// w w w . ja va 2 s . c o m } if (defaultSettings == null) { // save default view before apply custom defaultSettings = DocumentHelper.createDocument(); defaultSettings.setRootElement(defaultSettings.addElement("presentation")); saveSettings(defaultSettings.getRootElement()); } tableSettings.apply(element, isSortable()); }