01: /**
02: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
03: *
04: * Permission is hereby granted, free of charge, to any person obtaining a copy
05: * of this software and associated documentation files (the "Software"), to deal
06: * in the Software without restriction, including without limitation the rights
07: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
08: * copies of the Software, and to permit persons to whom the Software is
09: * furnished to do so, subject to the following conditions:
10: *
11: * The above copyright notice and this permission notice shall be included in
12: * all copies or substantial portions of the Software.
13: *
14: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20: * SOFTWARE.
21: */package com.liferay.portal.util;
22:
23: import com.liferay.portal.kernel.util.StringUtil;
24: import com.liferay.util.CollectionFactory;
25:
26: import java.io.IOException;
27:
28: import java.util.Map;
29:
30: import org.apache.commons.logging.Log;
31: import org.apache.commons.logging.LogFactory;
32:
33: /**
34: * <a href="ContentUtil.java.html"><b><i>View Source</i></b></a>
35: *
36: * @author Brian Wing Shun Chan
37: *
38: */
39: public class ContentUtil {
40:
41: public static String get(String location) {
42: return _instance._get(location, false);
43: }
44:
45: public static String get(String location, boolean all) {
46: return _instance._get(location, all);
47: }
48:
49: private ContentUtil() {
50: _contentPool = CollectionFactory.getHashMap();
51: }
52:
53: private String _get(String location, boolean all) {
54: String content = (String) _contentPool.get(location);
55:
56: if (content == null) {
57: try {
58: content = StringUtil.read(getClass().getClassLoader(),
59: location, all);
60:
61: _put(location, content);
62: } catch (IOException ioe) {
63: _log.error(ioe, ioe);
64: }
65: }
66:
67: return content;
68: }
69:
70: private void _put(String location, String content) {
71: _contentPool.put(location, content);
72: }
73:
74: private static Log _log = LogFactory.getLog(ContentUtil.class);
75:
76: private static ContentUtil _instance = new ContentUtil();
77:
78: private Map _contentPool;
79:
80: }
|