1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.ole.sys.document.web.renderers;
17  
18  import java.io.IOException;
19  
20  import javax.servlet.jsp.JspException;
21  import javax.servlet.jsp.JspWriter;
22  import javax.servlet.jsp.PageContext;
23  import javax.servlet.jsp.tagext.Tag;
24  
25  import org.apache.commons.lang.StringUtils;
26  import org.kuali.ole.sys.OLEConstants;
27  import org.kuali.ole.sys.context.SpringContext;
28  import org.kuali.rice.core.api.config.property.ConfigurationService;
29  import org.kuali.rice.krad.util.KRADConstants;
30  
31  
32  
33  
34  
35  public class LabelRenderer implements Renderer {
36      private boolean required = false;
37      private boolean readOnly = false;
38      private String label;
39      private String fullClassNameForHelp;
40      private String attributeEntryForHelp;
41      private String labelFor;
42  
43      
44  
45  
46  
47      public String getAttributeEntryForHelp() {
48          return attributeEntryForHelp;
49      }
50  
51      
52  
53  
54  
55      public void setAttributeEntryForHelp(String attributeEntryForHelp) {
56          this.attributeEntryForHelp = attributeEntryForHelp;
57      }
58  
59      
60  
61  
62  
63      public String getFullClassNameForHelp() {
64          return fullClassNameForHelp;
65      }
66  
67      
68  
69  
70  
71      public void setFullClassNameForHelp(String fullClassNameForHelp) {
72          this.fullClassNameForHelp = fullClassNameForHelp;
73      }
74  
75      
76  
77  
78  
79      public String getLabel() {
80          return label;
81      }
82  
83      
84  
85  
86  
87      public void setLabel(String label) {
88          this.label = label;
89      }
90  
91      
92  
93  
94  
95      public boolean isRequired() {
96          return required;
97      }
98  
99      
100 
101 
102 
103     public void setRequired(boolean required) {
104         this.required = required;
105     }
106 
107     
108 
109 
110 
111     public boolean isReadOnly() {
112         return readOnly;
113     }
114 
115     
116 
117 
118 
119     public void setReadOnly(boolean readOnly) {
120         this.readOnly = readOnly;
121     }
122 
123     
124 
125 
126 
127     public String getLabelFor() {
128         return labelFor;
129     }
130 
131     
132 
133 
134 
135     public void setLabelFor(String labelFor) {
136         this.labelFor = labelFor;
137     }
138 
139     
140 
141 
142 
143     public void clear() {
144         readOnly = false;
145         required = false;
146         label = null;
147         fullClassNameForHelp = null;
148         attributeEntryForHelp = null;
149         labelFor = null;
150     }
151 
152     private static String APPLICATION_URL;
153     
154     protected String getApplicationURL() {
155         if ( APPLICATION_URL == null ) {
156             APPLICATION_URL = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(KRADConstants.APPLICATION_URL_KEY);
157         }
158         return APPLICATION_URL;
159     }
160     
161     
162 
163 
164 
165     public void render(PageContext pageContext, Tag parentTag) throws JspException {
166         try {
167             JspWriter out = pageContext.getOut();
168             if (!StringUtils.isBlank(labelFor)) {
169                 out.write("<label for=\""+labelFor+"\">");
170             }
171             if (required) {
172                 out.write(OLEConstants.REQUIRED_FIELD_SYMBOL);
173                 out.write(" ");
174             }
175             if (!StringUtils.isBlank(fullClassNameForHelp) && !StringUtils.isBlank(attributeEntryForHelp)) {
176                 out.write("<a href=\"");
177                 out.write(getApplicationURL());
178                 out.write("/kr/help.do?methodToCall=getAttributeHelpText&businessObjectClassName=");
179                 out.write(fullClassNameForHelp);
180                 out.write("&attributeName=");
181                 out.write(attributeEntryForHelp);
182                 out.write("\" target=\"_blank\">");
183             }
184             out.write(label);
185             if (!StringUtils.isBlank(fullClassNameForHelp) && !StringUtils.isBlank(attributeEntryForHelp)) {
186                 out.write("</a>");
187             }
188             if (!StringUtils.isBlank(labelFor)) {
189                 out.write("</label>");
190             }
191         }
192         catch (IOException ioe) {
193             throw new JspException("Difficulty rendering label", ioe);
194         }
195     }
196 
197 }