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.tools.workplace.rfsfile;
029
030import org.opencms.jsp.CmsJspActionElement;
031import org.opencms.main.OpenCms;
032import org.opencms.security.CmsRoleViolationException;
033import org.opencms.util.CmsRfsFileViewer;
034import org.opencms.workplace.CmsWidgetDialog;
035
036import java.util.ArrayList;
037import java.util.List;
038
039import javax.servlet.http.HttpServletRequest;
040import javax.servlet.http.HttpServletResponse;
041import javax.servlet.jsp.PageContext;
042
043/**
044 * Extending this class enables different
045 * <code>{@link org.opencms.workplace.CmsWidgetDialog}</code> implementations to
046 * share the access to a file in the RFS via the member {@link #m_logView}.<p>
047 *
048 * Here the support for the init / commit lifecycle of this RFS file access is
049 * added transparently.<p>
050 *
051 * @since 6.0.0
052 */
053public abstract class A_CmsRfsFileWidgetDialog extends CmsWidgetDialog {
054
055    /** The pages array for possible multi-page dialogs. This is a dummy. */
056    public static String[] PAGES = {"page1"};
057
058    /** The bean that accesses the underlying file in portions. */
059    protected CmsRfsFileViewer m_logView;
060
061    /**
062     * Initializes the dialog object: a <code>{@link CmsRfsFileViewer}</code> bean that
063     * is shared amongst all related dialog classes (subclasses of this class). <p>
064     *
065     * @param jsp the bundle of all request-response related information
066     */
067    public A_CmsRfsFileWidgetDialog(CmsJspActionElement jsp) {
068
069        super(jsp);
070    }
071
072    /**
073     * Delegates to the 2nd constructor. <p>
074     *
075     * @param context a PageContext
076     * @param req the HttpServletRequest
077     * @param res the HttpServletResponse
078     */
079    public A_CmsRfsFileWidgetDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) {
080
081        this(new CmsJspActionElement(context, req, res));
082    }
083
084    /**
085     * Commits the <code>{@link CmsRfsFileViewer}</code> to the
086     * <code>{@link org.opencms.workplace.CmsWorkplaceManager}</code>. <p>
087     *
088     * @see org.opencms.workplace.CmsWidgetDialog#actionCommit()
089     */
090    @Override
091    public void actionCommit() {
092
093        List<Throwable> errors = new ArrayList<Throwable>();
094        try {
095            OpenCms.getWorkplaceManager().setFileViewSettings(getCms(), m_logView);
096        } catch (CmsRoleViolationException e) {
097            errors.add(e);
098        }
099        // set the list of errors to display when saving failed
100        setCommitErrors(errors);
101    }
102
103    /**
104     * Subclasses have to invoke this method with <code>super.defineWidgets()</code>
105     * as here the internal bean <code>{@link #m_logView}</code> is retrieved. <p>
106     *
107     * @see org.opencms.workplace.CmsWidgetDialog#defineWidgets()
108     */
109    @Override
110    protected void defineWidgets() {
111
112        initLogfileViewBean();
113    }
114
115    /**
116     * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
117     */
118    @Override
119    protected String[] getPageArray() {
120
121        return PAGES;
122    }
123
124    /**
125     * Initializes the login message object for this dialog.<p>
126     *
127     * The {@link CmsRfsFileViewer} instance is obtained from the
128     * <code>{@link org.opencms.workplace.CmsWorkplaceManager}</code>.
129     */
130    protected void initLogfileViewBean() {
131
132        // clone to get a modifiable (not frozen) instance.
133        m_logView = (CmsRfsFileViewer)OpenCms.getWorkplaceManager().getFileViewSettings().clone();
134    }
135
136    /**
137     * @see org.opencms.workplace.CmsWorkplace#initMessages()
138     */
139    @Override
140    protected void initMessages() {
141
142        // add specific dialog resource bundle
143        addMessages(Messages.get().getBundleName());
144        // also include top-level messages to allow the admin navigation access messages of the module top-package
145        // that is shared with other tools.
146        addMessages(org.opencms.workplace.tools.workplace.Messages.get().getBundleName());
147        // add default resource bundles
148        super.initMessages();
149    }
150}