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, 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.ade.containerpage;
029
030import org.opencms.ade.containerpage.shared.CmsCntPageData;
031import org.opencms.ade.containerpage.shared.rpc.I_CmsContainerpageService;
032import org.opencms.gwt.CmsGwtActionElement;
033import org.opencms.gwt.CmsRpcException;
034import org.opencms.gwt.shared.CmsCoreData;
035import org.opencms.main.OpenCms;
036
037import javax.servlet.http.HttpServletRequest;
038import javax.servlet.http.HttpServletResponse;
039import javax.servlet.jsp.PageContext;
040
041/**
042 * Action element for container-page editor includes.<p>
043 *
044 * @since 8.0.0
045 */
046public class CmsContainerpageActionElement extends CmsGwtActionElement {
047
048    /** The OpenCms module name. */
049    public static final String CMS_MODULE_NAME = "org.opencms.ade.containerpage";
050
051    /** The GWT module name. */
052    public static final String GWT_MODULE_NAME = CmsCoreData.ModuleKey.containerpage.name();
053
054    /** The current container page data. */
055    private CmsCntPageData m_cntPageData;
056
057    /**
058     * Constructor.<p>
059     *
060     * @param context the JSP page context object
061     * @param req the JSP request
062     * @param res the JSP response
063     */
064    public CmsContainerpageActionElement(PageContext context, HttpServletRequest req, HttpServletResponse res) {
065
066        super(context, req, res);
067    }
068
069    /**
070     * @see org.opencms.gwt.CmsGwtActionElement#export()
071     */
072    @Override
073    public String export() throws Exception {
074
075        return "";
076    }
077
078    /**
079     * @see org.opencms.gwt.CmsGwtActionElement#exportAll()
080     */
081    @Override
082    public String exportAll() throws Exception {
083
084        StringBuffer sb = new StringBuffer();
085        sb.append(super.export());
086        String prefetchedData = exportDictionary(
087            CmsCntPageData.DICT_NAME,
088            I_CmsContainerpageService.class.getMethod("prefetch"),
089            getCntPageData());
090        sb.append(prefetchedData);
091        sb.append(exportModuleScriptTag(GWT_MODULE_NAME));
092        sb.append("<script type=\"text/javascript\" src=\"");
093        sb.append(
094            OpenCms.getLinkManager().substituteLinkForRootPath(
095                getCmsObject(),
096                "/system/workplace/editors/tinymce/opencms_plugin.js"));
097        sb.append("\"></script>\n<style type=\"text/css\">\n    html {\n        overflow-y: scroll;\n    }\n</style>");
098
099        return sb.toString();
100    }
101
102    /**
103     * Returns the needed server data for client-side usage.<p>
104     *
105     * @return the needed server data for client-side usage
106     */
107    public CmsCntPageData getCntPageData() {
108
109        if (m_cntPageData == null) {
110            try {
111                m_cntPageData = CmsContainerpageService.prefetch(getRequest());
112            } catch (@SuppressWarnings("unused") CmsRpcException e) {
113                // ignore, should never happen, and it is already logged
114            }
115        }
116        return m_cntPageData;
117    }
118}