diff options
Diffstat (limited to 'pki/base/common/src/com/netscape/cms/servlet/common/CMSFileLoader.java')
-rw-r--r-- | pki/base/common/src/com/netscape/cms/servlet/common/CMSFileLoader.java | 61 |
1 files changed, 31 insertions, 30 deletions
diff --git a/pki/base/common/src/com/netscape/cms/servlet/common/CMSFileLoader.java b/pki/base/common/src/com/netscape/cms/servlet/common/CMSFileLoader.java index 0d3fea99f..bf4c3cf6c 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/common/CMSFileLoader.java +++ b/pki/base/common/src/com/netscape/cms/servlet/common/CMSFileLoader.java @@ -17,6 +17,7 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cms.servlet.common; + import java.io.File; import java.io.IOException; import java.util.Enumeration; @@ -25,9 +26,10 @@ import java.util.Hashtable; import com.netscape.certsrv.base.EBaseException; import com.netscape.certsrv.base.IConfigStore; + /** * CMSFileLoader - file cache. - * + * * @version $Revision$, $Date$ */ @@ -43,14 +45,14 @@ public class CMSFileLoader { // property to cache templates only public final String PROP_CACHE_TEMPLATES_ONLY = "cacheTemplatesOnly"; - // hash of files to their content. + // hash of files to their content. private Hashtable mLoadedFiles = new Hashtable(); - // max number of files + // max number of files private int mMaxSize = MAX_SIZE; // number of files to clear when max is reached. - private int mClearSize = CLEAR_SIZE; + private int mClearSize = CLEAR_SIZE; // whether to cache templates and forms only. private boolean mCacheTemplatesOnly = true; @@ -61,17 +63,16 @@ public class CMSFileLoader { public void init(IConfigStore config) throws EBaseException { mMaxSize = config.getInteger(PROP_MAX_SIZE, MAX_SIZE); mClearSize = config.getInteger(PROP_CLEAR_SIZE, CLEAR_SIZE); - mCacheTemplatesOnly = config - .getBoolean(PROP_CACHE_TEMPLATES_ONLY, true); + mCacheTemplatesOnly = + config.getBoolean(PROP_CACHE_TEMPLATES_ONLY, true); } // Changed by bskim - // public byte[] get(String absPath) throws EBaseException, IOException { - // File file = new File(absPath); - // return get(file); - // } - public byte[] get(String absPath, String enc) throws EBaseException, - IOException { + //public byte[] get(String absPath) throws EBaseException, IOException { + // File file = new File(absPath); + // return get(file); + //} + public byte[] get(String absPath, String enc) throws EBaseException, IOException { File file = new File(absPath); return get(file, enc); @@ -80,20 +81,19 @@ public class CMSFileLoader { // Change end // Changed by bskim - // public byte[] get(File file) throws EBaseException, IOException { - // CMSFile cmsFile = getCMSFile(file); + //public byte[] get(File file) throws EBaseException, IOException { + // CMSFile cmsFile = getCMSFile(file); public byte[] get(File file, String enc) throws EBaseException, IOException { CMSFile cmsFile = getCMSFile(file, enc); - // Change end + // Change end return cmsFile.getContent(); } // Changed by bskim - // public CMSFile getCMSFile(File file) throws EBaseException, IOException { - public CMSFile getCMSFile(File file, String enc) throws EBaseException, - IOException { - // Change end + //public CMSFile getCMSFile(File file) throws EBaseException, IOException { + public CMSFile getCMSFile(File file, String enc) throws EBaseException, IOException { + // Change end String absPath = file.getAbsolutePath(); long modified = file.lastModified(); CMSFile cmsFile = (CMSFile) mLoadedFiles.get(absPath); @@ -102,8 +102,8 @@ public class CMSFileLoader { // new file. if (cmsFile == null || modified != lastModified) { // Changed by bskim - // cmsFile = updateFile(absPath, file); - cmsFile = updateFile(absPath, file, enc); + //cmsFile = updateFile(absPath, file); + cmsFile = updateFile(absPath, file, enc); // Change end } cmsFile.setLastAccess(System.currentTimeMillis()); @@ -111,10 +111,10 @@ public class CMSFileLoader { } // Changed by bskim - // private CMSFile updateFile(String absPath, File file) - private CMSFile updateFile(String absPath, File file, String enc) - // Change end - throws EBaseException, IOException { + //private CMSFile updateFile(String absPath, File file) + private CMSFile updateFile(String absPath, File file, String enc) + // Change end + throws EBaseException, IOException { // clear if cache size exceeded. if (mLoadedFiles.size() >= mMaxSize) { clearSomeFiles(); @@ -125,24 +125,24 @@ public class CMSFileLoader { // check if file is a js template or plain template by its first String if (absPath.endsWith(CMSTemplate.SUFFIX)) { // Changed by bskim - // cmsFile = new CMSTemplate(file); + //cmsFile = new CMSTemplate(file); cmsFile = new CMSTemplate(file, enc); // End of Change } else { cmsFile = new CMSFile(file); } - mLoadedFiles.put(absPath, cmsFile); // replace old one if any. + mLoadedFiles.put(absPath, cmsFile); // replace old one if any. return cmsFile; } private synchronized void clearSomeFiles() { // recheck this in case some other thread has cleared it. - if (mLoadedFiles.size() < mMaxSize) + if (mLoadedFiles.size() < mMaxSize) return; - // remove the LRU files. - // XXX could be optimized more. + // remove the LRU files. + // XXX could be optimized more. Enumeration elements = mLoadedFiles.elements(); for (int i = mClearSize; i > 0; i--) { @@ -160,3 +160,4 @@ public class CMSFileLoader { } } } + |