예제 #1
0
  protected List<Portlet> initPortlets(PluginPackage pluginPackage) throws Exception {

    ServletContext servletContext = getServletContext();

    String[] xmls =
        new String[] {
          HttpUtil.URLtoString(
              servletContext.getResource("/WEB-INF/" + Portal.PORTLET_XML_FILE_NAME_CUSTOM)),
          HttpUtil.URLtoString(servletContext.getResource("/WEB-INF/portlet-ext.xml")),
          HttpUtil.URLtoString(servletContext.getResource("/WEB-INF/liferay-portlet.xml")),
          HttpUtil.URLtoString(servletContext.getResource("/WEB-INF/liferay-portlet-ext.xml")),
          HttpUtil.URLtoString(servletContext.getResource("/WEB-INF/web.xml"))
        };

    PortletLocalServiceUtil.initEAR(servletContext, xmls, pluginPackage);

    PortletBagFactory portletBagFactory = new PortletBagFactory();

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

    List<Portlet> portlets = PortletLocalServiceUtil.getPortlets();

    for (int i = 0; i < portlets.size(); i++) {
      Portlet portlet = portlets.get(i);

      portletBagFactory.create(portlet);

      if (i == 0) {
        initPortletApp(portlet, servletContext);
      }
    }

    servletContext.setAttribute(WebKeys.PLUGIN_PORTLETS, portlets);

    return portlets;
  }
예제 #2
0
  protected com.liferay.portal.model.Portlet addingPortlet(
      ServiceReference<Portlet> serviceReference,
      Portlet portlet,
      String portletName,
      String portletId) {

    warnPorletProperties(portletName, serviceReference);

    Bundle bundle = serviceReference.getBundle();

    BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);

    ServiceRegistrations serviceRegistrations = getServiceRegistrations(bundle);

    BundlePortletApp bundlePortletApp =
        createBundlePortletApp(bundle, bundleWiring.getClassLoader(), serviceRegistrations);

    com.liferay.portal.model.Portlet portletModel = buildPortletModel(bundlePortletApp, portletId);

    portletModel.setPortletName(portletName);

    String displayName =
        GetterUtil.getString(
            serviceReference.getProperty("javax.portlet.display-name"), portletName);

    portletModel.setDisplayName(displayName);

    Class<?> portletClazz = portlet.getClass();

    portletModel.setPortletClass(portletClazz.getName());

    collectJxPortletFeatures(serviceReference, portletModel);
    collectLiferayFeatures(serviceReference, portletModel);

    PortletContextBag portletContextBag =
        new PortletContextBag(bundlePortletApp.getServletContextName());

    PortletContextBagPool.put(bundlePortletApp.getServletContextName(), portletContextBag);

    PortletBagFactory portletBagFactory = new BundlePortletBagFactory(portlet);

    portletBagFactory.setClassLoader(bundleWiring.getClassLoader());
    portletBagFactory.setServletContext(bundlePortletApp.getServletContext());
    portletBagFactory.setWARFile(true);

    try {
      portletBagFactory.create(portletModel);

      checkWebResources(
          bundle.getBundleContext(),
          bundlePortletApp.getServletContextName(),
          bundleWiring.getClassLoader(),
          serviceRegistrations);

      checkResourceBundles(
          bundle.getBundleContext(),
          bundleWiring.getClassLoader(),
          portletModel,
          serviceRegistrations);

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

      deployPortlet(serviceReference, portletModel, companies);

      checkResources(serviceReference, portletModel, companies);

      portletModel.setReady(true);

      if (_log.isInfoEnabled()) {
        _log.info("Added " + serviceReference);
      }

      serviceRegistrations.addServiceReference(serviceReference);

      return portletModel;
    } catch (Exception e) {
      _log.error("Portlet " + portletId + " from " + bundle + " failed to initialize", e);

      return null;
    }
  }