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: package org.apache.lenya.cms.usecase.cocoon;
19:
20: import java.util.Map;
21:
22: import org.apache.avalon.framework.configuration.Configuration;
23: import org.apache.avalon.framework.configuration.ConfigurationException;
24: import org.apache.avalon.framework.service.ServiceException;
25: import org.apache.avalon.framework.service.ServiceManager;
26: import org.apache.avalon.framework.service.Serviceable;
27: import org.apache.cocoon.components.modules.input.AbstractInputModule;
28: import org.apache.cocoon.environment.ObjectModelHelper;
29: import org.apache.cocoon.environment.Request;
30: import org.apache.lenya.cms.usecase.Usecase;
31: import org.apache.lenya.cms.usecase.UsecaseResolver;
32: import org.apache.lenya.cms.usecase.gui.Tab;
33: import org.apache.lenya.util.ServletHelper;
34:
35: /**
36: * Input module to obtain information about usecases.
37: */
38: public class UsecaseModule extends AbstractInputModule implements
39: Serviceable {
40:
41: public Object getAttribute(String name, Configuration modeConf,
42: Map objectModel) throws ConfigurationException {
43:
44: Object value = "";
45:
46: String prefix = "tabGroup:";
47: if (name.startsWith(prefix) && name.length() > prefix.length()) {
48: String[] steps = name.split(":");
49: String usecaseName = steps[1];
50:
51: Request request = ObjectModelHelper.getRequest(objectModel);
52: String webappUrl = ServletHelper.getWebappURI(request);
53:
54: UsecaseResolver resolver = null;
55: Usecase usecase = null;
56: try {
57: resolver = (UsecaseResolver) this .manager
58: .lookup(UsecaseResolver.ROLE);
59: usecase = resolver.resolve(webappUrl, usecaseName);
60: if (usecase.getView() != null) {
61: Tab tab = usecase.getView().getTab();
62: if (tab != null) {
63: value = tab.getGroup();
64: }
65: }
66: } catch (ServiceException e) {
67: throw new ConfigurationException("Error: ", e);
68: } finally {
69: if (resolver != null) {
70: if (usecase != null) {
71: try {
72: resolver.release(usecase);
73: } catch (ServiceException e) {
74: throw new RuntimeException(e);
75: }
76: }
77: this .manager.release(resolver);
78: }
79: }
80: }
81:
82: return value;
83:
84: }
85:
86: private ServiceManager manager;
87:
88: public void service(ServiceManager manager) throws ServiceException {
89: this.manager = manager;
90: }
91:
92: }
|