01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03:
04: package fitnesse.responders.editing;
05:
06: import fitnesse.*;
07: import fitnesse.authentication.*;
08: import fitnesse.responders.*;
09: import fitnesse.components.*;
10: import fitnesse.wiki.*;
11: import fitnesse.http.*;
12: import java.util.*;
13:
14: public class SavePropertiesResponder implements SecureResponder {
15: public Response makeResponse(FitNesseContext context,
16: Request request) throws Exception {
17: SimpleResponse response = new SimpleResponse();
18: String resource = request.getResource();
19: WikiPagePath path = PathParser.parse(resource);
20: WikiPage page = context.root.getPageCrawler().getPage(
21: context.root, path);
22: if (page == null)
23: return new NotFoundResponder().makeResponse(context,
24: request);
25: PageData data = page.getData();
26: saveAttributes(request, data);
27: VersionInfo commitRecord = page.commit(data);
28: response.addHeader("Previous-Version", commitRecord.getName());
29: RecentChanges.updateRecentChanges(data);
30: response.redirect(resource);
31:
32: return response;
33: }
34:
35: private void saveAttributes(Request request, PageData data)
36: throws Exception {
37: List attrs = new LinkedList();
38: attrs.addAll(Arrays.asList(WikiPage.NON_SECURITY_ATTRIBUTES));
39: attrs.addAll(Arrays.asList(WikiPage.SECURITY_ATTRIBUTES));
40:
41: for (Iterator i = attrs.iterator(); i.hasNext();) {
42: String attribute = (String) i.next();
43: if (isChecked(request, attribute))
44: data.setAttribute(attribute);
45: else
46: data.removeAttribute(attribute);
47: }
48:
49: String value = (String) request
50: .getInput(WikiPageProperties.VIRTUAL_WIKI_ATTRIBUTE);
51: if (value == null
52: || !value
53: .equals(data
54: .getAttribute(WikiPageProperties.VIRTUAL_WIKI_ATTRIBUTE))) {
55: WikiPage page = data.getWikiPage();
56: if (page.hasExtension(VirtualCouplingExtension.NAME)) {
57: VirtualCouplingExtension extension = (VirtualCouplingExtension) page
58: .getExtension(VirtualCouplingExtension.NAME);
59: extension.resetVirtualCoupling();
60: }
61: }
62: if (value == null || "".equals(value))
63: data
64: .removeAttribute(WikiPageProperties.VIRTUAL_WIKI_ATTRIBUTE);
65: else
66: data.setAttribute(
67: WikiPageProperties.VIRTUAL_WIKI_ATTRIBUTE, value);
68: }
69:
70: private boolean isChecked(Request request, String name) {
71: return (request.getInput(name) != null);
72: }
73:
74: public SecureOperation getSecureOperation() {
75: return new AlwaysSecureOperation();
76: }
77: }
|