001: /*
002: * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
003: *
004: * This file is part of TransferCM.
005: *
006: * TransferCM is free software; you can redistribute it and/or modify it under the
007: * terms of the GNU General Public License as published by the Free Software
008: * Foundation; either version 2 of the License, or (at your option) any later
009: * version.
010: *
011: * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
012: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
013: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
014: * details.
015: *
016: * You should have received a copy of the GNU General Public License along with
017: * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
018: * Fifth Floor, Boston, MA 02110-1301 USA
019: */
020:
021: package com.methodhead.shim;
022:
023: import com.methodhead.auth.AuthUser;
024: import com.methodhead.auth.AuthPolicy;
025: import com.methodhead.auth.SiteAuthUser;
026: import com.methodhead.res.FileManager;
027: import com.methodhead.res.FileTree;
028: import com.methodhead.res.ResPolicy;
029: import com.methodhead.sitecontext.SiteContext;
030: import com.methodhead.sitecontext.SiteContextPolicy;
031: import javax.servlet.http.HttpServletRequest;
032: import javax.servlet.ServletContext;
033: import java.io.File;
034: import com.methodhead.util.OperationContext;
035: import org.apache.struts.util.MessageResources;
036: import org.apache.struts.Globals;
037: import org.apache.struts.action.*;
038: import com.methodhead.tree.FoldingTreeNode;
039: import com.methodhead.test.*;
040:
041: public class DefaultShimPolicy implements ShimPolicy,
042: SiteContextPolicy, AuthPolicy {
043:
044: // constructors /////////////////////////////////////////////////////////////
045:
046: // constants ////////////////////////////////////////////////////////////////
047:
048: // classes //////////////////////////////////////////////////////////////////
049:
050: // methods //////////////////////////////////////////////////////////////////
051:
052: /**
053: * Returns a new {@link com.methodhead.test.TestUser TestUser}, convenient
054: * for testing. You'll most definitely want supply your own
055: * <tt>AuthPolicy</tt> implementation.
056: */
057: public AuthUser newUser() {
058: return new TestUser();
059: }
060:
061: /**
062: * Returns a new {@link com.methodhead.test.TestUser TestUser}, convenient
063: * for testing. You'll most definitely want supply your own
064: * <tt>AuthPolicy</tt> implementation.
065: */
066: public SiteAuthUser newSiteUser() {
067: return new TestSiteUser();
068: }
069:
070: public boolean autoLogin(AuthUser user, HttpServletRequest request,
071: ActionForm form) {
072:
073: return true;
074: }
075:
076: //
077: // ShimPolicy methods
078: //
079: public Page newPage() {
080: return new Page();
081: }
082:
083: public Template newTemplate() {
084: return new Template();
085: }
086:
087: public TextModule newTextModule() {
088: return new TextModule();
089: }
090:
091: public NavModule newNavModule() {
092: return new NavModule();
093: }
094:
095: public IncludeModule newIncludeModule() {
096: return new IncludeModule();
097: }
098:
099: public Thumbnailer newThumbnailer() {
100: return new Thumbnailer();
101: }
102:
103: public boolean isMappingAuthorized(AuthUser user, String path) {
104: return true;
105: }
106:
107: public String isHomeAuthorized(OperationContext op) {
108: return null;
109: }
110:
111: public String isSiteMapAuthorized(OperationContext op) {
112: return null;
113: }
114:
115: public String isLinkAuthorized(OperationContext op) {
116: return null;
117: }
118:
119: public String isHtmlFragmentDeleteAuthorized(OperationContext op) {
120: return null;
121: }
122:
123: public String isHtmlFragmentListAuthorized(OperationContext op) {
124: return null;
125: }
126:
127: public String isHtmlFragmentSaveAuthorized(OperationContext op) {
128: return null;
129: }
130:
131: public String isHtmlFragmentSaveNewAuthorized(OperationContext op) {
132: return null;
133: }
134:
135: public String isHtmlFragmentNewAuthorized(OperationContext op) {
136: return null;
137: }
138:
139: public String isHtmlFragmentEditAuthorized(OperationContext op) {
140: return null;
141: }
142:
143: public String isEditorListImagesAuthorized(OperationContext op) {
144: return null;
145: }
146:
147: public String isEditorPickImageAuthorized(OperationContext op) {
148: return null;
149: }
150:
151: public String isEditorDisplayFilesAuthorized(OperationContext op) {
152: return null;
153: }
154:
155: public String isEditorPickFileAuthorized(OperationContext op) {
156: return null;
157: }
158:
159: public String isEditorPickPageAuthorized(OperationContext op) {
160: return null;
161: }
162:
163: public String isEditorListPagesAuthorized(OperationContext op) {
164: return null;
165: }
166:
167: public String isConfigureTextModuleAuthorized(OperationContext op) {
168: return null;
169: }
170:
171: public String isConfigureNavModuleAuthorized(OperationContext op) {
172: return null;
173: }
174:
175: public String isConfigureIncludeModuleAuthorized(OperationContext op) {
176: return null;
177: }
178:
179: public String isNewPageFormAuthorized(OperationContext op) {
180: return null;
181: }
182:
183: public String isConfigurePageAuthorized(OperationContext op) {
184: return null;
185: }
186:
187: public String isConfigurePageFormAuthorized(OperationContext op) {
188: return null;
189: }
190:
191: public String isEditPageAuthorized(OperationContext op) {
192: return null;
193: }
194:
195: public String isConfigureModuleAuthorized(OperationContext op) {
196: return null;
197: }
198:
199: public String isEditPanelAuthorized(OperationContext op) {
200: return null;
201: }
202:
203: public String isSavePanelAuthorized(OperationContext op) {
204: return null;
205: }
206:
207: public String isDeletePageFormAuthorized(OperationContext op) {
208: return null;
209: }
210:
211: public String isDeletePageAuthorized(OperationContext op) {
212: return null;
213: }
214:
215: public String isMovePageFormAuthorized(OperationContext op) {
216: return null;
217: }
218:
219: public String isMovePageAuthorized(OperationContext op) {
220: return null;
221: }
222:
223: public String isConfigurePanelFormAuthorized(OperationContext op) {
224: return null;
225: }
226:
227: public String isConfigurePanelAuthorized(OperationContext op) {
228: return null;
229: }
230:
231: public String isSwitchAuthorized(OperationContext op) {
232: return null;
233: }
234:
235: private static FoldingTreeNode buildBaseMenu(
236: MessageResources resources) {
237:
238: FoldingTreeNode main = new FoldingTreeNode();
239:
240: //
241: // session menu
242: //
243: FoldingTreeNode menu = new FoldingTreeNode();
244: menu.setLabel(resources.getMessage("shim.menu.session"));
245: menu.setUrl("");
246:
247: FoldingTreeNode item = new FoldingTreeNode();
248: item.setLabel(resources.getMessage("shim.menu.logout"));
249: item.setUrl("logout.do");
250: menu.add(item);
251:
252: main.add(menu);
253:
254: //
255: // site menu
256: //
257: menu = new FoldingTreeNode();
258: menu.setLabel(resources.getMessage("shim.menu.site"));
259: menu.setUrl("");
260:
261: item = new FoldingTreeNode();
262: item.setLabel(resources.getMessage("shim.menu.newsite"));
263: item.setUrl("siteContext.do?action=new");
264: menu.add(item);
265:
266: item = new FoldingTreeNode();
267: item.setLabel(resources.getMessage("shim.menu.list"));
268: item.setUrl("siteContext.do?action=list");
269: menu.add(item);
270:
271: main.add(menu);
272:
273: //
274: // page menu
275: //
276: menu = new FoldingTreeNode();
277: menu.setLabel(resources.getMessage("shim.menu.page"));
278: menu.setUrl("");
279:
280: main.add(menu);
281:
282: return main;
283: }
284:
285: public void setUpMenu(OperationContext op) {
286:
287: FoldingTreeNode item = null;
288: FoldingTreeNode subitem = null;
289:
290: MessageResources resources = (MessageResources) op.request
291: .getAttribute(Globals.MESSAGES_KEY);
292:
293: //
294: // get the base menu
295: //
296: FoldingTreeNode menu = buildBaseMenu(resources);
297: FoldingTreeNode pageMenu = (FoldingTreeNode) menu.getChildAt(2);
298:
299: //
300: // new
301: //
302: item = new FoldingTreeNode();
303: item.setLabel(resources.getMessage("shim.menu.fragments"));
304: item.setUrl("htmlFragment.do?action=list");
305: pageMenu.add(item);
306:
307: item = new FoldingTreeNode();
308: item.setLabel(resources.getMessage("shim.menu.new"));
309: item.setUrl("newPageForm.do");
310: pageMenu.add(item);
311:
312: op.request.setAttribute(ShimGlobals.MENU_KEY, menu);
313: }
314:
315: public void setUpEditorMenu(OperationContext op, Page page) {
316:
317: MessageResources resources = (MessageResources) op.request
318: .getAttribute(Globals.MESSAGES_KEY);
319:
320: SiteMap siteMap = ShimUtils.getSiteMap(op.request);
321:
322: Link link = siteMap.find(page.getInt("id"));
323:
324: FoldingTreeNode item = null;
325: FoldingTreeNode subitem = null;
326:
327: //
328: // get the base menu
329: //
330: FoldingTreeNode menu = buildBaseMenu(resources);
331: FoldingTreeNode pageMenu = (FoldingTreeNode) menu.getChildAt(2);
332:
333: //
334: // new
335: //
336: item = new FoldingTreeNode();
337: item.setLabel(resources.getMessage("shim.menu.fragments"));
338: item.setUrl("htmlFragment.do?action=list");
339: pageMenu.add(item);
340:
341: item = new FoldingTreeNode();
342: item.setLabel(resources.getMessage("shim.menu.new"));
343: item.setUrl("");
344: pageMenu.add(item);
345:
346: if (link != siteMap.getRoot()) {
347: subitem = new FoldingTreeNode();
348: subitem.setLabel(resources.getMessage("shim.menu.before"));
349: subitem.setUrl("newPageForm.do?destid=" + page.getInt("id")
350: + "&position=before");
351: item.add(subitem);
352:
353: subitem = new FoldingTreeNode();
354: subitem.setLabel(resources.getMessage("shim.menu.after"));
355: subitem.setUrl("newPageForm.do?destid=" + page.getInt("id")
356: + "&position=after");
357: item.add(subitem);
358: }
359:
360: subitem = new FoldingTreeNode();
361: subitem.setLabel(resources.getMessage("shim.menu.under"));
362: subitem.setUrl("newPageForm.do?destid=" + page.getInt("id")
363: + "&position=under");
364: item.add(subitem);
365:
366: item = new FoldingTreeNode();
367: item.setLabel(resources.getMessage("shim.menu.properties"));
368: item.setUrl("configurePageForm.do?id=" + page.get("id"));
369: pageMenu.add(item);
370:
371: if (link != siteMap.getRoot()) {
372: item = new FoldingTreeNode();
373: item.setLabel(resources.getMessage("shim.menu.move"));
374: item.setUrl("movePageForm.do?id=" + page.get("id"));
375: pageMenu.add(item);
376: }
377:
378: item = new FoldingTreeNode();
379: item.setLabel(resources.getMessage("shim.menu.delete"));
380: item.setUrl("deletePage.do?id=" + page.get("id"));
381: pageMenu.add(item);
382:
383: op.request.setAttribute(ShimGlobals.MENU_KEY, menu);
384: }
385:
386: public String isSiteContextDeleteAuthorized(OperationContext op) {
387: return null;
388: }
389:
390: public String isSiteContextSaveNewAuthorized(OperationContext op) {
391: return null;
392: }
393:
394: public String isSiteContextListAuthorized(OperationContext op) {
395: return null;
396: }
397:
398: public String isSiteContextEditAuthorized(OperationContext op) {
399: return null;
400: }
401:
402: public String isSiteContextNewAuthorized(OperationContext op) {
403: return null;
404: }
405:
406: public String isSiteContextSaveAuthorized(OperationContext op) {
407: return null;
408: }
409:
410: // properties ///////////////////////////////////////////////////////////////
411:
412: // attributes ///////////////////////////////////////////////////////////////
413: }
|