📄 cmsdirecteditdefaultprovider.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/editors/directedit/CmsDirectEditDefaultProvider.java,v $
* Date : $Date: 2006/10/26 12:25:34 $
* Version: $Revision: 1.2 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2002 - 2005 Alkacon Software (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, 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.directedit;
import org.opencms.cache.CmsMemoryObjectCache;
import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsProject;
import org.opencms.file.CmsProperty;
import org.opencms.file.CmsPropertyDefinition;
import org.opencms.i18n.CmsEncoder;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.util.CmsMacroResolver;
import org.opencms.workplace.CmsWorkplace;
import org.opencms.workplace.editors.Messages;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import org.apache.commons.logging.Log;
/**
* Provider for the OpenCms default graphical "direct edit" buttons.<p>
*
* Since OpenCms version 6.2.3,
* this provider is configured as the standard direct edit provider in a common OpenCms installation.<p>
*
* This provider DOES NOT support {@link CmsDirectEditMode#MANUAL} mode.<p>
*
* @author Alexander Kandzior
*
* @version $Revision: 1.2 $
*
* @since 6.2.3
*/
public class CmsDirectEditDefaultProvider extends A_CmsDirectEditProvider implements I_CmsDirectEditProvider {
/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(CmsDirectEditDefaultProvider.class);
/** Indicates the permissions for the last element the was opened. */
protected int m_lastPermissionMode;
/** The include file used by this provider. */
private String m_headerInclude;
/**
* Returns the end HTML for a disabled direct edit button.<p>
*
* @return the end HTML for a disabled direct edit button
*/
public String endDirectEditDisabled() {
return "</div>\n<!-- EDIT BLOCK END (DISABLED) -->\n";
}
/**
* Returns the end HTML for an enabled direct edit button.<p>
*
* @return the end HTML for an enabled direct edit button
*/
public String endDirectEditEnabled() {
return "</div>\n<!-- EDIT BLOCK END (ENABLED) -->\n";
}
/**
* Returns the direct edit include HTML to insert in the page beginning.<p> t
*
* @param params the parameters for the direct edit includes
*
* @return the direct edit include HTML to insert in the page beginning
*/
public String getDirectEditIncludes(CmsDirectEditParams params) {
String closeLink = getLink(params.getLinkForClose());
String deleteLink = getLink(params.getLinkForDelete());
String titleForNew = m_messages.key(Messages.GUI_EDITOR_TITLE_NEW_0);
String skinUri = CmsWorkplace.getSkinUri();
// resolve macros in include header
CmsMacroResolver resolver = CmsMacroResolver.newInstance();
resolver.addMacro("closeLink", closeLink);
resolver.addMacro("deleteLink", deleteLink);
resolver.addMacro("titleForNew", titleForNew);
resolver.addMacro("skinUri", skinUri);
return resolver.resolveMacros(m_headerInclude);
}
/**
* @see org.opencms.workplace.editors.directedit.A_CmsDirectEditProvider#init(org.opencms.file.CmsObject, org.opencms.workplace.editors.directedit.CmsDirectEditMode, java.lang.String)
*/
public void init(CmsObject cms, CmsDirectEditMode mode, String fileName) {
super.init(cms, mode, fileName);
// check if the selected include file is available in the cache
CmsMemoryObjectCache cache = CmsMemoryObjectCache.getInstance();
m_headerInclude = (String)cache.getCachedObject(CmsDirectEditDefaultProvider.class, m_fileName);
if (m_headerInclude == null) {
// the file is not available in the cache
try {
CmsFile file = m_cms.readFile(m_fileName);
// get the encoding for the resource
CmsProperty p = m_cms.readPropertyObject(file, CmsPropertyDefinition.PROPERTY_CONTENT_ENCODING, true);
String e = p.getValue();
if (e == null) {
e = OpenCms.getSystemInfo().getDefaultEncoding();
}
// create a String with the right encoding
m_headerInclude = CmsEncoder.createString(file.getContents(), e);
// store this in the cache
cache.putCachedObject(CmsDirectEditDefaultProvider.class, m_fileName, m_headerInclude);
} catch (CmsException e) {
// this should better not happen
m_headerInclude = "";
LOG.error(Messages.get().getBundle().key(Messages.LOG_DIRECT_EDIT_NO_HEADER_1, fileName), e);
}
}
}
/**
* @see org.opencms.workplace.editors.directedit.I_CmsDirectEditProvider#insertDirectEditEnd(javax.servlet.jsp.PageContext)
*/
public void insertDirectEditEnd(PageContext context) throws JspException {
String content;
switch (m_lastPermissionMode) {
case 1: // disabled
content = endDirectEditDisabled();
break;
case 2: // enabled
content = endDirectEditEnabled();
break;
default: // inactive or undefined
content = null;
}
m_lastPermissionMode = 0;
print(context, content);
}
/**
* @see org.opencms.workplace.editors.directedit.I_CmsDirectEditProvider#insertDirectEditIncludes(javax.servlet.jsp.PageContext, org.opencms.workplace.editors.directedit.CmsDirectEditParams)
*/
public void insertDirectEditIncludes(PageContext context, CmsDirectEditParams params) throws JspException {
print(context, getDirectEditIncludes(params));
}
/**
* @see org.opencms.workplace.editors.directedit.I_CmsDirectEditProvider#insertDirectEditStart(javax.servlet.jsp.PageContext, org.opencms.workplace.editors.directedit.CmsDirectEditParams)
*/
public boolean insertDirectEditStart(PageContext context, CmsDirectEditParams params) throws JspException {
String content;
// check the direct edit permissions of the current user
CmsDirectEditResourceInfo resourceInfo = getResourceInfo(params.getResourceName());
// check the permission mode
m_lastPermissionMode = resourceInfo.getPermissions().getPermission();
switch (m_lastPermissionMode) {
case 1: // disabled
content = startDirectEditDisabled(params, resourceInfo);
break;
case 2: // enabled
content = startDirectEditEnabled(params, resourceInfo);
break;
default: // inactive or undefined
content = null;
}
print(context, content);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -