@Override
  public void clear(Portlet portlet, boolean resetRemotePortletBag) {
    String rootPortletId = portlet.getRootPortletId();

    Map<String, InvokerPortlet> portletInstances = _pool.remove(rootPortletId);

    if (portletInstances != null) {
      InvokerPortlet rootInvokerPortletInstance = portletInstances.remove(rootPortletId);

      if (rootInvokerPortletInstance != null) {
        rootInvokerPortletInstance.destroy();
      }

      portletInstances.clear();
    }

    PortletApp portletApp = portlet.getPortletApp();

    if (resetRemotePortletBag && portletApp.isWARFile()) {
      PortletBag portletBag = PortletBagPool.remove(rootPortletId);

      if (portletBag != null) {
        portletBag.destroy();
      }
    }
  }
  public static void importPortletsLanguages() throws Exception {
    List<Portlet> portlets = PortletLocalServiceUtil.getPortlets();

    for (Portlet portlet : portlets) {
      if (StringUtils.isNotBlank(portlet.getContextPath())) {

        String portletId = portlet.getPortletId();
        String bundleName = portlet.getPluginPackage().getName();
        if (StringUtils.isBlank(bundleName)) {
          bundleName = portlet.getPortletName();
        }

        com.liferay.portal.kernel.portlet.PortletBag portletBag =
            com.liferay.portal.kernel.portlet.PortletBagPool.get(portletId);
        if (portletBag != null) {
          ServletContext servletContext = portletBag.getServletContext();
          importPortletLanguages(servletContext, bundleName);
        }
      }
    }
  }
예제 #3
0
  @Override
  public void removedService(
      ServiceReference<Portlet> serviceReference, com.liferay.portal.model.Portlet portletModel) {

    portletModel.unsetReady();

    ServiceRegistrations serviceRegistrations =
        _serviceRegistrations.get(serviceReference.getBundle());

    if (serviceRegistrations == null) {
      return;
    }

    BundlePortletApp bundlePortletApp = serviceRegistrations.getBundlePortletApp();

    bundlePortletApp.removePortlet(portletModel);

    serviceRegistrations.removeServiceReference(serviceReference);

    BundleContext bundleContext = _componentContext.getBundleContext();

    bundleContext.ungetService(serviceReference);

    _portletInstanceFactory.destroy(portletModel);

    List<Company> companies = _companyLocalService.getCompanies();

    for (Company company : companies) {
      PortletCategory portletCategory =
          (PortletCategory) WebAppPool.get(company.getCompanyId(), WebKeys.PORTLET_CATEGORY);

      portletCategory.separate(portletModel.getRootPortletId());
    }

    PortletBag portletBag = PortletBagPool.remove(portletModel.getRootPortletId());

    if (portletBag != null) {
      portletBag.destroy();
    }
  }
  @Override
  public InvokerPortlet create(
      Portlet portlet, ServletContext servletContext, boolean destroyPrevious)
      throws PortletException {

    if (destroyPrevious) {
      destroyRelated(portlet);
    }

    boolean instanceable = false;

    boolean deployed = !portlet.isUndeployedPortlet();

    if (portlet.isInstanceable()
        && deployed
        && PortletConstants.hasInstanceId(portlet.getPortletId())) {

      instanceable = true;
    }

    String rootPortletId = portlet.getRootPortletId();

    InvokerPortlet rootInvokerPortletInstance = null;

    Map<String, InvokerPortlet> portletInstances = null;

    if (deployed) {
      portletInstances = _pool.get(rootPortletId);

      if (portletInstances == null) {
        portletInstances = new ConcurrentHashMap<>();

        _pool.put(rootPortletId, portletInstances);
      } else {
        if (instanceable) {
          InvokerPortlet instanceInvokerPortletInstance =
              portletInstances.get(portlet.getPortletId());

          if (instanceInvokerPortletInstance != null) {
            return instanceInvokerPortletInstance;
          }
        }

        rootInvokerPortletInstance = portletInstances.get(rootPortletId);
      }
    }

    if (rootInvokerPortletInstance == null) {
      PortletBag portletBag = PortletBagPool.get(rootPortletId);

      // Portlet bag should never be null unless the portlet has been
      // undeployed

      if (portletBag == null) {
        PortletBagFactory portletBagFactory = new PortletBagFactory();

        portletBagFactory.setClassLoader(ClassLoaderUtil.getPortalClassLoader());
        portletBagFactory.setServletContext(servletContext);
        portletBagFactory.setWARFile(false);

        try {
          portletBag = portletBagFactory.create(portlet);
        } catch (Exception e) {
          throw new PortletException(e);
        }
      }

      PortletConfig portletConfig = PortletConfigFactoryUtil.create(portlet, servletContext);

      rootInvokerPortletInstance = init(portlet, portletConfig, portletBag.getPortletInstance());

      if (deployed) {
        portletInstances.put(rootPortletId, rootInvokerPortletInstance);
      }
    }

    if (!instanceable) {
      return rootInvokerPortletInstance;
    }

    javax.portlet.Portlet portletInstance = rootInvokerPortletInstance.getPortletInstance();

    PortletConfig portletConfig = PortletConfigFactoryUtil.create(portlet, servletContext);

    PortletContext portletContext = portletConfig.getPortletContext();
    boolean checkAuthToken = rootInvokerPortletInstance.isCheckAuthToken();
    boolean facesPortlet = rootInvokerPortletInstance.isFacesPortlet();
    boolean strutsPortlet = rootInvokerPortletInstance.isStrutsPortlet();
    boolean strutsBridgePortlet = rootInvokerPortletInstance.isStrutsBridgePortlet();

    InvokerPortlet instanceInvokerPortletInstance =
        _invokerPortletFactory.create(
            portlet,
            portletInstance,
            portletConfig,
            portletContext,
            (InvokerFilterContainer) rootInvokerPortletInstance,
            checkAuthToken,
            facesPortlet,
            strutsPortlet,
            strutsBridgePortlet);

    if (deployed) {
      portletInstances.put(portlet.getPortletId(), instanceInvokerPortletInstance);
    }

    return instanceInvokerPortletInstance;
  }