Example usage for org.dom4j Document getRootElement

List of usage examples for org.dom4j Document getRootElement

Introduction

In this page you can find the example usage for org.dom4j Document getRootElement.

Prototype

Element getRootElement();

Source Link

Document

Returns the root Element for this document.

Usage

From source file:com.liferay.portal.tools.EJBXMLBuilder.java

License:Open Source License

private void _buildBorlandXML() throws Exception {
    StringBuffer sb = new StringBuffer();

    sb.append("<?xml version=\"1.0\"?>\n");
    sb.append(/*from w ww . j  a  v a 2s  . co m*/
            "<!DOCTYPE ejb-jar PUBLIC \"-//Borland Software Corporation//DTD Enterprise JavaBeans 2.0//EN\" \"http://www.borland.com/devsupport/appserver/dtds/ejb-jar_2_0-borland.dtd\">\n");

    sb.append("\n<ejb-jar>\n");
    sb.append("\t<enterprise-beans>\n");

    SAXReader reader = new SAXReader();
    reader.setEntityResolver(new EntityResolver());

    Document doc = reader.read(new File("classes/META-INF/ejb-jar.xml"));

    Iterator itr = doc.getRootElement().element("enterprise-beans").elements("session").iterator();

    while (itr.hasNext()) {
        Element entity = (Element) itr.next();

        sb.append("\t\t<session>\n");
        sb.append("\t\t\t<ejb-name>").append(entity.elementText("ejb-name")).append("</ejb-name>\n");

        if (entity.elementText("display-name").endsWith("LocalManagerEJB")) {
            sb.append("\t\t\t<bean-local-home-name>ejb/liferay/").append(entity.elementText("display-name"))
                    .append("Home</bean-local-home-name>\n");
        } else {
            sb.append("\t\t\t<bean-home-name>").append(entity.elementText("ejb-name"))
                    .append("</bean-home-name>\n");
        }

        sb.append("\t\t</session>\n");
    }

    sb.append("\t</enterprise-beans>\n");
    sb.append("\t<property>\n");
    sb.append("\t\t<prop-name>ejb.default_transaction_attribute</prop-name>\n");
    sb.append("\t\t<prop-type>String</prop-type>\n");
    sb.append("\t\t<prop-value>Supports</prop-value>\n");
    sb.append("\t</property>\n");
    sb.append("</ejb-jar>");

    File outputFile = new File("classes/META-INF/ejb-borland.xml");

    if (!outputFile.exists() || !FileUtil.read(outputFile).equals(sb.toString())) {

        FileUtil.write(outputFile, sb.toString());

        Logger.info(this, outputFile.toString());
    }
}

From source file:com.liferay.portal.tools.EJBXMLBuilder.java

License:Open Source License

private void _buildJOnASXML() throws Exception {
    StringBuffer sb = new StringBuffer();

    sb.append("<?xml version=\"1.0\"?>\n");
    sb.append(//ww  w  .j av a  2 s  .c  o m
            "<!DOCTYPE jonas-ejb-jar PUBLIC \"-//ObjectWeb//DTD JOnAS 3.2//EN\" \"http://www.objectweb.org/jonas/dtds/jonas-ejb-jar_3_2.dtd\">\n");

    sb.append("\n<jonas-ejb-jar>\n");

    SAXReader reader = new SAXReader();
    reader.setEntityResolver(new EntityResolver());

    Document doc = reader.read(new File("classes/META-INF/ejb-jar.xml"));

    Iterator itr = doc.getRootElement().element("enterprise-beans").elements("session").iterator();

    while (itr.hasNext()) {
        Element entity = (Element) itr.next();

        sb.append("\t<jonas-session>\n");
        sb.append("\t\t<ejb-name>").append(entity.elementText("ejb-name")).append("</ejb-name>\n");

        if (entity.elementText("display-name").endsWith("LocalManagerEJB")) {
            sb.append("\t\t<jndi-name>ejb/liferay/").append(entity.elementText("display-name"))
                    .append("Home</jndi-name>\n");
        } else {
            sb.append("\t\t<jndi-name>").append(entity.elementText("ejb-name")).append("</jndi-name>\n");
        }

        sb.append("\t</jonas-session>\n");
    }

    sb.append("</jonas-ejb-jar>");

    File outputFile = new File("classes/META-INF/jonas-ejb-jar.xml");

    if (!outputFile.exists() || !FileUtil.read(outputFile).equals(sb.toString())) {

        FileUtil.write(outputFile, sb.toString());

        Logger.info(this, outputFile.toString());
    }
}

