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.portal.acting;
18:
19: import java.util.Map;
20:
21: import org.apache.avalon.framework.parameters.Parameters;
22: import org.apache.avalon.framework.service.ServiceException;
23: import org.apache.avalon.framework.thread.ThreadSafe;
24: import org.apache.cocoon.ProcessingException;
25: import org.apache.cocoon.acting.ServiceableAction;
26: import org.apache.cocoon.environment.Redirector;
27: import org.apache.cocoon.environment.SourceResolver;
28: import org.apache.cocoon.portal.Constants;
29: import org.apache.cocoon.portal.PortalService;
30:
31: /**
32: * Prepare the portal by setting the portal name.
33: *
34: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
35: * @version CVS $Id: PreparePortalAction.java 526440 2007-04-07 15:28:30Z rgoers $
36: */
37: public class PreparePortalAction extends ServiceableAction implements
38: ThreadSafe {
39:
40: /* (non-Javadoc)
41: * @see org.apache.cocoon.acting.Action#act(org.apache.cocoon.environment.Redirector, org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
42: */
43: public Map act(Redirector redirector, SourceResolver resolver,
44: Map objectModel, String source, Parameters parameters)
45: throws Exception {
46: PortalService portalService = null;
47: try {
48:
49: portalService = (PortalService) this .manager
50: .lookup(PortalService.ROLE);
51:
52: if (portalService.getPortalName() == null) {
53: final String portalName = parameters.getParameter(
54: "portal-name", (String) objectModel
55: .get(Constants.PORTAL_NAME_KEY));
56: portalService.setPortalName(portalName);
57: }
58: return EMPTY_MAP;
59:
60: } catch (ServiceException e) {
61: throw new ProcessingException(
62: "Unable to lookup portal service.", e);
63: } finally {
64: this.manager.release(portalService);
65: }
66: }
67: }
|