List of usage examples for com.liferay.portal.kernel.util PropertiesUtil load
public static void load(Properties properties, String s) throws IOException
From source file:br.com.thiagomoreira.liferay.plugins.portalpropertiesprettier.PortalPropertiesPrettierPortlet.java
License:Apache License
protected String prettify(PortletRequest request) throws IOException, PortletException { UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(request); String liferayVersion = ParamUtil.getString(uploadPortletRequest, "liferayVersion", "6.2.3-ga4"); boolean printDefaultValue = ParamUtil.getBoolean(uploadPortletRequest, "printDefaultValue"); Properties customProperties = PropertiesUtil .load(uploadPortletRequest.getFileAsStream("portalPropertiesFile"), "UTF-8"); String prettyProperties = prettier.prettify(customProperties, liferayVersion, printDefaultValue); incrementCounter(request);/*from www . j av a 2s. c om*/ return prettyProperties; }
From source file:com.liferay.exportimport.resources.importer.internal.util.PluginPackageProperties.java
License:Open Source License
public PluginPackageProperties(ServletContext servletContext) throws IOException { InputStream inputStream = servletContext.getResourceAsStream("/WEB-INF/liferay-plugin-package.properties"); if (inputStream == null) { return;/*from w w w. ja va 2 s . c o m*/ } String propertiesString = StringUtil.read(inputStream); String contextPath = servletContext.getRealPath(StringPool.SLASH); if (contextPath == null) { contextPath = servletContext.getContextPath(); } contextPath = StringUtil.replace(contextPath, CharPool.BACK_SLASH, CharPool.SLASH); propertiesString = propertiesString.replace("${context.path}", contextPath); PropertiesUtil.load(_properties, propertiesString); }
From source file:com.liferay.marketplace.internal.lpkg.deployer.LPKGDeployerRegistrar.java
License:Open Source License
private void _register(Bundle lpkgBundle, List<Bundle> bundles) throws Exception { URL url = lpkgBundle.getEntry("liferay-marketplace.properties"); Properties properties = PropertiesUtil.load(url.openStream(), StringPool.ISO_8859_1); long remoteAppId = GetterUtil.getLong(properties.getProperty("remote-app-id")); String version = properties.getProperty("version"); if ((remoteAppId <= 0) || Validator.isNull(version)) { return;/* w w w .j a va 2 s .c o m*/ } String title = properties.getProperty("title"); String description = properties.getProperty("description"); String category = properties.getProperty("category"); String iconURL = properties.getProperty("icon-url"); boolean required = GetterUtil.getBoolean(properties.getProperty("required")); App app = _appLocalService.updateApp(0, remoteAppId, title, description, category, iconURL, version, required, null); _moduleLocalService.deleteModules(app.getAppId()); if (!bundles.isEmpty()) { for (Bundle bundle : bundles) { Dictionary<String, String> headers = bundle.getHeaders(); String contextName = ContextUtil .getContextName(GetterUtil.getString(headers.get("Web-ContextPath"))); _moduleLocalService.addModule(app.getAppId(), bundle.getSymbolicName(), String.valueOf(bundle.getVersion()), contextName); } } else { String[] bundleStrings = StringUtil.split(properties.getProperty("bundles")); for (String bundleString : bundleStrings) { String[] bundleStringParts = StringUtil.split(bundleString, CharPool.POUND); String bundleSymbolicName = bundleStringParts[0]; String bundleVersion = bundleStringParts[1]; String contextName = bundleStringParts[2]; _moduleLocalService.addModule(app.getAppId(), bundleSymbolicName, bundleVersion, contextName); } String[] contextNames = StringUtil.split(properties.getProperty("context-names")); for (String contextName : contextNames) { _moduleLocalService.addModule(app.getAppId(), contextName, StringPool.BLANK, contextName); } } }
From source file:com.liferay.portlet.journal.util.PropertiesTransformerListener.java
License:Open Source License
/** * Replace the properties in a given string with their values fetched from * the template GLOBAL-PROPERTIES./*from w w w .jav a 2 s .c o m*/ * * @return the processed string */ protected String replace(String s) { Map<String, String> tokens = getTokens(); String templateId = tokens.get("template_id"); if ((templateId == null) || ((templateId != null) && (templateId.equals(_GLOBAL_PROPERTIES)))) { // Return the original string if no template ID is specified or if // the template ID is GLOBAL-PROPERTIES to prevent an infinite loop. return s; } Properties properties = new Properties(); try { Map<String, String> newTokens = new HashMap<String, String>(); MapUtil.copy(tokens, newTokens); newTokens.put("template_id", _GLOBAL_PROPERTIES); long groupId = GetterUtil.getLong(tokens.get("group_id")); String script = JournalUtil.getTemplateScript(groupId, _GLOBAL_PROPERTIES, newTokens, getLanguageId()); PropertiesUtil.load(properties, script); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn(e); } } if (properties.isEmpty()) { return s; } String[] escapedKeys = new String[properties.size()]; String[] escapedValues = new String[properties.size()]; String[] keys = new String[properties.size()]; String[] values = new String[properties.size()]; String[] tempEscapedKeys = new String[properties.size()]; String[] tempEscapedValues = new String[properties.size()]; int counter = 0; Iterator<Map.Entry<Object, Object>> itr = properties.entrySet().iterator(); while (itr.hasNext()) { Map.Entry<Object, Object> entry = itr.next(); String key = (String) entry.getKey(); String value = (String) entry.getValue(); String escapedKey = StringPool.AT + StringPool.AT + key + StringPool.AT + StringPool.AT; String actualKey = StringPool.AT + key + StringPool.AT; String tempEscapedKey = TokensTransformerListener.TEMP_ESCAPED_AT_OPEN + key + TokensTransformerListener.TEMP_ESCAPED_AT_CLOSE; escapedKeys[counter] = escapedKey; escapedValues[counter] = tempEscapedKey; keys[counter] = actualKey; values[counter] = value; tempEscapedKeys[counter] = tempEscapedKey; tempEscapedValues[counter] = actualKey; counter++; } s = StringUtil.replace(s, escapedKeys, escapedValues); s = StringUtil.replace(s, keys, values); s = StringUtil.replace(s, tempEscapedKeys, tempEscapedValues); return s; }
From source file:com.liferay.resourcesimporter.messaging.HotDeployMessageListener.java
License:Open Source License
protected Properties getPluginPackageProperties(ServletContext servletContext) { Properties properties = new Properties(); try {//w w w . j av a 2 s .co m String propertiesString = StringUtil .read(servletContext.getResourceAsStream("/WEB-INF/liferay-plugin-package.properties")); if (propertiesString != null) { String contextPath = servletContext.getRealPath(StringPool.SLASH); contextPath = StringUtil.replace(contextPath, StringPool.BACK_SLASH, StringPool.SLASH); propertiesString = propertiesString.replace("${context.path}", contextPath); PropertiesUtil.load(properties, propertiesString); } } catch (IOException e) { _log.error(e, e); } return properties; }
From source file:com.liferay.resourcesimporter.servlet.ResourcesImporterServletContextListener.java
License:Open Source License
protected Properties getPluginPackageProperties(ServletContext servletContext) { Properties properties = new Properties(); try {//from ww w .j a v a 2 s . c o m String propertiesString = StringUtil .read(servletContext.getResourceAsStream("/WEB-INF/liferay-plugin-package.properties")); if (propertiesString == null) { return properties; } String contextPath = servletContext.getRealPath(StringPool.SLASH); contextPath = StringUtil.replace(contextPath, StringPool.BACK_SLASH, StringPool.SLASH); propertiesString = propertiesString.replace("${context.path}", contextPath); PropertiesUtil.load(properties, propertiesString); } catch (IOException ioe) { _log.error(ioe, ioe); } return properties; }
From source file:com.liferay.resourcesimporter.util.PluginPackageProperties.java
License:Open Source License
public PluginPackageProperties(ServletContext servletContext) throws IOException { String propertiesString = StringUtil .read(servletContext.getResourceAsStream("/WEB-INF/liferay-plugin-package.properties")); if (propertiesString == null) { return;/*from w w w . jav a 2 s. c o m*/ } String contextPath = servletContext.getRealPath(StringPool.SLASH); contextPath = StringUtil.replace(contextPath, StringPool.BACK_SLASH, StringPool.SLASH); propertiesString = propertiesString.replace("${context.path}", contextPath); PropertiesUtil.load(_properties, propertiesString); }
From source file:com.liferay.tools.sourceformatter.SourceFormatterHelper.java
License:Open Source License
public void init() throws IOException { if (!_useProperties) { return;/*from w w w .j a v a 2 s . co m*/ } File basedirFile = new File("./"); String basedirAbsolutePath = StringUtil.replace(basedirFile.getAbsolutePath(), new String[] { ".", ":", "/", "\\" }, new String[] { "_", "_", "_", "_" }); String propertiesFileName = System.getProperty("java.io.tmpdir") + "/SourceFormatter." + basedirAbsolutePath; _propertiesFile = new File(propertiesFileName); if (_propertiesFile.exists()) { _propertiesContent = _fileUtil.read(_propertiesFile); PropertiesUtil.load(_properties, _propertiesContent); } }
From source file:com.liferay.tools.sourceformatter.XMLSourceProcessor.java
License:Open Source License
protected String formatWebXML(String fileName, String content) throws Exception { if (!portalSource) { String webXML = ContentUtil.get("com/liferay/portal/deploy/dependencies/web.xml"); if (content.equals(webXML)) { processErrorMessage(fileName, fileName); }/*from w w w .j a v a2 s . c o m*/ return content; } Properties properties = new Properties(); String propertiesContent = fileUtil.read(BASEDIR + "portal-impl/src/portal.properties"); PropertiesUtil.load(properties, propertiesContent); String[] locales = StringUtil.split(properties.getProperty(PropsKeys.LOCALES)); Arrays.sort(locales); Set<String> urlPatterns = new TreeSet<String>(); for (String locale : locales) { int pos = locale.indexOf(StringPool.UNDERLINE); String languageCode = locale.substring(0, pos); urlPatterns.add(languageCode); urlPatterns.add(locale); } StringBundler sb = new StringBundler(6 * urlPatterns.size()); for (String urlPattern : urlPatterns) { sb.append("\t<servlet-mapping>\n"); sb.append("\t\t<servlet-name>I18n Servlet</servlet-name>\n"); sb.append("\t\t<url-pattern>/"); sb.append(urlPattern); sb.append("/*</url-pattern>\n"); sb.append("\t</servlet-mapping>\n"); } int x = content.indexOf("<servlet-mapping>"); x = content.indexOf("<servlet-name>I18n Servlet</servlet-name>", x); x = content.lastIndexOf("<servlet-mapping>", x) - 1; int y = content.lastIndexOf("<servlet-name>I18n Servlet</servlet-name>"); y = content.indexOf("</servlet-mapping>", y) + 19; String newContent = content.substring(0, x) + sb.toString() + content.substring(y); x = newContent.indexOf("<security-constraint>"); x = newContent.indexOf("<web-resource-name>/c/portal/protected</web-resource-name>", x); x = newContent.indexOf("<url-pattern>", x) - 3; y = newContent.indexOf("<http-method>", x); y = newContent.lastIndexOf("</url-pattern>", y) + 15; sb = new StringBundler(3 * urlPatterns.size() + 1); sb.append("\t\t\t<url-pattern>/c/portal/protected</url-pattern>\n"); for (String urlPattern : urlPatterns) { sb.append("\t\t\t<url-pattern>/"); sb.append(urlPattern); sb.append("/c/portal/protected</url-pattern>\n"); } return newContent.substring(0, x) + sb.toString() + newContent.substring(y); }