001
014
015 package com.liferay.portal.servlet.filters.aggregate;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.kernel.util.FileUtil;
020 import com.liferay.portal.kernel.util.StringPool;
021
022 import java.io.IOException;
023
024
028 public class FileAggregateContext extends BaseAggregateContext {
029
030 public FileAggregateContext(String docrootPath, String resourcePath) {
031 int pos = resourcePath.lastIndexOf(StringPool.SLASH);
032
033 if (pos > -1) {
034 resourcePath = resourcePath.substring(0, pos + 1);
035 }
036
037 pushPath(docrootPath);
038 pushPath(resourcePath);
039 }
040
041 @Override
042 public String getContent(String path) {
043 try {
044 pushPath(path);
045
046 String fullPath = getFullPath(StringPool.BLANK);
047
048 popPath();
049
050 return FileUtil.read(fullPath);
051 }
052 catch (IOException ioe) {
053 _log.error(ioe, ioe);
054 }
055
056 return null;
057 }
058
059 @Override
060 public String getResourcePath(String path) {
061 String docrootPath = shiftPath();
062
063 String fullPath = getFullPath(StringPool.BLANK);
064
065 unshiftPath(docrootPath);
066
067 return fullPath.concat(path);
068 }
069
070 private static Log _log = LogFactoryUtil.getLog(FileAggregateContext.class);
071
072 }