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.cocoon.components.modules.input;
19:
20: import org.apache.avalon.framework.activity.Initializable;
21: import org.apache.avalon.framework.context.Context;
22: import org.apache.avalon.framework.context.ContextException;
23: import org.apache.avalon.framework.context.Contextualizable;
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.ContextHelper;
28: import org.apache.cocoon.components.modules.input.AbstractInputModule;
29: import org.apache.cocoon.environment.Request;
30: import org.apache.lenya.cms.publication.DocumentFactory;
31: import org.apache.lenya.cms.publication.DocumentUtil;
32: import org.apache.lenya.cms.repository.RepositoryException;
33: import org.apache.lenya.cms.repository.RepositoryUtil;
34: import org.apache.lenya.cms.repository.Session;
35:
36: /**
37: * Super class for operation-based input modules.
38: *
39: * @version $Id: OperationModule.java 473861 2006-11-12 03:51:14Z gregor $
40: */
41: public class OperationModule extends AbstractInputModule implements
42: Serviceable, Initializable, Contextualizable {
43:
44: /**
45: * Ctor.
46: */
47: public OperationModule() {
48: super ();
49: }
50:
51: private DocumentFactory documentIdentityMap;
52:
53: private Request request;
54:
55: protected DocumentFactory getDocumentFactory() {
56: if (this .documentIdentityMap == null) {
57: try {
58: Session session = RepositoryUtil.getSession(
59: this .manager, this .request);
60: this .documentIdentityMap = DocumentUtil
61: .createDocumentFactory(this .manager, session);
62: } catch (RepositoryException e) {
63: throw new RuntimeException(e);
64: }
65: }
66: return this .documentIdentityMap;
67: }
68:
69: protected ServiceManager manager;
70:
71: /**
72: * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
73: */
74: public void service(ServiceManager _manager)
75: throws ServiceException {
76: this .manager = _manager;
77: }
78:
79: /**
80: * @see org.apache.avalon.framework.activity.Initializable#initialize()
81: */
82: public void initialize() throws Exception {
83: // do nothing
84: }
85:
86: public void contextualize(Context context) throws ContextException {
87: this.request = ContextHelper.getRequest(context);
88: }
89:
90: }
|