1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.danube.tapestry;
14
15 import java.net.URL;
16 import java.util.ArrayList;
17 import java.util.HashMap;
18 import java.util.List;
19 import java.util.Map;
20
21 import javax.activation.FileTypeMap;
22
23 import org.apache.tapestry.describe.DescriptionReceiver;
24 import org.apache.tapestry.web.WebContext;
25
26
27
28
29
30
31
32 public class DanubeContext implements WebContext {
33
34
35 protected Map<String, Object> attributes = new HashMap<String, Object>();
36
37
38 protected TapestryConnectionHandler handler;
39
40
41
42
43
44 public DanubeContext(TapestryConnectionHandler handler) {
45 this.handler = handler;
46 }
47
48
49
50
51
52
53 public URL getResource(String path) {
54 if (path.startsWith("/")) {
55 path = path.substring(1);
56 }
57 ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
58 URL url = classLoader.getResource(path);
59 return url;
60 }
61
62
63
64
65
66
67 public String getMimeType(String resourcePath) {
68 if (resourcePath.endsWith(".js")) {
69 return "text/javascript";
70 }
71
72 if (resourcePath.endsWith(".css")) {
73 return "text/css";
74 }
75
76 FileTypeMap map = FileTypeMap.getDefaultFileTypeMap();
77
78 String mimeType = map.getContentType(resourcePath);
79 return mimeType;
80 }
81
82
83
84
85
86 @SuppressWarnings("unchecked")
87 public List getAttributeNames() {
88 return new ArrayList<String>(attributes.keySet());
89 }
90
91
92
93
94
95
96 public Object getAttribute(String name) {
97 return attributes.get(name);
98 }
99
100
101
102
103
104
105 public void setAttribute(String name, Object attribute) {
106 attributes.put(name, attribute);
107 }
108
109
110
111
112
113 @SuppressWarnings("unchecked")
114 public List getInitParameterNames() {
115 ArrayList<String> names = new ArrayList<String>(handler.getInitialParameters().keySet());
116 return names;
117 }
118
119
120
121
122
123
124 public String getInitParameterValue(String name) {
125 return handler.getInitialParameters().get(name);
126 }
127
128
129
130
131
132 public void describeTo(DescriptionReceiver receiver) {
133 }
134
135 }