List of usage examples for com.liferay.portal.kernel.portlet PortletBagPool put
public static void put(String portletId, PortletBag portletBag)
From source file:com.liferay.opensocial.service.impl.GadgetLocalServiceImpl.java
License:Open Source License
protected Portlet getPortlet(String uuid, long companyId, String name) throws Exception { Portlet portlet = _portletsPool.get(uuid); if (portlet != null) { return portlet; }//from w w w . j a v a 2 s .c om String portletId = getPortletId(uuid); portlet = PortletLocalServiceUtil.clonePortlet(_GADGET_PORTLET_ID); portlet.setCompanyId(companyId); portlet.setPortletId(portletId); PortletApp portletApp = PortletLocalServiceUtil.getPortletApp(ClpSerializer.getServletContextName()); portlet.setPortletApp(portletApp); portlet.setPortletName(portletId); portlet.setDisplayName(portletId); portlet.setPortletClass(GadgetPortlet.class.getName()); Map<String, String> initParams = portlet.getInitParams(); initParams.put(InvokerPortlet.INIT_INVOKER_PORTLET_NAME, _GADGET_PORTLET_NAME); addPortletExtraInfo(portlet, portletApp, name); _portletsPool.put(uuid, portlet); PortletBag portletBag = PortletBagPool.get(_GADGET_PORTLET_ID); portletBag = (PortletBag) portletBag.clone(); portletBag.setPortletName(portletId); portletBag.setPortletInstance(new GadgetPortlet()); PortletBagPool.put(portletId, portletBag); return portlet; }
From source file:com.liferay.portlet.PortletBagFactory.java
License:Open Source License
public PortletBag create(Portlet portlet) throws Exception { PortletApp portletApp = portlet.getPortletApp(); if (!portletApp.isWARFile() && _warFile) { String contextPath = PortalUtil.getPathContext(); _servletContext = ServletContextPool.get(contextPath); _classLoader = PortalClassLoaderUtil.getClassLoader(); }// ww w.j a v a2 s . co m Class<?> portletClass = null; try { portletClass = _classLoader.loadClass(portlet.getPortletClass()); } catch (Throwable e) { _log.error(e, e); PortletLocalServiceUtil.destroyPortlet(portlet); return null; } javax.portlet.Portlet portletInstance = (javax.portlet.Portlet) portletClass.newInstance(); ConfigurationAction configurationActionInstance = newConfigurationAction(portlet); List<Indexer> indexerInstances = newIndexers(portlet); OpenSearch openSearchInstance = newOpenSearch(portlet); initSchedulers(portlet); FriendlyURLMapper friendlyURLMapperInstance = newFriendlyURLMapper(portlet); URLEncoder urlEncoderInstance = newURLEncoder(portlet); PortletDataHandler portletDataHandlerInstance = newPortletDataHandler(portlet); PortletLayoutListener portletLayoutListenerInstance = newPortletLayoutListener(portlet); PollerProcessor pollerProcessorInstance = newPollerProcessor(portlet); MessageListener popMessageListenerInstance = newPOPMessageListener(portlet); SocialActivityInterpreter socialActivityInterpreterInstance = initSocialActivityInterpreterInstance( portlet); SocialRequestInterpreter socialRequestInterpreterInstance = null; if (Validator.isNotNull(portlet.getSocialRequestInterpreterClass())) { socialRequestInterpreterInstance = (SocialRequestInterpreter) newInstance( SocialRequestInterpreter.class, portlet.getSocialRequestInterpreterClass()); socialRequestInterpreterInstance = new SocialRequestInterpreterImpl(portlet.getPortletId(), socialRequestInterpreterInstance); SocialRequestInterpreterLocalServiceUtil.addRequestInterpreter(socialRequestInterpreterInstance); } WebDAVStorage webDAVStorageInstance = null; if (Validator.isNotNull(portlet.getWebDAVStorageClass())) { webDAVStorageInstance = (WebDAVStorage) newInstance(WebDAVStorage.class, portlet.getWebDAVStorageClass()); webDAVStorageInstance.setToken(portlet.getWebDAVStorageToken()); WebDAVUtil.addStorage(webDAVStorageInstance); } Method xmlRpcMethodInstance = null; if (Validator.isNotNull(portlet.getXmlRpcMethodClass())) { xmlRpcMethodInstance = (Method) newInstance(Method.class, portlet.getXmlRpcMethodClass()); XmlRpcServlet.registerMethod(xmlRpcMethodInstance); } ControlPanelEntry controlPanelEntryInstance = null; if (Validator.isNotNull(portlet.getControlPanelEntryClass())) { controlPanelEntryInstance = (ControlPanelEntry) newInstance(ControlPanelEntry.class, portlet.getControlPanelEntryClass()); } List<AssetRendererFactory> assetRendererFactoryInstances = newAssetRendererFactoryInstances(portlet); List<AtomCollectionAdapter<?>> atomCollectionAdapterInstances = newAtomCollectionAdapterInstances(portlet); List<CustomAttributesDisplay> customAttributesDisplayInstances = new ArrayList<CustomAttributesDisplay>(); for (String customAttributesDisplayClass : portlet.getCustomAttributesDisplayClasses()) { CustomAttributesDisplay customAttributesDisplayInstance = (CustomAttributesDisplay) newInstance( CustomAttributesDisplay.class, customAttributesDisplayClass); customAttributesDisplayInstance .setClassNameId(PortalUtil.getClassNameId(customAttributesDisplayInstance.getClassName())); customAttributesDisplayInstance.setPortletId(portlet.getPortletId()); customAttributesDisplayInstances.add(customAttributesDisplayInstance); } PermissionPropagator permissionPropagatorInstance = newPermissionPropagator(portlet); List<WorkflowHandler> workflowHandlerInstances = new ArrayList<WorkflowHandler>(); for (String workflowHandlerClass : portlet.getWorkflowHandlerClasses()) { WorkflowHandler workflowHandlerInstance = (WorkflowHandler) newInstance(WorkflowHandler.class, workflowHandlerClass); workflowHandlerInstances.add(workflowHandlerInstance); WorkflowHandlerRegistryUtil.register(workflowHandlerInstance); } PreferencesValidator preferencesValidatorInstance = null; if (Validator.isNotNull(portlet.getPreferencesValidator())) { preferencesValidatorInstance = (PreferencesValidator) newInstance(PreferencesValidator.class, portlet.getPreferencesValidator()); try { if (PropsValues.PREFERENCE_VALIDATE_ON_STARTUP) { preferencesValidatorInstance.validate( PortletPreferencesFactoryUtil.fromDefaultXML(portlet.getDefaultPreferences())); } } catch (Exception e) { _log.warn("Portlet with the name " + portlet.getPortletId() + " does not have valid default preferences"); } } Map<String, ResourceBundle> resourceBundles = null; String resourceBundle = portlet.getResourceBundle(); if (Validator.isNotNull(resourceBundle) && !resourceBundle.equals(StrutsResourceBundle.class.getName())) { resourceBundles = new HashMap<String, ResourceBundle>(); initResourceBundle(resourceBundles, portlet, null); initResourceBundle(resourceBundles, portlet, LocaleUtil.getDefault()); Set<String> supportedLocales = portlet.getSupportedLocales(); if (supportedLocales.isEmpty()) { supportedLocales = SetUtil.fromArray(PropsValues.LOCALES); } for (String supportedLocale : supportedLocales) { Locale locale = LocaleUtil.fromLanguageId(supportedLocale); initResourceBundle(resourceBundles, portlet, locale); } } PortletBag portletBag = new PortletBagImpl(portlet.getPortletId(), _servletContext, portletInstance, configurationActionInstance, indexerInstances, openSearchInstance, friendlyURLMapperInstance, urlEncoderInstance, portletDataHandlerInstance, portletLayoutListenerInstance, pollerProcessorInstance, popMessageListenerInstance, socialActivityInterpreterInstance, socialRequestInterpreterInstance, webDAVStorageInstance, xmlRpcMethodInstance, controlPanelEntryInstance, assetRendererFactoryInstances, atomCollectionAdapterInstances, customAttributesDisplayInstances, permissionPropagatorInstance, workflowHandlerInstances, preferencesValidatorInstance, resourceBundles); PortletBagPool.put(portlet.getRootPortletId(), portletBag); try { PortletInstanceFactoryUtil.create(portlet, _servletContext); } catch (Exception e) { _log.error(e, e); } return portletBag; }
From source file:com.liferay.wsrp.service.impl.WSRPConsumerPortletLocalServiceImpl.java
License:Open Source License
protected Portlet getPortlet(long companyId, long wsrpConsumerId, String wsrpConsumerPortletUuid, String name, String portletHandle) throws Exception { Portlet portlet = _portletsPool.get(wsrpConsumerPortletUuid); if ((portlet != null) && portlet.isActive()) { return portlet; }//from ww w . j a v a2 s . c om String portletId = getPortletId(wsrpConsumerPortletUuid); portlet = PortletLocalServiceUtil.clonePortlet(_CONSUMER_PORTLET_ID); portlet.setCompanyId(companyId); portlet.setPortletId(portletId); PortletApp portletApp = PortletLocalServiceUtil.getPortletApp(ClpSerializer.getServletContextName()); portlet.setPortletApp(portletApp); portlet.setPortletName(portletId); portlet.setDisplayName(portletId); Map<String, String> initParams = portlet.getInitParams(); initParams.put(InvokerPortlet.INIT_INVOKER_PORTLET_NAME, _CONSUMER_PORTLET_NAME); WSRPConsumer wsrpConsumer = wsrpConsumerPersistence.findByPrimaryKey(wsrpConsumerId); PortletDescription portletDescription = null; try { WSRPConsumerManager wsrpConsumerManager = WSRPConsumerManagerFactory .getWSRPConsumerManager(wsrpConsumer); portletDescription = wsrpConsumerManager.getPortletDescription(portletHandle); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Unable to connect to WSRP producer for portlet " + wsrpConsumerPortletUuid, e); } } if (portletDescription != null) { addPortletExtraInfo(portlet, portletApp, portletDescription, name); portlet.setActive(true); } else { PortletInfo portletInfo = new PortletInfo(name, name, StringPool.BLANK, StringPool.BLANK); portlet.setPortletInfo(portletInfo); } _portletsPool.put(wsrpConsumerPortletUuid, portlet); PortletBag portletBag = PortletBagPool.get(_CONSUMER_PORTLET_ID); portletBag = (PortletBag) portletBag.clone(); portletBag.setPortletName(portletId); ConsumerPortlet consumerPortletInstance = getConsumerPortletInstance(portlet); portletBag.setPortletInstance(consumerPortletInstance); PortletBagPool.put(portletId, portletBag); return portlet; }