List of usage examples for org.dom4j DocumentFactory getInstance
public static synchronized DocumentFactory getInstance()
From source file:com.mg.framework.support.ui.UIProducer.java
License:Open Source License
public static Document performDocument(Document document, RuntimeMacrosLoader runtimeMacrosLoader) { logger.debug("Original form descriptor:\n".concat(document.asXML())); Document result = DocumentFactory.getInstance().createDocument(document.getXMLEncoding()); result.setDocType(document.getDocType()); result.setRootElement(copyElement(document.getRootElement(), runtimeMacrosLoader)); result.getRootElement().addNamespace(document.getRootElement().getNamespacePrefix(), document.getRootElement().getNamespaceURI()); try {/* ww w .j av a 2 s. c o m*/ //? ?, ? ? namespaces result = DocumentHelper.parseText(result.asXML()); logger.debug("Finished form descriptor:\n".concat(result.asXML())); return result; } catch (DocumentException e) { throw new ApplicationException(e); } }
From source file:com.nokia.helium.environment.EnvironmentXMLWriter.java
License:Open Source License
/** * Writes an environment definition in XML to output. * @param environment Enviroment definition. * @throws IOException If I/O error occurs. *///from ww w . ja v a2s . co m public void write(Environment environment) throws IOException { doc = DocumentFactory.getInstance().createDocument(); doc.addElement("environment"); List<Executable> executables = environment.getExecutables(); for (Iterator<Executable> iterator = executables.iterator(); iterator.hasNext();) { Executable executable = (Executable) iterator.next(); write(executable); } XMLWriter writer = new XMLWriter(out, OutputFormat.createPrettyPrint()); writer.write(doc); writer.close(); }
From source file:com.noterik.bart.fs.action.GenericIndexQueueAction.java
License:Open Source License
private void addJob(String objectUri, String eventUri) { /* only add valid object */ if (objectUri.startsWith("/")) { long timestamp = new Date().getTime(); Document xml = DocumentFactory.getInstance().createDocument(); Element fsxml = xml.addElement("fsxml"); Element properties = fsxml.addElement("properties"); properties.addElement(type).addText(objectUri); properties.addElement("priority").addText(String.valueOf(getPriority(eventUri))); properties.addElement("timestamp").addText(String.valueOf(timestamp)); properties.addElement("type").addText(type); Element object = fsxml.addElement(type); object.addAttribute("id", "1"); object.addAttribute("referid", objectUri); logger.debug(xml.asXML());/*from w ww . j av a2 s . c o m*/ logger.debug(queueUri); FSXMLRequestHandler.instance().handlePOST(queueUri, xml.asXML()); } }
From source file:com.noterik.bart.fs.action.PresentationIndexQueueAction.java
License:Open Source License
private void addJob(String presentationUri, String eventUri) { /* only add valid presentations */ if (presentationUri.startsWith("/")) { long timestamp = new Date().getTime(); Document xml = DocumentFactory.getInstance().createDocument(); Element fsxml = xml.addElement("fsxml"); Element properties = fsxml.addElement("properties"); properties.addElement("presentation").addText(presentationUri); properties.addElement("priority").addText(String.valueOf(getPriority(eventUri))); properties.addElement("timestamp").addText(String.valueOf(timestamp)); Element presentation = fsxml.addElement("presentation"); presentation.addAttribute("id", "1"); presentation.addAttribute("referid", presentationUri); logger.debug(xml.asXML());/*from ww w . j a v a 2s . co m*/ logger.debug(queueUri); FSXMLRequestHandler.instance().handlePOST(queueUri, xml.asXML()); } }
From source file:com.openedit.users.filesystem.FileSystemUserManager.java
License:Open Source License
public void saveUser(User user) throws UserManagerException { if (user.isVirtual()) { log.error("Cannot save virtual users: " + user.getUserName()); return;/* www .ja v a 2s . c o m*/ } DocumentFactory factory = DocumentFactory.getInstance(); Document doc = factory.createDocument(); Element userElem = doc.addElement("user"); userElem.addAttribute("enabled", Boolean.toString(user.isEnabled())); if (user.getUserName() == null) { int id = getUserIdCounter().incrementCount(); String newid = String.valueOf(id); user.setId(newid); } Element userNameElem = userElem.addElement("user-name"); userNameElem.setText(user.getUserName()); Element passwordElem = userElem.addElement("password"); // if (user.getPassword() != null && !user.getPassword().equals("")) { String ps = user.getPassword(); ps = encrypt(ps); //password may have changed we should set it so it's not in plain text anymore. user.setPassword(ps); passwordElem.setText(ps); } Element creationDateElem = userElem.addElement("creation-date"); if (user.getCreationDate() != null) { creationDateElem.setText(String.valueOf(user.getCreationDate().getTime())); } else { creationDateElem.setText(String.valueOf(System.currentTimeMillis())); } //Tuan add property lastLogined-Time Element lastLoginTime = userElem.addElement("lastLogined-Time"); lastLoginTime.setText(DateStorageUtil.getStorageUtil().formatForStorage(new Date())); MapPropertyContainer map = (MapPropertyContainer) user.getPropertyContainer(); if (map != null) { Element propertiesElem = map.createPropertiesElement("properties"); userElem.add(propertiesElem); } if (user.getGroups() != null) { for (Iterator iter = user.getGroups().iterator(); iter.hasNext();) { Group group = (Group) iter.next(); Element child = userElem.addElement("group"); child.addAttribute("id", group.getId()); } } File file = loadUserFile(user.getUserName()); getXmlUtil().saveXml(doc, file); getUserNameToUserMap().put(user.getUserName(), user); }
From source file:com.openedit.users.filesystem.FileSystemUserManager.java
License:Open Source License
public void saveGroup(Group inGroup) throws UserManagerException { Document doc = DocumentFactory.getInstance().createDocument(); Element root = doc.addElement("group"); if (inGroup.getId() == null) { int id = getUserIdCounter().incrementCount(); String inAccount = String.valueOf(id); inGroup.setId(inAccount);/*from w ww.j a va 2 s .c o m*/ } root.addAttribute("id", inGroup.getId()); Element groupNameElem = root.addElement("group-name"); groupNameElem.setText(inGroup.getName()); Element permissionsElem = root.addElement("permissions"); for (Iterator iter = inGroup.getPermissions().iterator(); iter.hasNext();) { Object permission = (Object) iter.next(); Element permissionElem = permissionsElem.addElement("permission"); permissionElem.setText(permission.toString()); } MapPropertyContainer map = (MapPropertyContainer) inGroup.getPropertyContainer(); if (map != null) { Element propertiesElem = map.createPropertiesElement("properties"); root.add(propertiesElem); } File file = loadGroupFile(inGroup.getId()); getXmlUtil().saveXml(doc, file); getGroupIdToGroupMap().put(inGroup.getId(), inGroup); }
From source file:com.openedit.users.filesystem.MapPropertyContainer.java
License:Open Source License
protected Element createPropertiesElement(String inElementName) { Element propertiesElem = DocumentFactory.getInstance().createElement(inElementName); for (Iterator iter = getRealProperties().entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); if (entry.getValue() != null) { Element propertyElem = propertiesElem.addElement("property"); propertyElem.addAttribute("name", entry.getKey().toString()); propertyElem.addAttribute("value", entry.getValue().toString()); }//from w w w . j av a2s .c o m } return propertiesElem; }
From source file:com.openedit.users.filesystem.XmlUserArchive.java
License:Open Source License
public void saveUser(User user) throws UserManagerException { if (user.isVirtual()) { log.error("Cannot save virtual users: " + user.getUserName()); return;//from w ww .j a v a 2 s.c om } DocumentFactory factory = DocumentFactory.getInstance(); Document doc = factory.createDocument(); Element userElem = doc.addElement("user"); userElem.addAttribute("enabled", Boolean.toString(user.isEnabled())); if (user.getUserName() == null) { int id = getUserIdCounter().incrementCount(); String newid = String.valueOf(id); user.setId(newid); } Element userNameElem = userElem.addElement("user-name"); userNameElem.addCDATA(user.getUserName()); Element passwordElem = userElem.addElement("password"); // if (user.getPassword() != null && !user.getPassword().equals("")) { String ps = user.getPassword(); ps = encrypt(ps); // password may have changed we should set it so it's not in plain // text anymore. user.setPassword(ps); passwordElem.addCDATA(ps); } Element creationDateElem = userElem.addElement("creation-date"); if (user.getCreationDate() != null) { creationDateElem.setText(String.valueOf(user.getCreationDate().getTime())); } else { creationDateElem.setText(String.valueOf(System.currentTimeMillis())); } // Tuan add property lastLogined-Time Element lastLoginTime = userElem.addElement("lastLogined-Time"); lastLoginTime.setText(DateStorageUtil.getStorageUtil().formatForStorage(new Date())); MapPropertyContainer map = (MapPropertyContainer) user.getPropertyContainer(); if (map != null) { Element propertiesElem = map.createPropertiesElement("properties"); userElem.add(propertiesElem); } if (user.getGroups() != null) { for (Iterator iter = user.getGroups().iterator(); iter.hasNext();) { Group group = (Group) iter.next(); Element child = userElem.addElement("group"); child.addAttribute("id", group.getId()); } } synchronized (user) { // File file = loadUserFile(user.getUserName()); XmlFile xfile = new XmlFile(); xfile.setRoot(doc.getRootElement()); xfile.setPath(getUserDirectory() + "/" + user.getUserName() + ".xml"); getXmlArchive().saveXml(xfile, null); getUserNameToUserMap().put(user.getUserName(), user); } }
From source file:com.openedit.users.filesystem.XmlUserArchive.java
License:Open Source License
public void saveGroup(Group inGroup) throws UserManagerException { Document doc = DocumentFactory.getInstance().createDocument(); Element root = doc.addElement("group"); if (inGroup.getId() == null) { int id = getUserIdCounter().incrementCount(); String inAccount = String.valueOf(id); inGroup.setId(inAccount);// ww w . ja v a 2 s . c o m } root.addAttribute("id", inGroup.getId()); Element groupNameElem = root.addElement("group-name"); groupNameElem.setText(inGroup.getName()); Element permissionsElem = root.addElement("permissions"); for (Iterator iter = inGroup.getPermissions().iterator(); iter.hasNext();) { Object permission = (Object) iter.next(); Element permissionElem = permissionsElem.addElement("permission"); permissionElem.setText(permission.toString()); } MapPropertyContainer map = (MapPropertyContainer) inGroup.getPropertyContainer(); if (map != null) { Element propertiesElem = map.createPropertiesElement("properties"); root.add(propertiesElem); } File file = loadGroupFile(inGroup.getId()); getXmlUtil().saveXml(doc, file); getGroupIdToGroupMap().remove(inGroup.getId()); }
From source file:com.org.dms.action.service.claimmng.WorkDispatchMngAction.java
/** * /*from w w w .j a va 2 s.co m*/ * @param type 2? 1 * @param remark * @param type workId * @return */ public String dispatchResult(String type, Map<String, String> map) { Document domresult = DocumentFactory.getInstance().createDocument(); Element root = domresult.addElement("DBSET"); Element r = root.addElement("R"); Element c01 = r.addElement("C"); c01.addAttribute("N", "BACK_ID");//???ID if (map.get("workId") != null && !"".equals(map.get("workId"))) { c01.addText(map.get("workId")); } Element c02 = r.addElement("C"); c02.addAttribute("N", "JOBORDER_PK");//400? if (map.get("joborderPk") != null && !"".equals(map.get("joborderPk"))) { c02.addText(map.get("joborderPk")); } Element c03 = r.addElement("C"); c03.addAttribute("N", "JOBORDER_CODE");//400?? if (map.get("joborderCoe") != null && !"".equals(map.get("joborderCoe"))) { c03.addText(map.get("joborderCoe")); } Element c04 = r.addElement("C"); c04.addAttribute("N", "BACK_TYPE");//??12 c04.addText(type); Element c05 = r.addElement("C"); c05.addAttribute("N", "BACK_MSG");// if (map.get("remarks") != null && !"".equals(map.get("remarks"))) { c05.addText(map.get("remarks")); } Element c06 = r.addElement("C"); c06.addAttribute("N", "JOBORDER_DNAME");//???(??) if (map.get("orgCode") != null && !"".equals(map.get("orgCode"))) { c06.addText(map.get("orgCode")); } Element c07 = r.addElement("C"); c07.addAttribute("N", "JOBORDER_OUT");//? if (map.get("ifout") != null && !"".equals(map.get("ifout"))) { c07.addText(map.get("ifout")); } Element c08 = r.addElement("C"); c08.addAttribute("N", "REPAIRER_NAME");//?? if (map.get("userName") != null && !"".equals(map.get("userName"))) { c08.addText(map.get("userName")); } Element c09 = r.addElement("C"); c09.addAttribute("N", "REPAIRER_CONTACT");//?? if (map.get("mobils") != null && !"".equals(map.get("mobils"))) { c09.addText(map.get("mobils")); } Element c10 = r.addElement("C"); c10.addAttribute("N", "VEHICLE_FLAG");//VEHICLE_FLAG ??10? if (map.get("ifVehicle") != null && !"".equals(map.get("ifVehicle"))) { c10.addText(map.get("ifVehicle")); } Element c11 = r.addElement("C"); c11.addAttribute("N", "VEHICLE_NUMBER");//? if (map.get("licensePlate") != null && !"".equals(map.get("licensePlate"))) { c11.addText(map.get("licensePlate")); } Element c12 = r.addElement("C"); c12.addAttribute("N", "JOBORDER_DTIME");//(YYYY-MM-DD HH24:MI:SS) if (map.get("dtime") != null && !"".equals(map.get("dtime"))) { c12.addText(Pub.getCurrentDate().toLocaleString()); } else { c12.addText(Pub.getCurrentDate().toLocaleString()); } Element c13 = r.addElement("C"); c13.addAttribute("N", "REMARK");// if (map.get("remarks") != null && !"".equals(map.get("remarks"))) { c13.addText(map.get("remarks")); } return domresult.getRootElement().asXML(); }