📄 cmseditor.java
字号:
if(content == null) {
try {
content = new String(editFile.getContents(), encoding);
} catch (UnsupportedEncodingException e) {
content = new String(editFile.getContents());
}
content = Encoder.escapeWBlanks(content, Encoder.C_URI_ENCODING);
parameters.put(C_PARA_CONTENT, content);
}
// If the user requested a file save, write the file content
// back to the database.
if(saveRequested) {
try{
String decodedContent = Encoder.unescape(content, Encoder.C_URI_ENCODING);
try {
editFile.setContents(decodedContent.getBytes(encoding));
} catch (UnsupportedEncodingException e) {
editFile.setContents(decodedContent.getBytes());
}
cms.writeFile(editFile);
} catch (CmsException e){
saveerror = e.getShortException();
}
}
}
// Check if we should leave th editor instead of start processing
if(exitRequested && ((saveerror == null) || ("".equals(saveerror)))) {
try {
cms.getRequestContext().getResponse().sendCmsRedirect("/system/workplace/action/index.html");
}
catch(IOException e) {
throwException("Could not send redirect to workplace main screen.", e);
}
//return "".getBytes();
return null;
}
// Load the template file and get the browser specific section name
CmsXmlWpTemplateFile xmlTemplateDocument = (CmsXmlWpTemplateFile)getOwnTemplateFile(cms,
templateFile, elementName, parameters, templateSelector);
String sectionName = getBrowserSpecificSection(cms, xmlTemplateDocument, parameters);
// Put the "file" datablock for processing in the template file.
// It will be inserted in a hidden input field and given back when submitting.
xmlTemplateDocument.setData(C_PARA_FILE, file);
xmlTemplateDocument.setData(C_PARA_JSFILE, jsfile);
xmlTemplateDocument.setData("editorframe", editorframe);
xmlTemplateDocument.setData("OpenCmsContext",
A_OpenCms.getOpenCmsContext().substring(0, A_OpenCms.getOpenCmsContext().length()-1));
// Announcement of path and file name in the header of the browser.
if(checkit==true){
xmlTemplateDocument.setData("fileName", (String) editFile.getName());
xmlTemplateDocument.setData("pathName", (String) editFile.getPath());
}
String lasturlname = null;
if(!"".equals(saveerror)){
if(file != null){
file = file.trim();
session.putValue(C_PARA_FILE, file);
}
if(content != null){
session.putValue(C_PARA_CONTENT, content);
}
if(jsfile != null){
session.putValue(C_PARA_JSFILE, jsfile);
}
if(editorframe != null){
session.putValue("editorframe", editorframe);
}
sectionName = "errorsave";
xmlTemplateDocument.setData("errordetail", saveerror);
lasturlname=(String)parameters.get("editor._TEMPLATE_");
if (lasturlname != null){
lasturlname=lasturlname.substring(lasturlname.lastIndexOf("/")+1, lasturlname.length());
}
xmlTemplateDocument.setData("errorlasturl", lasturlname+".html");
}
// test if the "help"- button has to be displayed for the user's current language
String userLanguage = CmsXmlLanguageFile.getCurrentUserLanguage(cms);
xmlTemplateDocument.setData("LOCALE", "" + userLanguage);
try {
cms.readFolder(C_VFS_PATH_HELP + userLanguage);
// the localized help- folder exists
xmlTemplateDocument.setData("HELP", xmlTemplateDocument.getProcessedDataValue("HELP_ENABLED", this));
}
catch (CmsException e) {
// the localized help- folder does not exist
try {
xmlTemplateDocument.setData("HELP", xmlTemplateDocument.getProcessedDataValue("HELP_DISABLED", this));
}
catch (Exception ex) {
// ignore this error so the workplace can still be used
}
}
return startProcessing(cms, xmlTemplateDocument, elementName, parameters, sectionName);
}
/**
* 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;
}
/**
* Reads in the requested file to be edited by calling the corresponding
* method in the cms object.
* @param cms Cms object for accessing system resources
* @param filename Name of the file to be loaded
* @return CmsFile object of the loaded file
*/
protected CmsFile readFile(CmsObject cms, String filename) throws CmsException {
CmsFile result = null;
try {
result = cms.readFile(filename);
}
catch(Exception e) {
// Anything is wrong. Perhaps a wrong file name ???
String errorMessage = "Error while reading file " + filename + ": " + e;
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(C_OPENCMS_CRITICAL, getClassName() + errorMessage);
}
// throw this exception again, so it can be displayed in the servlet.
if(e instanceof CmsException) {
throw (CmsException)e;
}
else {
throw new CmsException(errorMessage, CmsException.C_UNKNOWN_EXCEPTION);
}
}
return result;
}
/**
* User method for setting the editable text in the editor window.
* <P>
* This method can be called in the editor's template file using
* <code><METHOD name="setText"/>></code>. This call will be replaced
* by the content of the file that should be edited.
*
* @param cms CmsObject Object for accessing system resources.
* @param tagcontent Unused in this special case of a user method. Can be ignored.
* @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
* @param userObj Hashtable with parameters.
* @return String or byte[] with the content of the file that should be edited.
*/
public Object setText(CmsObject cms, String tagcontent, A_CmsXmlContent doc,
Object userObj) {
Hashtable parameters = (Hashtable)userObj;
String content = (String)parameters.get(C_PARA_CONTENT);
if(content == null) {
content = "";
}
return content;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -