📄 cmsnewresourceupload.java
字号:
/**
* Creates the HTML code of the file upload applet with all required parameters.<p>
*
* @return string containing the applet HTML code
*/
public String createAppletCode() {
StringBuffer applet = new StringBuffer(2048);
// collect some required server data first
String scheme = getJsp().getRequest().getScheme();
String host = getJsp().getRequest().getServerName();
String path = OpenCms.getSystemInfo().getContextPath() + OpenCms.getSystemInfo().getServletPath();
int port = getJsp().getRequest().getServerPort();
String webapp = scheme + "://" + host + ":" + port + OpenCms.getSystemInfo().getContextPath();
// get all file extensions
String fileExtensions = "";
Map extensions = OpenCms.getResourceManager().getExtensionMapping();
Iterator keys = extensions.entrySet().iterator();
while (keys.hasNext()) {
Map.Entry entry = (Map.Entry)keys.next();
String key = (String)entry.getKey();
String value = (String)entry.getValue();
fileExtensions += key + "=" + value + ",";
}
fileExtensions = fileExtensions.substring(0, fileExtensions.length() - 1);
// get the file size upload limitation value (value is in bytes for the applet)
long maxFileSize = OpenCms.getWorkplaceManager().getFileBytesMaxUploadSize(getCms());
// get the current folder
String currentFolder = getParamCurrentFolder();
// get the current session id
HttpSession session = getJsp().getRequest().getSession(false);
// we assume we always have a session here, otherwise an unhandled NPE will occur
String sessionId = session.getId();
// define the required colors.
// currently this is hard coded here
String colors = "bgColor=#C0C0C0,outerBorderRightBottom=#333333,outerBorderLeftTop=#C0C0C0";
colors += ",innerBorderRightBottom=#777777,innerBorderLeftTop=#F0F0F0";
colors += ",bgHeadline=#000066,colorHeadline=#FFFFFF";
colors += ",colorText=#000000,progessBar=#E10050";
// create the upload applet html code
applet.append("<applet code=\"org.opencms.applet.upload.FileUploadApplet.class\" archive=\"");
applet.append(webapp);
applet.append("/resources/components/upload_applet/upload.jar\" width=\"500\" height=\"100\">\n");
applet.append("<param name=\"opencms\" value=\"");
applet.append(scheme);
applet.append("://");
applet.append(host);
applet.append(":");
applet.append(port);
applet.append(getSkinUri());
applet.append("filetypes/\">\n");
applet.append("<param name=\"target\" value=\"");
applet.append(scheme);
applet.append("://");
applet.append(host);
applet.append(":");
applet.append(port);
applet.append(path);
applet.append("/system/workplace/commons/newresource_upload.jsp\">\n");
applet.append("<param name=\"redirect\" value=\"");
applet.append(scheme);
applet.append("://");
applet.append(host);
applet.append(":");
applet.append(port);
applet.append(path);
// check if the redirect url is given by request parameter. if not use the default
if (CmsStringUtil.isEmpty(getParamRedirectUrl())) {
applet.append(CmsWorkplace.FILE_EXPLORER_FILELIST);
} else {
applet.append(getParamRedirectUrl());
}
// append some parameters to prevent caching of URL by Applet
applet.append("?time=" + System.currentTimeMillis());
applet.append("\">\n");
applet.append("<param name=\"targetframe\" value=\"");
applet.append(getParamTargetFrame());
applet.append("\">\n");
applet.append("<param name=error value=\"");
applet.append(scheme);
applet.append("://");
applet.append(host);
applet.append(":");
applet.append(port);
applet.append(path);
applet.append("/system/workplace/action/explorer_files_new_upload.html\">\n");
applet.append("<param name=\"sessionId\" value=\"");
applet.append(sessionId);
applet.append("\">\n");
applet.append("<param name=\"filelist\" value=\"");
applet.append(currentFolder);
applet.append("\">\n");
applet.append("<param name=\"colors\" value=\"");
applet.append(colors);
applet.append("\">\n");
applet.append("<param name=\"fileExtensions\" value=\"");
applet.append(fileExtensions);
applet.append("\">\n\n");
applet.append("<param name=\"maxsize\" value=\"");
applet.append(maxFileSize);
applet.append("\">\n");
applet.append("<param name=\"actionOutputSelect\" value=\"");
applet.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_UPLOADAPPLET_ACTION_SELECT_0));
applet.append("\">\n");
applet.append("<param name=\"actionOutputCount\"value=\"");
applet.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_UPLOADAPPLET_ACTION_COUNT_0));
applet.append("\">\n");
applet.append("<param name=\"actionOutputCreate\" value=\"");
applet.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_UPLOADAPPLET_ACTION_CREATE_0));
applet.append("\">\n");
applet.append("<param name=\"actionOutputUpload\" value=\"");
applet.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_UPLOADAPPLET_ACTION_UPLOAD_0));
applet.append("\">\n");
applet.append("<param name=\"messageOutputUpload\" value=\"");
applet.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_UPLOADAPPLET_MESSAGE_UPLOAD_0));
applet.append("\">\n");
applet.append("<param name=\"messageOutputErrorZip\" value=\"");
applet.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_UPLOADAPPLET_MESSAGE_ERROR_ZIP_0));
applet.append("\">\n");
applet.append("<param name=\"messageOutputErrorSize\" value=\"");
applet.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_UPLOADAPPLET_MESSAGE_ERROR_SIZE_0));
applet.append("\">\n");
applet.append("<param name=\"messageNoPreview\" value=\"");
applet.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_UPLOADAPPLET_MESSAGE_NOPREVIEW_0));
applet.append("\">\n");
applet.append("<param name=\"messageOutputAdding\" value=\"");
applet.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_UPLOADAPPLET_MESSAGE_ADDING_0));
applet.append(" \">\n");
applet.append("<param name=\"errorTitle\" value=\"");
applet.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_UPLOADAPPLET_ERROR_TITLE_0));
applet.append(" \">\n");
applet.append("<param name=\"errorLine1\" value=\"");
applet.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_UPLOADAPPLET_ERROR_LINE1_0));
applet.append(" \">\n");
applet.append("</applet>\n");
return applet.toString();
}
/**
* Returns the new resource name of the uploaded file.<p>
*
* @return the new resource name of the uploaded file
*/
public String getParamNewResourceName() {
return m_paramNewResourceName;
}
/**
* Returns the paramRedirectUrl.<p>
*
* @return the paramRedirectUrl
*/
public String getParamRedirectUrl() {
return m_paramRedirectUrl;
}
/**
* Returns the paramTargetFrame.<p>
*
* @return the paramTargetFrame
*/
public String getParamTargetFrame() {
if (CmsStringUtil.isEmpty(m_paramTargetFrame)) {
return "explorer_files";
}
return m_paramTargetFrame;
}
/**
* Returns true if the upload file should be unzipped, otherwise false.<p>
*
* @return true if the upload file should be unzipped, otherwise false
*/
public String getParamUnzipFile() {
return m_paramUnzipFile;
}
/**
* Returns the upload error message for the error dialog.<p>
*
* @return the upload error message for the error dialog
*/
public String getParamUploadError() {
return m_paramUploadError;
}
/**
* Returns the upload file name.<p>
*
* @return the upload file name
*/
public String getParamUploadFile() {
return m_paramUploadFile;
}
/**
* Returns the upload folder name.<p>
*
* @return the upload folder name
*/
public String getParamUploadFolder() {
return m_paramUploadFolder;
}
/**
* Sets the new resource name of the uploaded file.<p>
*
* @param newResourceName the new resource name of the uploaded file
*/
public void setParamNewResourceName(String newResourceName) {
m_paramNewResourceName = newResourceName;
}
/**
* Sets the paramRedirectUrl.<p>
*
* @param paramRedirectUrl the paramRedirectUrl to set
*/
public void setParamRedirectUrl(String paramRedirectUrl) {
m_paramRedirectUrl = paramRedirectUrl;
}
/**
* Sets the paramTargetFrame.<p>
*
* @param paramTargetFrame the paramTargetFrame to set
*/
public void setParamTargetFrame(String paramTargetFrame) {
m_paramTargetFrame = paramTargetFrame;
}
/**
* Sets if the upload file should be unzipped.<p>
*
* @param unzipFile true if the upload file should be unzipped
*/
public void setParamUnzipFile(String unzipFile) {
m_paramUnzipFile = unzipFile;
}
/**
* Sets the upload error message for the error dialog.<p>
*
* @param uploadError the upload error message for the error dialog
*/
public void setParamUploadError(String uploadError) {
m_paramUploadError = uploadError;
}
/**
* Sets the upload file name.<p>
*
* @param uploadFile the upload file name
*/
public void setParamUploadFile(String uploadFile) {
m_paramUploadFile = uploadFile;
}
/**
* Sets the upload folder name.<p>
*
* @param uploadFolder the upload folder name
*/
public void setParamUploadFolder(String uploadFolder) {
m_paramUploadFolder = uploadFolder;
}
/**
* Returns if the upload file should be unzipped.<p>
*
* @return true if the upload file should be unzipped, otherwise false
*/
public boolean unzipUpload() {
return Boolean.valueOf(getParamUnzipFile()).booleanValue();
}
/**
* @see org.opencms.workplace.CmsWorkplace#initWorkplaceMembers(org.opencms.jsp.CmsJspActionElement)
*/
protected void initWorkplaceMembers(CmsJspActionElement jsp) {
String siteRoot = jsp.getRequestContext().getSiteRoot();
// In case of the upload applet the site stored in the user preferences must NOT be made the current
// site even if we have a new session! Since the upload applet will create a new session for the upload itself,
// we must make sure to use the site of the request, NOT the site stored in the user preferences.
// The default logic will erase the request site in case of a new session.
// With this workaround the site from the request is made the current site as required.
super.initWorkplaceMembers(jsp);
if (!siteRoot.equals(getSettings().getSite())) {
getSettings().setSite(siteRoot);
jsp.getRequestContext().setSiteRoot(siteRoot);
}
}
/**
* @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
*/
protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {
// fill the parameter values in the get/set methods
fillParamValues(request);
// set the dialog type
setParamDialogtype(DIALOG_TYPE);
// set the action for the JSP switch
if (DIALOG_OK.equals(getParamAction())) {
setAction(ACTION_OK);
} else if (DIALOG_SUBMITFORM.equals(getParamAction())) {
setAction(ACTION_SUBMITFORM);
} else if (DIALOG_SUBMITFORM2.equals(getParamAction())) {
setAction(ACTION_SUBMITFORM2);
} else if (DIALOG_CANCEL.equals(getParamAction())) {
setAction(ACTION_CANCEL);
} else {
if (getSettings().getUserSettings().useUploadApplet()) {
setAction(ACTION_APPLET);
} else {
setAction(ACTION_DEFAULT);
}
// build title for new resource dialog
setParamTitle(key(Messages.GUI_NEWRESOURCE_UPLOAD_0));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -