001
014
015 package com.liferay.portal.util;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.kernel.util.StringUtil;
020
021 import java.io.IOException;
022
023 import java.util.HashMap;
024 import java.util.Map;
025
026
030 public class ContentUtil {
031
032 public static String get(String location) {
033 return _instance._get(location, false);
034 }
035
036 public static String get(String location, boolean all) {
037 return _instance._get(location, all);
038 }
039
040 public static String get(ClassLoader classLoader, String location) {
041 return _instance._get(classLoader, location, false);
042 }
043
044 public static String get(
045 ClassLoader classLoader, String location, boolean all) {
046
047 return _instance._get(classLoader, location, all);
048 }
049
050 private ContentUtil() {
051 _contentPool = new HashMap<String, String>();
052 }
053
054 private String _get(String location, boolean all) {
055 return _get(getClass().getClassLoader(), location, all);
056 }
057
058 private String _get(ClassLoader classLoader, String location, boolean all) {
059 String content = _contentPool.get(location);
060
061 if (content == null) {
062 try {
063 content = StringUtil.read(classLoader, location, all);
064
065 _put(location, content);
066 }
067 catch (IOException ioe) {
068 _log.error(ioe, ioe);
069 }
070 }
071
072 return content;
073 }
074
075 private void _put(String location, String content) {
076 _contentPool.put(location, content);
077 }
078
079 private static Log _log = LogFactoryUtil.getLog(ContentUtil.class);
080
081 private static ContentUtil _instance = new ContentUtil();
082
083 private Map<String, String> _contentPool;
084
085 }