From source file:com.liferay.portal.tools.EJBXMLBuilder.java

License:Open Source License

private void _buildJRunXML() throws Exception {
    StringBuffer sb = new StringBuffer();

    sb.append("<?xml version=\"1.0\"?>\n");
    sb.append(/*from w ww  .  j av  a 2 s.  c o m*/
            "<!DOCTYPE jrun-ejb-jar PUBLIC \"-//Macromedia, Inc.//DTD jrun-ejb-jar 4.0//EN\" \"http://jrun.macromedia.com/dtds/jrun-ejb-jar.dtd\">\n");

    sb.append("\n<jrun-ejb-jar>\n");
    sb.append("\t<enterprise-beans>\n");

    SAXReader reader = new SAXReader();
    reader.setEntityResolver(new EntityResolver());

    Document doc = reader.read(new File("classes/META-INF/ejb-jar.xml"));

    Iterator itr = doc.getRootElement().element("enterprise-beans").elements("session").iterator();

    while (itr.hasNext()) {
        Element entity = (Element) itr.next();

        sb.append("\t\t<session>\n");
        sb.append("\t\t\t<ejb-name>").append(entity.elementText("ejb-name")).append("</ejb-name>\n");

        if (entity.elementText("display-name").endsWith("LocalManagerEJB")) {
            sb.append("\t\t\t<local-jndi-name>ejb/liferay/").append(entity.elementText("display-name"))
                    .append("Home</local-jndi-name>\n");
        } else {
            sb.append("\t\t\t<jndi-name>").append(entity.elementText("ejb-name")).append("</jndi-name>\n");
        }

        sb.append("\t\t\t<cluster-home>false</cluster-home>\n");
        sb.append("\t\t\t<cluster-object>false</cluster-object>\n");
        sb.append("\t\t\t<timeout>3000</timeout>\n");
        sb.append("\t\t</session>\n");
    }

    sb.append("\t</enterprise-beans>\n");
    sb.append("</jrun-ejb-jar>");

    File outputFile = new File("classes/META-INF/jrun-ejb-jar.xml");

    if (!outputFile.exists() || !FileUtil.read(outputFile).equals(sb.toString())) {

        FileUtil.write(outputFile, sb.toString());

        Logger.info(EJBXMLBuilder.class, outputFile.toString());
    }
}

From source file:com.liferay.portal.tools.EJBXMLBuilder.java

License:Open Source License

private void _buildPramatiXML() throws Exception {
    Map tableNames = new HashMap();

    StringBuffer sb = new StringBuffer();

    sb.append("<?xml version=\"1.0\"?>\n");
    sb.append(/*from w w w  .  j a  v  a 2s  .com*/
            "<!DOCTYPE pramati-j2ee-server PUBLIC \"-//Pramati Technologies //DTD Pramati J2ee Server 3.5 SP5//EN\" \"http://www.pramati.com/dtd/pramati-j2ee-server_3_5.dtd\">\n");

    sb.append("\n<pramati-j2ee-server>\n");
    sb.append("\t<vhost-name>default</vhost-name>\n");
    sb.append("\t<auto-start>TRUE</auto-start>\n");
    sb.append("\t<realm-name />\n");
    sb.append("\t<ejb-module>\n");
    sb.append("\t\t<name>").append(_jarFileName).append("</name>\n");

    SAXReader reader = new SAXReader();
    reader.setEntityResolver(new EntityResolver());

    Document doc = reader.read(new File("classes/META-INF/ejb-jar.xml"));

    Iterator itr = doc.getRootElement().element("enterprise-beans").elements("session").iterator();

    while (itr.hasNext()) {
        Element entity = (Element) itr.next();

        sb.append("\t\t<ejb>\n");
        sb.append("\t\t\t<name>").append(entity.elementText("ejb-name")).append("</name>\n");
        sb.append("\t\t\t<max-pool-size>40</max-pool-size>\n");
        sb.append("\t\t\t<min-pool-size>20</min-pool-size>\n");
        sb.append("\t\t\t<enable-freepool>false</enable-freepool>\n");
        sb.append("\t\t\t<pool-waittimeout-millis>60000</pool-waittimeout-millis>\n");

        sb.append("\t\t\t<low-activity-interval>20</low-activity-interval>\n");
        sb.append("\t\t\t<is-secure>false</is-secure>\n");
        sb.append("\t\t\t<is-clustered>true</is-clustered>\n");

        if (entity.elementText("display-name").endsWith("LocalManagerEJB")) {
            sb.append("\t\t\t<jndi-name>ejb/liferay/").append(entity.elementText("display-name"))
                    .append("Home</jndi-name>\n");
        } else {
            sb.append("\t\t\t<jndi-name>").append(entity.elementText("ejb-name")).append("</jndi-name>\n");
        }

        sb.append("\t\t\t<local-jndi-name>").append(entity.elementText("ejb-name")).append("__PRAMATI_LOCAL")
                .append("</local-jndi-name>\n");

        sb.append(_buildPramatiXMLRefs(entity));

        sb.append("\t\t</ejb>\n");
    }

    sb.append("\t</ejb-module>\n");
    sb.append("</pramati-j2ee-server>");

    File outputFile = new File("classes/pramati-j2ee-server.xml");

    if (!outputFile.exists() || !FileUtil.read(outputFile).equals(sb.toString())) {

        FileUtil.write(outputFile, sb.toString());

        Logger.info(EJBXMLBuilder.class, outputFile.toString());
    }
}

