1 package mx.com.brained.taglib;
2
3 import javax.servlet.jsp.tagext.*;
4 import javax.servlet.jsp.JspWriter;
5 import javax.servlet.jsp.JspException;
6 import java.io.IOException;
7 import javax.servlet.http.HttpServletResponse;
8 import org.apache.struts.taglib.TagUtils;
9 import org.springframework.web.context.WebApplicationContext;
10 import mx.com.brained.resource.ResourceManagerIface;
11 import org.apache.commons.lang.StringUtils;
12
13 /***
14 *
15 * <p>Title: AwTaglib</p>
16 *
17 * <p>Description: Tag that creates the necessary import js files</p>
18 *
19 * <p>Copyright: Copyright (c) 2005</p>
20 *
21 * <p>Company: Brain-ED</p>
22 *
23 * @author Isidoro Treviņo, Eliseo Partida
24 * @version 1.0
25 *
26 *
27 * @jsp.tag
28 * name="gridLibrary"
29 * body-content="JSP"
30 * description="Tag that creates the necessary import js files"
31 */
32 public class GridLibraryTag extends TagSupport {
33 private String action = "/resource";
34
35 public GridLibraryTag() {
36 }
37
38 /***
39 * Set the action to be used to load the resources
40 * @param action String
41 */
42 public void setAction(String action) {
43 this.action = action;
44 }
45
46 /***
47 *
48 * @return Object
49 * @jsp.attribute
50 * required="false"
51 * rtexprvalue="true"
52 */
53 public String getAction() {
54 return action;
55 }
56
57 /***
58 * Render the libraries
59 * @return int
60 * @throws JspException
61 */
62 public int doStartTag() throws JspException {
63 JspWriter writer = pageContext.getOut();
64 try {
65 String url=TagUtils.getInstance().getActionMappingURL(action,this.pageContext);
66 WebApplicationContext context = (WebApplicationContext) pageContext.
67 getServletContext().
68 getAttribute(WebApplicationContext.
69 ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
70 ResourceManagerIface resource = (ResourceManagerIface) context.
71 getBean(GridConstants.
72 RESOURCEMANAGER);
73 String result = resource.getResourceAsString(GridConstants.LIBRARY_SCRIPT);
74 result = StringUtils.replace(result,GridConstants.RESOURCE_TOKEN,url);
75 writer.println(result);
76 } catch (Exception ex) {
77 throw new JspException(ex);
78 }
79 return this.SKIP_BODY;
80 }
81
82 }