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: */
18:
19: /* $Id: LanguageExistsAction.java 565765 2007-08-14 14:06:03Z andreas $ */
20:
21: package org.apache.lenya.cms.cocoon.acting;
22:
23: import java.util.Collections;
24: import java.util.Map;
25:
26: import org.apache.avalon.framework.parameters.Parameters;
27: import org.apache.cocoon.acting.ServiceableAction;
28: import org.apache.cocoon.environment.ObjectModelHelper;
29: import org.apache.cocoon.environment.Redirector;
30: import org.apache.cocoon.environment.Request;
31: import org.apache.cocoon.environment.SourceResolver;
32: import org.apache.lenya.cms.publication.DocumentFactory;
33: import org.apache.lenya.cms.publication.DocumentUtil;
34: import org.apache.lenya.util.ServletHelper;
35:
36: /**
37: * Action that checks if the current URL represents an existing document.
38: */
39: public class LanguageExistsAction extends ServiceableAction {
40:
41: /**
42: * Check if the current URL represents an existing document.
43: * @return an empty <code>Map</code> if there is a version of this document for the current
44: * language, <code>null</code> otherwise.
45: * @throws Exception if an error occurs
46: */
47: public Map act(Redirector redirector, SourceResolver resolver,
48: Map objectModel, String source, Parameters parameters)
49: throws Exception {
50:
51: Request request = ObjectModelHelper.getRequest(objectModel);
52: DocumentFactory factory = DocumentUtil.getDocumentFactory(
53: this .manager, request);
54:
55: String url = ServletHelper.getWebappURI(request);
56: if (factory.isDocument(url)) {
57: return Collections.unmodifiableMap(Collections.EMPTY_MAP);
58: } else {
59: return null;
60: }
61: }
62: }
|