KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > transformation > DeliTransformer


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.cocoon.transformation;
18
19 import org.apache.avalon.framework.service.ServiceException;
20 import org.apache.avalon.framework.service.ServiceManager;
21 import org.apache.cocoon.environment.ObjectModelHelper;
22 import org.apache.cocoon.environment.Request;
23 import org.apache.cocoon.components.deli.Deli;
24
25 import java.util.Map JavaDoc;
26 import java.util.HashMap JavaDoc;
27
28 /**
29  * This Transformer is used to transform this incoming SAX stream using
30  * a XSLT stylesheet and have parameters available to the stylesheet
31  * augmented by the DELI CC/PP user-agent profile database
32  *
33  * This transformer extends the default TraxTransformer and thus inherits
34  * all the properties and configuration parameters of that transformer.
35  * Please refer to its documentation for more information.
36  *
37  * @author <a HREF="mailto:marbut@hplb.hpl.hp.com">Mark H. Butler</a>
38  * @author <a HREF="mailto:stefano@apache.org">Stefano Mazzocchi</a>
39  * @version CVS $Id: DeliTransformer.java 30932 2004-07-29 17:35:38Z vgritsenko $
40  */

41 public class DeliTransformer extends TraxTransformer {
42
43     /** The DELI service instance */
44     private Deli deli;
45
46     /**
47      * Set the current <code>ServiceManager</code> instance used by this
48      * <code>Serviceable</code>.
49      */

50     public void service(ServiceManager manager) throws ServiceException {
51         super.service(manager);
52
53         this.deli = (Deli) this.manager.lookup(Deli.ROLE);
54     }
55
56     /**
57      * Get the parameters for the logicsheet
58      */

59     protected Map JavaDoc getLogicSheetParameters() {
60         Map JavaDoc map = super.getLogicSheetParameters();
61         
62         if (this.deli != null) {
63             try {
64                 Request request = ObjectModelHelper.getRequest(objectModel);
65                 if (map == null) {
66                     map = new HashMap JavaDoc();
67                 }
68
69                 org.w3c.dom.Document JavaDoc deliCapabilities = this.deli.getUACapabilities(request);
70                 map.put("deli-capabilities", deliCapabilities);
71
72                 String JavaDoc accept = request.getParameter("accept");
73                 if (accept == null) {
74                    accept = request.getHeader("accept");
75                 }
76                 
77                 // add the accept param
78
map.put("accept", accept);
79             } catch (Exception JavaDoc e) {
80                 getLogger().error("Error setting DELI info", e);
81             }
82         }
83         
84         this.logicSheetParameters = map;
85         return this.logicSheetParameters;
86     }
87     
88     /**
89      * Disposable
90      */

91     public void dispose() {
92         if ( this.manager != null ) {
93             this.manager.release(this.deli);
94             this.deli = null;
95         }
96         super.dispose();
97     }
98 }
99
Popular Tags