📄 cmsdefaultpageeditor.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/editors/CmsDefaultPageEditor.java,v $
* Date : $Date: 2006/03/27 14:52:49 $
* Version: $Revision: 1.22 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software GmbH, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.workplace.editors;
import org.opencms.file.CmsFile;
import org.opencms.file.CmsPropertyDefinition;
import org.opencms.file.CmsRequestContext;
import org.opencms.i18n.CmsEncoder;
import org.opencms.i18n.CmsLocaleManager;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.util.CmsHtmlConverter;
import org.opencms.util.CmsStringUtil;
import org.opencms.xml.page.CmsXmlPage;
import org.opencms.xml.page.CmsXmlPageFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import javax.servlet.ServletException;
import javax.servlet.jsp.JspException;
import org.apache.commons.logging.Log;
/**
* Provides methods for building editors for the CmsDefaultPage page type.<p>
*
* Extend this class for all editors that work with the CmsDefaultPage.<p>
*
* @author Andreas Zahner
*
* @version $Revision: 1.22 $
*
* @since 6.0.0
*/
public abstract class CmsDefaultPageEditor extends CmsEditor {
/** Parameter name for the request parameter "element name". */
public static final String PARAM_ELEMENTNAME = "elementname";
/** Parameter name for the request parameter "old element name". */
public static final String PARAM_OLDELEMENTNAME = "oldelementname";
/** Name of the special body element from an XMLTemplate. */
public static final String XML_BODY_ELEMENT = "body";
/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(CmsDefaultPageEditor.class);
/** File object used to read and write contents. */
protected CmsFile m_file;
/** Page object used from the action and init methods, be sure to initialize this e.g. in the initWorkplaceRequestValues method. */
protected CmsXmlPage m_page;
private List m_elementList;
/** The element locale. */
private Locale m_elementLocale;
private String m_paramElementname;
private String m_paramOldelementname;
/** option values for font select boxes. */
public static final String[] SELECTBOX_FONTS = {
"Arial",
"Arial Narrow",
"System",
"Times New Roman",
"Verdana",
"Monospace",
"SansSerif"};
/**
* Public constructor.<p>
*
* @param jsp an initialized JSP action element
*/
public CmsDefaultPageEditor(CmsJspActionElement jsp) {
super(jsp);
}
/**
* Performs the change body action of the editor.<p>
*/
public void actionChangeBodyElement() {
try {
// save eventually changed content of the editor to the temporary file
Locale oldLocale = CmsLocaleManager.getLocale(getParamOldelementlanguage());
performSaveContent(getParamOldelementname(), oldLocale);
} catch (CmsException e) {
// show error page
try {
showErrorPage(this, e);
} catch (JspException exc) {
// should usually never happen
if (LOG.isInfoEnabled()) {
LOG.info(exc);
}
}
}
// re-initialize the element name if the language has changed
if (!getParamElementlanguage().equals(getParamOldelementlanguage())) {
initBodyElementName(getParamOldelementname());
}
// get the new editor content
initContent();
}
/**
* Performs the cleanup body action of the editor.<p>
*/
public void actionCleanupBodyElement() {
try {
// save eventually changed content of the editor to the temporary file
Locale oldLocale = CmsLocaleManager.getLocale(getParamOldelementlanguage());
performSaveContent(getParamOldelementname(), oldLocale);
} catch (CmsException e) {
// show error page
try {
showErrorPage(this, e);
} catch (JspException exc) {
// should usually never happen
if (LOG.isInfoEnabled()) {
LOG.info(exc);
}
}
}
}
/**
* @see org.opencms.workplace.editors.CmsEditor#actionClear(boolean)
*/
public void actionClear(boolean forceUnlock) {
// delete the temporary file
deleteTempFile();
boolean directEditMode = Boolean.valueOf(getParamDirectedit()).booleanValue();
boolean modified = Boolean.valueOf(getParamModified()).booleanValue();
if (directEditMode || forceUnlock || !modified) {
// unlock the resource when in direct edit mode, force unlock is true or resource was not modified
try {
getCms().unlockResource(getParamResource());
} catch (CmsException e) {
// should usually never happen
if (LOG.isInfoEnabled()) {
LOG.info(e);
}
}
}
}
/**
* Performs a configurable action performed by the editor.<p>
*
* The default action is: save resource, clear temporary files and publish the resource directly.<p>
*
* @throws IOException if a forward fails
* @throws JspException if including a JSP fails
* @throws ServletException if a forward fails
*/
public void actionDirectEdit() throws IOException, JspException, ServletException {
// get the action class from the OpenCms runtime property
I_CmsEditorActionHandler actionClass = OpenCms.getWorkplaceManager().getEditorActionHandler();
if (actionClass == null) {
// error getting the action class, save content and exit the editor
actionSave();
actionExit();
} else {
actionClass.editorAction(this, getJsp());
}
}
/**
* Performs the exit editor action and deletes the temporary file.<p>
*
* @see org.opencms.workplace.editors.CmsEditor#actionExit()
*/
public void actionExit() throws IOException, JspException, ServletException {
if (getAction() == ACTION_CANCEL) {
// save and exit was canceled
return;
}
// clear temporary file and unlock resource, if in directedit mode
actionClear(false);
// close the editor
actionClose();
}
/**
* Performs the preview page action in a new browser window.<p>
*
* @throws IOException if redirect fails
* @throws JspException if inclusion of error page fails
*/
public void actionPreview() throws IOException, JspException {
try {
// save content of the editor to the temporary file
performSaveContent(getParamElementname(), getElementLocale());
} catch (CmsException e) {
// show error page
showErrorPage(this, e);
}
// redirect to the temporary file with current active element language
String param = "?" + org.opencms.i18n.CmsLocaleManager.PARAMETER_LOCALE + "=" + getParamElementlanguage();
sendCmsRedirect(getParamTempfile() + param);
}
/**
* @see org.opencms.workplace.editors.CmsEditor#actionSave()
*/
public void actionSave() throws JspException {
try {
// save content to temporary file
performSaveContent(getParamElementname(), getElementLocale());
// copy the temporary file content back to the original file
commitTempFile();
// set the modified parameter
setParamModified(Boolean.TRUE.toString());
} catch (CmsException e) {
showErrorPage(e);
}
if (getAction() != ACTION_CANCEL) {
// save successful, set save action
setAction(ACTION_SAVE);
}
}
/**
* Builds the html String for the gallery buttons.<p>
*
* @param options the display configuration for the editor
* @param buttonStyle the style for the buttons
* @param displayOptions the display options for the editor
* @return the html String for the gallery buttons
*/
public abstract String buildGalleryButtons(
CmsEditorDisplayOptions options,
int buttonStyle,
Properties displayOptions);
/**
* Builds the html String for the element language selector.<p>
*
* @param attributes optional attributes for the <select> tag
* @return the html for the element language selectbox
*/
public String buildSelectElementLanguage(String attributes) {
return buildSelectElementLanguage(attributes, getParamTempfile(), getElementLocale());
}
/**
* Builds the html String for the element name selector.<p>
*
* @param attributes optional attributes for the <select> tag
* @return the html for the element name selectbox
*/
public String buildSelectElementName(String attributes) {
// get the active page elements
List elementList = getElementList();
int counter = 0;
int currentIndex = -1;
List options = new ArrayList(elementList.size());
List values = new ArrayList(elementList.size());
String elementName = getParamElementname();
if (CmsStringUtil.isEmpty(elementName)) {
elementName = getParamOldelementname();
}
for (int i = 0; i < elementList.size(); i++) {
// get the current list element
CmsDialogElement element = (CmsDialogElement)elementList.get(i);
if (CmsStringUtil.isNotEmpty(elementName) && elementName.equals(element.getName())) {
// current element is the displayed one, mark it as selected
currentIndex = counter;
}
if ((!m_page.hasValue(element.getName(), getElementLocale()) && element.isMandantory())
|| m_page.isEnabled(element.getName(), getElementLocale())) {
// add element if it is not available or if it is enabled
options.add(element.getNiceName());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -