1 |
|
|
2 |
|
package net.wotonomy.web; |
3 |
|
|
4 |
|
import net.wotonomy.foundation.NSArray; |
5 |
|
import net.wotonomy.foundation.NSData; |
6 |
|
import net.wotonomy.foundation.NSDictionary; |
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
public class WOImage extends WODynamicElement { |
25 |
|
|
26 |
|
protected String src; |
27 |
|
protected String filename; |
28 |
|
protected String framework; |
29 |
|
protected NSData data; |
30 |
|
protected String mimeType; |
31 |
|
|
32 |
|
protected WOImage() { |
33 |
0 |
super(); |
34 |
0 |
} |
35 |
|
|
36 |
|
public WOImage(String aName, NSDictionary aMap, WOElement template) { |
37 |
0 |
super(aName, aMap, template); |
38 |
0 |
} |
39 |
|
|
40 |
|
public void setSrc(String value) { |
41 |
0 |
src = value; |
42 |
0 |
} |
43 |
|
public String src() { |
44 |
0 |
return src; |
45 |
|
} |
46 |
|
|
47 |
|
public void setFilename(String value) { |
48 |
0 |
filename = value; |
49 |
0 |
} |
50 |
|
|
51 |
|
public String filename() { |
52 |
0 |
return filename; |
53 |
|
} |
54 |
|
|
55 |
|
public void setFramework(String value) { |
56 |
0 |
framework = value; |
57 |
0 |
} |
58 |
|
public String framework() { |
59 |
0 |
return framework; |
60 |
|
} |
61 |
|
|
62 |
|
public void setData(NSData value) { |
63 |
0 |
data = value; |
64 |
0 |
} |
65 |
|
public NSData data() { |
66 |
0 |
return data; |
67 |
|
} |
68 |
|
|
69 |
|
public void setMimeType(String value) { |
70 |
0 |
mimeType = value; |
71 |
0 |
} |
72 |
|
public String mimeType() { |
73 |
0 |
return mimeType(); |
74 |
|
} |
75 |
|
|
76 |
|
public String sourceURL(WOContext c) { |
77 |
0 |
if (associations.objectForKey("src") != null) |
78 |
0 |
return (String)valueForProperty("src", c.component()); |
79 |
0 |
if (associations.objectForKey("data") != null) { |
80 |
0 |
return c.componentActionURL(); |
81 |
|
} |
82 |
0 |
if (associations.objectForKey("filename") != null) { |
83 |
0 |
WOComponent component = c.component(); |
84 |
|
|
85 |
0 |
String framework = stringForProperty("framework", component); |
86 |
0 |
String filename = stringForProperty( "filename", component ); |
87 |
0 |
if ( filename != null && framework == null ) |
88 |
|
{ |
89 |
0 |
if ( filename.startsWith("/" ) ) |
90 |
|
{ |
91 |
0 |
int i = filename.lastIndexOf( "/" ); |
92 |
0 |
if ( i > 0 ) |
93 |
|
{ |
94 |
0 |
framework = filename.substring( 0, i ); |
95 |
0 |
if ( i < filename.length() ) |
96 |
|
{ |
97 |
0 |
filename = filename.substring( i+1 ); |
98 |
|
} |
99 |
|
} |
100 |
0 |
} |
101 |
|
else |
102 |
|
{ |
103 |
|
|
104 |
0 |
framework = component.frameworkName(); |
105 |
0 |
if ( framework != null ) |
106 |
|
{ |
107 |
0 |
framework = framework + '/' + component.name() + ".wo"; |
108 |
0 |
} |
109 |
|
else |
110 |
|
{ |
111 |
0 |
framework = '/' + component.name() + ".wo"; |
112 |
|
} |
113 |
|
} |
114 |
|
} |
115 |
0 |
return WOApplication.application().resourceManager().urlForResourceNamed( |
116 |
0 |
filename, framework, c.request().browserLanguages(), c.request() ); |
117 |
|
} |
118 |
0 |
return "NO SOURCE"; |
119 |
|
} |
120 |
|
|
121 |
|
public void appendToResponse(WOResponse r, WOContext c) { |
122 |
0 |
r.appendContentString("<IMG SRC=\""); |
123 |
0 |
r.appendContentString(sourceURL(c)); |
124 |
0 |
r.appendContentString("\""); |
125 |
0 |
r.appendContentString(additionalHTMLProperties(c.component(), new NSArray(new Object[]{ |
126 |
0 |
"src", "filename", "framework", "data", "mimeType" }))); |
127 |
0 |
r.appendContentString(">"); |
128 |
0 |
} |
129 |
|
|
130 |
|
public WOActionResults invokeAction(WORequest r, WOContext c) { |
131 |
0 |
if (c.senderID().equals(c.elementID())) { |
132 |
0 |
Object data = valueForProperty("data", c.component()); |
133 |
0 |
if (data instanceof byte[]) data = new NSData( (byte[]) data ); |
134 |
0 |
if (data instanceof NSData) { |
135 |
0 |
String mt = stringForProperty("mimeType", c.component()); |
136 |
0 |
if (mt == null) |
137 |
0 |
throw new IllegalArgumentException("WOImage: No mimeType specified for data."); |
138 |
0 |
WOResponse img = new WOResponse(); |
139 |
0 |
img.setContent((NSData)data); |
140 |
0 |
img.setHeader(mt, "content-type"); |
141 |
0 |
return img; |
142 |
0 |
} else if (filename() != null) { |
143 |
|
|
144 |
|
|
145 |
|
} |
146 |
|
} |
147 |
0 |
return null; |
148 |
|
} |
149 |
|
|
150 |
|
} |