12 package org.zkoss.zkmax.zul;
14 import java.util.Iterator;
15 import java.util.List;
16 import static org.zkoss.lang.Generics.cast;
17 import org.zkoss.lang.Objects;
18 import org.zkoss.util.media.Media;
19 import org.zkoss.zk.au.AuRequest;
20 import org.zkoss.zk.ui.Desktop;
21 import org.zkoss.zk.ui.event.Event;
22 import org.zkoss.zk.ui.event.Events;
23 import org.zkoss.zk.ui.event.UploadEvent;
24 import org.zkoss.zk.ui.sys.ContentRenderer;
25 import org.zkoss.zk.ui.util.Configuration;
26 import org.zkoss.zul.impl.XulElement;
49 @SuppressWarnings(
"serial")
51 private static final String DEFAULT_DETECTION =
"browser";
58 private String _viewerClass;
59 private String _detection = DEFAULT_DETECTION;
60 private String _content;
61 private boolean _native;
76 if (_maxsize != value) {
78 smartUpdate(
"maxsize", _maxsize);
104 if (!_detection.equals(value)) {
106 smartUpdate(
"detection", _detection);
122 if (value !=
null && value.length() == 0) {
126 if (!Objects.equals(_viewerClass, value)) {
127 _viewerClass = value;
128 smartUpdate(
"viewerClass", _viewerClass);
145 if (value !=
null && !value.equals(_content)) {
147 smartUpdate(
"content", _content);
159 if (value != _native) {
161 smartUpdate(
"native", _native);
171 throws java.io.IOException {
173 _maxsize = this.getDesktop().getWebApp().getConfiguration().getMaxUploadSize();
176 super.renderProperties(renderer);
177 if (!Objects.equals(_detection, DEFAULT_DETECTION)) {
178 render(renderer,
"detection", _detection);
180 render(renderer,
"maxsize", _maxsize);
181 render(renderer,
"viewerClass", _viewerClass);
182 render(renderer,
"content", _content);
183 render(renderer,
"native", _native);
191 public void service(AuRequest request,
boolean everError) {
192 final String cmd = request.getCommand();
193 if (Events.ON_UPLOAD.equals(cmd)) {
194 Desktop desktop = getDesktop();
195 final List<Media> result = cast((List) desktop.getAttribute(
this.getUuid()));
196 desktop.removeAttribute(this.getUuid());
197 Event
event =
new UploadEvent(
199 desktop.getComponentByUuid(
this.getUuid()), parseResult(result)
201 Events.postEvent(event);
203 super.service(request, everError);
208 private static Media[] parseResult(List<Media> result) {
209 if (result !=
null) {
211 for (Iterator<Media> it = result.iterator(); it.hasNext();) {
212 final Media media = it.next();
213 if (media !=
null && media.inMemory() && media.isBinary()) {
214 final String nm = media.getName();
215 if (nm ==
null || nm.length() == 0) {
216 final byte[] bs = media.getByteData();
217 if (bs ==
null || bs.length == 0)
224 if (!result.isEmpty())
225 return result.toArray(
new Media[result.size()]);
void setViewerClass(String value)
void setDetection(String value)
void setContent(String value)
void renderProperties(ContentRenderer renderer)
void service(AuRequest request, boolean everError)
void setNative(boolean value)
void setMaxsize(int value)