001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.ade.upload; 029 030import org.opencms.gwt.CmsGwtActionElement; 031import org.opencms.gwt.shared.CmsCoreData; 032import org.opencms.gwt.shared.I_CmsUploadConstants; 033import org.opencms.jsp.CmsJspActionElement; 034import org.opencms.util.CmsStringUtil; 035import org.opencms.workplace.CmsDialog; 036import org.opencms.workplace.CmsWorkplace; 037 038import javax.servlet.http.HttpServletRequest; 039import javax.servlet.http.HttpServletResponse; 040import javax.servlet.jsp.PageContext; 041 042/** 043 * Upload action element, used to generate the upload dialog.<p> 044 * 045 * @since 8.0.0 046 */ 047public class CmsUploadActionElement extends CmsGwtActionElement { 048 049 /** 050 * A CMS dialog that makes the {@link Dialog#computeCurrentFolder} method visible.<p> 051 */ 052 private class Dialog extends CmsDialog { 053 054 /** 055 * Constructor.<p> 056 * 057 * @param jsp the JSP Action Element 058 */ 059 public Dialog(CmsJspActionElement jsp) { 060 061 super(jsp); 062 063 } 064 065 /** 066 * @see org.opencms.workplace.CmsDialog#computeCurrentFolder() 067 */ 068 @Override 069 public String computeCurrentFolder() { 070 071 return super.computeCurrentFolder(); 072 } 073 } 074 075 /** The OpenCms module name. */ 076 public static final String CMS_MODULE_NAME = "org.opencms.ade.upload"; 077 078 /** The GWT module name. */ 079 public static final String GWT_MODULE_NAME = CmsCoreData.ModuleKey.upload.name(); 080 081 /** 082 * Constructor.<p> 083 * 084 * @param context the JSP page context object 085 * @param req the JSP request 086 * @param res the JSP response 087 */ 088 public CmsUploadActionElement(PageContext context, HttpServletRequest req, HttpServletResponse res) { 089 090 super(context, req, res); 091 } 092 093 /** 094 * @see org.opencms.gwt.CmsGwtActionElement#export() 095 */ 096 @Override 097 public String export() throws Exception { 098 099 return ""; 100 } 101 102 /** 103 * @see org.opencms.gwt.CmsGwtActionElement#exportAll() 104 */ 105 @Override 106 public String exportAll() throws Exception { 107 108 StringBuffer sb = new StringBuffer(); 109 sb.append(super.export()); 110 sb.append(exportTargetFolder()); 111 sb.append(exportCloseLink()); 112 sb.append(exportModuleScriptTag(GWT_MODULE_NAME)); 113 return sb.toString(); 114 } 115 116 /** 117 * Special export for the button mode.<p> 118 * 119 * @return the data 120 * 121 * @throws Exception if something goes wrong 122 */ 123 public String exportButton() throws Exception { 124 125 StringBuffer sb = new StringBuffer(); 126 sb.append(exportAll()); 127 sb.append(exportDialogMode()); 128 return sb.toString(); 129 } 130 131 /** 132 * Returns the upload dialog title.<p> 133 * 134 * @return the upload dialog title 135 */ 136 public String getTitle() { 137 138 return Messages.get().getBundle(getWorkplaceLocale()).key(Messages.GUI_UPLOAD_TITLE_0); 139 } 140 141 /** 142 * Returns a javascript tag that contains a variable deceleration that has the close link as value.<p> 143 * 144 * @return a javascript tag that contains a variable deceleration that has the close link as value 145 */ 146 private String exportCloseLink() { 147 148 String closeLink = null; 149 if (getRequest().getAttribute(I_CmsUploadConstants.ATTR_CLOSE_LINK) != null) { 150 closeLink = (String)getRequest().getAttribute(I_CmsUploadConstants.ATTR_CLOSE_LINK); 151 } 152 if (CmsStringUtil.isEmptyOrWhitespaceOnly(closeLink)) { 153 closeLink = CmsWorkplace.FILE_EXPLORER_FILELIST; 154 } 155 156 StringBuffer sb = new StringBuffer(); 157 // var closeLink = '/system/workplace/views/explorer/explorer_files.jsp'; 158 sb.append(wrapScript("var ", I_CmsUploadConstants.ATTR_CLOSE_LINK, " = \'", closeLink, "\';")); 159 return sb.toString(); 160 } 161 162 /** 163 * Returns a javascript tag that contains a variable deceleration that has the close link as value.<p> 164 * 165 * @return a javascript tag that contains a variable deceleration that has the close link as value 166 */ 167 private String exportDialogMode() { 168 169 // var dialogMode = 'button'; 170 return wrapScript("var ", I_CmsUploadConstants.ATTR_DIALOG_MODE, " = 'button';"); 171 } 172 173 /** 174 * Returns a javascript tag that contains a variable deceleration that has the target folder as value.<p> 175 * 176 * @return a javascript tag that contains a variable deceleration that has the target folder as value 177 */ 178 private String exportTargetFolder() { 179 180 String targetFolder = null; 181 if (getRequest().getAttribute(I_CmsUploadConstants.ATTR_CURRENT_FOLDER) != null) { 182 targetFolder = (String)getRequest().getAttribute(I_CmsUploadConstants.ATTR_CURRENT_FOLDER); 183 } 184 if (CmsStringUtil.isEmptyOrWhitespaceOnly(targetFolder)) { 185 targetFolder = new Dialog(this).computeCurrentFolder(); 186 } 187 StringBuffer sb = new StringBuffer(); 188 // var targetFolder = '/demo_t3/'; 189 sb.append(wrapScript("var ", I_CmsUploadConstants.VAR_TARGET_FOLDER, " = \'", targetFolder, "\';")); 190 return sb.toString(); 191 } 192}