KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > methodhead > shim > DefaultShimPolicy


1 /*
2  * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
3  *
4  * This file is part of TransferCM.
5  *
6  * TransferCM is free software; you can redistribute it and/or modify it under the
7  * terms of the GNU General Public License as published by the Free Software
8  * Foundation; either version 2 of the License, or (at your option) any later
9  * version.
10  *
11  * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
18  * Fifth Floor, Boston, MA 02110-1301 USA
19  */

20
21 package com.methodhead.shim;
22
23 import com.methodhead.auth.AuthUser;
24 import com.methodhead.auth.AuthPolicy;
25 import com.methodhead.auth.SiteAuthUser;
26 import com.methodhead.res.FileManager;
27 import com.methodhead.res.FileTree;
28 import com.methodhead.res.ResPolicy;
29 import com.methodhead.sitecontext.SiteContext;
30 import com.methodhead.sitecontext.SiteContextPolicy;
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32 import javax.servlet.ServletContext JavaDoc;
33 import java.io.File JavaDoc;
34 import com.methodhead.util.OperationContext;
35 import org.apache.struts.util.MessageResources;
36 import org.apache.struts.Globals;
37 import org.apache.struts.action.*;
38 import com.methodhead.tree.FoldingTreeNode;
39 import com.methodhead.test.*;
40
41 public class DefaultShimPolicy
42 implements
43   ShimPolicy,
44   SiteContextPolicy,
45   AuthPolicy {
46
47   // constructors /////////////////////////////////////////////////////////////
48

49   // constants ////////////////////////////////////////////////////////////////
50

51   // classes //////////////////////////////////////////////////////////////////
52

53   // methods //////////////////////////////////////////////////////////////////
54

55   /**
56    * Returns a new {@link com.methodhead.test.TestUser TestUser}, convenient
57    * for testing. You'll most definitely want supply your own
58    * <tt>AuthPolicy</tt> implementation.
59    */

60   public AuthUser newUser() {
61     return new TestUser();
62   }
63
64   /**
65    * Returns a new {@link com.methodhead.test.TestUser TestUser}, convenient
66    * for testing. You'll most definitely want supply your own
67    * <tt>AuthPolicy</tt> implementation.
68    */

69   public SiteAuthUser newSiteUser() {
70     return new TestSiteUser();
71   }
72
73   public boolean autoLogin(
74     AuthUser user,
75     HttpServletRequest JavaDoc request,
76     ActionForm form ) {
77
78     return true;
79   }
80
81   //
82
// ShimPolicy methods
83
//
84
public Page newPage() {
85     return new Page();
86   }
87
88   public Template newTemplate() {
89     return new Template();
90   }
91
92   public TextModule newTextModule() {
93     return new TextModule();
94   }
95
96   public NavModule newNavModule() {
97     return new NavModule();
98   }
99
100   public IncludeModule newIncludeModule() {
101     return new IncludeModule();
102   }
103
104   public Thumbnailer newThumbnailer() {
105     return new Thumbnailer();
106   }
107
108   public boolean isMappingAuthorized(
109     AuthUser user,
110     String JavaDoc path ) {
111     return true;
112   }
113
114   public String JavaDoc isHomeAuthorized(
115     OperationContext op ) {
116     return null;
117   }
118
119   public String JavaDoc isSiteMapAuthorized(
120     OperationContext op ) {
121     return null;
122   }
123
124   public String JavaDoc isLinkAuthorized(
125     OperationContext op ) {
126     return null;
127   }
128
129   public String JavaDoc isHtmlFragmentDeleteAuthorized(
130     OperationContext op ) {
131     return null;
132   }
133
134   public String JavaDoc isHtmlFragmentListAuthorized(
135     OperationContext op ) {
136     return null;
137   }
138
139   public String JavaDoc isHtmlFragmentSaveAuthorized(
140     OperationContext op ) {
141     return null;
142   }
143
144   public String JavaDoc isHtmlFragmentSaveNewAuthorized(
145     OperationContext op ) {
146     return null;
147   }
148
149   public String JavaDoc isHtmlFragmentNewAuthorized(
150     OperationContext op ) {
151     return null;
152   }
153
154   public String JavaDoc isHtmlFragmentEditAuthorized(
155     OperationContext op ) {
156     return null;
157   }
158
159   public String JavaDoc isEditorListImagesAuthorized(
160     OperationContext op ) {
161     return null;
162   }
163
164   public String JavaDoc isEditorPickImageAuthorized(
165     OperationContext op ) {
166     return null;
167   }
168
169   public String JavaDoc isEditorDisplayFilesAuthorized(
170     OperationContext op ) {
171     return null;
172   }
173
174   public String JavaDoc isEditorPickFileAuthorized(
175     OperationContext op ) {
176     return null;
177   }
178
179   public String JavaDoc isEditorPickPageAuthorized(
180     OperationContext op ) {
181     return null;
182   }
183
184   public String JavaDoc isEditorListPagesAuthorized(
185     OperationContext op ) {
186     return null;
187   }
188
189   public String JavaDoc isConfigureTextModuleAuthorized(
190     OperationContext op ) {
191     return null;
192   }
193
194   public String JavaDoc isConfigureNavModuleAuthorized(
195     OperationContext op ) {
196     return null;
197   }
198
199   public String JavaDoc isConfigureIncludeModuleAuthorized(
200     OperationContext op ) {
201     return null;
202   }
203
204   public String JavaDoc isNewPageFormAuthorized(
205     OperationContext op ) {
206     return null;
207   }
208
209   public String JavaDoc isConfigurePageAuthorized(
210     OperationContext op ) {
211     return null;
212   }
213
214   public String JavaDoc isConfigurePageFormAuthorized(
215     OperationContext op ) {
216     return null;
217   }
218
219   public String JavaDoc isEditPageAuthorized(
220     OperationContext op ) {
221     return null;
222   }
223
224   public String JavaDoc isConfigureModuleAuthorized(
225     OperationContext op ) {
226     return null;
227   }
228
229   public String JavaDoc isEditPanelAuthorized(
230     OperationContext op ) {
231     return null;
232   }
233
234   public String JavaDoc isSavePanelAuthorized(
235     OperationContext op ) {
236     return null;
237   }
238
239   public String JavaDoc isDeletePageFormAuthorized(
240     OperationContext op ) {
241     return null;
242   }
243
244   public String JavaDoc isDeletePageAuthorized(
245     OperationContext op ) {
246     return null;
247   }
248
249   public String JavaDoc isMovePageFormAuthorized(
250     OperationContext op ) {
251     return null;
252   }
253
254   public String JavaDoc isMovePageAuthorized(
255     OperationContext op ) {
256     return null;
257   }
258
259   public String JavaDoc isConfigurePanelFormAuthorized(
260     OperationContext op ) {
261     return null;
262   }
263
264   public String JavaDoc isConfigurePanelAuthorized(
265     OperationContext op ) {
266     return null;
267   }
268
269   public String JavaDoc isSwitchAuthorized(
270     OperationContext op ) {
271     return null;
272   }
273
274   private static FoldingTreeNode buildBaseMenu(
275     MessageResources resources ) {
276
277     FoldingTreeNode main = new FoldingTreeNode();
278
279     //
280
// session menu
281
//
282
FoldingTreeNode menu = new FoldingTreeNode();
283     menu.setLabel( resources.getMessage( "shim.menu.session" ) );
284     menu.setUrl( "" );
285
286     FoldingTreeNode item = new FoldingTreeNode();
287     item.setLabel( resources.getMessage( "shim.menu.logout" ) );
288     item.setUrl( "logout.do" );
289     menu.add( item );
290
291     main.add( menu );
292
293     //
294
// site menu
295
//
296
menu = new FoldingTreeNode();
297     menu.setLabel( resources.getMessage( "shim.menu.site" ) );
298     menu.setUrl( "" );
299
300     item = new FoldingTreeNode();
301     item.setLabel( resources.getMessage( "shim.menu.newsite" ) );
302     item.setUrl( "siteContext.do?action=new" );
303     menu.add( item );
304
305     item = new FoldingTreeNode();
306     item.setLabel( resources.getMessage( "shim.menu.list" ) );
307     item.setUrl( "siteContext.do?action=list" );
308     menu.add( item );
309
310     main.add( menu );
311
312     //
313
// page menu
314
//
315
menu = new FoldingTreeNode();
316     menu.setLabel( resources.getMessage( "shim.menu.page" ) );
317     menu.setUrl( "" );
318
319     main.add( menu );
320
321     return main;
322   }
323
324   public void setUpMenu(
325     OperationContext op ) {
326
327     FoldingTreeNode item = null;
328     FoldingTreeNode subitem = null;
329
330     MessageResources resources =
331       ( MessageResources )op.request.getAttribute( Globals.MESSAGES_KEY );
332
333     //
334
// get the base menu
335
//
336
FoldingTreeNode menu = buildBaseMenu( resources );
337     FoldingTreeNode pageMenu = ( FoldingTreeNode )menu.getChildAt( 2 );
338
339     //
340
// new
341
//
342
item = new FoldingTreeNode();
343     item.setLabel( resources.getMessage( "shim.menu.fragments" ) );
344     item.setUrl( "htmlFragment.do?action=list" );
345     pageMenu.add( item );
346
347     item = new FoldingTreeNode();
348     item.setLabel( resources.getMessage( "shim.menu.new" ) );
349     item.setUrl( "newPageForm.do" );
350     pageMenu.add( item );
351
352     op.request.setAttribute( ShimGlobals.MENU_KEY, menu );
353   }
354
355   public void setUpEditorMenu(
356     OperationContext op,
357     Page page ) {
358
359     MessageResources resources =
360       ( MessageResources )op.request.getAttribute( Globals.MESSAGES_KEY );
361
362     SiteMap siteMap = ShimUtils.getSiteMap( op.request );
363
364     Link link = siteMap.find( page.getInt( "id" ) );
365
366     FoldingTreeNode item = null;
367     FoldingTreeNode subitem = null;
368
369     //
370
// get the base menu
371
//
372
FoldingTreeNode menu = buildBaseMenu( resources );
373     FoldingTreeNode pageMenu = ( FoldingTreeNode )menu.getChildAt( 2 );
374
375     //
376
// new
377
//
378
item = new FoldingTreeNode();
379     item.setLabel( resources.getMessage( "shim.menu.fragments" ) );
380     item.setUrl( "htmlFragment.do?action=list" );
381     pageMenu.add( item );
382
383     item = new FoldingTreeNode();
384     item.setLabel( resources.getMessage( "shim.menu.new" ) );
385     item.setUrl( "" );
386     pageMenu.add( item );
387
388     if ( link != siteMap.getRoot() ) {
389       subitem = new FoldingTreeNode();
390       subitem.setLabel( resources.getMessage( "shim.menu.before" ) );
391       subitem.setUrl(
392         "newPageForm.do?destid=" + page.getInt( "id" ) + "&position=before" );
393       item.add( subitem );
394
395       subitem = new FoldingTreeNode();
396       subitem.setLabel( resources.getMessage( "shim.menu.after" ) );
397       subitem.setUrl(
398         "newPageForm.do?destid=" + page.getInt( "id" ) + "&position=after" );
399       item.add( subitem );
400     }
401
402     subitem = new FoldingTreeNode();
403     subitem.setLabel( resources.getMessage( "shim.menu.under" ) );
404     subitem.setUrl(
405       "newPageForm.do?destid=" + page.getInt( "id" ) + "&position=under" );
406     item.add( subitem );
407
408     item = new FoldingTreeNode();
409     item.setLabel( resources.getMessage( "shim.menu.properties" ) );
410     item.setUrl( "configurePageForm.do?id=" + page.get( "id" ) );
411     pageMenu.add( item );
412
413     if ( link != siteMap.getRoot() ) {
414       item = new FoldingTreeNode();
415       item.setLabel( resources.getMessage( "shim.menu.move" ) );
416       item.setUrl( "movePageForm.do?id=" + page.get( "id" ) );
417       pageMenu.add( item );
418     }
419
420     item = new FoldingTreeNode();
421     item.setLabel( resources.getMessage( "shim.menu.delete" ) );
422     item.setUrl( "deletePage.do?id=" + page.get( "id" ) );
423     pageMenu.add( item );
424
425     op.request.setAttribute( ShimGlobals.MENU_KEY, menu );
426   }
427
428   public String JavaDoc isSiteContextDeleteAuthorized(
429     OperationContext op ) {
430     return null;
431   }
432
433   public String JavaDoc isSiteContextSaveNewAuthorized(
434     OperationContext op ) {
435     return null;
436   }
437
438   public String JavaDoc isSiteContextListAuthorized(
439     OperationContext op ) {
440     return null;
441   }
442
443   public String JavaDoc isSiteContextEditAuthorized(
444     OperationContext op ) {
445     return null;
446   }
447
448   public String JavaDoc isSiteContextNewAuthorized(
449     OperationContext op ) {
450     return null;
451   }
452
453   public String JavaDoc isSiteContextSaveAuthorized(
454     OperationContext op ) {
455     return null;
456   }
457
458
459   // properties ///////////////////////////////////////////////////////////////
460

461   // attributes ///////////////////////////////////////////////////////////////
462
}
463
Popular Tags