public static List<Portlet> getAlwaysExportablePortlets(long companyId) throws Exception {

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

    Iterator<Portlet> itr = portlets.iterator();

    while (itr.hasNext()) {
      Portlet portlet = itr.next();

      if (!portlet.isActive()) {
        itr.remove();

        continue;
      }

      PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance();

      if ((portletDataHandler == null) || !portletDataHandler.isAlwaysExportable()) {

        itr.remove();
      }
    }

    return portlets;
  }
예제 #2
0
  protected String deletePortletData(
      PortletDataContext portletDataContext,
      String portletId,
      PortletPreferences portletPreferences)
      throws Exception {

    Portlet portlet =
        PortletLocalServiceUtil.getPortletById(portletDataContext.getCompanyId(), portletId);

    if (portlet == null) {
      if (_log.isDebugEnabled()) {
        _log.debug(
            "Do not delete portlet data for " + portletId + " because the portlet does not exist");
      }

      return null;
    }

    PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance();

    if (portletDataHandler == null) {
      if (_log.isDebugEnabled()) {
        _log.debug(
            "Do not delete portlet data for "
                + portletId
                + " because the portlet does not have a "
                + "PortletDataHandler");
      }

      return null;
    }

    if (_log.isDebugEnabled()) {
      _log.debug("Deleting data for " + portletId);
    }

    PortletPreferencesImpl portletPreferencesImpl =
        (PortletPreferencesImpl)
            PortletPreferencesFactoryUtil.fromDefaultXML(portletPreferences.getPreferences());

    try {
      portletPreferencesImpl =
          (PortletPreferencesImpl)
              portletDataHandler.deleteData(portletDataContext, portletId, portletPreferencesImpl);
    } finally {
      portletDataContext.setGroupId(portletDataContext.getScopeGroupId());
    }

    if (portletPreferencesImpl == null) {
      return null;
    }

    return PortletPreferencesFactoryUtil.toXML(portletPreferencesImpl);
  }
  public static List<Portlet> getPortletDataHandlerPortlets(List<Layout> layouts) throws Exception {

    List<Portlet> portlets = new ArrayList<Portlet>();
    Set<String> rootPortletIds = new HashSet<String>();

    for (Layout layout : layouts) {
      if (!layout.isTypePortlet()) {
        continue;
      }

      LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

      for (String portletId : layoutTypePortlet.getPortletIds()) {
        Portlet portlet = PortletLocalServiceUtil.getPortletById(layout.getCompanyId(), portletId);

        if ((portlet == null) || rootPortletIds.contains(portlet.getRootPortletId())) {

          continue;
        }

        PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance();

        PortletDataHandlerControl[] portletDataHandlerControls =
            portletDataHandler.getExportConfigurationControls(
                layout.getCompanyId(), layout.getGroupId(), portlet, layout.getPrivateLayout());

        if (ArrayUtil.isNotEmpty(portletDataHandlerControls)) {
          rootPortletIds.add(portlet.getRootPortletId());

          portlets.add(portlet);
        }
      }
    }

    return portlets;
  }
