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: package org.apache.pluto.driver.services.impl.resource;
018:
019: import java.io.IOException;
020: import java.io.InputStream;
021:
022: import org.apache.commons.digester.Digester;
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025: import org.apache.pluto.driver.services.portal.PageConfig;
026: import org.apache.pluto.driver.services.portal.RenderConfig;
027: import org.xml.sax.SAXException;
028:
029: /**
030: * @version 1.0
031: * @since Sep 23, 2004
032: */
033: public class ResourceConfigReader {
034:
035: private static final Log LOG = LogFactory
036: .getLog(ResourceConfigReader.class);
037:
038: public static final String CONFIG_FILE = "/WEB-INF/pluto-portal-driver-config.xml";
039:
040: private static ResourceConfigReader factory;
041:
042: public static ResourceConfigReader getFactory() {
043: if (factory == null) {
044: factory = new ResourceConfigReader();
045: }
046: return factory;
047: }
048:
049: private Digester digester;
050:
051: private ResourceConfigReader() {
052: digester = new Digester();
053: // digester.setLogger(LOG); // Too many log messages.
054: digester.setClassLoader(Thread.currentThread()
055: .getContextClassLoader());
056: init();
057: }
058:
059: public ResourceConfig parse(InputStream in) throws IOException,
060: SAXException {
061: return (ResourceConfig) digester.parse(in);
062: }
063:
064: // Digester Setup
065:
066: private void init() {
067: if (LOG.isDebugEnabled()) {
068: LOG.debug("Setting up digester...");
069: }
070: digester.addObjectCreate("pluto-portal-driver",
071: ResourceConfig.class);
072: digester.addBeanPropertySetter(
073: "pluto-portal-driver/portal-name", "portalName");
074: digester.addBeanPropertySetter(
075: "pluto-portal-driver/portal-version", "portalVersion");
076: digester.addBeanPropertySetter(
077: "pluto-portal-driver/container-name", "containerName");
078:
079: digester.addCallMethod(
080: "pluto-portal-driver/supports/portlet-mode",
081: "addSupportedPortletMode", 0);
082: digester.addCallMethod(
083: "pluto-portal-driver/supports/window-state",
084: "addSupportedWindowState", 0);
085:
086: digester.addObjectCreate("pluto-portal-driver/render-config",
087: RenderConfig.class);
088: digester.addSetProperties("pluto-portal-driver/render-config",
089: "default", "defaultPageId");
090: digester.addObjectCreate(
091: "pluto-portal-driver/render-config/page",
092: PageConfig.class);
093: digester
094: .addSetProperties("pluto-portal-driver/render-config/page");
095: digester.addCallMethod(
096: "pluto-portal-driver/render-config/page/portlet",
097: "addPortlet", 2);
098: digester.addCallParam(
099: "pluto-portal-driver/render-config/page/portlet", 0,
100: "context");
101: digester.addCallParam(
102: "pluto-portal-driver/render-config/page/portlet", 1,
103: "name");
104: digester.addSetNext("pluto-portal-driver/render-config/page",
105: "addPage");
106: digester.addSetNext("pluto-portal-driver/render-config",
107: "setRenderConfig");
108: }
109:
110: }
|