1 25 26 29 30 package net.killingar.forum.tags; 31 32 import javax.servlet.jsp.JspException ; 33 import javax.servlet.jsp.JspTagException ; 34 35 public class LinkTag extends webwork.view.taglib.URLTag 36 { 37 protected String nameAttr = null; 39 protected String classAttr = null; 40 protected String targetAttr = null; 41 protected String anchorAttr = null; 42 43 public void setName(String in) { nameAttr = in; } 45 public void setCssclass(String in) { classAttr = in; } 46 public void setTarget(String in) { targetAttr = in; } 47 public void setAnchor(String in) { anchorAttr = in; } 48 49 public int doStartTag() throws JspException 51 { 52 try 53 { 54 pageContext.getOut().write("<a HREF=\""); 55 int r = super.doStartTag(); 56 return r; 57 } 58 catch (Exception e) 59 { 60 e.printStackTrace(); 61 throw new JspTagException ("Could not show value " + valueAttr + ":" + e); 62 } 63 } 64 65 public int doEndTag() throws JspException 66 { 67 try 68 { 69 int r = super.doEndTag(); 70 71 if (anchorAttr != null) 72 { 73 pageContext.getOut().write("#"); 74 pageContext.getOut().write(anchorAttr); 75 } 76 77 if (classAttr != null) 78 { 79 pageContext.getOut().write("\" class=\""); 80 pageContext.getOut().write(classAttr); 81 } 82 83 String accessKey = (String )findValue("text('"+nameAttr+".accesskey')"); 85 if (accessKey != null && !"".equals(accessKey)) 86 { 87 accessKey = accessKey.toUpperCase(); 88 pageContext.getOut().write("\" accesskey=\""); 89 pageContext.getOut().write(accessKey); 90 } 91 92 if (targetAttr != null) 93 { 94 pageContext.getOut().write("\" target=\""); 95 pageContext.getOut().write(targetAttr); 96 } 97 98 pageContext.getOut().write("\">"); 99 100 String name = (String )findValue("text('"+nameAttr+"')"); 102 103 if (name == null) 104 { 105 System.err.println("ERROR: could not find resource string \""+nameAttr+"\""); 106 pageContext.getOut().write("[ERROR: could not find resource string \""+nameAttr+"\"]</a>"); 107 return r; 108 } 109 110 String nameUpper = name.toUpperCase(); 111 int index = accessKey == null || "".equals(accessKey)? -1: nameUpper.indexOf(accessKey); 112 if (index != -1) 113 { 114 pageContext.getOut().write(name.substring(0, index)); 115 pageContext.getOut().write("<span class=\"accesskey\">"); 116 pageContext.getOut().write(name.charAt(index)); 117 pageContext.getOut().write("</span>"); 118 pageContext.getOut().write(name.substring(index+accessKey.length())); 119 } 120 else 121 pageContext.getOut().write(name); 122 123 pageContext.getOut().write("</a>"); 125 return r; 126 } 127 catch (Exception e) 128 { 129 e.printStackTrace(); 130 throw new JspTagException ("Could not show value " + valueAttr + ":" + e); 131 } 132 } 133 } | Popular Tags |