From source file:com.liferay.portal.tools.EJBXMLBuilder.java

License:Open Source License

private void _buildRexIPXML() throws Exception {
    StringBuffer sb = new StringBuffer();

    sb.append("<?xml version=\"1.0\"?>\n");

    sb.append("\n<rexip-ejb-jar>\n");
    sb.append("\t<enterprise-beans>\n");

    SAXReader reader = new SAXReader();
    reader.setEntityResolver(new EntityResolver());

    Document doc = reader.read(new File("classes/META-INF/ejb-jar.xml"));

    Iterator itr = doc.getRootElement().element("enterprise-beans").elements("session").iterator();

    while (itr.hasNext()) {
        Element entity = (Element) itr.next();

        sb.append("\t\t<session>\n");
        sb.append("\t\t\t<ejb-name>").append(entity.elementText("ejb-name")).append("</ejb-name>\n");

        if (entity.elementText("display-name").endsWith("LocalManagerEJB")) {
            sb.append("\t\t\t<local-jndi-name>ejb/liferay/").append(entity.elementText("display-name"))
                    .append("Home</local-jndi-name>\n");
        } else {/*  w w w.j a va2  s  .  c o m*/
            sb.append("\t\t\t<jndi-name>").append(entity.elementText("ejb-name")).append("</jndi-name>\n");
        }

        sb.append("\t\t\t<clustered>true</clustered>\n");
        sb.append("\t\t\t<pool-size>20</pool-size>\n");
        sb.append("\t\t\t<cache-size>20</cache-size>\n");
        sb.append("\t\t</session>\n");
    }

    sb.append("\t</enterprise-beans>\n");
    sb.append("</rexip-ejb-jar>");

    File outputFile = new File("classes/META-INF/rexip-ejb-jar.xml");

    if (!outputFile.exists() || !FileUtil.read(outputFile).equals(sb.toString())) {

        FileUtil.write(outputFile, sb.toString());

        Logger.info(EJBXMLBuilder.class, outputFile.toString());
    }
}

From source file:com.liferay.portal.tools.EJBXMLBuilder.java

License:Open Source License

private void _buildSunXML() throws Exception {
    StringBuffer sb = new StringBuffer();

    sb.append("<?xml version=\"1.0\"?>\n");
    sb.append(//from w  w  w  . j ava  2 s . co  m
            "<!DOCTYPE sun-ejb-jar PUBLIC \"-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 EJB 2.0//EN\" \"http://www.sun.com/software/sunone/appserver/dtds/sun-ejb-jar_2_0-0.dtd\">\n");

    sb.append("\n<sun-ejb-jar>\n");
    sb.append("\t<enterprise-beans>\n");

    SAXReader reader = new SAXReader();
    reader.setEntityResolver(new EntityResolver());

    Document doc = reader.read(new File("classes/META-INF/ejb-jar.xml"));

    Iterator itr = doc.getRootElement().element("enterprise-beans").elements("session").iterator();

    while (itr.hasNext()) {
        Element entity = (Element) itr.next();

        sb.append("\t\t<ejb>\n");
        sb.append("\t\t\t<ejb-name>").append(entity.elementText("ejb-name")).append("</ejb-name>\n");

        if (entity.elementText("display-name").endsWith("LocalManagerEJB")) {
            sb.append("\t\t\t<jndi-name>ejb/liferay/").append(entity.elementText("display-name"))
                    .append("Home</jndi-name>\n");
        } else {
            sb.append("\t\t\t<jndi-name>").append(entity.elementText("ejb-name")).append("</jndi-name>\n");
        }

        sb.append("\t\t\t<bean-pool>\n");
        sb.append("\t\t\t\t<steady-pool-size>0</steady-pool-size>\n");
        sb.append("\t\t\t\t<resize-quantity>60</resize-quantity>\n");
        sb.append("\t\t\t\t<max-pool-size>60</max-pool-size>\n");
        sb.append("\t\t\t\t<pool-idle-timeout-in-seconds>900</pool-idle-timeout-in-seconds>\n");
        sb.append("\t\t\t</bean-pool>\n");
        sb.append("\t\t</ejb>\n");
    }

    sb.append("\t</enterprise-beans>\n");
    sb.append("</sun-ejb-jar>");

    File outputFile = new File("classes/META-INF/sun-ejb-jar.xml");

    if (!outputFile.exists() || !FileUtil.read(outputFile).equals(sb.toString())) {

        FileUtil.write(outputFile, sb.toString());

        Logger.info(EJBXMLBuilder.class, outputFile.toString());
    }
}

