List of usage examples for org.dom4j.io SAXReader SAXReader
public SAXReader()
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(// w w w. j a v 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(//w w w .j a v a 2 s.co m "<!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 {/*from w ww. ja v a 2 s . c om*/ 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(/*w w w. j a v a 2s .c om*/ "<!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 w w . j a va 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 w w .j a v a 2s . 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"); }/*from w w w .ja v a2 s .co m*/ 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); } }
From source file:com.liferay.portal.tools.WebSiteBuilder.java
License:Open Source License
public static List getWebSites() throws Exception { File file = new File("../web-sites/web-sites.xml"); SAXReader reader = new SAXReader(); Document doc = null;/*from w w w. ja v a 2s . c o m*/ try { doc = reader.read(file); } catch (DocumentException de) { Logger.error(WebSiteBuilder.class, de.getMessage(), de); } Element root = doc.getRootElement(); List webSites = new ArrayList(); Iterator itr = root.elements("web-site").iterator(); while (itr.hasNext()) { Element webSite = (Element) itr.next(); String id = webSite.attributeValue("id"); boolean httpEnabled = GetterUtil.getBoolean(webSite.attributeValue("http-enabled"), true); String keystore = GetterUtil.getString(webSite.attributeValue("keystore")); String keystorePassword = GetterUtil.getString(webSite.attributeValue("keystore-password")); String virtualHosts = GetterUtil.getString(webSite.attributeValue("virtual-hosts")); String forwardURL = GetterUtil.getString(webSite.attributeValue("forward-url"), "/c"); webSites.add(new WebSite(id, httpEnabled, keystore, keystorePassword, virtualHosts, forwardURL)); } return webSites; }
From source file:com.liferay.portlet.PortletPreferencesSerializer.java
License:Open Source License
public static PortletPreferences fromDefaultXML(String xml) throws PortalException, SystemException { PortletPreferencesImpl prefs = new PortletPreferencesImpl(); if (Validator.isNull(xml)) { return prefs; }/*ww w . j a v a 2s .c o m*/ Map preferences = prefs.getPreferences(); try { Document doc = new SAXReader().read(new StringReader(xml)); Element root = doc.getRootElement(); Iterator itr1 = root.elements("preference").iterator(); while (itr1.hasNext()) { Element prefEl = (Element) itr1.next(); String name = prefEl.elementTextTrim("name"); List values = new ArrayList(); Iterator itr2 = prefEl.elements("value").iterator(); while (itr2.hasNext()) { Element valueEl = (Element) itr2.next(); /*if (valueEl.nodeCount() <= 0) { values.add(valueEl.getText()); } else { values.add(valueEl.node(0).asXML()); }*/ values.add(valueEl.getTextTrim()); } boolean readOnly = GetterUtil.get(prefEl.elementText("read-only"), false); Preference preference = new Preference(name, (String[]) values.toArray(new String[0]), readOnly); preferences.put(name, preference); } return prefs; } catch (DocumentException de) { throw new SystemException(de); } }
From source file:com.liferay.util.log4j.Log4JUtil.java
License:Open Source License
public static void configureLog4J(URL url) { if (url == null) { return;//w ww. j a v a2s.co m } String urlContent = _getURLContent(url); if (urlContent == null) { return; } // See LPS-6029, LPS-8865, and LPS-24280 DOMConfigurator domConfigurator = new DOMConfigurator(); Reader urlReader = new StringReader(urlContent); domConfigurator.doConfigure(urlReader, LogManager.getLoggerRepository()); Set<String> currentLoggerNames = new HashSet<String>(); Enumeration<Logger> enu = LogManager.getCurrentLoggers(); while (enu.hasMoreElements()) { Logger logger = enu.nextElement(); currentLoggerNames.add(logger.getName()); } try { SAXReader saxReader = new SAXReader(); Reader reader = new StringReader(urlContent); Document document = saxReader.read(reader, url.toExternalForm()); Element rootElement = document.getRootElement(); List<Element> categoryElements = rootElement.elements("category"); for (Element categoryElement : categoryElements) { String name = categoryElement.attributeValue("name"); Element priorityElement = categoryElement.element("priority"); String priority = priorityElement.attributeValue("value"); setLevel(name, priority, false); } } catch (Exception e) { e.printStackTrace(); } }