KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > field > FileTag


1 package fr.improve.struts.taglib.layout.field;
2
3 import javax.servlet.jsp.JspException JavaDoc;
4
5 import org.apache.struts.taglib.html.BaseHandlerTag;
6
7 import fr.improve.struts.taglib.layout.util.LayoutUtils;
8 import fr.improve.struts.taglib.layout.util.TagUtils;
9 /**
10  * A struts file tag modifief to display a link to the file if there is one already in the system.
11  *
12  * @author: JeanNoŽl Ribette
13  */

14 public class FileTag extends AbstractFieldTag {
15     protected String JavaDoc fileName;
16     protected String JavaDoc fileKey;
17     protected String JavaDoc filePath;
18     protected String JavaDoc target;
19     
20 protected boolean doBeforeValue() throws JspException JavaDoc {
21     StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
22     if (filePath!=null) {
23         // display a link to the already existing file
24
buffer.append("<a HREF=\"");
25         Object JavaDoc lc_url = LayoutUtils.getBeanFromPageContext(pageContext, name, filePath);
26         buffer.append(LayoutUtils.computeURL(pageContext, null, lc_url==null ? "" : lc_url.toString(), null, null, null, null, null, false, target));
27         buffer.append("\" class=\"");
28         buffer.append(styleClass);
29         if (target!=null) {
30             buffer.append("\" target=\"");
31             buffer.append(target);
32         }
33         buffer.append("\">");
34         if (fileName != null)
35             buffer.append(LayoutUtils.getBeanFromPageContext(pageContext, name, fileName));
36         else
37             buffer.append(LayoutUtils.getLabel(pageContext, fileKey, null));
38         buffer.append("</a>");
39     }
40     value = null;
41
42     switch (getFieldDisplayMode()) {
43         case MODE_EDIT :
44             if (filePath!=null) {
45                 buffer.append("<br>");
46             }
47             TagUtils.write(pageContext, buffer.toString());
48             break;
49         case MODE_INSPECT :
50             TagUtils.write(pageContext, buffer.toString());
51             return false;
52     }
53
54     // set the inner tag to be a FileTag
55
fieldTag = new org.apache.struts.taglib.html.FileTag();
56     return true;
57 }
58 /**
59  * Return the value to display.
60  */

61 protected Object JavaDoc getFieldValue() throws JspException JavaDoc {
62     return fileName;
63 }
64 /**
65  * Insert the method's description here.
66  * Creation date: (06/09/2001 18:12:17)
67  * @return java.lang.String
68  */

69 java.lang.String JavaDoc getFileKey() {
70     return fileKey;
71 }
72 /**
73  * Insert the method's description here.
74  * Creation date: (06/09/2001 18:12:19)
75  * @return java.lang.String
76  */

77 java.lang.String JavaDoc getFileName() {
78     return fileName;
79 }
80 /**
81  * Insert the method's description here.
82  * Creation date: (06/09/2001 18:12:19)
83  * @return java.lang.String
84  */

85 java.lang.String JavaDoc getFilePath() {
86     return filePath;
87 }
88     public void release() {
89         super.release();
90         fileName = null;
91         fileKey = null;
92         filePath = null;
93         target = null;
94     }
95 /**
96  * Insert the method's description here.
97  * Creation date: (06/09/2001 18:12:17)
98  * @param newFileKey java.lang.String
99  */

100 public void setFileKey(java.lang.String JavaDoc newFileKey) {
101     fileKey = newFileKey;
102 }
103 /**
104  * Insert the method's description here.
105  * Creation date: (06/09/2001 18:12:19)
106  * @param newFileName java.lang.String
107  */

108 public void setFileName(java.lang.String JavaDoc newFileName) {
109     fileName = newFileName;
110 }
111 /**
112  * Insert the method's description here.
113  * Creation date: (06/09/2001 18:12:19)
114  * @param newFilePath java.lang.String
115  */

116 public void setFilePath(java.lang.String JavaDoc newFilePath) {
117     filePath = newFilePath;
118 }
119     /**
120      * Returns the target.
121      * @return String
122      */

123     public String JavaDoc getTarget() {
124         return target;
125     }
126
127     /**
128      * Sets the target.
129      * @param target The target to set
130      */

131     public void setTarget(String JavaDoc target) {
132         this.target = target;
133     }
134     
135     protected void copyProperties(BaseHandlerTag in_dest) throws JspException JavaDoc {
136         super.copyProperties(in_dest);
137         org.apache.struts.taglib.html.FileTag tag = (org.apache.struts.taglib.html.FileTag) in_dest;
138         tag.setAccept(getAccept());
139         tag.setName(getName());
140         
141         tag.setCols(getCols());
142         tag.setMaxlength(getMaxlength());
143         tag.setProperty(getProperty());
144         tag.setRows(getRows());
145         tag.setValue(getValue());
146             
147     }
148
149 }
150
Popular Tags