From source file:com.liferay.portal.tools.EJBXMLBuilder.java

License:Open Source License

private void _buildWebLogicXML() throws Exception {
    StringBuffer sb = new StringBuffer();

    sb.append("<?xml version=\"1.0\"?>\n");
    sb.append(/*from   w ww .  j  av  a 2s .  co m*/
            "<!DOCTYPE weblogic-ejb-jar PUBLIC \"-//BEA Systems, Inc.//DTD WebLogic 7.0.0 EJB//EN\" \"http://www.bea.com/servers/wls700/dtd/weblogic-ejb-jar.dtd\">\n");

    sb.append("\n<weblogic-ejb-jar>\n");

    SAXReader reader = new SAXReader();
    reader.setEntityResolver(new EntityResolver());

    Document doc = reader.read(new File("classes/META-INF/ejb-jar.xml"));

    Iterator itr = doc.getRootElement().element("enterprise-beans").elements("session").iterator();

    while (itr.hasNext()) {
        Element entity = (Element) itr.next();

        sb.append("\t<weblogic-enterprise-bean>\n");
        sb.append("\t\t<ejb-name>").append(entity.elementText("ejb-name")).append("</ejb-name>\n");

        if (entity.elementText("display-name").endsWith("LocalManagerEJB")) {
            sb.append("\t\t<local-jndi-name>ejb/liferay/").append(entity.elementText("display-name"))
                    .append("Home</local-jndi-name>\n");
        } else {
            sb.append("\t\t<jndi-name>").append(entity.elementText("ejb-name")).append("</jndi-name>\n");
        }

        sb.append("\t</weblogic-enterprise-bean>\n");
    }

    sb.append("</weblogic-ejb-jar>");

    File outputFile = new File("classes/META-INF/weblogic-ejb-jar.xml");

    if (!outputFile.exists() || !FileUtil.read(outputFile).equals(sb.toString())) {

        FileUtil.write(outputFile, sb.toString());

        Logger.info(EJBXMLBuilder.class, outputFile.toString());
    }
}

From source file:com.liferay.portal.tools.EJBXMLBuilder.java

License:Open Source License

