1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
package net.wotonomy.web;
import net.wotonomy.foundation.NSArray;
import net.wotonomy.foundation.NSData;
import net.wotonomy.foundation.NSDictionary;
/**
* WOImage renders a dynamically generated IMG tag. The URL for the image SRC
* can be static, or it can be generated dynamically to return a NSData object
* (with a mime-type) or even return the contents of a file (not implemented
* yet).
*
* Bindings are:
* <UL>
* <LI>src: A static URL for the image source.</li>
* <li>data: A NSData object with the image content. Must be used with
* mimeType.</li>
* <li>mimeType: The MIME type for the image data. Can be used with filename or
* data bindings.</li>
* <li>filename: The path to a file containing an image.</li>
* <li>framework: The optional framework from whence the image should be
* retrieved (used in conjunction with filename).</li>
*
* @author ezamudio@nasoft.com
* @author $Author: cgruber $
* @version $Revision: 905 $
*/
public class WOImage extends WODynamicElement {
protected String src;
protected String filename;
protected String framework;
protected NSData data;
protected String mimeType;
protected WOImage() {
super();
}
public WOImage(String aName, NSDictionary aMap, WOElement template) {
super(aName, aMap, template);
}
public void setSrc(String value) {
src = value;
}
public String src() {
return src;
}
public void setFilename(String value) {
filename = value;
}
public String filename() {
return filename;
}
public void setFramework(String value) {
framework = value;
}
public String framework() {
return framework;
}
public void setData(NSData value) {
data = value;
}
public NSData data() {
return data;
}
public void setMimeType(String value) {
mimeType = value;
}
public String mimeType() {
return mimeType();
}
public String sourceURL(WOContext c) {
if (associations.objectForKey("src") != null)
return (String) valueForProperty("src", c.component());
if (associations.objectForKey("data") != null) {
return c.componentActionURL();
}
if (associations.objectForKey("filename") != null) {
WOComponent component = c.component();
String framework = stringForProperty("framework", component);
String filename = stringForProperty("filename", component);
if (filename != null && framework == null) {
if (filename.startsWith("/")) {
int i = filename.lastIndexOf("/");
if (i > 0) {
framework = filename.substring(0, i);
if (i < filename.length()) {
filename = filename.substring(i + 1);
}
}
} else {
// just until we figure out how we're handling bundles/localization
framework = component.frameworkName();
if (framework != null) {
framework = framework + '/' + component.name() + ".wo";
} else {
framework = '/' + component.name() + ".wo";
}
}
}
return WOApplication.application().resourceManager().urlForResourceNamed(filename, framework,
c.request().browserLanguages(), c.request());
}
return "NO SOURCE";
}
public void appendToResponse(WOResponse r, WOContext c) {
r.appendContentString("<IMG SRC=\"");
r.appendContentString(sourceURL(c));
r.appendContentString("\"");
r.appendContentString(additionalHTMLProperties(c.component(),
new NSArray(new Object[] { "src", "filename", "framework", "data", "mimeType" })));
r.appendContentString(">");
}
public WOActionResults invokeAction(WORequest r, WOContext c) {
if (c.senderID().equals(c.elementID())) {
Object data = valueForProperty("data", c.component());
if (data instanceof byte[])
data = new NSData((byte[]) data);
if (data instanceof NSData) {
String mt = stringForProperty("mimeType", c.component());
if (mt == null)
throw new IllegalArgumentException("WOImage: No mimeType specified for data.");
WOResponse img = new WOResponse();
img.setContent((NSData) data);
img.setHeader(mt, "content-type");
return img;
} else if (filename() != null) {
// will this thing use frameworks, or regular JAR files with resources?
// mp: both/either, depending on which resource manager implementation
}
}
return null;
}
}
|