1
14
15 package com.liferay.portal.util;
16
17 import com.liferay.portal.kernel.log.Log;
18 import com.liferay.portal.kernel.log.LogFactoryUtil;
19 import com.liferay.portal.kernel.util.StringUtil;
20
21 import java.io.IOException;
22
23 import java.util.HashMap;
24 import java.util.Map;
25
26
32 public class ContentUtil {
33
34 public static String get(String location) {
35 return _instance._get(location, false);
36 }
37
38 public static String get(String location, boolean all) {
39 return _instance._get(location, all);
40 }
41
42 public static String get(ClassLoader classLoader, String location) {
43 return _instance._get(classLoader, location, false);
44 }
45
46 public static String get(
47 ClassLoader classLoader, String location, boolean all) {
48
49 return _instance._get(classLoader, location, all);
50 }
51
52 private ContentUtil() {
53 _contentPool = new HashMap<String, String>();
54 }
55
56 private String _get(String location, boolean all) {
57 return _get(getClass().getClassLoader(), location, all);
58 }
59
60 private String _get(ClassLoader classLoader, String location, boolean all) {
61 String content = _contentPool.get(location);
62
63 if (content == null) {
64 try {
65 content = StringUtil.read(classLoader, location, all);
66
67 _put(location, content);
68 }
69 catch (IOException ioe) {
70 _log.error(ioe, ioe);
71 }
72 }
73
74 return content;
75 }
76
77 private void _put(String location, String content) {
78 _contentPool.put(location, content);
79 }
80
81 private static Log _log = LogFactoryUtil.getLog(ContentUtil.class);
82
83 private static ContentUtil _instance = new ContentUtil();
84
85 private Map<String, String> _contentPool;
86
87 }