protected ThemeLoader(String servletContextName, ServletContext servletContext, String[] xmls) { _servletContextName = servletContextName; _servletContext = servletContext; try { Document doc = SAXReaderUtil.read(xmls[0], true); Element root = doc.getRootElement(); _themesPath = GetterUtil.getString(root.elementText("themes-path"), "/themes"); String fileStorageValue = PropsValues.THEME_LOADER_STORAGE_PATH; fileStorageValue = GetterUtil.getString(root.elementText("file-storage"), fileStorageValue); if (Validator.isNotNull(fileStorageValue)) { _fileStorage = new File(fileStorageValue); _loadFromServletContext = false; } else { _fileStorage = new File(servletContext.getRealPath(_themesPath)); _loadFromServletContext = true; } if (!_fileStorage.exists()) { if (_log.isWarnEnabled()) { _log.warn("File storage " + _fileStorage + " does not exist"); } if (!_fileStorage.mkdirs()) { _log.error("Unable to create theme loader file storage at " + _fileStorage); } } } catch (Exception e) { _log.error(e, e); } loadThemes(); }
protected String importTheme(LayoutSet layoutSet, InputStream themeZip) throws Exception { ThemeLoader themeLoader = ThemeLoaderFactory.getDefaultThemeLoader(); if (themeLoader == null) { _log.error("No theme loaders are deployed"); return null; } ZipReader zipReader = ZipReaderFactoryUtil.getZipReader(themeZip); String lookAndFeelXML = zipReader.getEntryAsString("liferay-look-and-feel.xml"); String themeId = String.valueOf(layoutSet.getGroupId()); if (layoutSet.isPrivateLayout()) { themeId += "-private"; } else { themeId += "-public"; } if (PropsValues.THEME_LOADER_NEW_THEME_ID_ON_IMPORT) { Date now = new Date(); themeId += "-" + Time.getShortTimestamp(now); } String themeName = themeId; lookAndFeelXML = StringUtil.replace( lookAndFeelXML, new String[] {"[$GROUP_ID$]", "[$THEME_ID$]", "[$THEME_NAME$]"}, new String[] {String.valueOf(layoutSet.getGroupId()), themeId, themeName}); FileUtil.deltree(themeLoader.getFileStorage() + StringPool.SLASH + themeId); List<String> zipEntries = zipReader.getEntries(); for (String zipEntry : zipEntries) { String key = zipEntry; if (key.equals("liferay-look-and-feel.xml")) { FileUtil.write( themeLoader.getFileStorage() + StringPool.SLASH + themeId + StringPool.SLASH + key, lookAndFeelXML.getBytes()); } else { InputStream is = zipReader.getEntryAsInputStream(zipEntry); FileUtil.write( themeLoader.getFileStorage() + StringPool.SLASH + themeId + StringPool.SLASH + key, is); } } themeLoader.loadThemes(); ClusterRequest clusterRequest = ClusterRequest.createMulticastRequest(_loadThemesMethodHandler, true); clusterRequest.setFireAndForget(true); ClusterExecutorUtil.execute(clusterRequest); themeId += PortletConstants.WAR_SEPARATOR + themeLoader.getServletContextName(); return PortalUtil.getJsSafePortletId(themeId); }