Exemplo n.º 1
0
  @Override
  public String getAbsolutePath(PortletRequest portletRequest, long folderId)
      throws PortalException, SystemException {

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

    if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
      return themeDisplay.translate("home");
    }

    Folder folder = DLAppLocalServiceUtil.getFolder(folderId);

    List<Folder> folders = folder.getAncestors();

    Collections.reverse(folders);

    StringBundler sb = new StringBundler((folders.size() * 3) + 5);

    sb.append(themeDisplay.translate("home"));
    sb.append(StringPool.SPACE);

    for (Folder curFolder : folders) {
      sb.append(StringPool.RAQUO);
      sb.append(StringPool.SPACE);
      sb.append(curFolder.getName());
    }

    sb.append(StringPool.RAQUO);
    sb.append(StringPool.SPACE);
    sb.append(folder.getName());

    return sb.toString();
  }
  public static void addPortletBreadcrumbEntries(
      Folder folder, HttpServletRequest request, PortletURL portletURL) throws Exception {

    long defaultFolderId = _getDefaultFolderId(request);

    List<Folder> ancestorFolders = Collections.emptyList();

    if ((folder != null) && (folder.getFolderId() != defaultFolderId)) {
      ancestorFolders = folder.getAncestors();

      int indexOfRootFolder = -1;

      for (int i = 0; i < ancestorFolders.size(); i++) {
        Folder ancestorFolder = ancestorFolders.get(i);

        if (defaultFolderId == ancestorFolder.getFolderId()) {
          indexOfRootFolder = i;
        }
      }

      if (indexOfRootFolder > -1) {
        ancestorFolders = ancestorFolders.subList(0, indexOfRootFolder);
      }
    }

    Collections.reverse(ancestorFolders);

    for (Folder ancestorFolder : ancestorFolders) {
      portletURL.setParameter("folderId", String.valueOf(ancestorFolder.getFolderId()));

      Map<String, Object> data = new HashMap<String, Object>();

      data.put("folder-id", ancestorFolder.getFolderId());

      PortalUtil.addPortletBreadcrumbEntry(
          request, ancestorFolder.getName(), portletURL.toString(), data);
    }

    long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;

    if (folder != null) {
      folderId = folder.getFolderId();
    }

    portletURL.setParameter("folderId", String.valueOf(folderId));

    if ((folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) && (folderId != defaultFolderId)) {

      Map<String, Object> data = new HashMap<String, Object>();

      data.put("folder-id", folderId);

      PortalUtil.addPortletBreadcrumbEntry(request, folder.getName(), portletURL.toString(), data);
    }
  }
