List of usage examples for org.dom4j DocumentFactory getInstance
public static synchronized DocumentFactory getInstance()
From source file:de.innovationgate.wga.common.WGAXML.java
License:Apache License
/** * set the given information on the given domainElement * @param domainElement/*w w w . j a v a 2s.c om*/ * @param domainName * @param loginMode valid values - (WGAXML.DOMAIN_LOGINMODE_USERLOGINS, WGAXML.DOMAIN_LOGINMODE_MASTERLOGIN) * @param masterLoginUsername * @param masterLoginPassword * @return the updated domainElement */ public static Element setBasicDomainInformation(Element domainElement, String domainName, String loginMode, String masterLoginUsername, String masterLoginPassword) { domainElement.addAttribute("name", domainName); Element login = (Element) domainElement.selectSingleNode("login"); if (login == null) { login = (Element) DocumentFactory.getInstance().createElement("login"); domainElement.add(login); } login.addAttribute("mode", loginMode); login.addAttribute("username", masterLoginUsername); login.addAttribute("password", Base64.encode(masterLoginPassword.getBytes())); return domainElement; }
From source file:de.innovationgate.wga.common.WGAXML.java
License:Apache License
/** * add a default database element to the given parentElement (<contentdbs>) * @param parent/*from w ww . j a va 2 s. c om*/ * @param implClass * @return the created contentdb-element */ public static Element addContentDB(Element parent, String implClass) { DocumentFactory factory = DocumentFactory.getInstance(); Element database = factory.createElement("contentdb"); database.addAttribute("enabled", "true"); database.addAttribute("lazyconnect", "false"); Element elem = factory.createElement("type"); database.add(elem); elem.add(factory.createText(implClass)); elem = factory.createElement("dbkey"); database.add(elem); elem.add(factory.createText("(Enter database key here)")); elem = factory.createElement("dbpath"); database.add(elem); elem.add(factory.createText("(Enter database path here)")); elem = factory.createElement("title"); database.add(elem); elem = factory.createElement("domain"); database.add(elem); elem.add(factory.createText("default")); elem = factory.createElement("design"); database.add(elem); elem.addAttribute("provider", "none"); elem.addAttribute("mode", ""); elem.addAttribute("key", ""); elem = factory.createElement("dboptions"); database.add(elem); createDefaultDbOptions(elem); elem = factory.createElement("publisheroptions"); database.add(elem); createDefaultPublisherOptions(elem); database.add(factory.createElement("storedqueries")); database.add(factory.createElement("fieldmappings")); Element cache = database.addElement("cache"); cache.addAttribute("path", ""); cache.addAttribute("type", "de.innovationgate.wgpublisher.cache.WGACacheHSQLDB"); cache.addAttribute("maxpages", "3000"); //lucene config per db Element luceneDBConfig = factory.createElement("lucene"); luceneDBConfig.addAttribute("enabled", "false"); luceneDBConfig.addElement("itemrules"); LuceneIndexItemRule.addDefaultRule(luceneDBConfig); luceneDBConfig.addElement("filerules"); LuceneIndexFileRule.addDefaultRule(luceneDBConfig); database.add(luceneDBConfig); // Client restrictions Element clientrestrictions = database.addElement("clientrestrictions"); clientrestrictions.addAttribute("enabled", "false"); clientrestrictions.addElement("restrictions"); parent.add(database); return database; }
From source file:de.innovationgate.wga.common.WGAXML.java
License:Apache License
/** * add a default persDbElement to the given parentElement (<personalisationdbs>) * @param parent// w ww . j a v a2 s . c om * @param implClass * @return the created persDbElement */ public static Element addPersDB(Element parent, String implClass) { DocumentFactory factory = DocumentFactory.getInstance(); Element database = factory.createElement("personalisationdb"); database.addAttribute("enabled", "true"); database.addAttribute("lazyconnect", "false"); Element elem = factory.createElement("type"); database.add(elem); elem.add(factory.createText(implClass)); elem = factory.createElement("dbpath"); database.add(elem); elem.add(factory.createText("(Enter database path here)")); elem = factory.createElement("domain"); database.add(elem); elem.add(factory.createText("default")); elem = factory.createElement("persconfig"); database.add(elem); elem.addAttribute("mode", "auto"); elem = factory.createElement("dboptions"); database.add(elem); createDefaultDbOptions(elem); elem = factory.createElement("publisheroptions"); database.add(elem); createDefaultPublisherOptions(elem); database.add(factory.createElement("userclasses")); parent.add(database); return database; }
From source file:de.innovationgate.wga.common.WGAXML.java
License:Apache License
/** * set the given information on the given persDbElement * @param persDbElement/*from ww w . jav a 2 s .co m*/ * @param enabled * @param lazyConnect * @param dbImplClass * @param dbPath * @param mode - valid values (WGAXML.PERS_MODE_AUTO, WGAXML.PERS_MODE_LOGIN, WGAXML.PERS_MODE_CUSTOM) * @param statistics - valid values (WGAXML.PERS_STATISTICS_OFF, WGAXML.PERS_STATISTICS_SESSION, WGAXML.PERS_STATISTICS_HIT) * @param defaultLogin * @param username * @param password * @param domain * @return the updated persDbElement */ public static Element setBasicPersDBInformation(Element persDbElement, boolean enabled, boolean lazyConnect, String dbImplClass, String dbPath, String mode, String statistics, boolean defaultLogin, String username, String password, String domain) { persDbElement.addAttribute("enabled", String.valueOf(enabled)); persDbElement.addAttribute("lazyconnect", String.valueOf(lazyConnect)); persDbElement.selectSingleNode("type").setText(dbImplClass); persDbElement.selectSingleNode("dbpath").setText(dbPath); Element persconfig = (Element) persDbElement.selectSingleNode("persconfig"); persconfig.addAttribute("mode", mode); persconfig.addAttribute("statistics", statistics); Element login = (Element) persDbElement.selectSingleNode("login"); if (login == null) { login = (Element) DocumentFactory.getInstance().createElement("login"); persDbElement.add(login); } if (defaultLogin) { login.addAttribute("password", ""); login.addAttribute("username", ""); } else { login.addAttribute("password", Base64.encode(password.getBytes())); login.addAttribute("username", username); } login.addAttribute("encoding", "base64"); persDbElement.selectSingleNode("domain").setText(domain); return persDbElement; }
From source file:de.innovationgate.wgpublisher.WebTMLDebugger.java
License:Open Source License
private void showTMLTags(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws HttpErrorException, IOException { String urlStr = request.getParameter("url"); String indexStr = request.getParameter("index"); if (urlStr != null) { urlStr = _dispatcher.getCore().getURLEncoder().decode(urlStr); List<Document> debugDocuments = WGACore.getDebugDocumentsList(session); Document debugDoc;/*from w w w .j a v a2 s . com*/ for (int idx = 0; idx < debugDocuments.size(); idx++) { debugDoc = (Document) debugDocuments.get(idx); if (debugDoc.getRootElement().attributeValue("url", "").equals(urlStr)) { indexStr = String.valueOf(idx); break; } } } response.setContentType("text/html"); if (indexStr != null) { int index = Integer.valueOf(indexStr).intValue(); List<Document> debugDocuments = WGACore.getDebugDocumentsList(session); if (index == -1) { index = debugDocuments.size() - 1; } if (index >= debugDocuments.size()) { throw new HttpErrorException(HttpServletResponse.SC_BAD_REQUEST, "Index out of range: " + index + " where maximum index is " + (debugDocuments.size() - 1), null); } else { Document doc = (Document) debugDocuments.get(index); Element element = (Element) doc.selectSingleNode(request.getParameter("root")); doc = DocumentFactory.getInstance().createDocument(element.createCopy()); doc.getRootElement().addAttribute("index", String.valueOf(index)); try { DOMWriter domWriter = new DOMWriter(); org.w3c.dom.Document domDocument = domWriter.write(doc); Transformer trans = getDebugTagsTransformer(request.getParameter("throwAway") != null); trans.transform(new DOMSource(domDocument), new StreamResult(response.getOutputStream())); } catch (TransformerConfigurationException e) { response.sendError(500, e.getMessageAndLocation()); e.printStackTrace(); } catch (TransformerFactoryConfigurationError e) { response.sendError(500, e.getMessage()); e.printStackTrace(); } catch (TransformerException e) { response.sendError(500, e.getMessageAndLocation()); e.printStackTrace(); } catch (IOException e) { response.sendError(500, e.getMessage()); e.printStackTrace(); } catch (DocumentException e) { response.sendError(500, e.getMessage()); e.printStackTrace(); } } } else { throw new HttpErrorException(HttpServletResponse.SC_BAD_REQUEST, "You must include either parameter index or url to address the debug document to show", null); } }
From source file:de.xwic.sandbox.server.installer.XmlExport.java
License:Apache License
/** * @param secDump/*from ww w . ja v a2s .co m*/ */ public void exportSecurity(File secDump) throws IOException, ConfigurationException { Document doc = DocumentFactory.getInstance().createDocument(); Element root = doc.addElement(ELM_EXPORT); root.addAttribute("type", "security"); Element info = root.addElement(ELM_EXPORTDDATE); info.setText(DateFormat.getDateTimeInstance().format(new Date())); Element data = root.addElement(ELM_DATA); addAll(IActionDAO.class, data); addAll(IActionSetDAO.class, data); addAll(IScopeDAO.class, data); addAll(IRoleDAO.class, data); addAll(IRightDAO.class, data); addAll(IUserDAO.class, data); OutputFormat prettyFormat = OutputFormat.createPrettyPrint(); OutputStream out = new FileOutputStream(secDump); XMLWriter writer = new XMLWriter(out, prettyFormat); writer.write(doc); writer.flush(); out.close(); }
From source file:de.xwic.sandbox.server.installer.XmlExport.java
License:Apache License
/** * @param plDump/*ww w . ja va 2s . co m*/ */ public void exportPicklists(File plDump) throws IOException, ConfigurationException { Document doc = DocumentFactory.getInstance().createDocument(); Element root = doc.addElement(ELM_EXPORT); root.addAttribute("type", "picklists"); Element info = root.addElement(ELM_EXPORTDDATE); info.setText(DateFormat.getDateTimeInstance().format(new Date())); Element data = root.addElement(ELM_DATA); addPicklisten(data); OutputFormat prettyFormat = OutputFormat.createPrettyPrint(); OutputStream out = new FileOutputStream(plDump); XMLWriter writer = new XMLWriter(out, prettyFormat); writer.write(doc); writer.flush(); out.close(); }
From source file:dk.nsi.stamdata.replication.tools.SchemaGenerator.java
License:Mozilla Public License
public static void generate(Class<? extends View> entity, Writer writer) throws IOException { Document doc = DocumentFactory.getInstance().createDocument(); String targetNamespace = entity.getPackage().getAnnotation(XmlSchema.class).namespace(); String entityName = entity.getSimpleName().toLowerCase(); Element all = generate(doc, targetNamespace, entityName); for (Field method : entity.getDeclaredFields()) { if (method.isAnnotationPresent(XmlTransient.class)) continue; String name = method.getName(); String type = convert2SchemaType(method); addElement(all, name, type, null); }/*from w w w . ja va 2s. com*/ XMLWriter xmlWriter = new XMLWriter(writer, OutputFormat.createPrettyPrint()); xmlWriter.write(doc); }
From source file:dk.nsi.stamdata.replication.tools.SchemaGenerator.java
License:Mozilla Public License
public static void generate(RecordSpecification specification, Writer writer, String register) throws IOException { Document doc = DocumentFactory.getInstance().createDocument(); // FIXME: Register added to record spec. String namespace = Namespace.STAMDATA_3_0 + "/" + register; String entityName = specification.getTable().toLowerCase(); Element all = generate(doc, namespace, entityName); for (RecordSpecification.FieldSpecification field : specification.getFieldSpecs()) { addElement(all, field.name, convert2XsdType(field.type), field.length); }/*from w w w. ja v a 2 s . c om*/ all.addElement("xs:element").addAttribute("name", "validFrom").addAttribute("type", "xs:dateTime"); all.addElement("xs:element").addAttribute("name", "validTo").addAttribute("type", "xs:dateTime"); XMLWriter xmlWriter = new XMLWriter(writer, OutputFormat.createPrettyPrint()); xmlWriter.write(doc); }
From source file:edu.umd.cs.findbugs.ml.GenerateUIDs.java
License:Open Source License
@SuppressWarnings("unchecked") public void execute() throws IOException, DocumentException { InputStream in = null;//from w w w . j a va 2 s .c o m try { if (inputFilename.equals("-")) { in = System.in; } else { in = new BufferedInputStream(new FileInputStream(inputFilename)); if (inputFilename.endsWith(".gz")) in = new GZIPInputStream(in); } bugCollection.readXML(in); in = null; } finally { if (in != null) in.close(); } Document document = DocumentFactory.getInstance().createDocument(); Dom4JXMLOutput xmlOutput = new Dom4JXMLOutput(document); bugCollection.writeXML(xmlOutput); int count = 0; List<Element> bugInstanceList = document.selectNodes("/BugCollection/BugInstance"); for (Element element : bugInstanceList) { Attribute uidAttr = element.attribute("uid"); if (uidAttr == null) { element.addAttribute("uid", Integer.toString(count++)); } } OutputStream out; if (outputFilename.equals("-")) { out = System.out; } else { out = new BufferedOutputStream(new FileOutputStream(outputFilename)); } XMLWriter xmlWriter = new XMLWriter(out, OutputFormat.createPrettyPrint()); try { xmlWriter.write(document); } finally { xmlWriter.close(); } }