Example usage for com.liferay.portal.kernel.util HttpUtil fixPath

List of usage examples for com.liferay.portal.kernel.util HttpUtil fixPath

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util HttpUtil fixPath.

Prototype

public static String fixPath(String path) 

Source Link

Usage

From source file:com.liferay.sync.servlet.DownloadServlet.java

License:Open Source License

@Override
public void service(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    try {//w  ww. j a v a  2 s . c  om
        HttpSession session = request.getSession();

        if (PortalSessionThreadLocal.getHttpSession() == null) {
            PortalSessionThreadLocal.setHttpSession(session);
        }

        User user = PortalUtil.getUser(request);

        PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user);

        PermissionThreadLocal.setPermissionChecker(permissionChecker);

        String path = HttpUtil.fixPath(request.getPathInfo());
        String[] pathArray = StringUtil.split(path, CharPool.SLASH);

        if (pathArray[0].equals("image")) {
            long imageId = GetterUtil.getLong(pathArray[1]);

            sendImage(response, imageId);
        } else {
            long groupId = GetterUtil.getLong(pathArray[0]);
            String uuid = pathArray[1];

            boolean patch = ParamUtil.getBoolean(request, "patch");

            if (patch) {
                sendPatch(request, response, user, groupId, uuid);
            } else {
                sendFile(request, response, groupId, uuid);
            }
        }
    } catch (NoSuchFileEntryException nsfee) {
        PortalUtil.sendError(HttpServletResponse.SC_NOT_FOUND, nsfee, request, response);
    } catch (Exception e) {
        PortalUtil.sendError(e, request, response);
    }
}