001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.documentlibrary.action;
022:
023: import com.liferay.portal.kernel.util.ParamUtil;
024: import com.liferay.portal.kernel.util.Validator;
025: import com.liferay.portal.util.PortalUtil;
026: import com.liferay.portal.util.WebKeys;
027: import com.liferay.portlet.documentlibrary.NoSuchFileEntryException;
028: import com.liferay.portlet.documentlibrary.model.DLFileEntry;
029: import com.liferay.portlet.documentlibrary.model.DLFileShortcut;
030: import com.liferay.portlet.documentlibrary.model.DLFolder;
031: import com.liferay.portlet.documentlibrary.model.impl.DLFolderImpl;
032: import com.liferay.portlet.documentlibrary.service.DLFileEntryServiceUtil;
033: import com.liferay.portlet.documentlibrary.service.DLFileShortcutServiceUtil;
034: import com.liferay.portlet.documentlibrary.service.DLFolderServiceUtil;
035:
036: import javax.portlet.ActionRequest;
037: import javax.portlet.RenderRequest;
038:
039: import javax.servlet.http.HttpServletRequest;
040:
041: /**
042: * <a href="ActionUtil.java.html"><b><i>View Source</i></b></a>
043: *
044: * @author Brian Wing Shun Chan
045: *
046: */
047: public class ActionUtil {
048:
049: public static void getFileEntry(ActionRequest req) throws Exception {
050: HttpServletRequest httpReq = PortalUtil
051: .getHttpServletRequest(req);
052:
053: getFileEntry(httpReq);
054: }
055:
056: public static void getFileEntry(RenderRequest req) throws Exception {
057: HttpServletRequest httpReq = PortalUtil
058: .getHttpServletRequest(req);
059:
060: getFileEntry(httpReq);
061: }
062:
063: public static void getFileEntry(HttpServletRequest req)
064: throws Exception {
065: long folderId = ParamUtil.getLong(req, "folderId");
066: long newFolderId = ParamUtil.getLong(req, "newFolderId");
067: String name = ParamUtil.getString(req, "name");
068:
069: DLFileEntry fileEntry = null;
070:
071: if ((folderId > 0) && Validator.isNotNull(name)) {
072: try {
073: fileEntry = DLFileEntryServiceUtil.getFileEntry(
074: folderId, name);
075: } catch (NoSuchFileEntryException nsfe) {
076:
077: // This only happens when you're moving a file to a different
078: // folder
079:
080: fileEntry = DLFileEntryServiceUtil.getFileEntry(
081: newFolderId, name);
082: }
083: }
084:
085: req
086: .setAttribute(WebKeys.DOCUMENT_LIBRARY_FILE_ENTRY,
087: fileEntry);
088: }
089:
090: public static void getFileShortcut(ActionRequest req)
091: throws Exception {
092: HttpServletRequest httpReq = PortalUtil
093: .getHttpServletRequest(req);
094:
095: getFileShortcut(httpReq);
096: }
097:
098: public static void getFileShortcut(RenderRequest req)
099: throws Exception {
100: HttpServletRequest httpReq = PortalUtil
101: .getHttpServletRequest(req);
102:
103: getFileShortcut(httpReq);
104: }
105:
106: public static void getFileShortcut(HttpServletRequest req)
107: throws Exception {
108:
109: long fileShortcutId = ParamUtil.getLong(req, "fileShortcutId");
110:
111: DLFileShortcut fileShortcut = null;
112:
113: if (fileShortcutId > 0) {
114: fileShortcut = DLFileShortcutServiceUtil
115: .getFileShortcut(fileShortcutId);
116: }
117:
118: req.setAttribute(WebKeys.DOCUMENT_LIBRARY_FILE_SHORTCUT,
119: fileShortcut);
120: }
121:
122: public static void getFolder(ActionRequest req) throws Exception {
123: HttpServletRequest httpReq = PortalUtil
124: .getHttpServletRequest(req);
125:
126: getFolder(httpReq);
127: }
128:
129: public static void getFolder(RenderRequest req) throws Exception {
130: HttpServletRequest httpReq = PortalUtil
131: .getHttpServletRequest(req);
132:
133: getFolder(httpReq);
134: }
135:
136: public static void getFolder(HttpServletRequest req)
137: throws Exception {
138: long folderId = ParamUtil.getLong(req, "folderId");
139:
140: DLFolder folder = null;
141:
142: if ((folderId > 0)
143: && (folderId != DLFolderImpl.DEFAULT_PARENT_FOLDER_ID)) {
144:
145: folder = DLFolderServiceUtil.getFolder(folderId);
146: }
147:
148: req.setAttribute(WebKeys.DOCUMENT_LIBRARY_FOLDER, folder);
149: }
150:
151: }
|