KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > tools > transformation > PortalToolsI18nTransformer


1 /*
2  * Copyright 1999-2005 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 package org.apache.cocoon.portal.tools.transformation;
17
18 import java.util.Iterator JavaDoc;
19 import java.util.List JavaDoc;
20
21 import org.apache.avalon.framework.configuration.Configuration;
22 import org.apache.avalon.framework.configuration.ConfigurationException;
23 import org.apache.avalon.framework.configuration.DefaultConfiguration;
24 import org.apache.avalon.framework.service.ServiceException;
25 import org.apache.cocoon.portal.tools.PortalToolCatalogue;
26 import org.apache.cocoon.portal.tools.PortalToolManager;
27 import org.apache.cocoon.transformation.I18nTransformer;
28
29 /**
30  *
31  * @version CVS $Id: PortalToolsI18nTransformer.java 149055 2005-01-29 18:21:34Z cziegeler $
32  */

33 public class PortalToolsI18nTransformer extends I18nTransformer {
34     
35     public static String JavaDoc ROLE = PortalToolsI18nTransformer.class.getName();
36     
37     /* (non-Javadoc)
38      * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
39      */

40     public void configure(Configuration conf) throws ConfigurationException {
41         /*
42         <catalogues default="portalTools">
43           <catalogue id="portalTools" name="portalTools" location="cocoon:/i18n"/>
44         </catalogues>
45         */

46         
47         if (conf.getChild("catalogues").getAttribute("new", "no").equals("no")) {
48             super.configure(conf);
49             return;
50         }
51         DefaultConfiguration root = new DefaultConfiguration("root");
52         DefaultConfiguration defconf = new DefaultConfiguration("catalogues");
53         defconf.setAttribute("default", "default");
54         root.addChild(defconf);
55         PortalToolManager ptm = null;
56         try {
57             ptm = (PortalToolManager) this.manager.lookup(PortalToolManager.ROLE);
58             List JavaDoc i18nc = ptm.getI18n();
59             for(Iterator JavaDoc it = i18nc.iterator(); it.hasNext();) {
60                 PortalToolCatalogue ptc = (PortalToolCatalogue) it.next();
61                 DefaultConfiguration catConf = new DefaultConfiguration("catalogue");
62                 catConf.setAttribute("id", ptc.getId());
63                 catConf.setAttribute("name", ptc.getName());
64                 catConf.setAttribute("location", ptc.getLocation());
65                 defconf.addChild(catConf);
66             }
67             super.configure(root);
68         } catch (ServiceException e) {
69            e.printStackTrace();
70         } catch (ConfigurationException e) {
71            e.printStackTrace();
72         } finally {
73             this.manager.release(ptm);
74         }
75     }
76
77 }
78
Popular Tags