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.ui.actions;
029
030import org.opencms.file.CmsResource;
031import org.opencms.main.OpenCms;
032import org.opencms.ui.A_CmsUI;
033import org.opencms.ui.I_CmsDialogContext;
034import org.opencms.ui.components.extensions.CmsJSPBrowserFrameExtension;
035
036import java.util.List;
037
038/**
039 * Abstract class for actions to display a JSP file in a vaadin window.<p>
040 *
041 * How to pass resources to and from JSP:
042 * -GET request parameter "resource" returns an array of UUIDs as String.<p>
043 * -JavaScript function "window.parent.changedResources(resources);" closes the window and returns the String array "resources" to the server<p>
044 */
045public abstract class A_CmsJSPAction extends A_CmsWorkplaceAction {
046
047    /**
048     * @see org.opencms.ui.actions.I_CmsWorkplaceAction#executeAction(org.opencms.ui.I_CmsDialogContext)
049     */
050    public void executeAction(I_CmsDialogContext context) {
051
052        String link = OpenCms.getLinkManager().substituteLinkForRootPath(A_CmsUI.getCmsObject(), getJSPPath())
053            + getRequestString(context.getResources());
054        CmsJSPBrowserFrameExtension.showExtendedBrowserFrame(link, context);
055    }
056
057    /**
058     * Sets the absolute path (in the vfs) to a jsp file used for the action.<p>
059     *
060     * @return path of jsp file
061     */
062    public abstract String getJSPPath();
063
064    /**
065     * Creates string for get—request with given list of resources.<p>
066     *
067     * @param resources to be transmitted
068     * @return valid string for get-request
069     */
070    protected String getRequestString(List<CmsResource> resources) {
071
072        String res = "?";
073
074        for (CmsResource resource : resources) {
075            res += "resources=" + resource.getStructureId().getStringValue() + "&";
076        }
077        return res.substring(0, res.length() - 1); //Remove last "&"
078    }
079}