List of usage examples for org.dom4j DocumentHelper createDocument
public static Document createDocument()
From source file:org.cipango.littleims.scscf.charging.CDF.java
License:Apache License
public void event(SipServletRequest event, int role) { log.debug("Generate Event CDR"); Document document = DocumentHelper.createDocument(); Element root = document.addElement("ims-cdr"); root.addElement("sip-method").setText(event.getMethod()); root.addElement("role-of-node").setText(String.valueOf(role)); root.addElement("session-id").setText(event.getCallId()); root.addElement("calling-party-address").setText(event.getFrom().getURI().toString()); root.addElement("called-party-address").setText(event.getTo().getURI().toString()); try {/*from w w w.j a va 2s. c o m*/ File cdr = new File(_chargingDirectory, idGenerator.newRandomID() + ".xml"); FileOutputStream cdrOut = new FileOutputStream(cdr); synchronized (xmlWriter) { xmlWriter.setOutputStream(cdrOut); xmlWriter.write(document); xmlWriter.flush(); } cdrOut.close(); } catch (IOException e) { log.error("Error while writing CDR", e); } }
From source file:org.codehaus.aspectwerkz.metadata.AttributeC.java
License:Open Source License
/** * Creates a DOM documents out of the definition. * * @param definition the AspectWerkz definition * @param uuid the UUID for the definition * @return the DOM document//from w w w .j av a2 s . c om */ public static Document createDocument(final AspectWerkzDefinitionImpl definition, final String uuid) { if (definition == null) throw new IllegalArgumentException("definition can not be null"); Document document = DocumentHelper.createDocument(); document.addDocType("aspectwerkz", "-//AspectWerkz//DTD//EN", "http://aspectwerkz.codehaus.org/dtd/aspectwerkz.dtd"); Element root = document.addElement("aspectwerkz"); Element system = root.addElement("system"); system.addAttribute("id", uuid); handleIntroductionDefinitions(system, definition); handleAdviceDefinitions(system, definition); handleAspectDefinitions(system, definition); return document; }
From source file:org.codehaus.cargo.container.jrun.internal.JRun4xConfigurationBuilder.java
License:Apache License
/** * @return a datasource xml fragment that can be embedded directly into the jrun-resources.xml * file//from w ww . j a va 2 s . co m * @param ds the DataSource we are configuring. * @param className the implementation class used for this DataSource */ protected String configureDataSourceWithImplementationClass(DataSource ds, String className) { Element datasourceElement = DocumentHelper.createDocument().addElement("data-source"); // settings from the DataSource instance. datasourceElement.addElement("dbname").setText(ds.getId()); datasourceElement.addElement("jndi-name").setText(ds.getJndiLocation()); datasourceElement.addElement("driver").setText(ds.getDriverClass()); datasourceElement.addElement("url").setText(ds.getUrl()); datasourceElement.addElement("username").setText(ds.getUsername()); datasourceElement.addElement("password").setText(ds.getPassword()); // some default settings not available from DataSource instance datasourceElement.addElement("isolation-level").setText("READ_UNCOMMITTED"); datasourceElement.addElement("native-results").setText("true"); datasourceElement.addElement("pool-statements").setText("true"); datasourceElement.addElement("pool-name").setText("pool"); datasourceElement.addElement("initial-connections").setText("1"); datasourceElement.addElement("minimum-size").setText("1"); datasourceElement.addElement("maximum-size").setText("70"); datasourceElement.addElement("connection-timeout").setText("60"); datasourceElement.addElement("user-timeout").setText("120"); datasourceElement.addElement("skimmer-frequency").setText("1800"); datasourceElement.addElement("shrink-by").setText("10"); datasourceElement.addElement("debugging").setText("true"); datasourceElement.addElement("transaction-timeout").setText("10"); datasourceElement.addElement("cache-enabled").setText("false"); datasourceElement.addElement("cache-size").setText("10"); datasourceElement.addElement("remove-on-exceptions").setText("false"); return datasourceElement.asXML(); }
From source file:org.codehaus.cargo.container.jrun.JRun4xFilterChain.java
License:Apache License
/** * @return an Ant filter token containing all the user-defined users *///ww w .j a va 2s .c o m protected ReplaceTokens.Token createUserToken() { StringBuilder token = new StringBuilder(); // Add token filters for authenticated users if (getPropertyValue(ServletPropertySet.USERS) != null) { for (User user : User.parseUsers(getPropertyValue(ServletPropertySet.USERS))) { // create user elements Element userElement = DocumentHelper.createDocument().addElement("user"); userElement.addElement("user-name").setText(user.getName()); userElement.addElement("password").setText(user.getPassword()); token.append(userElement.asXML()); // add role elements for (String role : user.getRoles()) { Element roleElement = DocumentHelper.createDocument().addElement("role"); roleElement.addElement("role-name").setText(role); roleElement.addElement("user-name").setText(user.getName()); token.append(roleElement.asXML()); } } } ReplaceTokens.Token tokenUsers = new ReplaceTokens.Token(); tokenUsers.setKey("jrun.users"); tokenUsers.setValue(token.toString()); return tokenUsers; }
From source file:org.codehaus.cargo.container.weblogic.internal.WebLogic8xConfigurationBuilder.java
License:Apache License
/** * @return a datasource xml fragment that can be embedded directly into the config.xml file * @param ds the DataSource we are configuring. * @param className the implementation class used for this DataSource *///from w w w . ja va 2 s .com protected String configureDataSourceWithImplementationClass(DataSource ds, String className) { Element connectionPool = DocumentHelper.createDocument().addElement("JDBCConnectionPool"); connectionPool.addAttribute("Name", ds.getJndiLocation()); connectionPool.addAttribute("Targets", getServerName()); if (ds.getUrl() != null) { connectionPool.addAttribute("URL", ds.getUrl()); } connectionPool.addAttribute("DriverName", className); connectionPool.addAttribute("Password", ds.getPassword()); // there is no native property for user in WebLogic JDBCConnectionPool ds.getConnectionProperties().setProperty("user", ds.getUsername()); connectionPool.addAttribute("Properties", new DataSourceConverter().getConnectionPropertiesAsASemicolonDelimitedString(ds)); Element dataSource = null; if (ds.getTransactionSupport().equals(TransactionSupport.NO_TRANSACTION)) { dataSource = DocumentHelper.createDocument().addElement("JDBCDataSource"); } else { dataSource = DocumentHelper.createDocument().addElement("JDBCTxDataSource"); } if (ds.getTransactionSupport().equals(TransactionSupport.XA_TRANSACTION) && ds.getDriverClass() != null) { dataSource.addAttribute("EnableTwoPhaseCommit", "true"); } dataSource.addAttribute("Name", ds.getJndiLocation()); dataSource.addAttribute("PoolName", ds.getJndiLocation()); dataSource.addAttribute("JNDIName", ds.getJndiLocation()); dataSource.addAttribute("Targets", getServerName()); StringBuilder out = new StringBuilder(); out.append(connectionPool.asXML()); out.append("\n"); out.append(dataSource.asXML()); return out.toString(); }
From source file:org.codehaus.cargo.container.weblogic.internal.WebLogic9x10x103x12xConfigurationBuilder.java
License:Apache License
/** * {@inheritDoc}//from www . ja va2s.c om * * In WebLogic 9.x DataSource definitions are located in separate files linked to config.xml. * This method creates the definition of the datasource. This file must be linked to the * config.xml to become useful. */ @Override protected String configureDataSourceWithImplementationClass(DataSource ds, String className) { Element nameElement = DocumentHelper.createDocument().addElement("name"); nameElement.setText(ds.getId()); Element driverElement = DocumentHelper.createDocument().addElement("jdbc-driver-params"); if (ds.getUrl() != null) { driverElement.addElement("url").setText(ds.getUrl()); } driverElement.addElement("driver-name").setText(className); Element properties = driverElement.addElement("properties"); ds.getConnectionProperties().setProperty("user", ds.getUsername()); Iterator<Object> driverProperties = ds.getConnectionProperties().keySet().iterator(); while (driverProperties.hasNext()) { String name = driverProperties.next().toString(); String value = ds.getConnectionProperties().getProperty(name); Element property = properties.addElement("property"); property.addElement("name").setText(name); property.addElement("value").setText(value); } Element dataSourceElement = DocumentHelper.createDocument().addElement("jdbc-data-source-params"); dataSourceElement.addElement("jndi-name").setText(ds.getJndiLocation()); if (ds.getConnectionType().equals(ConfigurationEntryType.XA_DATASOURCE)) { dataSourceElement.addElement("global-transactions-protocol").setText("TwoPhaseCommit"); } else if (ds.getTransactionSupport().equals(TransactionSupport.XA_TRANSACTION)) { dataSourceElement.addElement("global-transactions-protocol").setText("EmulateTwoPhaseCommit"); } else { dataSourceElement.addElement("global-transactions-protocol").setText("None"); } if (ds.getPassword() != null) { driverElement.addElement("password-encrypted").setText(ds.getPassword()); } StringBuilder out = new StringBuilder(); out.append(nameElement.asXML()); out.append("\n"); out.append(driverElement.asXML()); out.append("\n"); out.append(dataSourceElement.asXML()); return out.toString(); }
From source file:org.codehaus.cargo.container.weblogic.internal.WebLogic9x10xAnd103xConfigurationBuilder.java
License:Apache License
/** * {@inheritDoc}/*from w w w . j av a 2s . c o m*/ * * In WebLogic 9.x DataSource definitions are located in separate files linked to config.xml. * This method creates the definition of the datasource. This file must be linked to the * config.xml to become useful. */ protected String configureDataSourceWithImplementationClass(DataSource ds, String className) { Element nameElement = DocumentHelper.createDocument().addElement("name"); nameElement.setText(ds.getId()); Element driverElement = DocumentHelper.createDocument().addElement("jdbc-driver-params"); if (ds.getUrl() != null) { driverElement.addElement("url").setText(ds.getUrl()); } driverElement.addElement("driver-name").setText(className); Element properties = driverElement.addElement("properties"); ds.getConnectionProperties().setProperty("user", ds.getUsername()); Iterator driverProperties = ds.getConnectionProperties().keySet().iterator(); while (driverProperties.hasNext()) { String name = driverProperties.next().toString(); String value = ds.getConnectionProperties().getProperty(name); Element property = properties.addElement("property"); property.addElement("name").setText(name); property.addElement("value").setText(value); } Element dataSourceElement = DocumentHelper.createDocument().addElement("jdbc-data-source-params"); dataSourceElement.addElement("jndi-name").setText(ds.getJndiLocation()); if (ds.getConnectionType().equals(ConfigurationEntryType.XA_DATASOURCE)) { dataSourceElement.addElement("global-transactions-protocol").setText("TwoPhaseCommit"); } else if (ds.getTransactionSupport().equals(TransactionSupport.XA_TRANSACTION)) { dataSourceElement.addElement("global-transactions-protocol").setText("EmulateTwoPhaseCommit"); } else { dataSourceElement.addElement("global-transactions-protocol").setText("None"); } if (ds.getPassword() != null) { driverElement.addElement("password-encrypted").setText(ds.getPassword()); } StringBuffer out = new StringBuffer(); out.append(nameElement.asXML()); out.append("\n"); out.append(driverElement.asXML()); out.append("\n"); out.append(dataSourceElement.asXML()); return out.toString(); }
From source file:org.codehaus.cargo.container.weblogic.WebLogic9xStandaloneLocalConfiguration.java
License:Apache License
/** * Create a blank datasource file with correct namespace. * /* w w w. jav a 2 s. c om*/ * @param path where to create the base file. */ protected void createBlankDataSourceFile(String path) { Document document = DocumentHelper.createDocument(); Element dataSource = document.addElement("jdbc-data-source"); document.setRootElement(dataSource); dataSource.addNamespace("", "http://www.bea.com/ns/weblogic/90"); xmlTool.saveXml(document, path); }
From source file:org.codehaus.modello.plugin.jaxrs.JaxRSMappingModelloGenerator.java
License:Apache License
private void generateJaxRS(File webXml, Model model) throws IOException, ModelloException { OutputStreamWriter fileWriter = new OutputStreamWriter(new FileOutputStream(webXml), "UTF-8"); org.dom4j.io.XMLWriter writer = null; namespace = DocumentHelper.createNamespace("", "http://java.sun.com/xml/ns/j2ee"); Document document = DocumentHelper.createDocument(); Element root = document.addElement("web-app"); root.addNamespace("", "http://java.sun.com/xml/ns/j2ee"); root.addAttribute("version", "2.4"); root.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.addAttribute("xsi:schemaLocation", "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"); Element displayName = addElement(root, "display-name", model.getName()); // add the declaration for the Jersey servlet Element servlet = addElement(root, "servlet"); addElement(servlet, "servlet-name", JERSEY_SERVLET_NAME); addElement(servlet, "servlet-class", "com.sun.jersey.spi.container.servlet.ServletContainer"); Element pkgsParam = addElement(servlet, "init-param"); addElement(pkgsParam, "param-name", "com.sun.jersey.config.property.packages"); addElement(servlet, "load-on-startup", "1"); Set<String> pkgs = new HashSet<String>(); // Processed classes to be mapped here for (Iterator it = model.getClasses(getGeneratedVersion()).iterator(); it.hasNext();) { ModelClass modelClass = (ModelClass) it.next(); JaxRSClassLevelMetadata metadata = (JaxRSClassLevelMetadata) modelClass .getMetadata(JaxRSClassLevelMetadata.ID); // only generate servlet-mappings for classes which have a jaxrs.urls parameter if (!isEmpty(metadata.getUrls())) { String packageName = modelClass.getPackageName(isPackageWithVersion(), getGeneratedVersion()); if (!pkgs.contains(packageName)) { pkgs.add(packageName);/*w w w .j a v a 2 s .co m*/ } String[] urls = metadata.getUrls().split(","); for (String url : urls) { Element mapping = addElement(root, "servlet-mapping"); addElement(mapping, "servlet-name", JERSEY_SERVLET_NAME); addElement(mapping, "url-pattern", url); } } } String pkgsString = ""; for (String s : pkgs) { if (!"".equals(pkgsString)) pkgsString += ","; pkgsString += s; } addElement(pkgsParam, "param-value", pkgsString); OutputFormat format = OutputFormat.createPrettyPrint(); writer = new XMLWriter(fileWriter, format); writer.write(document); writer.close(); }
From source file:org.codehaus.modello.plugin.jpa.JpaOrmMappingModelloGenerator.java
License:Apache License
private void generateOrm(File orm, Model model) throws IOException, ModelloException { OutputStreamWriter fileWriter = new OutputStreamWriter(new FileOutputStream(orm), "UTF-8"); org.dom4j.io.XMLWriter writer = null; JpaModelMetadata modelMetadata = (JpaModelMetadata) model.getMetadata(JpaModelMetadata.ID); String jpaVersion = modelMetadata.getVersion(); String jpaUnit = modelMetadata.getUnit(); Document document = DocumentHelper.createDocument(); Element root = null;//from www .j a v a 2 s . c om if (JpaMetadataPlugin.JPA_VERSION_1.equals(jpaVersion) || (jpaVersion == null)) { namespace = DocumentHelper.createNamespace("", "http://java.sun.com/xml/ns/persistence/orm"); root = document.addElement("entity-mappings"); root.addNamespace("", "http://java.sun.com/xml/ns/persistence/orm"); root.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.addAttribute("xsi:schemaLocation", "http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"); root.addAttribute("version", "1.0"); } else if (JpaMetadataPlugin.JPA_VERSION_2.equals(jpaVersion)) { namespace = DocumentHelper.createNamespace("", "http://java.sun.com/xml/ns/persistence"); root = document.addElement("persistence"); root.addNamespace("", "http://java.sun.com/xml/ns/persistence"); root.addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.addAttribute("version", "2.0"); root.addAttribute("xsi:schemaLocation", "http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"); Element persistenceUnit = addElement(root, "persistence-unit"); persistenceUnit.addAttribute("name", jpaUnit); addElement(persistenceUnit, "provider", "org.apache.openjpa.persistence.PersistenceProviderImpl"); } // Processed classes to be mapped here for (Iterator it = model.getClasses(getGeneratedVersion()).iterator(); it.hasNext();) { ModelClass modelClass = (ModelClass) it.next(); String packageName = modelClass.getPackageName(isPackageWithVersion(), getGeneratedVersion()); JpaClassLevelMetadata metadata = (JpaClassLevelMetadata) modelClass .getMetadata(JpaClassLevelMetadata.ID); List processorMetadataList = metadata.getProcessorMetadata(); for (Iterator it2 = processorMetadataList.iterator(); it2.hasNext();) { ProcessorMetadata procMetadata = (ProcessorMetadata) it2.next(); try { ((ClassMetadataProcessorMetadata) procMetadata).setModelClass(modelClass); ((ClassMetadataProcessorMetadata) procMetadata).setPackageName(modelClass.getPackageName()); MetadataProcessor metadataProcessor = processorFactory.createMetadataProcessor(procMetadata); // set up Processor Context. MetadataProcessorContext processorContext = new MetadataProcessorContext(); processorContext.setDocument(document); processorContext.setModel(model); boolean valid = metadataProcessor.validate(processorContext, procMetadata); if (valid) metadataProcessor.process(processorContext, procMetadata); else throw new ModelloException( "Processor Metadata validate failed for '" + procMetadata.getKey() + "' in class " + modelClass.getPackageName() + '.' + modelClass.getName()); } catch (MetadataProcessorInstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MetadataProcessorException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } if (JpaMetadataPlugin.JPA_VERSION_2.equals(jpaVersion)) { Element persistenceUnit = root.element("persistence-unit"); addElement(persistenceUnit, "validation-mode", "NONE"); File propsFile = new File("src/main/resources/" + jpaUnit + ".properties"); if (propsFile.exists()) { Element properties = addElement(persistenceUnit, "properties"); Properties persistenceProviderProps = new Properties(); persistenceProviderProps.load(new FileInputStream(propsFile)); Iterator it = persistenceProviderProps.keySet().iterator(); while (it.hasNext()) { String k = it.next().toString(); String v = persistenceProviderProps.getProperty(k); Element property = addElement(properties, "property"); property.addAttribute("name", k); property.addAttribute("value", v); } } } OutputFormat format = OutputFormat.createPrettyPrint(); writer = new XMLWriter(fileWriter, format); writer.write(document); writer.close(); }