KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > killingar > forum > actions > area > AbstractAreaCustomizer


1 /* Copyright 2000-2005 Anders Hovmöller
2  *
3  * The person or persons who have associated their work with
4  * this document (the "Dedicator") hereby dedicate the entire
5  * copyright in the work of authorship identified below (the
6  * "Work") to the public domain.
7  *
8  * Dedicator makes this dedication for the benefit of the
9  * public at large and to the detriment of Dedicator's heirs
10  * and successors. Dedicator intends this dedication to be an
11  * overt act of relinquishment in perpetuity of all present
12  * and future rights under copyright law, whether vested or
13  * contingent, in the Work. Dedicator understands that such
14  * relinquishment of all rights includes the relinquishment of
15  * all rights to enforce (by lawsuit or otherwise) those
16  * copyrights in the Work.
17  *
18  * Dedicator recognizes that, once placed in the public
19  * domain, the Work may be freely reproduced, distributed,
20  * transmitted, used, modified, built upon, or otherwise
21  * exploited by anyone for any purpose, commercial or non-
22  * commercial, and in any way, including by methods that have
23  * not yet been invented or conceived.
24  */

25
26 package net.killingar.forum.actions.area;
27
28 import net.killingar.BeanUtil;
29 import net.killingar.forum.internal.Area;
30 import net.killingar.forum.internal.FieldData;
31 import net.killingar.forum.internal.PropertyData;
32 import webwork.action.ActionContext;
33
34 import java.util.Map JavaDoc;
35
36 public class AbstractAreaCustomizer implements AreaCustomizer
37 {
38   // Statics --------------------------------------------------------
39
public static final String JavaDoc
40         WRITE_VIEW = "write.jsp",
41         MESSAGE_VIEW = "default-message.jsp",
42         VIEW = "view.jsp";
43
44     public static final AbstractAreaCustomizer DEFAULT_CUSTOMIZER = new AbstractAreaCustomizer();
45
46   // Methods --------------------------------------------------------
47
public static String JavaDoc getParam(String JavaDoc key)
48     {
49         return getParam(key, null);
50     }
51
52     public static String JavaDoc getParam(String JavaDoc key, String JavaDoc def)
53     {
54         String JavaDoc[] a = ((String JavaDoc[])ActionContext.getParameters().get(key));
55         if (a == null)
56             return def;
57
58         return a[0];
59     }
60
61     public static String JavaDoc putParam(Map JavaDoc map, String JavaDoc key, String JavaDoc def)
62     {
63         String JavaDoc r = getParam(key, def);
64         map.put(key, r);
65         return r;
66     }
67
68     public void updateParam(String JavaDoc key, FieldData fd)
69     {
70         Map JavaDoc m = fd.getFields();
71         String JavaDoc defaultValue = (String JavaDoc)BeanUtil.getProperty(key, this);
72         String JavaDoc value = putParam(m, key, defaultValue);
73         BeanUtil.setProperty(key, value, this);
74     }
75
76     public Object JavaDoc findValue(String JavaDoc path)
77     {
78         return ActionContext.getValueStack().findValue(path);
79     }
80
81   // Types ----------------------------------------------------------
82

83   // Setters --------------------------------------------------------
84

85   // Getters --------------------------------------------------------
86
public String JavaDoc getWriteView() { return WRITE_VIEW; }
87     public String JavaDoc getEditMessageView() { return getWriteView(); }
88     public String JavaDoc getMessageView() { return MESSAGE_VIEW; }
89     public String JavaDoc getView() { return VIEW; }
90
91     public static AreaCustomizer getAreaCustomizer(Area area)
92     {
93         try
94         {
95             String JavaDoc s = area.getCustom();
96             int i = s.indexOf('\n');
97             if (i != -1)
98             {
99                 AreaCustomizer ac = (AreaCustomizer)Class.forName(s.substring(0, i-1)).newInstance();
100                 BeanUtil.setProperties(new PropertyData(s.substring(i)).getFields(), ac);
101
102                 return ac;
103             }
104             else return (AreaCustomizer)Class.forName(s).newInstance();
105         }
106         catch (Exception JavaDoc e)
107         {
108             return DEFAULT_CUSTOMIZER;
109         }
110     }
111
112     public boolean addMessagePreProccess(WriteMessage in) { return true; }
113     public boolean editMessagePreProccess(EditMessage in) { return true; }
114     public void previewMessage(WriteMessage in) {}
115     public void previewMessage(EditMessage in) {}
116 }
Popular Tags