01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.wicket.util.resource;
18:
19: /**
20: * A StringResourceStream is an IResource implementation for strings.
21: *
22: * @see org.apache.wicket.util.resource.IResourceStream
23: * @see org.apache.wicket.util.watch.IModifiable
24: * @author Jonathan Locke
25: */
26: public final class StringResourceStream extends
27: AbstractStringResourceStream {
28: private static final long serialVersionUID = 1L;
29:
30: /** The string resource */
31: private final CharSequence string;
32:
33: /**
34: * Construct.
35: *
36: * @param string
37: * The resource string
38: */
39: public StringResourceStream(final CharSequence string) {
40: this .string = string;
41: }
42:
43: /**
44: * Construct.
45: *
46: * @param string
47: * The resource string
48: * @param contentType The mime type of this resource, such as "image/jpeg" or
49: * "text/html"
50: */
51: public StringResourceStream(final CharSequence string,
52: final String contentType) {
53: super (contentType);
54: this .string = string;
55: }
56:
57: /**
58: * @see java.lang.Object#toString()
59: */
60: public String toString() {
61: return string.toString();
62: }
63:
64: /**
65: * @see org.apache.wicket.util.resource.AbstractStringResourceStream#getString()
66: */
67: protected String getString() {
68: return toString();
69: }
70:
71: /**
72: * @see org.apache.wicket.util.resource.AbstractResourceStream#asString()
73: */
74: public String asString() {
75: return getString();
76: }
77:
78: /**
79: * @see org.apache.wicket.util.resource.IResourceStream#length()
80: */
81: public long length() {
82: return string.length();
83: }
84:
85: }
|