KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > configuration > StringResource


1 /*
2  * Copyright 2006-2007 The Scriptella Project Team.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package scriptella.configuration;
17
18 import scriptella.spi.Resource;
19
20 import java.io.IOException JavaDoc;
21 import java.io.Reader JavaDoc;
22 import java.io.StringReader JavaDoc;
23
24 /**
25  * Represents String as a resource.
26  * <p>This implementation is intended to represent
27  * small text blocks.
28  *
29  * @author Fyodor Kupolov
30  * @version 1.0
31  */

32 public class StringResource implements Resource {
33     private final String JavaDoc string;
34     private final String JavaDoc description;
35
36     /**
37      * Creates a resource based on String content.
38      * @param string resource content.
39      */

40     public StringResource(String JavaDoc string) {
41         this(string, null);
42     }
43
44     /**
45      * Creates a resource based on String content.
46      * @param string resource content.
47      * @param description resource description.
48      */

49     public StringResource(String JavaDoc string, String JavaDoc description) {
50         this.string = string;
51         this.description = description;
52     }
53
54     public Reader JavaDoc open() throws IOException JavaDoc {
55         return new StringReader JavaDoc(string);
56     }
57
58
59     /**
60      * Returns the string wrapped by this resource.
61      */

62     public String JavaDoc getString() {
63         return string;
64     }
65
66     public String JavaDoc toString() {
67         return description==null?"Text block":description;
68     }
69 }
70
Popular Tags