KickJava   Java API By Example, From Geeks To Geeks.

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


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.Version;
29 import com.portalwizard.util.ReadException;
30
31 public class Edit extends WikiAction
32 {
33     String JavaDoc mode;
34     String JavaDoc submit;
35
36     String JavaDoc content;
37     String JavaDoc title;
38     String JavaDoc author = "none";
39     String JavaDoc mimetype = "text/wiki";
40
41     public void setSubmit(String JavaDoc submit) { this.submit = submit; }
42     public void setMode(String JavaDoc mode) { this.mode = mode; }
43     public void setContent(String JavaDoc content){ this.content = content; }
44     public void setMimetype(String JavaDoc mimetype){ this.mimetype = mimetype; }
45     public void setAuthor(String JavaDoc author) { this.author = author; }
46     public void setTitle(String JavaDoc in) { title = in; }
47
48     public String JavaDoc getSubmit() { return submit; }
49     public String JavaDoc getMode() { return mode; }
50     public String JavaDoc getContent() { return content; }
51     public String JavaDoc getMimetype() { return mimetype; }
52     public String JavaDoc getAuthor() { return author; }
53     public String JavaDoc getTitle() { return title; }
54
55     protected String JavaDoc doExecute() throws Exception JavaDoc
56     {
57         if (getSubmit() != null)
58         {
59             // they submitted something: let's store it!
60
Version ov = null;
61
62             try { ov = vm.get(getContext(), getWiki()); } catch (ReadException e){}
63
64             if (ov != null && ov.getContent().equals(getContent()))
65             {
66                 addErrorMessage("document unaltered");
67                 return INPUT;
68             }
69
70             Version nv = new Version(getContext(), getWiki());
71             nv.setContent(getContent());
72             nv.setMimetype(getMimetype());
73             nv.setAuthor(getAuthor());
74             if (getTitle() != null && !"".equals(getTitle()))
75                 nv.setTitle(getTitle());
76             else
77                 nv.setTitle(getWiki());
78             vm.store(nv);
79
80             return SUCCESS;
81         }
82         else
83         {
84             if (getMode() == null || !getMode().equals("preview"))
85             {
86                 try
87                 {
88                     Version v = vm.get(getContext(), getWiki());
89                     content = v.getContent();
90                     author = v.getAuthor();
91                     mimetype = v.getMimetype();
92                     title = v.getTitle();
93                 }
94                 catch (Exception JavaDoc e){}
95             }
96         }
97
98         return INPUT;
99     }
100 }
101
Popular Tags