protected void verifyCustomJsps(String contextId, CustomJspBag customJspBag) throws DuplicateCustomJspException { Set<String> customJsps = new HashSet<>(); for (String customJsp : customJspBag.getCustomJsps()) { String portalJsp = getPortalJsp(customJsp, customJspBag.getCustomJspDir()); customJsps.add(portalJsp); } Map<String, String> conflictingCustomJsps = new HashMap<>(); for (Map.Entry<ServiceReference<CustomJspBag>, CustomJspBag> entry : _customJspBagsMap.entrySet()) { CustomJspBag currentCustomJspBag = entry.getValue(); if (!currentCustomJspBag.isCustomJspGlobal()) { continue; } ServiceReference<CustomJspBag> serviceReference = entry.getKey(); String contextName = GetterUtil.getString(serviceReference.getProperty("context.name")); List<String> currentCustomJsps = currentCustomJspBag.getCustomJsps(); for (String currentCustomJsp : currentCustomJsps) { String currentPortalJsp = getPortalJsp(currentCustomJsp, currentCustomJspBag.getCustomJspDir()); if (customJsps.contains(currentPortalJsp)) { conflictingCustomJsps.put(currentPortalJsp, contextName); } } } if (conflictingCustomJsps.isEmpty()) { return; } _log.error(contextId + " conflicts with the installed hooks"); if (_log.isDebugEnabled()) { Log log = SanitizerLogWrapper.allowCRLF(_log); StringBundler sb = new StringBundler(conflictingCustomJsps.size() * 4 + 2); sb.append("Colliding JSP files in "); sb.append(contextId); sb.append(StringPool.NEW_LINE); int i = 0; for (Map.Entry<String, String> entry : conflictingCustomJsps.entrySet()) { sb.append(entry.getKey()); sb.append(" with "); sb.append(entry.getValue()); if ((i + 1) < conflictingCustomJsps.size()) { sb.append(StringPool.NEW_LINE); } i++; } log.debug(sb.toString()); } throw new DuplicateCustomJspException(); }
@Override public CustomJspBag addingService(ServiceReference<CustomJspBag> serviceReference) { Registry registry = RegistryUtil.getRegistry(); CustomJspBag customJspBag = registry.getService(serviceReference); List<String> customJsps = customJspBag.getCustomJsps(); if (customJsps.isEmpty()) { getCustomJsps( customJspBag.getURLContainer(), customJspBag.getCustomJspDir(), customJspBag.getCustomJsps()); customJsps = customJspBag.getCustomJsps(); if (customJsps.isEmpty()) { return null; } } if (_log.isDebugEnabled()) { StringBundler sb = new StringBundler(customJsps.size() * 2); sb.append("Custom JSP files:\n"); for (int i = 0; i < customJsps.size(); i++) { String customJsp = customJsps.get(0); sb.append(customJsp); if ((i + 1) < customJsps.size()) { sb.append(StringPool.NEW_LINE); } } Log log = SanitizerLogWrapper.allowCRLF(_log); log.debug(sb.toString()); } String contextId = GetterUtil.getString(serviceReference.getProperty("context.id")); if (customJspBag.isCustomJspGlobal() && !_customJspBagsMap.isEmpty()) { try { verifyCustomJsps(contextId, customJspBag); } catch (DuplicateCustomJspException e) { return null; } } _customJspBagsMap.put(serviceReference, customJspBag); String contextName = GetterUtil.getString(serviceReference.getProperty("context.name")); try { initCustomJspBag(contextId, contextName, customJspBag); } catch (Exception e) { return null; } return customJspBag; }
public static synchronized void init() { if (_initialized) { return; } StopWatch stopWatch = new StopWatch(); stopWatch.start(); // Set the default locale used by Liferay. This locale is no longer set // at the VM level. See LEP-2584. String userLanguage = SystemProperties.get("user.language"); String userCountry = SystemProperties.get("user.country"); String userVariant = SystemProperties.get("user.variant"); LocaleUtil.setDefault(userLanguage, userCountry, userVariant); // Set the default time zone used by Liferay. This time zone is no // longer set at the VM level. See LEP-2584. String userTimeZone = SystemProperties.get("user.timezone"); TimeZoneUtil.setDefault(userTimeZone); // Shared class loader try { PortalClassLoaderUtil.setClassLoader(ClassLoaderUtil.getContextClassLoader()); } catch (Exception e) { e.printStackTrace(); } // Properties com.liferay.portal.kernel.util.PropsUtil.setProps(new PropsImpl()); // Log4J if (GetterUtil.getBoolean(SystemProperties.get("log4j.configure.on.startup"), true)) { ClassLoader classLoader = InitUtil.class.getClassLoader(); Log4JUtil.configureLog4J(classLoader); } // Shared log try { LogFactoryUtil.setLogFactory(new Log4jLogFactoryImpl()); } catch (Exception e) { e.printStackTrace(); } // Log sanitizer SanitizerLogWrapper.init(); // Java properties JavaDetector.isJDK5(); // Security manager SecurityManagerUtil.init(); if (SecurityManagerUtil.ENABLED) { com.liferay.portal.kernel.util.PropsUtil.setProps( DoPrivilegedUtil.wrap(com.liferay.portal.kernel.util.PropsUtil.getProps())); LogFactoryUtil.setLogFactory(DoPrivilegedUtil.wrap(LogFactoryUtil.getLogFactory())); } // Cache registry CacheRegistryUtil.setCacheRegistry(DoPrivilegedUtil.wrap(new CacheRegistryImpl())); // Configuration factory ConfigurationFactoryUtil.setConfigurationFactory( DoPrivilegedUtil.wrap(new ConfigurationFactoryImpl())); // Data source factory DataSourceFactoryUtil.setDataSourceFactory(DoPrivilegedUtil.wrap(new DataSourceFactoryImpl())); // DB factory DBFactoryUtil.setDBFactory(DoPrivilegedUtil.wrap(new DBFactoryImpl())); // ROME XmlReader.setDefaultEncoding(StringPool.UTF8); if (_PRINT_TIME) { System.out.println("InitAction takes " + stopWatch.getTime() + " ms"); } _initialized = true; }