KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > cocoon > transformation > IncludeTransformer


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
18 /* $Id: IncludeTransformer.java 111361 2004-12-09 08:24:59Z edith $ */
19
20 package org.apache.lenya.cms.cocoon.transformation;
21
22 import org.apache.avalon.framework.configuration.Configurable;
23 import org.apache.avalon.framework.configuration.Configuration;
24 import org.apache.avalon.framework.configuration.ConfigurationException;
25 import org.apache.cocoon.transformation.AbstractDOMTransformer;
26 import org.apache.cocoon.environment.ObjectModelHelper;
27 import org.apache.cocoon.environment.Request;
28 import org.apache.excalibur.source.Source;
29 import org.w3c.dom.Document JavaDoc;
30
31
32 public class IncludeTransformer extends AbstractDOMTransformer implements Configurable {
33     private String JavaDoc domain = "127.0.0.1";
34     private String JavaDoc context = null;
35     private String JavaDoc publication = null;
36
37     /**
38      * DOCUMENT ME!
39      *
40      * @param conf DOCUMENT ME!
41      *
42      * @throws ConfigurationException DOCUMENT ME!
43      */

44     public void configure(Configuration conf) throws ConfigurationException {
45         if (conf != null) {
46             publication = conf.getChild("publication").getAttribute("type");
47             getLogger().debug("PUBLICATION TYPE: " + publication);
48         } else {
49             getLogger().error("Configuration is null");
50         }
51     }
52
53     /**
54      * (non-Javadoc)
55      * @see org.apache.lenya.cms.cocoon.transformation.AbstractDOMTransformer#transform(org.w3c.dom.Document)
56      */

57     protected Document JavaDoc transform(Document JavaDoc doc) {
58         try {
59             Source input_source = this.resolver.resolveURI("");
60             String JavaDoc sitemapPath = input_source.getURI();
61             getLogger().debug("Absolute SITEMAP Directory: " + sitemapPath);
62
63             String JavaDoc href = this.parameters.getParameter("href", null);
64
65             if (href != null) {
66                 getLogger().debug("Parameter href = " + href);
67             } else {
68                 getLogger().debug("No Parameter");
69             }
70
71             Request request = ObjectModelHelper.getRequest(objectModel);
72
73             String JavaDoc request_uri = request.getRequestURI();
74             String JavaDoc sitemap_uri = request.getSitemapURI();
75             getLogger().debug("REQUEST URI: " + request_uri);
76             getLogger().debug("SITEMAP URI: " + sitemap_uri);
77
78             context = request.getContextPath();
79
80             String JavaDoc context_publication = context + "/" + publication;
81             int port = request.getServerPort();
82             String JavaDoc cocoon_base_request = "http://" + domain + ":" + port + context_publication;
83             getLogger().debug("COCOON_BASE_REQUEST: " + cocoon_base_request);
84
85             if (href != null) {
86                 return new org.apache.lenya.xml.XPSAssembler().assemble(doc, sitemapPath + href,
87                     cocoon_base_request);
88             } else {
89                 return new org.apache.lenya.xml.XPSAssembler().assemble(doc,
90                     sitemapPath + sitemap_uri, cocoon_base_request);
91             }
92         } catch (Exception JavaDoc e) {
93             getLogger().error(".transform(): " + e, e);
94         }
95
96         return doc;
97     }
98 }
99
Popular Tags