KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > content > CmsTagReplaceDialog


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/content/CmsTagReplaceDialog.java,v $
3  * Date : $Date: 2006/03/28 10:01:22 $
4  * Version: $Revision: 1.3 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.tools.content;
33
34 import org.opencms.jsp.CmsJspActionElement;
35 import org.opencms.main.CmsIllegalArgumentException;
36 import org.opencms.util.CmsStringUtil;
37 import org.opencms.widgets.CmsInputWidget;
38 import org.opencms.widgets.CmsVfsFileWidget;
39 import org.opencms.workplace.CmsWidgetDialog;
40 import org.opencms.workplace.CmsWidgetDialogParameter;
41 import org.opencms.workplace.CmsWorkplaceSettings;
42 import org.opencms.workplace.tools.CmsToolDialog;
43 import org.opencms.workplace.tools.CmsToolManager;
44
45 import java.io.IOException JavaDoc;
46 import java.util.ArrayList JavaDoc;
47 import java.util.HashMap JavaDoc;
48 import java.util.List JavaDoc;
49 import java.util.Map JavaDoc;
50
51 import javax.servlet.ServletException JavaDoc;
52 import javax.servlet.http.HttpServletRequest JavaDoc;
53 import javax.servlet.http.HttpServletResponse JavaDoc;
54 import javax.servlet.jsp.PageContext JavaDoc;
55
56 /**
57  * Widget dialog that sets the settings to replace HTML Tags in pages below a folder.
58  * <p>
59  *
60  * @author Achim Westermann
61  *
62  * @version $Revision: 1.3 $
63  *
64  * @since 6.1.7
65  */

66 public class CmsTagReplaceDialog extends CmsWidgetDialog {
67
68     /** Localized message keys prefix. */
69     public static final String JavaDoc KEY_PREFIX = "tagreplace";
70
71     /** Defines which pages are valid for this dialog. */
72     public static final String JavaDoc[] PAGES = {"page1"};
73
74     /** The import JSP report workplace URI. */
75     protected static final String JavaDoc TAGREPLACE_ACTION_REPORT = PATH_WORKPLACE
76         + "admin/contenttools/reports/tagreplace.jsp";
77
78     /** The settings object that is edited on this dialog. */
79     private CmsTagReplaceSettings m_settings;
80
81     /**
82      * Public constructor with JSP action element.
83      * <p>
84      *
85      * @param jsp an initialized JSP action element
86      */

87     public CmsTagReplaceDialog(CmsJspActionElement jsp) {
88
89         super(jsp);
90     }
91
92     /**
93      * Public constructor with JSP variables.
94      * <p>
95      *
96      * @param context the JSP page context
97      * @param req the JSP request
98      * @param res the JSP response
99      */

100     public CmsTagReplaceDialog(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
101
102         this(new CmsJspActionElement(context, req, res));
103     }
104
105     /**
106      * @see org.opencms.workplace.CmsWidgetDialog#actionCommit()
107      */

108     public void actionCommit() throws IOException JavaDoc, ServletException JavaDoc {
109
110         List JavaDoc errors = new ArrayList JavaDoc();
111         setDialogObject(m_settings);
112
113         try {
114
115             Map JavaDoc params = new HashMap JavaDoc();
116             // set style to display report in correct layout
117
params.put(PARAM_STYLE, CmsToolDialog.STYLE_NEW);
118             // set close link to get back to overview after finishing the import
119
params.put(PARAM_CLOSELINK, CmsToolManager.linkForToolPath(getJsp(), "/contenttools"));
120             // redirect to the report output JSP
121
getToolManager().jspForwardPage(this, TAGREPLACE_ACTION_REPORT, params);
122
123         } catch (CmsIllegalArgumentException e) {
124             errors.add(e);
125         }
126         // set the list of errors to display when saving failed
127
setCommitErrors(errors);
128     }
129
130     /**
131      * @see org.opencms.workplace.CmsWidgetDialog#createDialogHtml(java.lang.String)
132      */

133     protected String JavaDoc createDialogHtml(String JavaDoc dialog) {
134
135         StringBuffer JavaDoc result = new StringBuffer JavaDoc(1024);
136
137         // create table
138
result.append(createWidgetTableStart());
139
140         // show error header once if there were validation errors
141
result.append(createWidgetErrorHeader());
142
143         // create export file name block
144
result.append(createWidgetBlockStart(Messages.get().getBundle(getLocale()).key(
145             Messages.GUI_TAGREPLACE_DIALOG_BLOCK_SETTINGS_0)));
146         result.append(createDialogRowsHtml(0, 2));
147         result.append(createWidgetBlockEnd());
148
149         // close table
150
result.append(createWidgetTableEnd());
151
152         return result.toString();
153     }
154
155     /**
156      * @see org.opencms.workplace.CmsWidgetDialog#defineWidgets()
157      */

158     protected void defineWidgets() {
159
160         // initialize the export object to use for the dialog
161
initSettingsObject();
162
163         // set localized key prefix
164
setKeyPrefix(KEY_PREFIX);
165         addWidget(new CmsWidgetDialogParameter(m_settings, "replacements", PAGES[0], new CmsInputWidget()));
166         addWidget(new CmsWidgetDialogParameter(m_settings, "workPath", "/", PAGES[0], new CmsVfsFileWidget(
167             false,
168             getCms().getRequestContext().getSiteRoot()), 1, 1));
169
170         addWidget(new CmsWidgetDialogParameter(
171             m_settings,
172             "propertyValueTagReplaceID",
173             PAGES[0],
174             new CmsInputWidget("")));
175     }
176
177     /**
178      * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
179      */

180     protected String JavaDoc[] getPageArray() {
181
182         return PAGES;
183     }
184
185     /**
186      * @see org.opencms.workplace.CmsWorkplace#initMessages()
187      */

188     protected void initMessages() {
189
190         // add specific dialog resource bundle
191
addMessages(Messages.get().getBundleName());
192         // add workplace messages
193
addMessages("org.opencms.workplace.workplace");
194         // add default resource bundles
195
super.initMessages();
196     }
197
198     /**
199      * Initializes the settings object to work with depending on the dialog state and request
200      * parameters.
201      * <p>
202      */

203     protected void initSettingsObject() {
204
205         Object JavaDoc o;
206         if (CmsStringUtil.isEmpty(getParamAction())) {
207             o = new CmsTagReplaceSettings(getCms());
208         } else {
209             // this is not the initial call, get the job object from session
210
o = getDialogObject();
211         }
212
213         if (o == null) {
214             // create a new export handler object
215
m_settings = new CmsTagReplaceSettings(getCms());
216         } else {
217             // reuse export handler object stored in session
218
m_settings = (CmsTagReplaceSettings)o;
219         }
220
221     }
222
223     /**
224      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings,
225      * javax.servlet.http.HttpServletRequest)
226      */

227     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
228
229         // initialize parameters and dialog actions in super implementation
230
super.initWorkplaceRequestValues(settings, request);
231
232         // save the current state of the export handler (may be changed because of the widget
233
// values)
234
setDialogObject(m_settings);
235     }
236 }
Popular Tags