01: /*
02: * Copyright 2000,2005 wingS development team.
03: *
04: * This file is part of wingS (http://wingsframework.org).
05: *
06: * wingS is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU Lesser General Public License
08: * as published by the Free Software Foundation; either version 2.1
09: * of the License, or (at your option) any later version.
10: *
11: * Please see COPYING for the complete licence.
12: */
13: package org.wings.externalizer;
14:
15: import org.wings.Renderable;
16: import org.wings.io.Device;
17: import org.wings.resource.StringResource;
18: import org.wings.resource.HttpHeader;
19: import org.wings.resource.ResourceNotFoundException;
20:
21: import java.io.IOException;
22: import java.util.Collection;
23:
24: /**
25: * @author <a href="mailto:haaf@mercatis.de">Armin Haaf</a>
26: * @author <a href="mailto:mreinsch@to.com">Michael Reinsch</a>
27: */
28: public class StringResourceExternalizer implements
29: Externalizer<StringResource> {
30:
31: private static final Class[] SUPPORTED_CLASSES = { StringResource.class };
32:
33: public static final StringResourceExternalizer SHARED_INSTANCE = new StringResourceExternalizer();
34:
35: public String getId(StringResource obj) {
36: return null;
37: }
38:
39: public String getExtension(StringResource obj) {
40: if (obj != null)
41: return obj.getExtension();
42: else
43: return "";
44: }
45:
46: public String getMimeType(StringResource obj) {
47: if (obj != null)
48: return obj.getMimeType();
49: else
50: return "unknown";
51: }
52:
53: public int getLength(StringResource obj) {
54: if (obj != null)
55: return obj.getLength();
56: return -1;
57: }
58:
59: public boolean isFinal(StringResource obj) {
60: return true;
61: }
62:
63: public void write(Object obj, Device out) throws IOException,
64: ResourceNotFoundException {
65: ((Renderable) obj).write(out);
66: }
67:
68: public Class[] getSupportedClasses() {
69: return SUPPORTED_CLASSES;
70: }
71:
72: public String[] getSupportedMimeTypes() {
73: return null;
74: }
75:
76: public Collection<HttpHeader> getHeaders(StringResource obj) {
77: if (obj != null)
78: return obj.getHeaders();
79: else
80: return null;
81: }
82: }
|