1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.fatwire.gst.foundation.taglib;
17
18 import java.io.IOException;
19
20 import javax.servlet.jsp.JspException;
21 import javax.servlet.jsp.tagext.JspTag;
22 import javax.servlet.jsp.tagext.SimpleTagSupport;
23
24 import COM.FutureTense.Interfaces.ICS;
25
26 import com.fatwire.gst.foundation.include.DefaultIncludeService;
27 import com.fatwire.gst.foundation.include.Include;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31
32
33
34
35
36
37
38 public final class IncludeTag extends GsfSimpleTag {
39
40 static final Log LOG = LogFactory.getLog(IncludeTag.class.getPackage().getName());
41
42 private String name;
43 private boolean silent = false;
44
45
46
47
48
49
50 @Override
51 public void doTag() throws JspException, IOException {
52
53 final ICS ics = getICS();
54
55 final Include inc = discover(name);
56 if (inc != null) {
57 inc.include(ics);
58 } else if (!silent) {
59 throw new IllegalStateException("Can't find object to include with the name " + name);
60 }
61
62 super.doTag();
63 }
64
65 protected Include discover(final String name) {
66 final DefaultIncludeService s = findService();
67 if (s == null)
68 throw new IllegalStateException(
69 "Can't find DefaultIncludeService from a parent tag. Does your Action have a @InjectForRequest field of type IncludeService."
70 + " This is required to make use of the include tag in your jsp.");
71
72 return s.find(name);
73 }
74
75 protected DefaultIncludeService findService() {
76 final JspTag parent = SimpleTagSupport.findAncestorWithClass(this, PageTag.class);
77 if (parent instanceof PageTag) {
78 final PageTag t = (PageTag) parent;
79 return t.getJspIncludeService();
80 }
81 throw new IllegalStateException("Cannot find a parent JSP tag of type PageTag. Is the include tag nested in a gsf:root tag?");
82
83 }
84
85
86
87
88 public String getName() {
89 return name;
90 }
91
92
93
94
95 public void setName(final String name) {
96 this.name = name;
97 }
98
99
100
101
102 public boolean isSilent() {
103 return silent;
104 }
105
106
107
108
109 public void setSilent(final boolean silent) {
110 this.silent = silent;
111 }
112
113 }