1 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 ; 38 import java.io.IOException ; 39 40 public class WebworkSiloRenderTag extends RenderTag 41 { 42 protected ServletValueStack stack; 43 protected String 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 in) { actionName = in; } 53 54 protected boolean isWikiLink(String context, String 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 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 )getStack().findValue("defaultContext")); 82 link.setDefaultWiki((String )getStack().findValue("defaultWiki")); 83 84 String context = (String )getStack().findValue("context"); 85 if (context == null) 86 context = (String )getStack().findValue("defaultContext"); 87 88 if (context == null) 89 throw new RuntimeException ("no context or default context present"); 90 91 if (link.getContext() == LinkNode.NO_CONTEXT_SET) 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 e) 112 { 113 e.printStackTrace(); 114 throw new JspException (e); 115 } 116 } 117 } 118 | Popular Tags |