예제 #4
0
  protected String importPortletData(
      PortletDataContext portletDataContext,
      String portletId,
      PortletPreferences portletPreferences,
      Element portletDataElement)
      throws Exception {

    Portlet portlet =
        PortletLocalServiceUtil.getPortletById(portletDataContext.getCompanyId(), portletId);

    if (portlet == null) {
      if (_log.isDebugEnabled()) {
        _log.debug(
            "Do not import portlet data for " + portletId + " because the portlet does not exist");
      }

      return null;
    }

    PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance();

    if (portletDataHandler == null) {
      if (_log.isDebugEnabled()) {
        _log.debug(
            "Do not import portlet data for "
                + portletId
                + " because the portlet does not have a "
                + "PortletDataHandler");
      }

      return null;
    }

    if (_log.isDebugEnabled()) {
      _log.debug("Importing data for " + portletId);
    }

    PortletPreferencesImpl portletPreferencesImpl = null;

    if (portletPreferences != null) {
      portletPreferencesImpl =
          (PortletPreferencesImpl)
              PortletPreferencesFactoryUtil.fromDefaultXML(portletPreferences.getPreferences());
    }

    String portletData =
        portletDataContext.getZipEntryAsString(portletDataElement.attributeValue("path"));

    try {
      AssetValidatorThreadLocal.setEnabled(false);
      SocialActivityThreadLocal.setEnabled(false);
      WorkflowThreadLocal.setEnabled(false);

      portletPreferencesImpl =
          (PortletPreferencesImpl)
              portletDataHandler.importData(
                  portletDataContext, portletId, portletPreferencesImpl, portletData);
    } catch (Exception e) {
      throw e;
    } finally {
      AssetValidatorThreadLocal.setEnabled(true);
      SocialActivityThreadLocal.setEnabled(true);
      WorkflowThreadLocal.setEnabled(true);
    }

    if (portletPreferencesImpl == null) {
      return null;
    }

    return PortletPreferencesFactoryUtil.toXML(portletPreferencesImpl);
  }
  protected void exportPortletData(
      PortletDataContext portletDataContext,
      Portlet portlet,
      Layout layout,
      javax.portlet.PortletPreferences jxPreferences,
      Element parentElement)
      throws Exception {

    PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance();

    if (portletDataHandler == null) {
      return;
    }

    String portletId = portlet.getPortletId();

    Group liveGroup = layout.getGroup();

    if (liveGroup.isStagingGroup()) {
      liveGroup = liveGroup.getLiveGroup();
    }

    boolean staged = liveGroup.isStagedPortlet(portlet.getRootPortletId());

    if (!staged && ImportExportThreadLocal.isLayoutExportInProcess()) {
      if (_log.isDebugEnabled()) {
        _log.debug(
            "Not exporting data for " + portletId + " because it is configured not to be staged");
      }

      return;
    }

    if (_log.isDebugEnabled()) {
      _log.debug("Exporting data for " + portletId);
    }

    StringBundler sb = new StringBundler(4);

    sb.append(portletDataContext.getPortletPath(portletId));
    sb.append(StringPool.SLASH);

    if (portlet.isPreferencesUniquePerLayout()) {
      sb.append(layout.getPlid());
    } else {
      sb.append(portletDataContext.getScopeGroupId());
    }

    sb.append("/portlet-data.xml");

    String path = sb.toString();

    if (!portletDataContext.isPathNotProcessed(path)) {
      return;
    }

    long lastPublishDate =
        GetterUtil.getLong(jxPreferences.getValue("last-publish-date", StringPool.BLANK));

    Date startDate = portletDataContext.getStartDate();

    if ((lastPublishDate > 0) && (startDate != null) && (lastPublishDate < startDate.getTime())) {

      portletDataContext.setStartDate(new Date(lastPublishDate));
    }

    String data = null;

    long groupId = portletDataContext.getGroupId();

    portletDataContext.setGroupId(portletDataContext.getScopeGroupId());

    try {
      data = portletDataHandler.exportData(portletDataContext, portletId, jxPreferences);
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      portletDataContext.setGroupId(groupId);
      portletDataContext.setStartDate(startDate);
    }

    if (Validator.isNull(data)) {
      if (_log.isDebugEnabled()) {
        _log.debug("Not exporting data for " + portletId + " because null data was returned");
      }

      return;
    }

    Element portletDataElement = parentElement.addElement("portlet-data");

    portletDataElement.addAttribute("path", path);

    portletDataContext.addZipEntry(path, data);

    Date endDate = portletDataContext.getEndDate();

    if (endDate != null) {
      try {
        jxPreferences.setValue("last-publish-date", String.valueOf(endDate.getTime()));

        jxPreferences.store();
      } catch (Exception e) {
        _log.error(e, e);
      }
    }
  }