001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (C) Alkacon Software (https://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: https://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: https://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.postupload;
029
030import org.opencms.ade.postupload.shared.CmsPostUploadDialogBean;
031import org.opencms.ade.postupload.shared.I_CmsDialogConstants;
032import org.opencms.ade.postupload.shared.rpc.I_CmsPostUploadDialogService;
033import org.opencms.gwt.CmsGwtActionElement;
034import org.opencms.gwt.CmsRpcException;
035import org.opencms.gwt.shared.CmsCoreData;
036import org.opencms.util.CmsStringUtil;
037import org.opencms.workplace.CmsWorkplace;
038
039import jakarta.servlet.http.HttpServletRequest;
040import jakarta.servlet.http.HttpServletResponse;
041import jakarta.servlet.jsp.PageContext;
042
043/**
044 * Action element class used by the upload hook JSP from the org.opencms.ade.postupload module.<p>
045 */
046public class CmsPostUploadDialogActionElement extends CmsGwtActionElement {
047
048    /** The OpenCms module name. */
049    public static final String CMS_MODULE_NAME = "org.opencms.ade.postupload";
050
051    /** The GWT module name. */
052    public static final String GWT_MODULE_NAME = CmsCoreData.ModuleKey.postupload.name();
053
054    /** The dialog data. */
055    private CmsPostUploadDialogBean m_dialogData;
056
057    /** Flag to control if property configuration should be used. */
058    private boolean m_useConfiguration;
059
060    /** Flag to control if configured basic properties should be shown. */
061    private boolean m_addBasicProperties;
062
063    /**
064     * Creates a new instance.<p>
065     *
066     * @param pageContext the current page context
067     * @param request the servlet request
068     * @param response the servlet response
069     */
070    public CmsPostUploadDialogActionElement(
071        PageContext pageContext,
072        HttpServletRequest request,
073        HttpServletResponse response) {
074
075        super(pageContext, request, response);
076    }
077
078    /**
079     * @see org.opencms.gwt.CmsGwtActionElement#export()
080     */
081    @Override
082    public String export() throws Exception {
083
084        return "";
085    }
086
087    /**
088     * @see org.opencms.gwt.CmsGwtActionElement#exportAll()
089     */
090    @Override
091    public String exportAll() throws Exception {
092
093        StringBuffer sb = new StringBuffer();
094        sb.append(super.export());
095        sb.append(exportCloseLink());
096        sb.append(
097            exportDictionary(
098                CmsPostUploadDialogBean.DICT_NAME,
099                I_CmsPostUploadDialogService.class.getMethod("prefetch"),
100                getDialogData()));
101        sb.append(exportModuleScriptTag(GWT_MODULE_NAME));
102        return sb.toString();
103    }
104
105    /**
106     * Returns the needed server data for client-side usage.<p>
107     *
108     * @return the needed server data for client-side usage
109     * @throws CmsRpcException if something goes wrong
110     */
111    public CmsPostUploadDialogBean getDialogData() throws CmsRpcException {
112
113        if (m_dialogData == null) {
114            m_dialogData = CmsPostUploadDialogService.prefetch(getRequest());
115        }
116        m_dialogData.setUsePropertyConfiguration(m_useConfiguration);
117        m_dialogData.setAddBasicProperties(m_addBasicProperties);
118        return m_dialogData;
119    }
120
121    /**
122     * Set a flag, indicating if basic properties as configured in the sitemap are merged into the
123     * properties shown on file upload.
124     *
125     * @param addBasicProperties flag, indicating if basic properties as configured in the sitemap should be added
126     */
127    public void setAddBasicProperties(final boolean addBasicProperties) {
128
129        m_addBasicProperties = addBasicProperties;
130    }
131
132    /**
133     * Enables / disables use of property configurations.<p>
134     *
135     * @param useConfiguration if true , use the property configurations
136     */
137    public void setUsePropertyConfiguration(boolean useConfiguration) {
138
139        m_useConfiguration = useConfiguration;
140    }
141
142    /**
143     * Returns a javascript tag that contains a variable deceleration that has the close link as value.<p>
144     *
145     * @return a javascript tag that contains a variable deceleration that has the close link as value
146     */
147    private String exportCloseLink() {
148
149        String closeLink = null;
150        if (getRequest().getAttribute(I_CmsDialogConstants.ATTR_CLOSE_LINK) != null) {
151            closeLink = (String)getRequest().getAttribute(I_CmsDialogConstants.ATTR_CLOSE_LINK);
152        }
153        if (CmsStringUtil.isEmptyOrWhitespaceOnly(closeLink)) {
154            closeLink = CmsWorkplace.FILE_EXPLORER_FILELIST;
155        }
156
157        StringBuffer sb = new StringBuffer();
158        // var closeLink = '/system/workplace/views/explorer/explorer_files.jsp';
159        sb.append(wrapScript("var ", I_CmsDialogConstants.ATTR_CLOSE_LINK, " = \'", closeLink, "\';"));
160        return sb.toString();
161    }
162
163}