📄 cmsxmltemplateeditor.java
字号:
cms.getRequestContext().setCurrentProject(cms.readProject(curProject));
try {
CmsXmlTemplateLoader.getResponse(cms.getRequestContext()).sendCmsRedirect(CmsWorkplaceAction.getWorkplaceUri(CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getOriginalRequest()));
}catch(IOException e) {
throwException("Could not send redirect to workplace main screen.", e);
}
return null;
}
// Include the datablocks of the layout file into the body file.
// So the "bodytag" and "style" data can be accessed by the body file.
Element bodyTag = layoutTemplateFile.getBodyTag();
bodyTemplateFile.setBodyTag(bodyTag);
// Load the body!
content = bodyTemplateFile.getEditableTemplateContent(this, parameters, body, editor.equals(CmsMSDHtmlEditor.SELECTBOX_EDITORVIEWS[0]), style);
// set the context & servlet path in editor content
content = CmsStringUtil.substitute(content, CmsStringUtil.MACRO_OPENCMS_CONTEXT + "/", OpenCms.getSystemInfo().getOpenCmsContext() + "/");
// escape content
content = CmsEncoder.escapeWBlanks(content, CmsEncoder.ENCODING_UTF_8);
parameters.put(CmsWorkplaceDefault.C_PARA_CONTENT, content);
// put the body parameter so that the selectbox can set the correct current value
parameters.put("body", body);
parameters.put("bodyfile", bodyElementFilename);
parameters.put("bodyclass", bodyElementClassName);
parameters.put("template", layoutTemplateFilename);
// remove all parameters that could be relevant for the
// included editor.
parameters.remove(CmsWorkplaceDefault.C_PARA_RESOURCE);
parameters.remove(CmsWorkplaceDefault.C_PARA_ACTION);
int numEditors = CmsMSDHtmlEditor.SELECTBOX_EDITORVIEWS.length;
for(int i = 0;i < numEditors;i++) {
if(editor.equals(CmsMSDHtmlEditor.SELECTBOX_EDITORVIEWS[i])) {
parameters.put("editor._CLASS_", C_SELECTBOX_EDITORVIEWS_CLASSES[i]);
parameters.put("editor._TEMPLATE_", CmsWorkplaceDefault.C_VFS_PATH_DEFAULT_INTERNAL + CmsWorkplaceDefault.C_SELECTBOX_EDITORVIEWS_TEMPLATES[i]);
}
}
session.putValue("te_file", file);
session.putValue("te_oldedit", editor);
session.putValue("te_oldbody", body);
session.putValue("te_oldbodytitle", bodytitle);
session.putValue("te_oldlayout", layoutTemplateFilename);
if(title != null) {
session.putValue("te_title", title);
}else {
session.putValue("te_title", "");
}
session.putValue("te_templateclass", layoutTemplateClassName);
CmsXmlWpTemplateFile xmlTemplateDocument = (CmsXmlWpTemplateFile)getOwnTemplateFile(cms,
templateFile, elementName, parameters, templateSelector);
xmlTemplateDocument.setData("editor", editor);
xmlTemplateDocument.setData("bodyfile", bodyElementFilename);
xmlTemplateDocument.setData("bodyclass", bodyElementClassName);
xmlTemplateDocument.setData("editorframe", (String)parameters.get("root.editorframe"));
if (bodytitle != null) {
xmlTemplateDocument.setData("bodytitle", bodytitle);
}
// 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(CmsWorkplaceDefault.C_PARA_RESOURCE, file);
if(!"".equals(saveerror)){
templateSelector = "errorsave";
xmlTemplateDocument.setData("errordetail", saveerror);
xmlTemplateDocument.setData("errorlasturl", xmlTemplateDocument.getFilename()+".html");
}
return startProcessing(cms, xmlTemplateDocument, elementName, parameters, templateSelector);
}
/** Gets all editor views available in the template editor screens.
* <P>
* The given vectors <code>names</code> and <code>values</code> will
* be filled with the appropriate information to be used for building
* a select box.
* <P>
* Used to build font select boxes in editors.
*
* @param cms CmsObject Object for accessing system resources.
* @param lang reference to the currently valid language file
* @param names Vector to be filled with the appropriate values in this method.
* @param values Vector to be filled with the appropriate values in this method.
* @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
* @return Index representing the user's current workplace view in the vectors.
* @throws CmsException
*/
public Integer getEditorViews(CmsObject cms, CmsXmlLanguageFile lang, Vector names, Vector values,
Hashtable parameters) throws CmsException {
Vector names2 = new Vector();
Vector values2 = new Vector();
getConstantSelectEntries(names2, values2, CmsMSDHtmlEditor.SELECTBOX_EDITORVIEWS, lang);
int browserId;
CmsRequestContext reqCont = cms.getRequestContext();
HttpServletRequest orgReq = CmsXmlTemplateLoader.getRequest(reqCont).getOriginalRequest();
String browser = orgReq.getHeader("user-agent");
if(browser.indexOf("MSIE") > -1) {
browserId = 0;
}
else {
browserId = 1;
}
int loop = 1;
int allowedEditors = CmsMSDHtmlEditor.SELECTBOX_EDITORVIEWS_ALLOWED[browserId];
if(((String)parameters.get("body")).equals("script")) {
allowedEditors = allowedEditors & 510;
}
for(int i = 0;i < names2.size();i++) {
if((allowedEditors & loop) > 0) {
values.addElement(values2.elementAt(i));
names.addElement(names2.elementAt(i));
}
loop <<= 1;
}
int currentIndex = values.indexOf(parameters.get("editor"));
return new Integer(currentIndex);
}
/**
* 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;
}
protected void preview(String previewPath, CmsRequestContext reqCont) throws CmsException {
String servletPath = CmsXmlTemplateLoader.getRequest(reqCont).getServletUrl();
try {
CmsXmlTemplateLoader.getResponse(reqCont).sendCmsRedirect(previewPath);
}
catch(IOException e) {
throwException("Could not send redirect preview file " + servletPath + previewPath, e);
}
}
/**
* User method to generate an URL for a preview.
* The currently selected temporary file name will be considered.
* <P>
* In the editor template file, this method can be invoked by
* <code><METHOD name="previewUrl"/></code>.
*
* @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 <em>(not used here)</em>.
* @param userObj Hashtable with parameters <em>(not used here)</em>.
* @return String with the pics URL.
* @throws CmsException
*/
public Object previewUrl(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObj) throws CmsException {
String servletPath = CmsXmlTemplateLoader.getRequest(cms.getRequestContext()).getServletUrl();
I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
String tempPath = (String)session.getValue("te_temppagefile");
String result = servletPath + tempPath;
return result;
}
/**
* Pre-Sets the value of the body title input field.
* This method is directly called by the content definiton.
* @param Cms The CmsObject.
* @param lang The language file.
* @param parameters User parameters.
* @return Value that is pre-set into the title field.
* @throws CmsExeption if something goes wrong.
*/
public String setBodyTitle(CmsObject cms, CmsXmlLanguageFile lang, Hashtable parameters) throws CmsException {
I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
String title = (String)session.getValue("te_oldbodytitle");
return CmsEncoder.escapeXml(title);
}
public Object getCharset(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObj) {
// Try to find property on file and all parent folders
String prop = null;
try {
I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
String file = (String)session.getValue("te_file");
prop = cms.readProperty(file, CmsPropertyDefinition.PROPERTY_CONTENT_ENCODING);
while ((prop == null) && (! "".equals(file))) {
file = file.substring(0, file.lastIndexOf("/"));
prop = cms.readProperty(file + "/", CmsPropertyDefinition.PROPERTY_CONTENT_ENCODING);
}
} catch (Exception e) {}
if (prop == null) prop = OpenCms.getSystemInfo().getDefaultEncoding();
return prop;
}
public Object setText(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObj) throws CmsException {
Hashtable parameters = (Hashtable)userObj;
String content = (String)parameters.get(CmsWorkplaceDefault.C_PARA_CONTENT);
boolean existsContentParam = (content != null && (!"".equals(content)));
// Check the existance of the "file" parameter
if(!existsContentParam) {
if(CmsLog.getLog(this).isWarnEnabled() ) {
CmsLog.getLog(this).warn("No content found");
}
content = "";
}
// Escape the text for including it in HTML text
return content;
}
/**
* Pre-Sets the value of the title input field.
* This method is directly called by the content definiton.
* @param Cms The CmsObject.
* @param lang The language file.
* @param parameters User parameters.
* @return Value that is pre-set into the title field.
* @throws CmsExeption if something goes wrong.
*/
public String setTitle(CmsObject cms, CmsXmlLanguageFile lang,
Hashtable parameters) throws CmsException {
I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
String name = (String)session.getValue("te_title");
return CmsEncoder.escapeXml(name);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -