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 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.publication.Document;
31: import org.apache.lenya.cms.publication.DocumentUtil;
32: import org.apache.lenya.cms.site.usecases.CreateUsecaseDocument;
33: import org.apache.lenya.xml.DocumentHelper;
34:
35: /**
36: * Module to retrieve information from a usecase resource type document.
37: */
38: public class UsecaseDocumentModule extends AbstractInputModule
39: implements Serviceable {
40:
41: protected static final String USECASE = "usecase";
42:
43: public Object getAttribute(String name, Configuration modeConf,
44: Map objectModel) throws ConfigurationException {
45:
46: Object value = null;
47: try {
48: if (name.equals(USECASE)) {
49: Request request = ObjectModelHelper
50: .getRequest(objectModel);
51: Document doc = DocumentUtil.getCurrentDocument(
52: this .manager, request);
53: org.w3c.dom.Document xmlDoc = DocumentHelper
54: .readDocument(doc.getInputStream());
55: String usecaseName = xmlDoc.getDocumentElement()
56: .getAttribute(
57: CreateUsecaseDocument.ATTRIBUTE_NAME);
58: value = usecaseName;
59: }
60: } catch (Exception e) {
61: throw new ConfigurationException(
62: "Could not obtain value: ", e);
63: }
64: return value;
65: }
66:
67: protected ServiceManager manager;
68:
69: public void service(ServiceManager manager) throws ServiceException {
70: this.manager = manager;
71: }
72:
73: }
|