01: package org.apache.velocity.runtime.resource.util;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21:
22: import java.util.Collections;
23: import java.util.HashMap;
24: import java.util.Map;
25:
26: import org.apache.velocity.runtime.resource.loader.StringResourceLoader;
27:
28: /**
29: * Default implementation of StringResourceRepository.
30: * Uses a HashMap for storage
31: *
32: * @author <a href="mailto:eelco.hillenius@openedge.nl">Eelco Hillenius</a>
33: * @author <a href="mailto:henning@apache.org">Henning P. Schmiedehausen</a>
34: * @version $Id: StringResourceRepositoryImpl.java 479060 2006-11-25 00:30:19Z henning $
35: */
36: public class StringResourceRepositoryImpl implements
37: StringResourceRepository {
38: /**
39: * mem store
40: */
41: protected Map resources = Collections
42: .synchronizedMap(new HashMap());
43:
44: /**
45: * Current Repository encoding.
46: */
47: private String encoding = StringResourceLoader.REPOSITORY_ENCODING_DEFAULT;
48:
49: /**
50: * @see StringResourceRepository#getStringResource(java.lang.String)
51: */
52: public StringResource getStringResource(final String name) {
53: return (StringResource) resources.get(name);
54: }
55:
56: /**
57: * @see StringResourceRepository#putStringResource(java.lang.String, java.lang.String)
58: */
59: public void putStringResource(final String name, final String body) {
60: resources.put(name, new StringResource(body, getEncoding()));
61: }
62:
63: /**
64: * @see StringResourceRepository#removeStringResource(java.lang.String)
65: */
66: public void removeStringResource(final String name) {
67: resources.remove(name);
68: }
69:
70: /**
71: * @see org.apache.velocity.runtime.resource.util.StringResourceRepository#getEncoding()
72: */
73: public String getEncoding() {
74: return encoding;
75: }
76:
77: /**
78: * @see org.apache.velocity.runtime.resource.util.StringResourceRepository#setEncoding(java.lang.String)
79: */
80: public void setEncoding(final String encoding) {
81: this.encoding = encoding;
82: }
83: }
|