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.database;
029
030import org.opencms.jsp.CmsJspActionElement;
031import org.opencms.main.CmsException;
032import org.opencms.main.OpenCms;
033import org.opencms.workplace.administration.A_CmsImportFromHttp;
034import org.opencms.workplace.tools.CmsToolDialog;
035import org.opencms.workplace.tools.CmsToolManager;
036
037import java.io.IOException;
038import java.util.HashMap;
039import java.util.Map;
040
041import javax.servlet.ServletException;
042import javax.servlet.http.HttpServletRequest;
043import javax.servlet.http.HttpServletResponse;
044import javax.servlet.jsp.PageContext;
045
046/**
047 * Class to upload a zip file containing VFS resources with HTTP upload.<p>
048 *
049 * @since 6.0.0
050 */
051public class CmsDatabaseImportFromHttp extends A_CmsImportFromHttp {
052
053    /** The dialog URI. */
054    public static final String DIALOG_URI = PATH_WORKPLACE + "admin/database/importhttp.jsp";
055
056    /** Keep permissions request parameter name. */
057    public static final String PARAM_KEEPPERMISSIONS = "keepPermissions";
058
059    /** The keep permissions flag stored by the check box widget. */
060    private String m_keepPermissions;
061
062    /**
063     * Public constructor with JSP action element.<p>
064     *
065     * @param jsp an initialized JSP action element
066     */
067    public CmsDatabaseImportFromHttp(CmsJspActionElement jsp) {
068
069        super(jsp);
070    }
071
072    /**
073     * Public constructor with JSP variables.<p>
074     *
075     * @param context the JSP page context
076     * @param req the JSP request
077     * @param res the JSP response
078     */
079    public CmsDatabaseImportFromHttp(PageContext context, HttpServletRequest req, HttpServletResponse res) {
080
081        this(new CmsJspActionElement(context, req, res));
082    }
083
084    /**
085     * @see org.opencms.workplace.administration.A_CmsImportFromHttp#actionCommit()
086     */
087    @Override
088    public void actionCommit() throws IOException, ServletException {
089
090        try {
091            copyFileToServer(OpenCms.getSystemInfo().getPackagesRfsPath());
092        } catch (CmsException e) {
093            // error copying the file to the OpenCms server
094            setException(e);
095            return;
096        }
097        Map params = new HashMap();
098        params.put(PARAM_FILE, getParamImportfile());
099        params.put(PARAM_KEEPPERMISSIONS.toLowerCase(), getParamKeepPermissions());
100        // set style to display report in correct layout
101        params.put(PARAM_STYLE, CmsToolDialog.STYLE_NEW);
102        // set close link to get back to overview after finishing the import
103        params.put(PARAM_CLOSELINK, CmsToolManager.linkForToolPath(getJsp(), "/database"));
104        // redirect to the report output JSP
105        getToolManager().jspForwardPage(this, CmsDatabaseImportFromServer.IMPORT_ACTION_REPORT, params);
106    }
107
108    /**
109     * @see org.opencms.workplace.administration.A_CmsImportFromHttp#getDialogReturnUri()
110     */
111    @Override
112    public String getDialogReturnUri() {
113
114        return DIALOG_URI;
115    }
116
117    /**
118     * @see org.opencms.workplace.administration.A_CmsImportFromHttp#getImportMessage()
119     */
120    @Override
121    public String getImportMessage() {
122
123        return key(Messages.GUI_DATABASE_IMPORT_FILE_0);
124    }
125
126    /**
127     * Returns the keepPermissions parameter.<p>
128     *
129     * @return the keepPermissions parameter
130     */
131    public String getParamKeepPermissions() {
132
133        return m_keepPermissions;
134    }
135
136    /**
137     * @see org.opencms.workplace.administration.A_CmsImportFromHttp#getStarttext()
138     */
139    @Override
140    public String getStarttext() {
141
142        return key(Messages.GUI_DATABASE_IMPORT_BLOCK_0);
143    }
144
145    /**
146     * Sets the keepPermissions parameter.<p>
147     *
148     * @param keepPermissions the keepPermissions parameter
149     */
150    public void setParamKeepPermissions(String keepPermissions) {
151
152        m_keepPermissions = keepPermissions;
153    }
154
155    /**
156     * @see org.opencms.workplace.CmsWorkplace#initMessages()
157     */
158    @Override
159    protected void initMessages() {
160
161        // add specific dialog resource bundle
162        addMessages(Messages.get().getBundleName());
163        // add default resource bundles
164        addMessages(org.opencms.workplace.Messages.get().getBundleName());
165        addMessages(org.opencms.workplace.tools.Messages.get().getBundleName());
166    }
167}