001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.cocoon.webapps.session.components;
019:
020: import java.util.Iterator;
021: import java.util.Map;
022:
023: import org.apache.avalon.framework.activity.Disposable;
024: import org.apache.avalon.framework.configuration.Configuration;
025: import org.apache.avalon.framework.configuration.ConfigurationException;
026: import org.apache.avalon.framework.service.ServiceException;
027: import org.apache.avalon.framework.service.ServiceManager;
028: import org.apache.avalon.framework.service.Serviceable;
029: import org.apache.avalon.framework.thread.ThreadSafe;
030: import org.apache.cocoon.ProcessingException;
031: import org.apache.cocoon.components.modules.input.InputModule;
032: import org.apache.cocoon.webapps.session.ContextManager;
033: import org.apache.cocoon.webapps.session.context.SessionContext;
034: import org.apache.cocoon.xml.dom.DOMUtil;
035: import org.w3c.dom.DocumentFragment;
036:
037: /**
038: * This input module provides access to the information of a session
039: * context using an XPath. The XPath expression that can be used
040: * is the same as for the session transformer.
041: * The first information in the path is the context, so for example
042: * {session-context:authentication/authentication/ID} delivers the ID of the
043: * current user and therefore delivers the same information as:
044: * <session:getxml context="authentication" path="/authentication/ID"/>
045: * using the session transformer.
046: *
047: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
048: * @deprecated This block is deprecated and will be removed in future versions.
049: * @version CVS $Id: ContextInputModule.java 433543 2006-08-22 06:22:54Z crossley $
050: */
051: public class ContextInputModule implements ThreadSafe, Serviceable,
052: Disposable, InputModule {
053:
054: protected ServiceManager manager;
055:
056: protected ContextManager contextManager;
057:
058: /* (non-Javadoc)
059: * @see org.apache.cocoon.components.modules.input.InputModule#getAttribute(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
060: */
061: public Object getAttribute(String name, Configuration modeConf,
062: Map objectModel) throws ConfigurationException {
063: if (name == null) {
064: return null;
065: }
066: int pos = name.indexOf('/');
067: if (pos != -1) {
068: final String contextName = name.substring(0, pos);
069: final String path = name.substring(pos);
070:
071: try {
072: SessionContext context = this .contextManager
073: .getContext(contextName);
074: if (context != null) {
075: DocumentFragment frag = context.getXML(path);
076: return DOMUtil.getValueOfNode(frag);
077: }
078: } catch (ProcessingException pe) {
079: throw new ConfigurationException(
080: "Unable to get information from context.", pe);
081: }
082:
083: }
084: return null;
085: }
086:
087: /* (non-Javadoc)
088: * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeNames(org.apache.avalon.framework.configuration.Configuration, java.util.Map)
089: */
090: public Iterator getAttributeNames(Configuration modeConf,
091: Map objectModel) throws ConfigurationException {
092: return null;
093: }
094:
095: /* (non-Javadoc)
096: * @see org.apache.cocoon.components.modules.input.InputModule#getAttributeValues(java.lang.String, org.apache.avalon.framework.configuration.Configuration, java.util.Map)
097: */
098: public Object[] getAttributeValues(String name,
099: Configuration modeConf, Map objectModel)
100: throws ConfigurationException {
101: final Object value = this .getAttribute(name, modeConf,
102: objectModel);
103: if (value != null) {
104: return new Object[] { value };
105: }
106: return null;
107: }
108:
109: /* (non-Javadoc)
110: * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
111: */
112: public void service(ServiceManager manager) throws ServiceException {
113: this .manager = manager;
114: this .contextManager = (ContextManager) this .manager
115: .lookup(ContextManager.ROLE);
116: }
117:
118: /* (non-Javadoc)
119: * @see org.apache.avalon.framework.activity.Disposable#dispose()
120: */
121: public void dispose() {
122: if (this.manager != null) {
123: this.manager.release(this.contextManager);
124: this.contextManager = null;
125: this.manager = null;
126: }
127:
128: }
129:
130: }
|