KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > environment > commandline > FileSavingEnvironment


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.environment.commandline;
17
18 import org.apache.avalon.framework.logger.Logger;
19
20 import org.apache.cocoon.Constants;
21 import org.apache.cocoon.environment.ObjectModelHelper;
22
23 import java.io.File JavaDoc;
24 import java.io.OutputStream JavaDoc;
25 import java.net.MalformedURLException JavaDoc;
26 import java.util.Map JavaDoc;
27 import java.util.List JavaDoc;
28
29 /**
30  * This environment is used to save the requested file to disk.
31  *
32  * @author <a HREF="mailto:stefano@apache.org">Stefano Mazzocchi</a>
33  * @author <a HREF="mailto:uv@upaya.co.uk">Upayavira</a>
34  * @version CVS $Id: FileSavingEnvironment.java 30932 2004-07-29 17:35:38Z vgritsenko $
35  */

36 public class FileSavingEnvironment extends AbstractCommandLineEnvironment {
37
38     protected boolean modified = true;
39     protected long sourceLastModified = 0L;
40
41     public FileSavingEnvironment(String JavaDoc uri,
42                                  long lastModified,
43                                  File JavaDoc context,
44                                  Map JavaDoc attributes,
45                                  Map JavaDoc parameters,
46                                  Map JavaDoc links,
47                                  List JavaDoc gatheredLinks,
48                                  CommandLineContext cliContext,
49                                  OutputStream JavaDoc stream,
50                                  Logger log)
51     throws MalformedURLException JavaDoc {
52         super(uri, null, context, stream, log);
53         this.objectModel.put(ObjectModelHelper.REQUEST_OBJECT,
54                              new CommandLineRequest(this, null, uri, null, attributes, parameters));
55         this.objectModel.put(ObjectModelHelper.RESPONSE_OBJECT,
56                              new CommandLineResponse());
57         this.objectModel.put(ObjectModelHelper.CONTEXT_OBJECT,
58                              cliContext);
59         this.sourceLastModified = lastModified;
60         if (links != null) {
61             this.objectModel.put(Constants.LINK_OBJECT, links);
62         }
63         if (gatheredLinks != null) {
64             this.objectModel.put(Constants.LINK_COLLECTION_OBJECT, gatheredLinks);
65         }
66     }
67     
68     public FileSavingEnvironment(String JavaDoc uri,
69                                  File JavaDoc context,
70                                  Map JavaDoc attributes,
71                                  Map JavaDoc parameters,
72                                  Map JavaDoc links,
73                                  List JavaDoc gatheredLinks,
74                                  CommandLineContext cliContext,
75                                  OutputStream JavaDoc stream,
76                                  Logger log)
77     throws MalformedURLException JavaDoc {
78         this(uri, 0L, context, attributes, parameters, links, gatheredLinks, cliContext, stream, log);
79     }
80
81     /**
82      * Check if the response has been modified since the same
83      * "resource" was requested.
84      * The caller has to test if it is really the same "resource"
85      * which is requested.
86      * @return true if the response is modified or if the
87      * environment is not able to test it
88      */

89     public boolean isResponseModified(long cacheLastModified) {
90         if (cacheLastModified != 0) {
91             return cacheLastModified / 1000 > sourceLastModified / 1000;
92         }
93         return true;
94     }
95
96     /**
97      * Mark the response as not modified.
98      */

99     public void setResponseIsNotModified() {
100        this.modified = false;
101     }
102
103     public boolean isModified() {
104         return this.modified;
105     }
106 }
107
Popular Tags