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.util.CmsStringUtil;
032import org.opencms.widgets.CmsDisplayWidget;
033import org.opencms.widgets.CmsHttpUploadWidget;
034import org.opencms.workplace.CmsWidgetDialogParameter;
035
036import java.util.Iterator;
037
038import javax.servlet.http.HttpServletRequest;
039import javax.servlet.http.HttpServletResponse;
040import javax.servlet.jsp.PageContext;
041
042/**
043 * Dialog to define an extended HTML import in the new Dialog for the current user.<p>
044 *
045 * If the advanced button is pressed or the validation is false, then the {@link #MODE_ADVANCED} mode
046 * of {@link CmsHtmlImportDialog} is shown. <p>
047 *
048 * The following files use this class:
049 * <ul>
050 * <li><code>/commons/newresource_uploadHtml.jsp</code> (Contains only a redirect to the uploadhtml.jsp)</li>
051 * <li><code>/explorer/uploadhtml/uploadhtml.jsp</code></li>
052 * </ul>
053 * <p>
054 *
055 * @see CmsHtmlImportDialog <p>
056 *
057 */
058public class CmsNewResourceExtendedHtmlImport extends CmsHtmlImportDialog {
059
060    /** the action parameter for the advanced button. */
061    public static final String ACTION_IMPORT = "dialogimport";
062
063    /** marker of using the advanced button. */
064    private boolean m_advanced;
065
066    /**
067     * Public constructor with JSP action element.<p>
068     *
069     * @param jsp an initialized JSP action element
070     */
071    public CmsNewResourceExtendedHtmlImport(CmsJspActionElement jsp) {
072
073        super(jsp);
074
075    }
076
077    /**
078     * Public constructor with JSP variables.<p>
079     *
080     * @param context the JSP page context
081     * @param req the JSP request
082     * @param res the JSP response
083     */
084    public CmsNewResourceExtendedHtmlImport(PageContext context, HttpServletRequest req, HttpServletResponse res) {
085
086        this(new CmsJspActionElement(context, req, res));
087    }
088
089    /**
090     * @see org.opencms.workplace.CmsWidgetDialog#dialogButtonsCustom()
091     */
092    @Override
093    public String dialogButtonsCustom() {
094
095        if (m_advanced) {
096            return super.dialogButtonsCustom();
097        }
098        boolean onlyDisplay = true;
099        Iterator it = getWidgets().iterator();
100        while (it.hasNext()) {
101            CmsWidgetDialogParameter wdp = (CmsWidgetDialogParameter)it.next();
102            if (!(wdp.getWidget() instanceof CmsDisplayWidget)) {
103                onlyDisplay = false;
104                break;
105            }
106        }
107        if (!onlyDisplay && !ACTION_IMPORT.equals(getParamAction())) {
108            // this is a single page dialog, create common buttons
109            return dialogButtons(
110                new int[] {BUTTON_OK, BUTTON_CANCEL, BUTTON_ADVANCED},
111                new String[] {"", "", " onclick=\"submitAction('" + ACTION_IMPORT + "', form);\""});
112        }
113        // this is a display only dialog
114        return "";
115    }
116
117    /**
118     * @see org.opencms.workplace.CmsWidgetDialog#createDialogHtml(java.lang.String)
119     */
120    @Override
121    protected String createDialogHtml(String dialog) {
122
123        if (m_advanced) {
124            return super.createDialogHtml(dialog);
125        }
126
127        StringBuffer result = new StringBuffer(1024);
128
129        result.append(createWidgetTableStart());
130        // show error header once if there were validation errors
131        result.append(createWidgetErrorHeader());
132
133        if (dialog.equals(PAGES[0])) {
134
135            result.append(createWidgetBlockStart(key(Messages.GUI_HTMLIMPORT_BLOCK_LABEL_FOLDER_0)));
136            result.append(createDialogRowsHtml(0, 0));
137            result.append(createWidgetBlockEnd());
138        }
139
140        result.append(createWidgetTableEnd());
141        return result.toString();
142
143    }
144
145    /**
146     * @see org.opencms.workplace.CmsWidgetDialog#defineWidgets()
147     */
148    @Override
149    protected void defineWidgets() {
150
151        m_advanced = !CmsStringUtil.isEmpty(getParamAction());
152        if (m_advanced) {
153            super.defineWidgets();
154        } else {
155
156            initHtmlImportObject();
157            setKeyPrefix(KEY_PREFIX);
158            addWidget(getDialogParameter("httpDir", new CmsHttpUploadWidget()));
159        }
160        // set the current directory as the destination directory
161        m_htmlimport.setDestinationDir(getSettings().getExplorerResource());
162        // it can only be imported with HTTP upload
163        m_htmlimport.setInputDir("");
164
165    }
166
167}