示例#1
0
  protected String getOriginalTitle(String title, String prefix) {
    if (!title.startsWith(prefix)) {
      return title;
    }

    title = title.substring(prefix.length());

    long trashEntryId = GetterUtil.getLong(title);

    if (trashEntryId <= 0) {
      return title;
    }

    try {
      TrashEntry trashEntry = TrashEntryLocalServiceUtil.fetchEntry(trashEntryId);

      if (trashEntry == null) {
        TrashVersion trashVersion = TrashVersionLocalServiceUtil.getTrashVersion(trashEntryId);

        title = trashVersion.getTypeSettingsProperty("title");
      } else {
        title = trashEntry.getTypeSettingsProperty("title");
      }
    } catch (Exception e) {
      if (_log.isDebugEnabled()) {
        _log.debug("No trash entry or trash version exists with ID " + trashEntryId);
      }
    }

    return title;
  }
示例#2
0
  @Override
  public List<TrashEntry> getEntries(Hits hits) {
    List<TrashEntry> entries = new ArrayList<TrashEntry>();

    for (Document document : hits.getDocs()) {
      String entryClassName = GetterUtil.getString(document.get(Field.ENTRY_CLASS_NAME));
      long classPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

      try {
        TrashEntry entry = TrashEntryLocalServiceUtil.fetchEntry(entryClassName, classPK);

        if (entry == null) {
          String userName = GetterUtil.getString(document.get(Field.REMOVED_BY_USER_NAME));

          Date removedDate = document.getDate(Field.REMOVED_DATE);

          entry = new TrashEntryImpl();

          entry.setClassName(entryClassName);
          entry.setClassPK(classPK);

          entry.setUserName(userName);
          entry.setCreateDate(removedDate);

          String rootEntryClassName =
              GetterUtil.getString(document.get(Field.ROOT_ENTRY_CLASS_NAME));
          long rootEntryClassPK = GetterUtil.getLong(document.get(Field.ROOT_ENTRY_CLASS_PK));

          TrashEntry rootTrashEntry =
              TrashEntryLocalServiceUtil.fetchEntry(rootEntryClassName, rootEntryClassPK);

          if (rootTrashEntry != null) {
            entry.setRootEntry(rootTrashEntry);
          }
        }

        entries.add(entry);
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          _log.warn(
              "Unable to find trash entry for " + entryClassName + " with primary key " + classPK);
        }
      }
    }

    return entries;
  }
示例#3
0
  @Override
  public PortletURL getViewContentURL(HttpServletRequest request, String className, long classPK)
      throws PortalException {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    if (!themeDisplay.isSignedIn()
        || !isTrashEnabled(themeDisplay.getScopeGroupId())
        || !PortletPermissionUtil.hasControlPanelAccessPermission(
            themeDisplay.getPermissionChecker(),
            themeDisplay.getScopeGroupId(),
            PortletKeys.TRASH)) {

      return null;
    }

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);

    if (trashHandler.isInTrashContainer(classPK)) {
      TrashEntry trashEntry = trashHandler.getTrashEntry(classPK);

      className = trashEntry.getClassName();
      classPK = trashEntry.getClassPK();

      trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);
    }

    TrashRenderer trashRenderer = trashHandler.getTrashRenderer(classPK);

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

    Layout layout = themeDisplay.getLayout();

    PortletURL portletURL =
        PortalUtil.getControlPanelPortletURL(
            request, PortletKeys.TRASH, layout.getLayoutId(), PortletRequest.RENDER_PHASE);

    portletURL.setParameter("struts_action", "/trash/view_content");
    portletURL.setParameter("redirect", themeDisplay.getURLCurrent());

    TrashEntry trashEntry = TrashEntryLocalServiceUtil.getEntry(className, classPK);

    if (trashEntry.getRootEntry() != null) {
      portletURL.setParameter("className", className);
      portletURL.setParameter("classPK", String.valueOf(classPK));
    } else {
      portletURL.setParameter("trashEntryId", String.valueOf(trashEntry.getEntryId()));
    }

    portletURL.setParameter("type", trashRenderer.getType());
    portletURL.setParameter("showActions", Boolean.FALSE.toString());
    portletURL.setParameter("showAssetMetadata", Boolean.TRUE.toString());
    portletURL.setParameter("showEditURL", Boolean.FALSE.toString());

    return portletURL;
  }