Exemplo n.º 3
0
  public static void addPortletBreadcrumbEntries(
      Folder folder, HttpServletRequest request, RenderResponse renderResponse) throws Exception {

    String mvcRenderCommandName = ParamUtil.getString(request, "mvcRenderCommandName");

    PortletURL portletURL = renderResponse.createRenderURL();

    if (mvcRenderCommandName.equals("/document_library/select_folder")) {
      ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

      portletURL.setParameter("mvcRenderCommandName", mvcRenderCommandName);
      portletURL.setWindowState(LiferayWindowState.POP_UP);

      PortalUtil.addPortletBreadcrumbEntry(
          request, themeDisplay.translate("home"), portletURL.toString());
    } else {
      portletURL.setParameter("mvcRenderCommandName", "/image_gallery_display/view");
    }

    long defaultFolderId = getDefaultFolderId(request);

    List<Folder> ancestorFolders = Collections.emptyList();

    if ((folder != null) && (folder.getFolderId() != defaultFolderId)) {
      ancestorFolders = folder.getAncestors();

      int indexOfRootFolder = -1;

      for (int i = 0; i < ancestorFolders.size(); i++) {
        Folder ancestorFolder = ancestorFolders.get(i);

        if (defaultFolderId == ancestorFolder.getFolderId()) {
          indexOfRootFolder = i;
        }
      }

      if (indexOfRootFolder > -1) {
        ancestorFolders = ancestorFolders.subList(0, indexOfRootFolder);
      }
    }

    Collections.reverse(ancestorFolders);

    for (Folder ancestorFolder : ancestorFolders) {
      portletURL.setParameter("folderId", String.valueOf(ancestorFolder.getFolderId()));

      PortalUtil.addPortletBreadcrumbEntry(
          request, ancestorFolder.getName(), portletURL.toString());
    }

    portletURL.setParameter("folderId", String.valueOf(folder.getFolderId()));

    PortalUtil.addPortletBreadcrumbEntry(request, folder.getName(), portletURL.toString());
  }
  private void _getFolders(CommandArgument commandArgument, Document document, Node rootNode)
      throws Exception {

    Element foldersElement = document.createElement("Folders");

    rootNode.appendChild(foldersElement);

    if (commandArgument.getCurrentFolder().equals(StringPool.SLASH)) {
      getRootFolders(commandArgument, document, foldersElement);
    } else {
      Group group = commandArgument.getCurrentGroup();

      Folder folder = _getFolder(group.getGroupId(), commandArgument.getCurrentFolder());

      List<Folder> folders = DLAppServiceUtil.getFolders(group.getGroupId(), folder.getFolderId());

      for (Folder curFolder : folders) {
        Element folderElement = document.createElement("Folder");

        foldersElement.appendChild(folderElement);

        folderElement.setAttribute("name", curFolder.getName());
      }
    }
  }
  private Folder _getFolder(long groupId, String folderName) throws Exception {

    DLFolder dlFolder = new DLFolderImpl();

    dlFolder.setFolderId(DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
    dlFolder.setGroupId(groupId);

    Folder folder = new LiferayFolder(dlFolder);

    if (folderName.equals(StringPool.SLASH)) {
      return folder;
    }

    StringTokenizer st = new StringTokenizer(folderName, StringPool.SLASH);

    while (st.hasMoreTokens()) {
      String curFolderName = st.nextToken();

      List<Folder> folders = DLAppServiceUtil.getFolders(groupId, folder.getFolderId());

      for (Folder curFolder : folders) {
        if (curFolder.getName().equals(curFolderName)) {
          folder = curFolder;

          break;
        }
      }
    }

    return folder;
  }
  public void moveFolder(Folder folder) throws PortalException, SystemException {

    if (!isStagingGroup(folder.getGroupId())) {
      dlSyncLocalService.updateSync(
          folder.getFolderId(),
          folder.getParentFolderId(),
          folder.getName(),
          folder.getDescription(),
          DLSyncConstants.EVENT_UPDATE,
          "-1");
    }
  }
  public void addFolder(Folder folder, ServiceContext serviceContext)
      throws PortalException, SystemException {

    if (!isStagingGroup(folder.getGroupId())) {
      dlSyncLocalService.addSync(
          folder.getFolderId(),
          folder.getUuid(),
          folder.getCompanyId(),
          folder.getRepositoryId(),
          folder.getParentFolderId(),
          folder.getName(),
          folder.getDescription(),
          DLSyncConstants.TYPE_FOLDER,
          "-1");
    }
  }
  public void deleteFolder(Folder folder) throws PortalException, SystemException {

    // Sync

    if (!isStagingGroup(folder.getGroupId())) {
      dlSyncLocalService.updateSync(
          folder.getFolderId(),
          folder.getParentFolderId(),
          folder.getName(),
          folder.getDescription(),
          DLSyncConstants.EVENT_DELETE,
          "-1");
    }

    // Trash

    if (folder.getModel() instanceof DLFolder) {
      trashEntryLocalService.deleteEntry(DLFolderConstants.getClassName(), folder.getFolderId());
    }
  }
  protected void copyFolder(
      Repository repository, Folder srcFolder, Folder destFolder, ServiceContext serviceContext)
      throws PortalException, SystemException {

    List<FileEntry> srcFileEntries =
        repository.getFileEntries(
            srcFolder.getFolderId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);

    for (FileEntry srcFileEntry : srcFileEntries) {
      try {
        FileEntry fileEntry =
            repository.copyFileEntry(
                destFolder.getGroupId(),
                srcFileEntry.getFileEntryId(),
                destFolder.getFolderId(),
                serviceContext);

        DLProcessorRegistryUtil.trigger(fileEntry);
      } catch (Exception e) {
        _log.error(e, e);

        continue;
      }
    }

    List<Folder> srcSubfolders =
        repository.getFolders(
            srcFolder.getFolderId(), false, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);

    for (Folder srcSubfolder : srcSubfolders) {
      Folder destSubfolder =
          repository.addFolder(
              destFolder.getFolderId(),
              srcSubfolder.getName(),
              srcSubfolder.getDescription(),
              serviceContext);

      copyFolder(repository, srcSubfolder, destSubfolder, serviceContext);
    }
  }
  protected String getFolderLink(long classPK, ServiceContext serviceContext) throws Exception {

    FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(classPK);

    if (fileEntry.getFolderId() <= 0) {
      return null;
    }

    StringBundler sb = new StringBundler(6);

    sb.append(serviceContext.getPortalURL());
    sb.append(serviceContext.getPathMain());
    sb.append("/document_library/find_folder?groupId=");
    sb.append(fileEntry.getRepositoryId());
    sb.append("&folderId=");
    sb.append(fileEntry.getFolderId());

    Folder folder = fileEntry.getFolder();

    String folderName = HtmlUtil.escape(folder.getName());

    return wrapLink(sb.toString(), folderName);
  }
  protected void sendDocumentLibrary(
      HttpServletRequest request,
      HttpServletResponse response,
      User user,
      String path,
      String[] pathArray)
      throws Exception {

    if (!PropsValues.WEB_SERVER_SERVLET_DIRECTORY_INDEXING_ENABLED) {
      response.setStatus(HttpServletResponse.SC_FORBIDDEN);

      return;
    }

    long groupId = _getGroupId(user.getCompanyId(), pathArray[0]);
    long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;

    for (int i = 1; i < pathArray.length; i++) {
      String name = pathArray[i];

      try {
        Folder folder = DLAppServiceUtil.getFolder(groupId, folderId, name);

        folderId = folder.getFolderId();
      } catch (NoSuchFolderException nsfe) {
        if (i != (pathArray.length - 1)) {
          throw nsfe;
        }

        String title = name;

        sendFile(response, user, groupId, folderId, title);

        return;
      }
    }

    try {
      sendFile(response, user, groupId, folderId, "index.html");

      return;
    } catch (Exception e) {
      if ((e instanceof NoSuchFileEntryException) || (e instanceof PrincipalException)) {

        try {
          sendFile(response, user, groupId, folderId, "index.htm");

          return;
        } catch (NoSuchFileEntryException nsfee) {
        } catch (PrincipalException pe) {
        }
      } else {
        throw e;
      }
    }

    List<WebServerEntry> webServerEntries = new ArrayList<WebServerEntry>();

    webServerEntries.add(new WebServerEntry(path, "../"));

    List<Folder> folders = DLAppServiceUtil.getFolders(groupId, folderId);

    for (Folder folder : folders) {
      WebServerEntry webServerEntry =
          new WebServerEntry(
              path,
              folder.getName() + StringPool.SLASH,
              folder.getCreateDate(),
              folder.getModifiedDate(),
              folder.getDescription(),
              0);

      webServerEntries.add(webServerEntry);
    }

    List<FileEntry> fileEntries = DLAppServiceUtil.getFileEntries(groupId, folderId);

    for (FileEntry fileEntry : fileEntries) {
      WebServerEntry webServerEntry =
          new WebServerEntry(
              path,
              fileEntry.getTitle(),
              fileEntry.getCreateDate(),
              fileEntry.getModifiedDate(),
              fileEntry.getDescription(),
              fileEntry.getSize());

      webServerEntries.add(webServerEntry);
    }

    sendHTML(response, path, webServerEntries);
  }
Exemplo n.º 12
0
  @Override
  public String getWebDavURL(
      ThemeDisplay themeDisplay,
      Folder folder,
      FileEntry fileEntry,
      boolean manualCheckInRequired,
      boolean openDocumentUrl)
      throws PortalException, SystemException {

    StringBundler webDavURL = new StringBundler(8);

    boolean secure = false;

    if (themeDisplay.isSecure() || PropsValues.WEBDAV_SERVLET_HTTPS_REQUIRED) {

      secure = true;
    }

    String portalURL =
        PortalUtil.getPortalURL(themeDisplay.getServerName(), themeDisplay.getServerPort(), secure);

    webDavURL.append(portalURL);

    webDavURL.append(themeDisplay.getPathContext());
    webDavURL.append("/webdav");

    if (manualCheckInRequired) {
      webDavURL.append(MANUAL_CHECK_IN_REQUIRED_PATH);
    }

    String fileEntryTitle = null;

    if (fileEntry != null) {
      String extension = fileEntry.getExtension();

      fileEntryTitle = HtmlUtil.unescape(fileEntry.getTitle());

      if (openDocumentUrl
          && isOfficeExtension(extension)
          && !fileEntryTitle.endsWith(StringPool.PERIOD + extension)) {

        webDavURL.append(OFFICE_EXTENSION_PATH);

        fileEntryTitle += StringPool.PERIOD + extension;
      }
    }

    Group group = themeDisplay.getScopeGroup();

    webDavURL.append(group.getFriendlyURL());
    webDavURL.append("/document_library");

    StringBuilder sb = new StringBuilder();

    if ((folder != null) && (folder.getFolderId() != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID)) {

      Folder curFolder = folder;

      while (true) {
        sb.insert(0, HttpUtil.encodeURL(curFolder.getName(), true));
        sb.insert(0, StringPool.SLASH);

        if (curFolder.getParentFolderId() == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

          break;
        }

        curFolder = DLAppLocalServiceUtil.getFolder(curFolder.getParentFolderId());
      }
    }

    if (fileEntry != null) {
      sb.append(StringPool.SLASH);
      sb.append(HttpUtil.encodeURL(fileEntryTitle, true));
    }

    webDavURL.append(sb.toString());

    return webDavURL.toString();
  }