01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.portal.tools.transformation;
18:
19: import java.util.Iterator;
20: import java.util.List;
21:
22: import org.apache.avalon.framework.configuration.Configuration;
23: import org.apache.avalon.framework.configuration.ConfigurationException;
24: import org.apache.avalon.framework.configuration.DefaultConfiguration;
25: import org.apache.avalon.framework.service.ServiceException;
26: import org.apache.cocoon.portal.tools.PortalToolCatalogue;
27: import org.apache.cocoon.portal.tools.PortalToolManager;
28: import org.apache.cocoon.transformation.I18nTransformer;
29:
30: /**
31: *
32: * @version CVS $Id: PortalToolsI18nTransformer.java 433543 2006-08-22 06:22:54Z crossley $
33: */
34: public class PortalToolsI18nTransformer extends I18nTransformer {
35:
36: public static String ROLE = PortalToolsI18nTransformer.class
37: .getName();
38:
39: /* (non-Javadoc)
40: * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
41: */
42: public void configure(Configuration conf)
43: throws ConfigurationException {
44: /*
45: <catalogues default="portalTools">
46: <catalogue id="portalTools" name="portalTools" location="cocoon:/i18n"/>
47: </catalogues>
48: */
49:
50: if (conf.getChild("catalogues").getAttribute("new", "no")
51: .equals("no")) {
52: super .configure(conf);
53: return;
54: }
55: DefaultConfiguration root = new DefaultConfiguration("root");
56: DefaultConfiguration defconf = new DefaultConfiguration(
57: "catalogues");
58: defconf.setAttribute("default", "default");
59: root.addChild(defconf);
60: PortalToolManager ptm = null;
61: try {
62: ptm = (PortalToolManager) this .manager
63: .lookup(PortalToolManager.ROLE);
64: List i18nc = ptm.getI18n();
65: for (Iterator it = i18nc.iterator(); it.hasNext();) {
66: PortalToolCatalogue ptc = (PortalToolCatalogue) it
67: .next();
68: DefaultConfiguration catConf = new DefaultConfiguration(
69: "catalogue");
70: catConf.setAttribute("id", ptc.getId());
71: catConf.setAttribute("name", ptc.getName());
72: catConf.setAttribute("location", ptc.getLocation());
73: defconf.addChild(catConf);
74: }
75: super .configure(root);
76: } catch (ServiceException e) {
77: e.printStackTrace();
78: } catch (ConfigurationException e) {
79: e.printStackTrace();
80: } finally {
81: this.manager.release(ptm);
82: }
83: }
84:
85: }
|