示例#4
0
  public String getViewContentURL(String className, long classPK, ThemeDisplay themeDisplay)
      throws PortalException, SystemException {

    if (!themeDisplay.isSignedIn()
        || !isTrashEnabled(themeDisplay.getScopeGroupId())
        || !PortletPermissionUtil.hasControlPanelAccessPermission(
            themeDisplay.getPermissionChecker(),
            themeDisplay.getScopeGroupId(),
            PortletKeys.TRASH)) {

      return null;
    }

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);

    if (trashHandler.isInTrashContainer(classPK)) {
      ContainerModel containerModel = trashHandler.getTrashContainer(classPK);

      className = containerModel.getModelClassName();
      classPK = containerModel.getContainerModelId();

      trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);
    }

    TrashRenderer trashRenderer = trashHandler.getTrashRenderer(classPK);

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

    String namespace = PortalUtil.getPortletNamespace(PortletKeys.TRASH);

    Map<String, String[]> params = new HashMap<String, String[]>();

    params.put(namespace + "struts_action", new String[] {"/trash/view_content"});
    params.put(namespace + "redirect", new String[] {themeDisplay.getURLCurrent()});

    TrashEntry trashEntry = TrashEntryLocalServiceUtil.getEntry(className, classPK);

    if (trashEntry.getRootEntry() != null) {
      params.put(namespace + "className", new String[] {className});
      params.put(namespace + "classPK", new String[] {String.valueOf(classPK)});
    } else {
      params.put(
          namespace + "trashEntryId", new String[] {String.valueOf(trashEntry.getEntryId())});
    }

    params.put(namespace + "type", new String[] {trashRenderer.getType()});
    params.put(namespace + "showActions", new String[] {Boolean.FALSE.toString()});
    params.put(namespace + "showAssetMetadata", new String[] {Boolean.TRUE.toString()});
    params.put(namespace + "showEditURL", new String[] {Boolean.FALSE.toString()});

    return PortalUtil.getControlPanelFullURL(
        themeDisplay.getScopeGroupId(), PortletKeys.TRASH, params);
  }
  @Override
  public boolean isInTrashExplicitly() throws SystemException {
    if (!isInTrash()) {
      return false;
    }

    TrashEntry trashEntry =
        TrashEntryLocalServiceUtil.fetchEntry(getModelClassName(), getTrashEntryClassPK());

    if (trashEntry != null) {
      return true;
    }

    return false;
  }
  @Override
  public TrashEntry getTrashEntry() throws PortalException {
    if (!isInTrash()) {
      return null;
    }

    TrashEntry trashEntry =
        TrashEntryLocalServiceUtil.fetchEntry(getModelClassName(), getTrashEntryClassPK());

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

    TrashHandler trashHandler = getTrashHandler();

    if (!Validator.isNull(trashHandler.getContainerModelClassName(getPrimaryKey()))) {
      ContainerModel containerModel = null;

      try {
        containerModel = trashHandler.getParentContainerModel(this);
      } catch (NoSuchModelException nsme) {
        return null;
      }

      while (containerModel != null) {
        if (containerModel instanceof TrashedModel) {
          TrashedModel trashedModel = (TrashedModel) containerModel;

          return trashedModel.getTrashEntry();
        }

        trashHandler =
            TrashHandlerRegistryUtil.getTrashHandler(
                trashHandler.getContainerModelClassName(containerModel.getContainerModelId()));

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

        containerModel = trashHandler.getContainerModel(containerModel.getParentContainerModelId());
      }
    }

    return null;
  }