001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/link/CmsInternalLinkValidationDialog.java,v $
003: * Date : $Date: 2008-02-27 12:05:44 $
004: * Version: $Revision: 1.4 $
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.link;
033:
034: import org.opencms.file.CmsResource;
035: import org.opencms.jsp.CmsJspActionElement;
036: import org.opencms.main.CmsException;
037: import org.opencms.main.OpenCms;
038: import org.opencms.util.CmsFileUtil;
039: import org.opencms.util.CmsStringUtil;
040: import org.opencms.widgets.CmsVfsFileWidget;
041: import org.opencms.workplace.CmsDialog;
042: import org.opencms.workplace.CmsWidgetDialog;
043: import org.opencms.workplace.CmsWidgetDialogParameter;
044: import org.opencms.workplace.CmsWorkplaceSettings;
045:
046: import java.util.ArrayList;
047: import java.util.Iterator;
048: import java.util.List;
049: import java.util.Map;
050:
051: import javax.servlet.http.HttpServletRequest;
052: import javax.servlet.http.HttpServletResponse;
053: import javax.servlet.jsp.PageContext;
054:
055: /**
056: * Dialog in the administration view, to edit the resources to check the internal links for.<p>
057: *
058: * @author Michael Moossen
059: *
060: * @version $Revision: 1.4 $
061: *
062: * @since 6.5.3
063: */
064: public class CmsInternalLinkValidationDialog extends CmsWidgetDialog {
065:
066: /** localized messages Keys prefix. */
067: public static final String KEY_PREFIX = "internallinks";
068:
069: /** Defines which pages are valid for this dialog. */
070: public static final String[] PAGES = { "page1" };
071:
072: /** Auxiliary Property for the VFS resources. */
073: private List m_resources;
074:
075: /**
076: * Public constructor with JSP action element.<p>
077: *
078: * @param jsp an initialized JSP action element
079: */
080: public CmsInternalLinkValidationDialog(CmsJspActionElement jsp) {
081:
082: super (jsp);
083: }
084:
085: /**
086: * Public constructor with JSP variables.<p>
087: *
088: * @param context the JSP page context
089: * @param req the JSP request
090: * @param res the JSP response
091: */
092: public CmsInternalLinkValidationDialog(PageContext context,
093: HttpServletRequest req, HttpServletResponse res) {
094:
095: this (new CmsJspActionElement(context, req, res));
096: }
097:
098: /**
099: * Commits the edited project to the db.<p>
100: */
101: public void actionCommit() {
102:
103: List errors = new ArrayList();
104:
105: try {
106: setDialogObject(m_resources);
107: // refresh the list
108: Map objects = (Map) getSettings().getListObject();
109: if (objects != null) {
110: objects.remove(CmsInternalLinkValidationList.class
111: .getName());
112: }
113: // forward to the list
114: getToolManager().jspForwardTool(this ,
115: "/linkvalidation/internallinks/list", null);
116: } catch (Throwable t) {
117: errors.add(t);
118: }
119: // set the list of errors to display when saving failed
120: setCommitErrors(errors);
121: }
122:
123: /**
124: * Returns the list of VFS resources.<p>
125: *
126: * @return the list of VFS resources
127: */
128: public List getResources() {
129:
130: if (m_resources == null || m_resources.isEmpty()) {
131: m_resources = new ArrayList();
132: m_resources.add("/");
133: }
134: return m_resources;
135: }
136:
137: /**
138: * Sets the resources list.<p>
139: *
140: * @param value the resources to set
141: */
142: public void setResources(List value) {
143:
144: if (value == null) {
145: m_resources = new ArrayList();
146: return;
147: }
148: m_resources = CmsFileUtil.removeRedundancies(value);
149: }
150:
151: /**
152: * @see org.opencms.workplace.CmsWidgetDialog#createDialogHtml(java.lang.String)
153: */
154: protected String createDialogHtml(String dialog) {
155:
156: StringBuffer result = new StringBuffer(1024);
157:
158: result.append(createWidgetTableStart());
159: // show error header once if there were validation errors
160: result.append(createWidgetErrorHeader());
161:
162: if (dialog.equals(PAGES[0])) {
163: // create the widgets for the first dialog page
164: result
165: .append(dialogBlockStart(key(Messages.GUI_INTERNALLINK_EDITOR_LABEL_BLOCK_0)));
166: result.append(createWidgetTableStart());
167: result.append(createDialogRowsHtml(0, 0));
168: result.append(createWidgetTableEnd());
169: result.append(dialogBlockEnd());
170: }
171:
172: result.append(createWidgetTableEnd());
173: return result.toString();
174: }
175:
176: /**
177: * Creates the list of widgets for this dialog.<p>
178: */
179: protected void defineWidgets() {
180:
181: // initialize the project object to use for the dialog
182: initSessionObject();
183:
184: setKeyPrefix(KEY_PREFIX);
185:
186: // widgets to display
187: addWidget(new CmsWidgetDialogParameter(this , "resources", "/",
188: PAGES[0], new CmsVfsFileWidget(false, null), 1,
189: CmsWidgetDialogParameter.MAX_OCCURENCES));
190: }
191:
192: /**
193: * @see org.opencms.workplace.CmsWidgetDialog#getPageArray()
194: */
195: protected String[] getPageArray() {
196:
197: return PAGES;
198: }
199:
200: /**
201: * @see org.opencms.workplace.CmsWorkplace#initMessages()
202: */
203: protected void initMessages() {
204:
205: // add specific dialog resource bundle
206: addMessages(Messages.get().getBundleName());
207: // add default resource bundles
208: super .initMessages();
209: }
210:
211: /**
212: * Initializes the session object to work with depending on the dialog state and request parameters.<p>
213: */
214: protected void initSessionObject() {
215:
216: try {
217: if (!CmsStringUtil.isEmpty(getParamAction())
218: && !CmsDialog.DIALOG_INITIAL
219: .equals(getParamAction())) {
220: m_resources = (List) getDialogObject();
221: // test
222: m_resources.size();
223: }
224: } catch (Exception e) {
225: // ignore
226: }
227: if (m_resources == null) {
228: // create a new project object
229: m_resources = new ArrayList();
230: try {
231: Iterator it = OpenCms
232: .getOrgUnitManager()
233: .getResourcesForOrganizationalUnit(getCms(),
234: getCms().getRequestContext().getOuFqn())
235: .iterator();
236: while (it.hasNext()) {
237: CmsResource res = (CmsResource) it.next();
238: m_resources.add(getCms().getSitePath(res));
239: }
240: } catch (CmsException e1) {
241: // should never happen
242: }
243: }
244: }
245:
246: /**
247: * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
248: */
249: protected void initWorkplaceRequestValues(
250: CmsWorkplaceSettings settings, HttpServletRequest request) {
251:
252: // initialize parameters and dialog actions in super implementation
253: super .initWorkplaceRequestValues(settings, request);
254:
255: // save the current state of the project (may be changed because of the widget values)
256: setDialogObject(m_resources);
257: }
258: }
|