Package de.odysseus.calyxo.panels

Source Code of de.odysseus.calyxo.panels.PanelsService

/*
* Copyright 2004, 2005, 2006 Odysseus Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.odysseus.calyxo.panels;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.StringTokenizer;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import de.odysseus.calyxo.base.ModuleContext;
import de.odysseus.calyxo.base.conf.ConfigException;
import de.odysseus.calyxo.panels.conf.PanelsRootConfig;
import de.odysseus.calyxo.panels.conf.impl.PanelsRootConfigParser;

/**
* The panels service class creates and installs/uninstalls an instance of
* {@link de.odysseus.calyxo.panels.PanelsSupport} into module context.
*
* @author Christoph Beck
*/
public class PanelsService {
  private static final Log log = LogFactory.getLog(PanelsService.class);

  /**
   * Create, initialize and install panels support instance in context scope.
   * @param context the module we're in
   * @param config comma-separated list of paths to configuration files
   * @throws ConfigException
   */
  public void init(ModuleContext context, String config) throws ConfigException {
    log.trace("init() start");
    // Create list of urls to config files
    ArrayList list = new ArrayList();
    StringTokenizer tokens = new StringTokenizer(config,",");
    while (tokens.hasMoreTokens()) {
      String token = tokens.nextToken().trim();
      URL url = null;
      try {
        url = context.getServletContext().getResource(token);
      } catch (MalformedURLException e) {
        throw new ConfigException(e);
      }
      if (url == null) {
        throw new ConfigException("Could not find resource " + token);
      } else {
        list.add(url);
      }
    }
    URL[] inputs = (URL[])list.toArray(new URL[list.size()]);

    // parse files into configuration bean
    PanelsRootConfig root = null;
    PanelsRootConfigParser parser = new PanelsRootConfigParser(context);
    root = parser.parse(inputs);

    // create and install support instance
    PanelsSupport support = new PanelsSupport(root);
    context.setAttribute(PanelsSupport.PANELS_SUPPORT_KEY, support);

    log.trace("init() end");
  }

  /**
   * Remove panels support instance from module scope
   * @param context the module we're in
   */
  public void destroy(ModuleContext context) {
    context.removeAttribute(PanelsSupport.PANELS_SUPPORT_KEY);
  }
}
TOP

Related Classes of de.odysseus.calyxo.panels.PanelsService

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.