001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (C) Alkacon Software (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.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 javax.servlet.http.HttpServletRequest;
040import javax.servlet.http.HttpServletResponse;
041import javax.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(exportDictionary(
097            CmsPostUploadDialogBean.DICT_NAME,
098            I_CmsPostUploadDialogService.class.getMethod("prefetch"),
099            getDialogData()));
100        sb.append(exportModuleScriptTag(GWT_MODULE_NAME));
101        return sb.toString();
102    }
103
104    /**
105     * Returns the needed server data for client-side usage.<p>
106     *
107     * @return the needed server data for client-side usage
108     * @throws CmsRpcException if something goes wrong
109     */
110    public CmsPostUploadDialogBean getDialogData() throws CmsRpcException {
111
112        if (m_dialogData == null) {
113            m_dialogData = CmsPostUploadDialogService.prefetch(getRequest());
114        }
115        m_dialogData.setUsePropertyConfiguration(m_useConfiguration);
116        m_dialogData.setAddBasicProperties(m_addBasicProperties);
117        return m_dialogData;
118    }
119
120    /**
121     * Set a flag, indicating if basic properties as configured in the sitemap are merged into the
122     * properties shown on file upload.
123     *
124     * @param addBasicProperties flag, indicating if basic properties as configured in the sitemap should be added
125     */
126    public void setAddBasicProperties(final boolean addBasicProperties) {
127
128        m_addBasicProperties = addBasicProperties;
129    }
130
131    /**
132     * Enables / disables use of property configurations.<p>
133     *
134     * @param useConfiguration if true , use the property configurations
135     */
136    public void setUsePropertyConfiguration(boolean useConfiguration) {
137
138        m_useConfiguration = useConfiguration;
139    }
140
141    /**
142     * Returns a javascript tag that contains a variable deceleration that has the close link as value.<p>
143     *
144     * @return a javascript tag that contains a variable deceleration that has the close link as value
145     */
146    private String exportCloseLink() {
147
148        String closeLink = null;
149        if (getRequest().getAttribute(I_CmsDialogConstants.ATTR_CLOSE_LINK) != null) {
150            closeLink = (String)getRequest().getAttribute(I_CmsDialogConstants.ATTR_CLOSE_LINK);
151        }
152        if (CmsStringUtil.isEmptyOrWhitespaceOnly(closeLink)) {
153            closeLink = CmsWorkplace.FILE_EXPLORER_FILELIST;
154        }
155
156        StringBuffer sb = new StringBuffer();
157        // var closeLink = '/system/workplace/views/explorer/explorer_files.jsp';
158        sb.append(wrapScript("var ", I_CmsDialogConstants.ATTR_CLOSE_LINK, " = \'", closeLink, "\';"));
159        return sb.toString();
160    }
161
162}