Search in sources :

Example 1 with NoSuchFolderException

use of com.liferay.portlet.documentlibrary.NoSuchFolderException in project liferay-ide by liferay.

the class WebServerServlet method sendDocumentLibrary.

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);
}
Also used : ArrayList(java.util.ArrayList) Folder(com.liferay.portal.kernel.repository.model.Folder) ServletException(javax.servlet.ServletException) RepositoryException(com.liferay.portal.kernel.repository.RepositoryException) NoSuchFileEntryException(com.liferay.portlet.documentlibrary.NoSuchFileEntryException) NoSuchFolderException(com.liferay.portlet.documentlibrary.NoSuchFolderException) PrincipalException(com.liferay.portal.security.auth.PrincipalException) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) IOException(java.io.IOException) NoSuchGroupException(com.liferay.portal.NoSuchGroupException) NoSuchFolderException(com.liferay.portlet.documentlibrary.NoSuchFolderException) PrincipalException(com.liferay.portal.security.auth.PrincipalException) NoSuchFileEntryException(com.liferay.portlet.documentlibrary.NoSuchFileEntryException) FileEntry(com.liferay.portal.kernel.repository.model.FileEntry) DLFileEntry(com.liferay.portlet.documentlibrary.model.DLFileEntry)

Example 2 with NoSuchFolderException

use of com.liferay.portlet.documentlibrary.NoSuchFolderException in project liferay-ide by liferay.

the class WebServerServlet method hasFiles.

/**
 * @see com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter
 */
public static boolean hasFiles(HttpServletRequest request) {
    try {
        // Do not use permission checking since this may be called from
        // other contexts that are also managing the principal
        User user = _getUser(request);
        String path = HttpUtil.fixPath(request.getPathInfo());
        String[] pathArray = StringUtil.split(path, CharPool.SLASH);
        if (pathArray.length == 0) {
            return true;
        } else if (_PATH_DDL.equals(pathArray[0])) {
            _checkDDLRecord(pathArray);
        } else if (Validator.isNumber(pathArray[0])) {
            _checkFileEntry(pathArray);
        } else {
            long groupId = _getGroupId(user.getCompanyId(), pathArray[0]);
            long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
            for (int i = 1; i < pathArray.length; i++) {
                try {
                    Folder folder = DLAppLocalServiceUtil.getFolder(groupId, folderId, pathArray[i]);
                    folderId = folder.getFolderId();
                } catch (NoSuchFolderException nsfe) {
                    if (i != pathArray.length - 1) {
                        return false;
                    }
                    pathArray = new String[] { String.valueOf(groupId), String.valueOf(folderId), pathArray[i] };
                    _checkFileEntry(pathArray);
                }
            }
        }
    } catch (Exception e) {
        return false;
    }
    return true;
}
Also used : NoSuchFolderException(com.liferay.portlet.documentlibrary.NoSuchFolderException) User(com.liferay.portal.model.User) Folder(com.liferay.portal.kernel.repository.model.Folder) ServletException(javax.servlet.ServletException) RepositoryException(com.liferay.portal.kernel.repository.RepositoryException) NoSuchFileEntryException(com.liferay.portlet.documentlibrary.NoSuchFileEntryException) NoSuchFolderException(com.liferay.portlet.documentlibrary.NoSuchFolderException) PrincipalException(com.liferay.portal.security.auth.PrincipalException) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) IOException(java.io.IOException) NoSuchGroupException(com.liferay.portal.NoSuchGroupException)

Aggregations

NoSuchGroupException (com.liferay.portal.NoSuchGroupException)2 PortalException (com.liferay.portal.kernel.exception.PortalException)2 SystemException (com.liferay.portal.kernel.exception.SystemException)2 RepositoryException (com.liferay.portal.kernel.repository.RepositoryException)2 Folder (com.liferay.portal.kernel.repository.model.Folder)2 PrincipalException (com.liferay.portal.security.auth.PrincipalException)2 NoSuchFileEntryException (com.liferay.portlet.documentlibrary.NoSuchFileEntryException)2 NoSuchFolderException (com.liferay.portlet.documentlibrary.NoSuchFolderException)2 IOException (java.io.IOException)2 ServletException (javax.servlet.ServletException)2 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)1 User (com.liferay.portal.model.User)1 DLFileEntry (com.liferay.portlet.documentlibrary.model.DLFileEntry)1 ArrayList (java.util.ArrayList)1