1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.fatwire.gst.foundation.controller.annotation;
18
19 import static COM.FutureTense.Interfaces.Utilities.goodString;
20
21 import java.lang.reflect.InvocationTargetException;
22 import java.lang.reflect.Method;
23
24 import COM.FutureTense.Util.ftErrors;
25 import COM.FutureTense.Util.ftMessage;
26
27 import com.fatwire.gst.foundation.CSRuntimeException;
28 import com.fatwire.gst.foundation.controller.AbstractController;
29 import com.fatwire.gst.foundation.facade.RenderUtils;
30 import com.fatwire.gst.foundation.facade.runtag.render.LogDep;
31
32
33
34
35
36
37
38
39
40
41
42
43 public abstract class AnnotationController extends AbstractController {
44
45
46
47
48
49
50 @Override
51 protected void doExecute() {
52
53
54 RenderUtils.recordBaseCompositionalDependencies(ics);
55 final ControllerMappingResolver resolver = new ControllerMappingResolver();
56 final Object target = getTarget();
57 final Method m = resolver.findControllerMethod(ics, target);
58 if (m == null) {
59 executeDefault();
60 } else {
61 invokeControllerMethod(m, target);
62 }
63 }
64
65
66
67
68
69 protected void invokeControllerMethod(final Method m, final Object target) {
70 try {
71 m.invoke(target, new Object[] { ics });
72 } catch (final IllegalArgumentException e) {
73 handleException(e);
74 } catch (final IllegalAccessException e) {
75 handleException(e);
76 } catch (final InvocationTargetException e) {
77 handleException(e);
78 }
79
80 }
81
82
83
84
85 protected Object getTarget() {
86 return this;
87 }
88
89
90
91
92
93 abstract void executeDefault();
94
95 @Override
96 protected void handleException(final Exception e) {
97 if (e instanceof CSRuntimeException) {
98 handleCSRuntimeException((CSRuntimeException) e);
99 } else {
100 sendError(500, e);
101 }
102 }
103
104
105
106
107
108
109
110
111
112
113
114 protected void handleCSRuntimeException(final CSRuntimeException e) {
115 switch (e.getErrno()) {
116 case 400:
117 case ftErrors.badparams:
118 sendError(400, e);
119 break;
120 case 404:
121 case ftErrors.pagenotfound:
122 sendError(404, e);
123 break;
124 case 403:
125 case ftErrors.noprivs:
126 sendError(403, e);
127 break;
128 default:
129 sendError(500, e);
130 break;
131 }
132 }
133
134
135
136
137 protected void recordCompositionalDependencies() {
138 if (ics.isCacheable(ics.GetVar(ftMessage.PageName))) {
139 if (goodString(ics.GetVar("seid"))) {
140 LogDep.logDep(ics, "SiteEntry", ics.GetVar("seid"));
141 }
142 if (goodString(ics.GetVar("eid"))) {
143 LogDep.logDep(ics, "CSElement", ics.GetVar("eid"));
144 }
145 }
146 }
147
148 }