📄 cmsnewresourceupload.java
字号:
} // else, zip was not valid, so continue ...
template = "step1";
}
}
}
else {
if(step.equals("2")) {
// get the selected resource and check if it is an image
I_CmsResourceType type = cms.getResourceType(newtype);
if(newtype.equals(C_TYPE_IMAGE_NAME)) {
// check if the resource already exists to get its title
try {
String oldTitle = cms.readProperty( currentFolder + filename, I_CmsConstants.C_PROPERTY_TITLE );
if (oldTitle!=null) {
xmlTemplateDocument.setData("TITLE", Encoder.escapeXml(oldTitle));
}
}
catch (CmsException e) {
// the resource doesn't exists yet...
xmlTemplateDocument.setData("TITLE", "");
}
// the file type is an image
template = "image";
xmlTemplateDocument.setData("MIME", filename);
xmlTemplateDocument.setData("SIZE", "Not yet available");
xmlTemplateDocument.setData("FILESIZE", new Integer(filecontent.length).toString() + " Bytes");
}
else {
// create the new file.
try {
cms.createResource(currentFolder + filename, type.getResourceTypeName(), new Hashtable(), filecontent, null);
}
catch (CmsException e) {
if (replaceResource) {
cms.lockResource(currentFolder + filename, true);
cms.replaceResource(currentFolder + filename, type.getResourceTypeName(), null, filecontent);
//cms.unlockResource( currentFolder + filename );
session.putValue(CmsNewResourceUpload.C_PARAM_OVERWRITE, "no");
}
else {
xmlTemplateDocument.setData("LAST_STEP", step);
xmlTemplateDocument.setData("FILENAME", filename);
return startProcessing(cms, xmlTemplateDocument, "", parameters, "overwrite");
}
}
// remove the values form the session
session.removeValue(C_PARA_FILE);
session.removeValue(C_PARA_FILECONTENT);
session.removeValue(C_PARA_NEWTYPE);
session.removeValue(C_PARA_TITLE);
session.removeValue(CmsNewResourceUpload.C_PARAM_OVERWRITE);
// return to the filelist
try {
//cms.getRequestContext().getResponse().sendCmsRedirect( getConfigFile(cms).getWorkplaceActionPath()+C_WP_EXPLORER_FILELIST);
if((lastUrl != null) && (lastUrl != "")) {
cms.getRequestContext().getResponse().sendRedirect(lastUrl);
}
else {
cms.getRequestContext().getResponse().sendCmsRedirect(getConfigFile(cms).getWorkplaceActionPath() + C_WP_EXPLORER_FILELIST);
}
}
catch(Exception ex) {
throw new CmsException("Redirect fails :" + getConfigFile(cms).getWorkplaceActionPath() + C_WP_EXPLORER_FILELIST, CmsException.C_UNKNOWN_EXCEPTION, ex);
}
return null;
}
}
else {
if(step.equals("3")) {
// get the data from the special image upload dialog
// check if a new filename is given
if(newname != null) {
filename = newname;
}
// create the new file.
// todo: error handling if file already exits
I_CmsResourceType type = cms.getResourceType(newtype);
Hashtable prop = new Hashtable();
// check if a file title was given
if (title != null) {
prop.put(C_PROPERTY_TITLE, title);
}
try {
cms.createResource(currentFolder + filename, type.getResourceTypeName(), prop, filecontent, null);
}
catch (CmsException e) {
if (replaceResource) {
cms.lockResource(currentFolder + filename, true);
cms.replaceResource(currentFolder + filename, type.getResourceTypeName(), prop, filecontent);
//cms.unlockResource( currentFolder + filename );
session.putValue(CmsNewResourceUpload.C_PARAM_OVERWRITE, "no");
}
else {
xmlTemplateDocument.setData("LAST_STEP", step);
xmlTemplateDocument.setData("FILENAME", filename);
return startProcessing(cms, xmlTemplateDocument, "", parameters, "overwrite");
}
}
// remove the values form the session
session.removeValue(C_PARA_FILE);
session.removeValue(C_PARA_FILECONTENT);
session.removeValue(C_PARA_NEWTYPE);
session.removeValue(C_PARA_TITLE);
session.removeValue(CmsNewResourceUpload.C_PARAM_OVERWRITE);
session.removeValue("lasturl");
// return to the filelist
try {
if((lastUrl != null) && (lastUrl != "")) {
cms.getRequestContext().getResponse().sendRedirect(lastUrl);
}
else {
cms.getRequestContext().getResponse().sendCmsRedirect(getConfigFile(cms).getWorkplaceActionPath() + C_WP_EXPLORER_FILELIST);
}
}
catch(Exception ex) {
throw new CmsException("Redirect fails :" + getConfigFile(cms).getWorkplaceActionPath() + C_WP_EXPLORER_FILELIST, CmsException.C_UNKNOWN_EXCEPTION, ex);
}
return null;
}
}
}
}
// display upload form with limitation of file size
else {
if (maxFileSize > 0) {
xmlTemplateDocument.setData("maxfilesize", "" + maxFileSize);
String limitation = xmlTemplateDocument.getProcessedDataValue("filesize_limited");
xmlTemplateDocument.setData("limitation", limitation);
}
else {
xmlTemplateDocument.setData("limitation", "");
}
}
if(filename != null) {
xmlTemplateDocument.setData("FILENAME", filename);
}
// process the selected template
return startProcessing(cms, xmlTemplateDocument, "", parameters, template);
}
/**
* Gets the resources displayed in the Radiobutton group on the chtype dialog.
* @param cms The CmsObject.
* @param lang The langauge definitions.
* @param names The names of the new rescources.
* @param values The links that are connected with each resource.
* @param parameters Hashtable of parameters (not used yet).
* @param descriptions Description that will be displayed for the new resource.
* @return The vectors names and values are filled with the information found in the workplace.ini.
* @return the number of the preselected item, -1 if none preselected
* @throws Throws CmsException if something goes wrong.
*/
public int getResources(CmsObject cms, CmsXmlLanguageFile lang, Vector names, Vector values, Vector descriptions, Hashtable parameters) throws CmsException {
I_CmsSession session = cms.getRequestContext().getSession(true);
String filename = (String)session.getValue(C_PARA_FILE);
String suffix = filename.substring(filename.lastIndexOf('.') + 1);
suffix = suffix.toLowerCase(); // file extension of filename
// read the known file extensions from the database
Hashtable extensions = cms.readFileExtensions();
String resType = new String();
if(extensions != null) {
resType = (String)extensions.get(suffix);
}
if(resType == null) {
resType = "";
}
int ret = 0;
// Check if the list of available resources is not yet loaded from the workplace.ini
if(m_names == null || m_values == null) {
m_names = new Vector();
m_values = new Vector();
CmsXmlWpConfigFile configFile = new CmsXmlWpConfigFile(cms);
configFile.getWorkplaceIniData(m_names, m_values, "RESOURCETYPES", "RESOURCE");
}
// Check if the temportary name and value vectors are not initialized, create
// them if nescessary.
if(names == null) {
names = new Vector();
}
if(values == null) {
values = new Vector();
}
if(descriptions == null) {
descriptions = new Vector();
}
// OK. Now m_names and m_values contain all available
// resource information.
// Loop through the vectors and fill the result vectors.
int numViews = m_names.size();
for(int i = 0;i < numViews;i++) {
String loopValue = (String)m_values.elementAt(i);
String loopName = (String)m_names.elementAt(i);
values.addElement(loopValue);
names.addElement("file_" + loopName);
String descr;
if(lang != null) {
descr = lang.getLanguageValue("fileicon." + loopName);
}
else {
descr = loopName;
}
descriptions.addElement(descr);
if(resType.equals(loopName)) {
// known file extension
ret = i;
}
}
return ret;
}
/**
* Indicates if the results of this class are cacheable.
*
* @param cms CmsObject Object for accessing system resources
* @param templateFile Filename of the template file
* @param elementName Element name of this template in our parent template.
* @param parameters Hashtable with all template class parameters.
* @param templateSelector template section that should be processed.
* @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
*/
public boolean isCacheable(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -