01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.components.store.impl;
18:
19: import org.apache.excalibur.store.impl.AbstractFilesystemStore;
20: import org.apache.avalon.framework.context.Context;
21: import org.apache.avalon.framework.context.ContextException;
22: import org.apache.avalon.framework.context.Contextualizable;
23: import org.apache.avalon.framework.parameters.Parameterizable;
24: import org.apache.avalon.framework.parameters.Parameters;
25: import org.apache.avalon.framework.parameters.ParameterException;
26: import org.apache.cocoon.Constants;
27: import org.apache.cocoon.util.IOUtils;
28: import java.io.File;
29: import java.io.IOException;
30:
31: /**
32: * Stores objects on the filesystem: String objects as text files,
33: * all other objects are serialized.
34: *
35: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
36: * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
37: * @version CVS $Id: FilesystemStore.java 433543 2006-08-22 06:22:54Z crossley $
38: */
39: public final class FilesystemStore 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",
55: false)) {
56: if (this .getLogger().isDebugEnabled())
57: getLogger().debug(
58: "Using cache directory: " + cacheDir);
59: setDirectory(cacheDir);
60: } else if (params.getParameterAsBoolean(
61: "use-work-directory", false)) {
62: if (this .getLogger().isDebugEnabled())
63: getLogger().debug(
64: "Using work directory: " + workDir);
65: setDirectory(workDir);
66: } else if (params.getParameter("directory", null) != null) {
67: String dir = params.getParameter("directory");
68: dir = IOUtils
69: .getContextFilePath(workDir.getPath(), dir);
70: if (this .getLogger().isDebugEnabled())
71: getLogger().debug("Using directory: " + dir);
72: setDirectory(new File(dir));
73: } else {
74: try {
75: // Legacy: use working directory by default
76: setDirectory(workDir);
77: } catch (IOException e) {
78: // Legacy: Always was ignored
79: }
80: }
81: } catch (IOException e) {
82: throw new ParameterException("Unable to set directory", e);
83: }
84: }
85: }
|