KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > killingar > wiki > taglib > WebworkSiloRenderTag


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.wiki.taglib;
27
28 import com.portalwizard.silo.IVersionMgr;
29 import com.portalwizard.silo.Version;
30 import com.portalwizard.silo.VersionMgr;
31 import com.portalwizard.util.ReadException;
32 import net.killingar.EscapedString;
33 import net.killingar.wiki.Node;
34 import net.killingar.wiki.impl.LinkNode;
35 import webwork.util.ServletValueStack;
36
37 import javax.servlet.jsp.JspException JavaDoc;
38 import java.io.IOException JavaDoc;
39
40 public class WebworkSiloRenderTag extends RenderTag
41 {
42   protected ServletValueStack stack;
43     protected String JavaDoc actionName;
44
45   protected ServletValueStack getStack()
46   {
47     if (stack == null)
48       stack = ServletValueStack.getStack(pageContext);
49     return stack;
50   }
51
52     public void setActionName(String JavaDoc in) { actionName = in; }
53
54     protected boolean isWikiLink(String JavaDoc context, String JavaDoc dockey)
55     {
56         IVersionMgr vm = VersionMgr.getInstance();
57
58         boolean found = false;
59         try
60         {
61             Version v = vm.get(context, dockey);
62             found = true;
63         }
64         catch (ReadException e)
65         {
66             found = false;
67         }
68         return found;
69     }
70
71     public void printNode(Node n) throws JspException JavaDoc
72     {
73         try
74         {
75             if (n instanceof LinkNode)
76             {
77                 LinkNode link = (LinkNode)n;
78
79                 if (link.getContextType() == LinkNode.CONTEXT_TYPE_WIKI)
80                 {
81                     link.setDefaultContext((String JavaDoc)getStack().findValue("defaultContext"));
82                     link.setDefaultWiki((String JavaDoc)getStack().findValue("defaultWiki"));
83
84                     String JavaDoc context = (String JavaDoc)getStack().findValue("context");
85                     if (context == null)
86                         context = (String JavaDoc)getStack().findValue("defaultContext");
87
88                     if (context == null)
89                         throw new RuntimeException JavaDoc("no context or default context present");
90
91                     if (link.getContext() == LinkNode.NO_CONTEXT_SET) // no context set
92
link.setContext(context);
93
94                     if (webwork.action.ActionContext.getContext() != null && "wiki.stripped".equals(webwork.action.ActionContext.getContext().getName()))
95                         link.setAction(webwork.action.ActionContext.getContext().getName()+".action");
96
97                     if (actionName != null)
98                         link.setAction(actionName);
99
100                     if (isWikiLink(link.getContext(), link.getWiki()))
101                         getPreviousOut().print(EscapedString.strip(link.getText()));
102                     else
103                         getPreviousOut().print(EscapedString.strip(link.getEditString()));
104                 }
105                 else
106                     super.printNode(n);
107             }
108             else
109                 super.printNode(n);
110         }
111         catch (IOException JavaDoc e)
112         {
113             e.printStackTrace();
114             throw new JspException JavaDoc(e);
115         }
116     }
117 }
118
Popular Tags