All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.liferay.portal.tools.ToolDependencies Maven / Gradle / Ivy
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portal.tools;
import com.liferay.portal.cache.key.SimpleCacheKeyGenerator;
import com.liferay.portal.json.JSONFactoryImpl;
import com.liferay.portal.kernel.cache.MultiVMPool;
import com.liferay.portal.kernel.cache.PortalCache;
import com.liferay.portal.kernel.cache.PortalCacheException;
import com.liferay.portal.kernel.cache.PortalCacheListener;
import com.liferay.portal.kernel.cache.PortalCacheListenerScope;
import com.liferay.portal.kernel.cache.PortalCacheManager;
import com.liferay.portal.kernel.cache.PortalCacheManagerListener;
import com.liferay.portal.kernel.cache.PortalCacheManagerNames;
import com.liferay.portal.kernel.cache.PortalCacheManagerProvider;
import com.liferay.portal.kernel.cache.SingleVMPool;
import com.liferay.portal.kernel.cache.key.CacheKeyGeneratorUtil;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.model.ModelHintsUtil;
import com.liferay.portal.kernel.security.auth.DefaultFullNameGenerator;
import com.liferay.portal.kernel.security.auth.FullNameGenerator;
import com.liferay.portal.kernel.security.permission.ResourceActionsUtil;
import com.liferay.portal.kernel.security.xml.SecureXMLFactoryProviderUtil;
import com.liferay.portal.kernel.service.permission.PortletPermissionUtil;
import com.liferay.portal.kernel.util.DigesterUtil;
import com.liferay.portal.kernel.util.FastDateFormatFactoryUtil;
import com.liferay.portal.kernel.util.FileUtil;
import com.liferay.portal.kernel.util.FriendlyURLNormalizerUtil;
import com.liferay.portal.kernel.util.HtmlUtil;
import com.liferay.portal.kernel.util.HttpUtil;
import com.liferay.portal.kernel.util.PortalUtil;
import com.liferay.portal.kernel.xml.SAXReaderUtil;
import com.liferay.portal.kernel.xml.UnsecureSAXReaderUtil;
import com.liferay.portal.model.DefaultModelHintsImpl;
import com.liferay.portal.security.permission.ResourceActionsImpl;
import com.liferay.portal.security.xml.SecureXMLFactoryProviderImpl;
import com.liferay.portal.service.permission.PortletPermissionImpl;
import com.liferay.portal.util.DigesterImpl;
import com.liferay.portal.util.FastDateFormatFactoryImpl;
import com.liferay.portal.util.FileImpl;
import com.liferay.portal.util.FriendlyURLNormalizerImpl;
import com.liferay.portal.util.HtmlImpl;
import com.liferay.portal.util.HttpImpl;
import com.liferay.portal.util.InitUtil;
import com.liferay.portal.util.PortalImpl;
import com.liferay.portal.xml.SAXReaderImpl;
import com.liferay.registry.BasicRegistryImpl;
import com.liferay.registry.Registry;
import com.liferay.registry.RegistryUtil;
import java.io.Serializable;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/**
* @author Raymond Augé
*/
public class ToolDependencies {
public static void wireBasic() {
InitUtil.init();
wireCaches();
Registry registry = RegistryUtil.getRegistry();
registry.registerService(
FullNameGenerator.class, new DefaultFullNameGenerator());
CacheKeyGeneratorUtil cacheKeyGeneratorUtil =
new CacheKeyGeneratorUtil();
cacheKeyGeneratorUtil.setDefaultCacheKeyGenerator(
new SimpleCacheKeyGenerator());
DigesterUtil digesterUtil = new DigesterUtil();
digesterUtil.setDigester(new DigesterImpl());
FastDateFormatFactoryUtil fastDateFormatFactoryUtil =
new FastDateFormatFactoryUtil();
fastDateFormatFactoryUtil.setFastDateFormatFactory(
new FastDateFormatFactoryImpl());
FileUtil fileUtil = new FileUtil();
fileUtil.setFile(new FileImpl());
FriendlyURLNormalizerUtil friendlyURLNormalizerUtil =
new FriendlyURLNormalizerUtil();
friendlyURLNormalizerUtil.setFriendlyURLNormalizer(
new FriendlyURLNormalizerImpl());
HtmlUtil htmlUtil = new HtmlUtil();
htmlUtil.setHtml(new HtmlImpl());
HttpUtil httpUtil = new HttpUtil();
httpUtil.setHttp(new HttpImpl());
JSONFactoryUtil jsonFactoryUtil = new JSONFactoryUtil();
jsonFactoryUtil.setJSONFactory(new JSONFactoryImpl());
PortletPermissionUtil portletPermissionUtil =
new PortletPermissionUtil();
portletPermissionUtil.setPortletPermission(new PortletPermissionImpl());
SAXReaderUtil saxReaderUtil = new SAXReaderUtil();
SAXReaderImpl secureSAXReader = new SAXReaderImpl();
secureSAXReader.setSecure(true);
saxReaderUtil.setSAXReader(secureSAXReader);
SecureXMLFactoryProviderUtil secureXMLFactoryProviderUtil =
new SecureXMLFactoryProviderUtil();
secureXMLFactoryProviderUtil.setSecureXMLFactoryProvider(
new SecureXMLFactoryProviderImpl());
UnsecureSAXReaderUtil unsecureSAXReaderUtil =
new UnsecureSAXReaderUtil();
SAXReaderImpl unsecureSAXReader = new SAXReaderImpl();
unsecureSAXReaderUtil.setSAXReader(unsecureSAXReader);
// DefaultModelHintsImpl requires SecureXMLFactoryProviderUtil
ModelHintsUtil modelHintsUtil = new ModelHintsUtil();
DefaultModelHintsImpl defaultModelHintsImpl =
new DefaultModelHintsImpl();
defaultModelHintsImpl.afterPropertiesSet();
modelHintsUtil.setModelHints(defaultModelHintsImpl);
}
public static void wireCaches() {
RegistryUtil.setRegistry(new BasicRegistryImpl());
Registry registry = RegistryUtil.getRegistry();
registry.registerService(
PortalCacheManager.class,
new TestPortalCacheManager<>(PortalCacheManagerNames.MULTI_VM));
registry.registerService(
PortalCacheManager.class,
new TestPortalCacheManager<>(PortalCacheManagerNames.SINGLE_VM));
registry.registerService(MultiVMPool.class, new TestMultiVMPool());
registry.registerService(SingleVMPool.class, new TestSingleVMPool());
}
public static void wireDeployers() {
wireBasic();
PortalUtil portalUtil = new PortalUtil();
portalUtil.setPortal(new PortalImpl());
}
public static void wireServiceBuilder() {
wireDeployers();
ResourceActionsUtil resourceActionsUtil = new ResourceActionsUtil();
ResourceActionsImpl resourceActionsImpl = new ResourceActionsImpl();
resourceActionsImpl.afterPropertiesSet();
resourceActionsUtil.setResourceActions(resourceActionsImpl);
}
private static class TestMultiVMPool implements MultiVMPool {
@Override
public void clear() {
_portalCacheManager.clearAll();
}
/**
* @deprecated As of Judson (7.1.x), replaced by {@link
* #getPortalCache(String)}
*/
@Deprecated
@Override
public PortalCache
getCache(String portalCacheName) {
return getPortalCache(portalCacheName);
}
/**
* @deprecated As of Judson (7.1.x), replaced by {@link
* #getPortalCache(String, boolean)}
*/
@Deprecated
@Override
public PortalCache
getCache(String portalCacheName, boolean blocking) {
return getPortalCache(portalCacheName, blocking);
}
/**
* @deprecated As of Judson (7.1.x), replaced by {@link
* #getPortalCacheManager()}
*/
@Deprecated
@Override
public PortalCacheManager
getCacheManager() {
return getPortalCacheManager();
}
@Override
public PortalCache
getPortalCache(String portalCacheName) {
return _portalCacheManager.getPortalCache(portalCacheName);
}
@Override
public PortalCache
getPortalCache(String portalCacheName, boolean blocking) {
return getPortalCache(portalCacheName);
}
@Override
public PortalCache
getPortalCache(
String portalCacheName, boolean blocking, boolean mvcc) {
return getPortalCache(portalCacheName);
}
@Override
public PortalCacheManager
getPortalCacheManager() {
return _portalCacheManager;
}
/**
* @deprecated As of Judson (7.1.x), replaced by {@link
* #removePortalCache(String)}
*/
@Deprecated
@Override
public void removeCache(String portalCacheName) {
removePortalCache(portalCacheName);
}
@Override
public void removePortalCache(String portalCacheName) {
_portalCacheManager.removePortalCache(portalCacheName);
}
private final PortalCacheManager
_portalCacheManager =
(PortalCacheManager
)
PortalCacheManagerProvider.getPortalCacheManager(
PortalCacheManagerNames.MULTI_VM);
}
private static class TestPortalCache
implements PortalCache {
public TestPortalCache(String portalCacheName) {
_portalCacheName = portalCacheName;
}
@Override
public V get(K key) {
return _map.get(key);
}
@Override
public List getKeys() {
return new ArrayList<>(_map.keySet());
}
/**
* @deprecated As of Judson (7.1.x), replaced by {@link
* #getPortalCacheName()}
*/
@Deprecated
@Override
public String getName() {
return getPortalCacheName();
}
@Override
public PortalCacheManager getPortalCacheManager() {
return null;
}
@Override
public String getPortalCacheName() {
return _portalCacheName;
}
@Override
public void put(K key, V value) {
put(key, value, DEFAULT_TIME_TO_LIVE);
}
@Override
public void put(K key, V value, int timeToLive) {
V oldValue = _map.put(key, value);
for (PortalCacheListener portalCacheListener :
_portalCacheListeners) {
if (oldValue != null) {
portalCacheListener.notifyEntryUpdated(
this, key, value, timeToLive);
}
else {
portalCacheListener.notifyEntryPut(
this, key, value, timeToLive);
}
}
}
@Override
public void registerPortalCacheListener(
PortalCacheListener portalCacheListener) {
_portalCacheListeners.add(portalCacheListener);
}
@Override
public void registerPortalCacheListener(
PortalCacheListener portalCacheListener,
PortalCacheListenerScope portalCacheListenerScope) {
_portalCacheListeners.add(portalCacheListener);
}
@Override
public void remove(K key) {
_map.remove(key);
for (PortalCacheListener portalCacheListener :
_portalCacheListeners) {
portalCacheListener.notifyEntryRemoved(
this, key, null, DEFAULT_TIME_TO_LIVE);
}
}
@Override
public void removeAll() {
_map.clear();
for (PortalCacheListener portalCacheListener :
_portalCacheListeners) {
portalCacheListener.notifyRemoveAll(this);
}
}
@Override
public void unregisterPortalCacheListener(
PortalCacheListener portalCacheListener) {
portalCacheListener.dispose();
_portalCacheListeners.remove(portalCacheListener);
}
@Override
public void unregisterPortalCacheListeners() {
for (PortalCacheListener portalCacheListener :
_portalCacheListeners) {
portalCacheListener.dispose();
}
_portalCacheListeners.clear();
}
private final Map _map = new ConcurrentHashMap<>();
private final List> _portalCacheListeners =
new ArrayList<>();
private final String _portalCacheName;
}
private static class TestPortalCacheManager
implements PortalCacheManager {
@Override
public void clearAll() throws PortalCacheException {
for (PortalCache portalCache : _portalCaches.values()) {
portalCache.removeAll();
}
}
@Override
public void destroy() {
_portalCaches.clear();
}
@Override
public PortalCache getPortalCache(String portalCacheName)
throws PortalCacheException {
return getPortalCache(portalCacheName, false);
}
@Override
public PortalCache getPortalCache(
String portalCacheName, boolean blocking)
throws PortalCacheException {
return getPortalCache(portalCacheName, blocking, false);
}
@Override
public PortalCache getPortalCache(
String portalCacheName, boolean blocking, boolean mvcc)
throws PortalCacheException {
PortalCache portalCache = _portalCaches.get(portalCacheName);
if (portalCache != null) {
return portalCache;
}
portalCache = new TestPortalCache<>(portalCacheName);
PortalCache previousPortalCache = _portalCaches.putIfAbsent(
portalCacheName, portalCache);
if (previousPortalCache != null) {
return previousPortalCache;
}
return portalCache;
}
@Override
public Set
getPortalCacheManagerListeners() {
return Collections.emptySet();
}
@Override
public String getPortalCacheManagerName() {
return _portalCacheManagerName;
}
@Override
public boolean isClusterAware() {
return false;
}
@Override
public void reconfigurePortalCaches(URL configurationURL) {
}
@Override
public boolean registerPortalCacheManagerListener(
PortalCacheManagerListener portalCacheManagerListener) {
return false;
}
@Override
public void removePortalCache(String portalCacheName) {
_portalCaches.remove(portalCacheName);
}
@Override
public boolean unregisterPortalCacheManagerListener(
PortalCacheManagerListener portalCacheManagerListener) {
return false;
}
@Override
public void unregisterPortalCacheManagerListeners() {
}
private TestPortalCacheManager(String portalCacheManagerName) {
_portalCacheManagerName = portalCacheManagerName;
}
private final String _portalCacheManagerName;
private final ConcurrentMap> _portalCaches =
new ConcurrentHashMap<>();
}
private static class TestSingleVMPool implements SingleVMPool {
@Override
public void clear() {
_portalCacheManager.clearAll();
}
/**
* @deprecated As of Judson (7.1.x), replaced by {@link
* #getPortalCache(String)}
*/
@Deprecated
@Override
public PortalCache getCache(
String portalCacheName) {
return getPortalCache(portalCacheName);
}
/**
* @deprecated As of Judson (7.1.x), replaced by {@link
* #getPortalCache(String, boolean)}
*/
@Deprecated
@Override
public PortalCache getCache(
String portalCacheName, boolean blocking) {
return getPortalCache(portalCacheName, blocking);
}
/**
* @deprecated As of Judson (7.1.x), replaced by {@link
* #getPortalCacheManager()}
*/
@Deprecated
@Override
public PortalCacheManager getCacheManager() {
return getPortalCacheManager();
}
@Override
public PortalCache getPortalCache(
String portalCacheName) {
return _portalCacheManager.getPortalCache(portalCacheName);
}
@Override
public PortalCache getPortalCache(
String portalCacheName, boolean blocking) {
return getPortalCache(portalCacheName);
}
@Override
public PortalCacheManager
getPortalCacheManager() {
return _portalCacheManager;
}
/**
* @deprecated As of Judson (7.1.x), replaced by {@link
* #removePortalCache(String)}
*/
@Deprecated
@Override
public void removeCache(String portalCacheName) {
removePortalCache(portalCacheName);
}
@Override
public void removePortalCache(String portalCacheName) {
_portalCacheManager.removePortalCache(portalCacheName);
}
private final PortalCacheManager
_portalCacheManager =
PortalCacheManagerProvider.getPortalCacheManager(
PortalCacheManagerNames.SINGLE_VM);
}
}