KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > externalizer > TextExternalizer


1 /*
2  * $Id: TextExternalizer.java,v 1.3 2004/12/01 07:54:08 hengels Exp $
3  */

4
5 /*
6  * $Id: TextExternalizer.java,v 1.3 2004/12/01 07:54:08 hengels Exp $
7  * Copyright 2000,2005 wingS development team.
8  *
9  * This file is part of wingS (http://www.j-wings.org).
10  *
11  * wingS is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License
13  * as published by the Free Software Foundation; either version 2.1
14  * of the License, or (at your option) any later version.
15  *
16  * Please see COPYING for the complete licence.
17  */

18 package org.wings.externalizer;
19
20 import org.wings.io.Device;
21
22 import java.io.Reader JavaDoc;
23 import java.io.StringReader JavaDoc;
24 import java.util.Collection JavaDoc;
25
26 public class TextExternalizer implements Externalizer {
27
28     private static final Class JavaDoc[] SUPPORTED_CLASSES = {String JavaDoc.class};
29
30     protected String JavaDoc extension;
31     protected String JavaDoc mimeType;
32     protected final String JavaDoc[] supportedMimeTypes = new String JavaDoc[1];
33
34
35     public TextExternalizer(String JavaDoc mimeType, String JavaDoc extension) {
36         this.mimeType = mimeType;
37         this.extension = extension;
38
39         supportedMimeTypes[0] = mimeType;
40     }
41
42     public TextExternalizer(String JavaDoc mimeType) {
43         this(mimeType, "txt");
44     }
45
46     public TextExternalizer() {
47         this("text/plain", "txt");
48     }
49
50     public void setExtension(String JavaDoc extension) {
51         this.extension = extension;
52     }
53
54     public String JavaDoc getExtension(Object JavaDoc obj) {
55         return extension;
56     }
57
58     public void setMimeType(String JavaDoc mimeType) {
59         this.mimeType = mimeType;
60     }
61
62     public String JavaDoc getMimeType(Object JavaDoc obj) {
63         return mimeType;
64     }
65
66     public boolean isFinal(Object JavaDoc obj) {
67         return true;
68     }
69
70     public int getLength(Object JavaDoc obj) {
71         return -1;
72     }
73
74     public void write(Object JavaDoc obj, Device out)
75             throws java.io.IOException JavaDoc {
76         Reader JavaDoc reader = new StringReader JavaDoc((String JavaDoc) obj);
77         char[] buffer = new char[2048];
78         int num;
79         while ((num = reader.read(buffer)) > 0) {
80             out.print(buffer, 0, num);
81         }
82         reader.close();
83     }
84
85     public Class JavaDoc[] getSupportedClasses() {
86         return SUPPORTED_CLASSES;
87     }
88
89     public String JavaDoc[] getSupportedMimeTypes() {
90         return supportedMimeTypes;
91     }
92
93     public Collection JavaDoc getHeaders(Object JavaDoc obj) {
94         return null;
95     }
96 }
97
98
99
Popular Tags