private void _buildWebSphereXML() throws Exception {
    StringBuffer sb = new StringBuffer();

    sb.append("<?xml version=\"1.0\"?>\n");

    sb.append(//from   w ww.j  a  v a  2  s  .  c  o  m
            "\n<com.ibm.ejs.models.base.bindings.ejbbnd:EJBJarBinding xmlns:com.ibm.ejs.models.base.bindings.ejbbnd=\"ejbbnd.xmi\" xmlns:xmi=\"http://www.omg.org/XMI\" xmlns:com.ibm.ejs.models.base.bindings.commonbnd=\"commonbnd.xmi\" xmlns:com.ibm.etools.ejb=\"ejb.xmi\" xmlns:com.ibm.etools.j2ee.common=\"common.xmi\" xmi:version=\"2.0\" xmi:id=\"ejb-jar_ID_Bnd\" currentBackendId=\"CLOUDSCAPE_V50_1\">\n");
    sb.append("\t<ejbJar href=\"META-INF/ejb-jar.xml#ejb-jar_ID\" />\n");

    SAXReader reader = new SAXReader();
    reader.setEntityResolver(new EntityResolver());

    Document doc = reader.read(new File("classes/META-INF/ejb-jar.xml"));

    int sessionCount = 0;
    int ejbLocalRefCount = 0;

    Iterator itr1 = doc.getRootElement().element("enterprise-beans").elements("session").iterator();

    while (itr1.hasNext()) {
        Element sessionEl = (Element) itr1.next();

        sb.append("\t<ejbBindings xmi:id=\"Session_").append(++sessionCount).append("_Bnd\" jndiName=\"");

        if (sessionEl.elementText("display-name").endsWith("LocalManagerEJB")) {
            sb.append("ejb/liferay/").append(sessionEl.elementText("display-name")).append("Home");
        } else {
            sb.append(sessionEl.elementText("ejb-name"));
        }

        sb.append("\">\n");

        sb.append(
                "\t\t<enterpriseBean xmi:type=\"com.ibm.etools.ejb:Session\" href=\"META-INF/ejb-jar.xml#Session_")
                .append(sessionCount).append("\" />\n");

        Iterator itr2 = sessionEl.elements("ejb-local-ref").iterator();

        while (itr2.hasNext()) {
            Element ejbLocalRefEl = (Element) itr2.next();

            sb.append("\t\t<ejbRefBindings xmi:id=\"EjbRefBinding_").append(++ejbLocalRefCount)
                    .append("\" jndiName=\"").append(ejbLocalRefEl.elementText("ejb-ref-name")).append("\">\n");
            sb.append(
                    "\t\t\t<bindingEjbRef xmi:type=\"com.ibm.etools.j2ee.common:EJBLocalRef\" href=\"META-INF/ejb-jar.xml#EjbRef_")
                    .append(ejbLocalRefCount).append("\" />\n");
            sb.append("\t\t</ejbRefBindings>\n");
        }

        sb.append("\t</ejbBindings>\n");
    }

    sb.append("</com.ibm.ejs.models.base.bindings.ejbbnd:EJBJarBinding>");

    File outputFile = new File("classes/META-INF/ibm-ejb-jar-bnd.xmi");

    if (!outputFile.exists() || !FileUtil.read(outputFile).equals(sb.toString())) {

        FileUtil.write(outputFile, sb.toString());

        Logger.info(EJBXMLBuilder.class, outputFile.toString());
    }
}

From source file:com.liferay.portal.tools.EJBXMLBuilder.java

License:Open Source License

private void _updateEJBXML() throws Exception {
    File xmlFile = new File("classes/META-INF/ejb-jar.xml");

    StringBuffer methodsSB = new StringBuffer();

    SAXReader reader = new SAXReader();
    reader.setEntityResolver(new EntityResolver());

    Document doc = reader.read(xmlFile);

    Iterator itr = doc.getRootElement().element("enterprise-beans").elements("entity").iterator();

    while (itr.hasNext()) {
        Element entity = (Element) itr.next();

        methodsSB.append("\t\t\t<method>\n");
        methodsSB.append("\t\t\t\t<ejb-name>" + entity.elementText("ejb-name") + "</ejb-name>\n");
        methodsSB.append("\t\t\t\t<method-name>*</method-name>\n");
        methodsSB.append("\t\t\t</method>\n");
    }/* w w w  . j a v a 2 s  .  c  om*/

    itr = doc.getRootElement().element("enterprise-beans").elements("session").iterator();

    while (itr.hasNext()) {
        Element entity = (Element) itr.next();

        methodsSB.append("\t\t\t<method>\n");
        methodsSB.append("\t\t\t\t<ejb-name>" + entity.elementText("ejb-name") + "</ejb-name>\n");
        methodsSB.append("\t\t\t\t<method-name>*</method-name>\n");
        methodsSB.append("\t\t\t</method>\n");
    }

    StringBuffer sb = new StringBuffer();

    sb.append("\t<assembly-descriptor>\n");
    sb.append("\t\t<method-permission>\n");
    sb.append("\t\t\t<unchecked />\n");
    sb.append(methodsSB);
    sb.append("\t\t</method-permission>\n");
    sb.append("\t\t<container-transaction>\n");
    sb.append(methodsSB);
    sb.append("\t\t\t<trans-attribute>Required</trans-attribute>\n");
    sb.append("\t\t</container-transaction>\n");
    sb.append("\t</assembly-descriptor>\n");

    String content = FileUtil.read(xmlFile);

    int x = content.indexOf("<assembly-descriptor>") - 1;
    int y = content.indexOf("</assembly-descriptor>", x) + 23;

    if (x < 0) {
        x = content.indexOf("</ejb-jar>");
        y = x;
    }

    String newContent = content.substring(0, x) + sb.toString() + content.substring(y, content.length());

    if (!content.equals(newContent)) {
        FileUtil.write(xmlFile, newContent);
    }
}