001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/database/CmsNewResourceExtendedHtmlImport.java,v $
003: * Date : $Date: 2008-02-27 12:05:51 $
004: * Version: $Revision: 1.2 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.workplace.tools.database;
033:
034: import org.opencms.jsp.CmsJspActionElement;
035: import org.opencms.util.CmsStringUtil;
036: import org.opencms.widgets.CmsDisplayWidget;
037: import org.opencms.widgets.CmsHttpUploadWidget;
038: import org.opencms.workplace.CmsWidgetDialogParameter;
039:
040: import java.util.Iterator;
041:
042: import javax.servlet.http.HttpServletRequest;
043: import javax.servlet.http.HttpServletResponse;
044: import javax.servlet.jsp.PageContext;
045:
046: /**
047: * Dialog to define an extended HTML import in the new Dialog for the current user.<p>
048: *
049: * If the advanced button is pressed or the validation is false, then the {@link #MODE_ADVANCED} mode
050: * of {@link CmsHtmlImportDialog} is shown. <p>
051: *
052: * The following files use this class:
053: * <ul>
054: * <li><code>/commons/newresource_uploadHtml.jsp</code> (Contains only a redirect to the uploadhtml.jsp)</li>
055: * <li><code>/explorer/uploadhtml/uploadhtml.jsp</code></li>
056: * </ul>
057: * <p>
058: *
059: * @see CmsHtmlImportDialog <p>
060: *
061: * @author Anja Röttgers
062: *
063: * @version $Revision: 1.2 $
064: *
065: */
066: public class CmsNewResourceExtendedHtmlImport extends
067: CmsHtmlImportDialog {
068:
069: /** the action parameter for the advanced button. */
070: public static final String ACTION_IMPORT = "dialogimport";
071:
072: /** marker of using the advanced button. */
073: private boolean m_advanced;
074:
075: /**
076: * Public constructor with JSP action element.<p>
077: *
078: * @param jsp an initialized JSP action element
079: */
080: public CmsNewResourceExtendedHtmlImport(CmsJspActionElement jsp) {
081:
082: super (jsp);
083:
084: }
085:
086: /**
087: * Public constructor with JSP variables.<p>
088: *
089: * @param context the JSP page context
090: * @param req the JSP request
091: * @param res the JSP response
092: */
093: public CmsNewResourceExtendedHtmlImport(PageContext context,
094: HttpServletRequest req, HttpServletResponse res) {
095:
096: this (new CmsJspActionElement(context, req, res));
097: }
098:
099: /**
100: * @see org.opencms.workplace.CmsWidgetDialog#dialogButtonsCustom()
101: */
102: public String dialogButtonsCustom() {
103:
104: if (m_advanced) {
105: return super .dialogButtonsCustom();
106: }
107: boolean onlyDisplay = true;
108: Iterator it = getWidgets().iterator();
109: while (it.hasNext()) {
110: CmsWidgetDialogParameter wdp = (CmsWidgetDialogParameter) it
111: .next();
112: if (!(wdp.getWidget() instanceof CmsDisplayWidget)) {
113: onlyDisplay = false;
114: break;
115: }
116: }
117: if (!onlyDisplay && !ACTION_IMPORT.equals(getParamAction())) {
118: // this is a single page dialog, create common buttons
119: return dialogButtons(new int[] { BUTTON_OK, BUTTON_CANCEL,
120: BUTTON_ADVANCED }, new String[] {
121: "",
122: "",
123: " onclick=\"submitAction('" + ACTION_IMPORT
124: + "', form);\"" });
125: }
126: // this is a display only dialog
127: return "";
128: }
129:
130: /**
131: * @see org.opencms.workplace.CmsWidgetDialog#createDialogHtml(java.lang.String)
132: */
133: protected String createDialogHtml(String dialog) {
134:
135: if (m_advanced) {
136: return super .createDialogHtml(dialog);
137: }
138:
139: StringBuffer result = new StringBuffer(1024);
140:
141: result.append(createWidgetTableStart());
142: // show error header once if there were validation errors
143: result.append(createWidgetErrorHeader());
144:
145: if (dialog.equals(PAGES[0])) {
146:
147: result
148: .append(createWidgetBlockStart(key(Messages.GUI_HTMLIMPORT_BLOCK_LABEL_FOLDER_0)));
149: result.append(createDialogRowsHtml(0, 0));
150: result.append(createWidgetBlockEnd());
151: }
152:
153: result.append(createWidgetTableEnd());
154: return result.toString();
155:
156: }
157:
158: /**
159: * @see org.opencms.workplace.CmsWidgetDialog#defineWidgets()
160: */
161: protected void defineWidgets() {
162:
163: m_advanced = !CmsStringUtil.isEmpty(getParamAction());
164: if (m_advanced) {
165: super .defineWidgets();
166: } else {
167:
168: initHtmlImportObject();
169: setKeyPrefix(KEY_PREFIX);
170: addWidget(getDialogParameter("httpDir",
171: new CmsHttpUploadWidget()));
172: }
173: // set the current directory as the destination directory
174: m_htmlimport.setDestinationDir(this .getSettings()
175: .getExplorerResource());
176: // it can only be imported with HTTP upload
177: m_htmlimport.setInputDir("");
178:
179: }
180:
181: }
|