KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > acting > ResourceExistsAction


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.acting;
17
18 import org.apache.avalon.framework.parameters.Parameters;
19 import org.apache.avalon.framework.thread.ThreadSafe;
20 import org.apache.cocoon.environment.Redirector;
21 import org.apache.cocoon.environment.SourceResolver;
22 import org.apache.excalibur.source.Source;
23 import org.apache.excalibur.source.SourceNotFoundException;
24
25 import java.util.Map JavaDoc;
26
27 /**
28  * This action simply checks to see if a resource identified by the <code>src</code>
29  * sitemap attribute exists or not. The action returns empty <code>Map</code> if
30  * resource exists, <code>null</code> otherwise.
31  *
32  * <p>Instead of src attribute, source can be specified using
33  * parameter named <code>url</code> (this is old syntax, should be removed soon).
34  *
35  * <p><b>NOTE:</b> {@link org.apache.cocoon.selection.ResourceExistsSelector}
36  * should be preferred to this component, as the semantics of a Selector better
37  * matches the supplied functionality.
38  *
39  * @author <a HREF="mailto:balld@apache.org">Donald Ball</a>
40  * @version CVS $Id: ResourceExistsAction.java 30932 2004-07-29 17:35:38Z vgritsenko $
41  */

42 public class ResourceExistsAction extends ServiceableAction implements ThreadSafe {
43
44     public Map JavaDoc act(Redirector redirector, SourceResolver resolver, Map JavaDoc objectModel, String JavaDoc src, Parameters parameters) throws Exception JavaDoc {
45         String JavaDoc resourceURI = parameters.getParameter("url", src);
46         Source source = null;
47         try {
48             source = resolver.resolveURI(resourceURI);
49             if (source.exists()) {
50                 return EMPTY_MAP;
51             }
52         } catch (SourceNotFoundException e) {
53             // Do not log
54
} catch (Exception JavaDoc e) {
55             getLogger().warn("Exception resolving resource " + resourceURI, e);
56         } finally {
57             if (source != null) {
58                 resolver.release(source);
59             }
60         }
61         return null;
62     }
63 }
64
Popular Tags