KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > killingar > actions > wiki > WikiAction


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.actions.wiki;
27
28 import com.portalwizard.silo.DocumentVersionMgr;
29 import com.portalwizard.silo.IDocumentVersionMgr;
30 import com.portalwizard.silo.IVersionMgr;
31 import com.portalwizard.silo.VersionMgr;
32 import net.killingar.actions.ActionSupport;
33
34 import java.util.Properties JavaDoc;
35
36 public class WikiAction extends ActionSupport
37 {
38     long start;
39
40     String JavaDoc wiki;
41     String JavaDoc context;
42     static String JavaDoc defaultWiki;
43     static String JavaDoc defaultContext;
44     public IVersionMgr vm;
45     public IDocumentVersionMgr dvm;
46
47     public String JavaDoc getWiki() { return wiki; }
48     public void setWiki(String JavaDoc wiki) { this.wiki = wiki; }
49     public String JavaDoc getContext() { return context == null? getDefaultContext() : context; }
50     public void setContext(String JavaDoc in) { context = in; }
51     public String JavaDoc getTitle() { return wiki; }
52
53     public long getExecutionTime() { return System.currentTimeMillis()-start; }
54
55     public String JavaDoc getDefaultWiki()
56     {
57         if (defaultWiki == null)
58         {
59             Properties JavaDoc p = net.killingar.Utils.getProperties();
60             defaultWiki = p.getProperty("net.killingar.actions.wiki.defaultDocument");
61             defaultContext = p.getProperty("net.killingar.actions.wiki.defaultContext");
62         }
63
64         if (defaultWiki == null)
65             throw new RuntimeException JavaDoc("no default wiki set");
66
67         if (defaultContext == null)
68             throw new RuntimeException JavaDoc("no default context set");
69
70         return defaultWiki;
71     }
72
73     public String JavaDoc getDefaultContext()
74     {
75         getDefaultWiki(); // make sure defaults are loaded
76
return defaultContext;
77     }
78
79     public WikiAction()
80     {
81         wiki = defaultWiki;
82         context = defaultContext;
83     }
84
85     public String JavaDoc execute() throws Exception JavaDoc
86     {
87         getDefaultWiki();
88
89     start = System.currentTimeMillis();
90
91         vm = VersionMgr.getInstance();
92         dvm = DocumentVersionMgr.getInstance();
93
94         if (getWiki() == null || "".equals(getWiki()))
95             setWiki(defaultWiki);
96
97         if (getContext() == null || "".equals(getContext()))
98             setContext(defaultContext);
99
100         if (wiki != null)
101             wiki = wiki.trim().toLowerCase();
102
103         return super.execute();
104     }
105 }
Popular Tags