KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > components > store > impl > FilesystemStore


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 JavaDoc;
28 import java.io.IOException JavaDoc;
29
30 /**
31  * Stores objects on the filesystem: String objects as text files,
32  * all other objects are serialized.
33  *
34  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
35  * @author <a HREF="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
36  * @version CVS $Id: FilesystemStore.java 30932 2004-07-29 17:35:38Z vgritsenko $
37  */

38 public final class FilesystemStore
39 extends AbstractFilesystemStore
40 implements Contextualizable, Parameterizable {
41
42     protected File JavaDoc workDir;
43     protected File JavaDoc cacheDir;
44
45     public void contextualize(final Context context)
46     throws ContextException {
47         this.workDir = (File JavaDoc)context.get(Constants.CONTEXT_WORK_DIR);
48         this.cacheDir = (File JavaDoc)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 JavaDoc 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 JavaDoc(dir));
68             } else {
69                 try {
70                     // Legacy: use working directory by default
71
setDirectory(workDir);
72                 } catch (IOException JavaDoc e) {
73                     // Legacy: Always was ignored
74
}
75             }
76         } catch (IOException JavaDoc e) {
77             throw new ParameterException("Unable to set directory", e);
78         }
79     }
80 }
81
Popular Tags