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.transformation;
019:
020: import org.apache.avalon.framework.service.ServiceException;
021: import org.apache.avalon.framework.service.ServiceManager;
022: import org.apache.cocoon.environment.ObjectModelHelper;
023: import org.apache.cocoon.environment.Request;
024: import org.apache.cocoon.components.deli.Deli;
025:
026: import java.util.Map;
027: import java.util.HashMap;
028:
029: /**
030: * This Transformer is used to transform this incoming SAX stream using
031: * a XSLT stylesheet and have parameters available to the stylesheet
032: * augmented by the DELI CC/PP user-agent profile database
033: *
034: * This transformer extends the default TraxTransformer and thus inherits
035: * all the properties and configuration parameters of that transformer.
036: * Please refer to its documentation for more information.
037: *
038: * @author <a href="mailto:marbut@hplb.hpl.hp.com">Mark H. Butler</a>
039: * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
040: * @version CVS $Id: DeliTransformer.java 433543 2006-08-22 06:22:54Z crossley $
041: */
042: public class DeliTransformer extends TraxTransformer {
043:
044: /** The DELI service instance */
045: private Deli deli;
046:
047: /**
048: * Set the current <code>ServiceManager</code> instance used by this
049: * <code>Serviceable</code>.
050: */
051: public void service(ServiceManager manager) throws ServiceException {
052: super .service(manager);
053:
054: this .deli = (Deli) this .manager.lookup(Deli.ROLE);
055: }
056:
057: /**
058: * Get the parameters for the logicsheet
059: */
060: protected Map getLogicSheetParameters() {
061: Map map = super .getLogicSheetParameters();
062:
063: if (this .deli != null) {
064: try {
065: Request request = ObjectModelHelper
066: .getRequest(objectModel);
067: if (map == null) {
068: map = new HashMap();
069: }
070:
071: org.w3c.dom.Document deliCapabilities = this .deli
072: .getUACapabilities(request);
073: map.put("deli-capabilities", deliCapabilities);
074:
075: String accept = request.getParameter("accept");
076: if (accept == null) {
077: accept = request.getHeader("accept");
078: }
079:
080: // add the accept param
081: map.put("accept", accept);
082: } catch (Exception e) {
083: getLogger().error("Error setting DELI info", e);
084: }
085: }
086:
087: this .logicSheetParameters = map;
088: return this .logicSheetParameters;
089: }
090:
091: /**
092: * Disposable
093: */
094: public void dispose() {
095: if (this.manager != null) {
096: this.manager.release(this.deli);
097: this.deli = null;
098: }
099: super.dispose();
100: }
101: }
|