001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.workplace.editors;
029
030import org.opencms.jsp.CmsJspActionElement;
031import org.opencms.main.CmsException;
032import org.opencms.main.CmsLog;
033import org.opencms.security.CmsPermissionSet;
034import org.opencms.util.CmsStringUtil;
035import org.opencms.workplace.CmsWorkplaceSettings;
036
037import javax.servlet.http.HttpServletRequest;
038
039import org.apache.commons.logging.Log;
040
041/**
042 * Helper class to create the editor frameset.<p>
043 *
044 * The following files use this class:
045 * <ul>
046 * <li>/jsp/editors/editor_html
047 * </ul>
048 * <p>
049 *
050 * @since 6.0.0
051 */
052public class CmsEditorFrameset extends CmsEditor {
053
054    /** The log object for this class. */
055    private static final Log LOG = CmsLog.getLog(CmsEditorFrameset.class);
056
057    /** The title to be displayed in the editor. */
058    private String m_paramEditorTitle;
059
060    /**
061     * Public constructor.<p>
062     *
063     * @param jsp an initialized JSP action element
064     */
065    public CmsEditorFrameset(CmsJspActionElement jsp) {
066
067        super(jsp);
068    }
069
070    /**
071     * Deletes the temporary file and unlocks the edited resource when in direct edit mode.<p>
072     *
073     * This method is needed in the editor close help frame, which is called when the user presses
074     * the "back" button or closes the browser window when editing a page.<p>
075     *
076     * @param forceUnlock if true, the resource will be unlocked anyway
077     */
078    @Override
079    public void actionClear(boolean forceUnlock) {
080
081        // delete the temporary file
082        deleteTempFile();
083        if (Boolean.valueOf(getParamDirectedit()).booleanValue() || forceUnlock) {
084            // unlock the resource when in direct edit mode or force unlock is true
085            try {
086                getCms().unlockResource(getParamResource());
087            } catch (CmsException e) {
088                // should usually never happen
089                if (LOG.isInfoEnabled()) {
090                    LOG.info(e.getLocalizedMessage(), e);
091                }
092            }
093        }
094    }
095
096    /**
097     * @see org.opencms.workplace.editors.CmsEditor#actionExit()
098     */
099    @Override
100    public final void actionExit() {
101
102        // do nothing
103    }
104
105    /**
106     * @see org.opencms.workplace.editors.CmsEditor#actionSave()
107     */
108    @Override
109    public final void actionSave() {
110
111        // do nothing
112    }
113
114    /**
115     * @see org.opencms.workplace.editors.CmsEditor#getEditorResourceUri()
116     */
117    @Override
118    public final String getEditorResourceUri() {
119
120        // return empty String
121        return "";
122    }
123
124    /**
125     * Returns the editor title.<p>
126     *
127     * @return the editor title
128     */
129    public String getParamEditorTitle() {
130
131        if (CmsStringUtil.isEmpty(m_paramEditorTitle)) {
132            return key(Messages.GUI_EDITOR_TITLE_PREFIX_0) + " " + getParamResource();
133        }
134        return m_paramEditorTitle;
135    }
136
137    /**
138     * Sets the editor title.<p>
139     *
140     * @param editorTitle the editor title to set
141     */
142    public void setParamEditorTitle(String editorTitle) {
143
144        m_paramEditorTitle = editorTitle;
145    }
146
147    /**
148     * @see org.opencms.workplace.editors.CmsEditor#initContent()
149     */
150    @Override
151    protected final void initContent() {
152
153        // do nothing
154    }
155
156    /**
157     * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
158     */
159    @Override
160    protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {
161
162        // fill the parameter values in the get/set methods
163        fillParamValues(settings, request);
164
165        if (getDialogRealUri().endsWith("editor.jsp")) {
166            // check the required permissions to edit the resource only in the main frame
167            if (!checkResourcePermissions(CmsPermissionSet.ACCESS_WRITE, false)) {
168                // not write permissions in the folder, close editor
169                try {
170                    actionClose();
171                } catch (Exception e) {
172                    // should usually never happen
173                    if (LOG.isInfoEnabled()) {
174                        LOG.info(e.getLocalizedMessage(), e);
175                    }
176                }
177            }
178        }
179    }
180}