List of usage examples for org.dom4j Element elementText
String elementText(QName qname);
From source file:com.liferay.maven.plugins.ThemeMergeMojo.java
License:Open Source License
protected Theme readTheme(Element themeElement) { String id = themeElement.attributeValue("id"); Theme theme = new Theme(id); ContextReplace themeContextReplace = new ContextReplace(); themeContextReplace.addValue("themes-path", null); String rootPath = GetterUtil.getString(themeElement.elementText("root-path"), "/"); rootPath = themeContextReplace.replace(rootPath); themeContextReplace.addValue("root-path", rootPath); theme.setRootPath(rootPath);/* www . jav a 2 s . c om*/ String templatesPath = GetterUtil.getString(themeElement.elementText("templates-path"), rootPath.concat("/templates")); templatesPath = themeContextReplace.replace(templatesPath); templatesPath = StringUtil.safePath(templatesPath); themeContextReplace.addValue("templates-path", templatesPath); theme.setTemplatesPath(templatesPath); String cssPath = GetterUtil.getString(themeElement.elementText("css-path"), rootPath.concat("/css")); cssPath = themeContextReplace.replace(cssPath); cssPath = StringUtil.safePath(cssPath); themeContextReplace.addValue("css-path", cssPath); theme.setCssPath(cssPath); String imagesPath = GetterUtil.getString(themeElement.elementText("images-path"), rootPath.concat("/images")); imagesPath = themeContextReplace.replace(imagesPath); imagesPath = StringUtil.safePath(imagesPath); themeContextReplace.addValue("images-path", imagesPath); theme.setImagesPath(imagesPath); String javaScriptPath = GetterUtil.getString(themeElement.elementText("javascript-path"), rootPath.concat("/js")); javaScriptPath = themeContextReplace.replace(javaScriptPath); javaScriptPath = StringUtil.safePath(javaScriptPath); themeContextReplace.addValue("javascript-path", javaScriptPath); theme.setJavaScriptPath(javaScriptPath); String templateExtension = GetterUtil.getString(themeElement.elementText("template-extension"), themeType); theme.setTemplateExtension(templateExtension); return theme; }
From source file:com.liferay.portal.ejb.PortletManagerImpl.java
License:Open Source License
private Set _readPortletXML(String servletContextName, String xml, Map portletsPool) throws DocumentException, IOException { Set portletIds = new HashSet(); if (xml == null) { return portletIds; }//from www . j a v a2s. c o m /*EntityResolver resolver = new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) { InputStream is = getClass().getClassLoader().getResourceAsStream( "com/liferay/portal/resources/portlet-app_1_0.xsd"); return new InputSource(is); } };*/ SAXReader reader = new SAXReader(); //reader.setEntityResolver(resolver); Document doc = reader.read(new StringReader(xml)); Element root = doc.getRootElement(); Set userAttributes = new HashSet(); Iterator itr1 = root.elements("user-attribute").iterator(); while (itr1.hasNext()) { Element userAttribute = (Element) itr1.next(); String name = userAttribute.elementText("name"); userAttributes.add(name); } itr1 = root.elements("portlet").iterator(); while (itr1.hasNext()) { Element portlet = (Element) itr1.next(); String portletId = portlet.elementText("portlet-name"); if (servletContextName != null) { portletId = servletContextName + PortletConfigImpl.WAR_SEPARATOR + portletId; } portletIds.add(portletId); Portlet portletModel = (Portlet) portletsPool.get(portletId); if (portletModel == null) { portletModel = new Portlet(new PortletPK(portletId, _SHARED_KEY, _SHARED_KEY)); portletsPool.put(portletId, portletModel); } if (servletContextName != null) { portletModel.setWARFile(true); } portletModel.setPortletClass(portlet.elementText("portlet-class")); Iterator itr2 = portlet.elements("init-param").iterator(); while (itr2.hasNext()) { Element initParam = (Element) itr2.next(); portletModel.getInitParams().put(initParam.elementText("name"), initParam.elementText("value")); } Element expirationCache = portlet.element("expiration-cache"); if (expirationCache != null) { portletModel.setExpCache(new Integer(GetterUtil.getInteger(expirationCache.getText()))); } itr2 = portlet.elements("supports").iterator(); while (itr2.hasNext()) { Element supports = (Element) itr2.next(); String mimeType = supports.elementText("mime-type"); Iterator itr3 = supports.elements("portlet-mode").iterator(); while (itr3.hasNext()) { Element portletMode = (Element) itr3.next(); Set mimeTypeModes = (Set) portletModel.getPortletModes().get(mimeType); if (mimeTypeModes == null) { mimeTypeModes = new HashSet(); portletModel.getPortletModes().put(mimeType, mimeTypeModes); } mimeTypeModes.add(portletMode.getTextTrim().toLowerCase()); } } Set supportedLocales = portletModel.getSupportedLocales(); supportedLocales.add(Locale.getDefault().getLanguage()); itr2 = portlet.elements("supported-locale").iterator(); while (itr2.hasNext()) { Element supportedLocaleEl = (Element) itr2.next(); String supportedLocale = supportedLocaleEl.getText(); supportedLocales.add(supportedLocale); } portletModel.setResourceBundle(portlet.elementText("resource-bundle")); Element portletInfo = portlet.element("portlet-info"); String portletInfoTitle = null; String portletInfoShortTitle = null; String portletInfoKeyWords = null; if (portletInfo != null) { portletInfoTitle = portletInfo.elementText("title"); portletInfoShortTitle = portletInfo.elementText("short-title"); portletInfoKeyWords = portletInfo.elementText("keywords"); } portletModel .setPortletInfo(new PortletInfo(portletInfoTitle, portletInfoShortTitle, portletInfoKeyWords)); Element portletPreferences = portlet.element("portlet-preferences"); String defaultPreferences = null; String prefsValidator = null; if (portletPreferences != null) { Element prefsValidatorEl = portletPreferences.element("preferences-validator"); String prefsValidatorName = null; if (prefsValidatorEl != null) { prefsValidator = prefsValidatorEl.getText(); portletPreferences.remove(prefsValidatorEl); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLWriter writer = new XMLWriter(baos, OutputFormat.createCompactFormat()); writer.write(portletPreferences); defaultPreferences = baos.toString(); } portletModel.setDefaultPreferences(defaultPreferences); portletModel.setPreferencesValidator(prefsValidator); if (!portletModel.isWARFile() && Validator.isNotNull(prefsValidator) && GetterUtil.getBoolean(PropsUtil.get(PropsUtil.PREFERENCE_VALIDATE_ON_STARTUP))) { try { PreferencesValidator prefsValidatorObj = PortalUtil.getPreferencesValidator(portletModel); prefsValidatorObj.validate(PortletPreferencesSerializer.fromDefaultXML(defaultPreferences)); } catch (Exception e) { _log.warn("Portlet with the name " + portletId + " does not have valid default preferences"); } } List roles = new ArrayList(); itr2 = portlet.elements("security-role-ref").iterator(); while (itr2.hasNext()) { Element role = (Element) itr2.next(); roles.add(role.elementText("role-name")); } portletModel.setRolesArray((String[]) roles.toArray(new String[0])); portletModel.getUserAttributes().addAll(userAttributes); } return portletIds; }
From source file:com.liferay.portal.servlet.MainServlet.java
License:Open Source License
private void _checkWebSettings(String xml) throws DocumentException { SAXReader reader = new SAXReader(); reader.setEntityResolver(null);/*from w w w . j av a 2 s . com*/ Document doc = reader.read(new StringReader(xml)); Element root = doc.getRootElement(); int timeout = GetterUtil.getInteger(PropsUtil.get(PropsUtil.SESSION_TIMEOUT)); Element sessionConfig = root.element("session-config"); if (sessionConfig != null) { String sessionTimeout = sessionConfig.elementText("session-timeout"); timeout = GetterUtil.get(sessionConfig.elementText("session-timeout"), timeout); } PropsUtil.set(PropsUtil.SESSION_TIMEOUT, Integer.toString(timeout)); }
From source file:com.liferay.portal.tools.EARXMLBuilder.java
License:Open Source License
private String _buildPramatiXMLWebModule(String path) throws DocumentException, IOException { String contextRoot = path.substring(2, path.length() - 4); String filePath = path + "/docroot/WEB-INF/web.xml"; if (path.endsWith("-complete")) { contextRoot = "/"; filePath = path.substring(0, path.length() - 9) + "/docroot/WEB-INF/web.xml"; }// w ww .j a v a 2s . co m StringBuffer sb = new StringBuffer(); sb.append("\t<web-module>\n"); sb.append("\t\t<name>").append(contextRoot).append("</name>\n"); sb.append("\t\t<module-name>").append(path.substring(3, path.length())).append(".war</module-name>\n"); SAXReader reader = new SAXReader(); reader.setEntityResolver(new EntityResolver()); Document doc = reader.read(new File(filePath)); Iterator itr = doc.getRootElement().elements("ejb-local-ref").iterator(); while (itr.hasNext()) { Element ejbLocalRef = (Element) itr.next(); sb.append("\t\t<ejb-local-ref>\n"); sb.append("\t\t\t<ejb-ref-name>").append(ejbLocalRef.elementText("ejb-ref-name")) .append("</ejb-ref-name>\n"); sb.append("\t\t\t<ejb-link>").append(ejbLocalRef.elementText("ejb-link")).append("</ejb-link>\n"); sb.append("\t\t</ejb-local-ref>\n"); } itr = doc.getRootElement().elements("resource-ref").iterator(); while (itr.hasNext()) { Element resourceRef = (Element) itr.next(); sb.append("\t\t<resource-mapping>\n"); sb.append("\t\t\t<resource-name>").append(resourceRef.elementText("res-ref-name")) .append("</resource-name>\n"); sb.append("\t\t\t<resource-type>").append(resourceRef.elementText("res-type")) .append("</resource-type>\n"); sb.append("\t\t\t<resource-link>").append(resourceRef.elementText("res-ref-name")) .append("</resource-link>\n"); sb.append("\t\t</resource-mapping>\n"); } sb.append("\t</web-module>\n"); return sb.toString(); }
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 w w .j a va 2 s . c om*/ "<!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(//from ww w. j a v 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(//w ww.j ava 2s. 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 ww w. ja v a2 s. c om*/ "<!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 String _buildPramatiXMLRefs(Element entity) { StringBuffer sb = new StringBuffer(); Iterator itr = entity.elements("ejb-local-ref").iterator(); while (itr.hasNext()) { Element ejbRef = (Element) itr.next(); sb.append("\t\t\t<ejb-local-ref>\n"); sb.append("\t\t\t\t<ejb-ref-name>").append(ejbRef.elementText("ejb-ref-name")) .append("</ejb-ref-name>\n"); sb.append("\t\t\t\t<ejb-link>").append(ejbRef.elementText("ejb-ref-name")).append("__PRAMATI_LOCAL") .append("</ejb-link>\n"); sb.append("\t\t\t</ejb-local-ref>\n"); }/*from w w w . jav a2 s .c o m*/ return sb.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 ww w . j a va 2 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()); } }