1 16 package org.apache.cocoon.components.store.impl; 17 18 import org.apache.excalibur.store.impl.AbstractFilesystemStore; 19 import org.apache.avalon.framework.context.Context; 20 import org.apache.avalon.framework.context.ContextException; 21 import org.apache.avalon.framework.context.Contextualizable; 22 import org.apache.avalon.framework.parameters.Parameterizable; 23 import org.apache.avalon.framework.parameters.Parameters; 24 import org.apache.avalon.framework.parameters.ParameterException; 25 import org.apache.cocoon.Constants; 26 import org.apache.cocoon.util.IOUtils; 27 import java.io.File ; 28 import java.io.IOException ; 29 30 38 public final class FilesystemStore 39 extends AbstractFilesystemStore 40 implements Contextualizable, Parameterizable { 41 42 protected File workDir; 43 protected File cacheDir; 44 45 public void contextualize(final Context context) 46 throws ContextException { 47 this.workDir = (File )context.get(Constants.CONTEXT_WORK_DIR); 48 this.cacheDir = (File )context.get(Constants.CONTEXT_CACHE_DIR); 49 } 50 51 public void parameterize(Parameters params) 52 throws ParameterException { 53 try { 54 if (params.getParameterAsBoolean("use-cache-directory", false)) { 55 if (this.getLogger().isDebugEnabled()) 56 getLogger().debug("Using cache directory: " + cacheDir); 57 setDirectory(cacheDir); 58 } else if (params.getParameterAsBoolean("use-work-directory", false)) { 59 if (this.getLogger().isDebugEnabled()) 60 getLogger().debug("Using work directory: " + workDir); 61 setDirectory(workDir); 62 } else if (params.getParameter("directory", null) != null) { 63 String dir = params.getParameter("directory"); 64 dir = IOUtils.getContextFilePath(workDir.getPath(), dir); 65 if (this.getLogger().isDebugEnabled()) 66 getLogger().debug("Using directory: " + dir); 67 setDirectory(new File (dir)); 68 } else { 69 try { 70 setDirectory(workDir); 72 } catch (IOException e) { 73 } 75 } 76 } catch (IOException e) { 77 throw new ParameterException("Unable to set directory", e); 78 } 79 } 80 } 81 | Popular Tags |