protected void addTrigger( SchedulerEntry schedulerEntry, ServiceReference<SchedulerEntry> serviceReference) { String propertyKey = schedulerEntry.getPropertyKey(); if (Validator.isNull(propertyKey)) { return; } long bundleId = GetterUtil.getLong(serviceReference.getProperty("bundle.id"), -1); String triggerValue = null; if (bundleId != 0) { Class<?> clazz = schedulerEntry.getClass(); ClassLoader classloader = clazz.getClassLoader(); triggerValue = getPluginPropertyValue(classloader, propertyKey); } else { triggerValue = PrefsPropsUtil.getString(propertyKey); } if (_log.isDebugEnabled()) { _log.debug("Scheduler property key " + propertyKey + " has trigger value " + triggerValue); } if (Validator.isNotNull(triggerValue)) { schedulerEntry.setTriggerValue(triggerValue); } }
@Override public SchedulerEntry addingService(ServiceReference<SchedulerEntry> serviceReference) { Registry registry = RegistryUtil.getRegistry(); SchedulerEntry schedulerEntry = registry.getService(serviceReference); StorageType storageType = StorageType.MEMORY_CLUSTERED; if (schedulerEntry instanceof StorageTypeAware) { StorageTypeAware storageTypeAware = (StorageTypeAware) schedulerEntry; storageType = storageTypeAware.getStorageType(); } addTrigger(schedulerEntry, serviceReference); String portletId = (String) serviceReference.getProperty("javax.portlet.name"); try { SchedulerEngineHelperUtil.schedule(schedulerEntry, storageType, portletId, 0); return schedulerEntry; } catch (SchedulerException e) { _log.error(e, e); } return null; }
@Override public IndexerPostProcessor addingService( ServiceReference<IndexerPostProcessor> serviceReference) { Registry registry = RegistryUtil.getRegistry(); IndexerPostProcessor indexerPostProcessor = registry.getService(serviceReference); List<String> indexerClassNames = StringPlus.asList(serviceReference.getProperty("indexer.class.name")); for (String indexerClassName : indexerClassNames) { Indexer indexer = IndexerRegistryUtil.getIndexer(indexerClassName); if (indexer == null) { _log.error("No indexer for " + indexerClassName + " was found"); continue; } indexer.registerIndexerPostProcessor(indexerPostProcessor); } return indexerPostProcessor; }
@Override public ResourceBundle addingService(ServiceReference<ResourceBundle> serviceReference) { Registry registry = RegistryUtil.getRegistry(); ResourceBundle resourceBundle = registry.getService(serviceReference); String languageId = GetterUtil.getString(serviceReference.getProperty("language.id"), StringPool.BLANK); Map<String, String> languageMap = new HashMap<>(); Locale locale = null; if (Validator.isNotNull(languageId)) { locale = LocaleUtil.fromLanguageId(languageId, true); } else { locale = new Locale(StringPool.BLANK); } Enumeration<String> keys = resourceBundle.getKeys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); String value = ResourceBundleUtil.getString(resourceBundle, key); languageMap.put(key, value); } Map<String, String> oldLanguageMap = _putLanguageMap(locale, languageMap); _oldLanguageMaps.put(serviceReference, oldLanguageMap); return resourceBundle; }
@Test public void testGetCustomJspBags() { Map<ServiceReference<CustomJspBag>, CustomJspBag> customJspBags = CustomJspBagRegistryUtil.getCustomJspBags(); for (Entry<ServiceReference<CustomJspBag>, CustomJspBag> entry : customJspBags.entrySet()) { ServiceReference<CustomJspBag> serviceReference = entry.getKey(); String contextId = GetterUtil.getString(serviceReference.getProperty("context.id")); if (!contextId.equals("TestCustomJspBag")) { continue; } return; } Assert.fail(); }
@Override public Object addingService(ServiceReference<Object> serviceReference) { List<String> authTokenIgnoreActions = StringPlus.asList(serviceReference.getProperty(PropsKeys.AUTH_TOKEN_IGNORE_ACTIONS)); _portletCSRFWhitelistActions.addAll(authTokenIgnoreActions); Registry registry = RegistryUtil.getRegistry(); return registry.getService(serviceReference); }
@Override public void removedService( ServiceReference<ResourceBundle> serviceReference, ResourceBundle resourceBundle) { Registry registry = RegistryUtil.getRegistry(); registry.ungetService(serviceReference); String languageId = (String) serviceReference.getProperty("language.id"); _resourceBundles.remove(languageId); }
@Override public ResourceBundle addingService(ServiceReference<ResourceBundle> serviceReference) { Registry registry = RegistryUtil.getRegistry(); ResourceBundle resourceBundle = registry.getService(serviceReference); String languageId = (String) serviceReference.getProperty("language.id"); _resourceBundles.put(languageId, resourceBundle); return resourceBundle; }
@Override public void removedService( ServiceReference<CustomJspBag> serviceReference, CustomJspBag customJspBag) { Registry registry = RegistryUtil.getRegistry(); registry.ungetService(serviceReference); String contextId = GetterUtil.getString(serviceReference.getProperty("context.id")); for (String customJsp : customJspBag.getCustomJsps()) { String customJspDir = customJspBag.getCustomJspDir(); int pos = customJsp.indexOf(customJspDir); String portalJsp = customJsp.substring(pos + customJspDir.length()); if (customJspBag.isCustomJspGlobal()) { File portalJspFile = new File(PortalUtil.getPortalWebDir() + portalJsp); File portalJspBackupFile = getPortalJspBackupFile(portalJspFile); if (portalJspBackupFile.exists()) { try { FileUtil.copyFile(portalJspBackupFile, portalJspFile); } catch (IOException e) { return; } portalJspBackupFile.delete(); } else if (portalJspFile.exists()) { portalJspFile.delete(); } } else { portalJsp = CustomJspRegistryUtil.getCustomJspFileName(contextId, portalJsp); File portalJspFile = new File(PortalUtil.getPortalWebDir() + portalJsp); if (portalJspFile.exists()) { portalJspFile.delete(); } } } if (!customJspBag.isCustomJspGlobal()) { CustomJspRegistryUtil.unregisterServletContextName(contextId); } _customJspBagsMap.remove(serviceReference); }
@Override public synchronized void removedService( ServiceReference<InvokerPortletFactory> serviceReference, InvokerPortletFactory invokerPortletFactory) { Registry registry = RegistryUtil.getRegistry(); registry.ungetService(serviceReference); serviceReference = registry.getServiceReference(InvokerPortletFactory.class); if (serviceReference != null) { _invokerPortletFactory = registry.getService(serviceReference); _serviceRanking = GetterUtil.getLong(serviceReference.getProperty("service.ranking")); } }
@Override public synchronized InvokerPortletFactory addingService( ServiceReference<InvokerPortletFactory> serviceReference) { Registry registry = RegistryUtil.getRegistry(); InvokerPortletFactory invokerPortletFactory = registry.getService(serviceReference); long serviceRanking = GetterUtil.getLong(serviceReference.getProperty("service.ranking")); if ((_invokerPortletFactory == null) || (serviceRanking > _serviceRanking)) { _invokerPortletFactory = invokerPortletFactory; _serviceRanking = serviceRanking; } return invokerPortletFactory; }
@Override public void removedService( ServiceReference<ResourceBundle> serviceReference, ResourceBundle resourceBundle) { Registry registry = RegistryUtil.getRegistry(); registry.ungetService(serviceReference); String languageId = GetterUtil.getString(serviceReference.getProperty("language.id"), StringPool.BLANK); Locale locale = null; if (Validator.isNotNull(languageId)) { locale = LocaleUtil.fromLanguageId(languageId, true); } else { locale = new Locale(StringPool.BLANK); } Map<String, String> languageMap = _oldLanguageMaps.get(serviceReference); _putLanguageMap(locale, languageMap); }
@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; }
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(); }