Package de.odysseus.calyxo.panels.control

Source Code of de.odysseus.calyxo.panels.control.PanelsDispatcher

/*
* 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.control;

import java.io.IOException;
import java.util.Locale;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import de.odysseus.calyxo.base.I18nSupport;
import de.odysseus.calyxo.base.ModuleContext;

import de.odysseus.calyxo.control.conf.DispatchConfig;
import de.odysseus.calyxo.control.impl.DefaultDispatcher;

import de.odysseus.calyxo.panels.PanelsContext;
import de.odysseus.calyxo.panels.PanelsSupport;
import de.odysseus.calyxo.panels.conf.PanelConfig;

/**
* Panels dispatcher implementation.
*
* This dispatcher modifies the standard behaviour for
* {@link de.odysseus.calyxo.control.conf.DispatchConfig} elements with
* the <code>path</code> property set. It searches for a toplevel
* panel element with <code>panel.name == dispatch.path</code>. If
* it finds one, it creates a panels context stack in request scope,
* pushes the panel and dispatches to <code>panel.path</code>.
*
* @author Christoph Beck
*/
public class PanelsDispatcher extends DefaultDispatcher {
  private PanelsSupport support;
  private I18nSupport i18n;

  public PanelsDispatcher(ModuleContext context) {
    super(context);

    support = PanelsSupport.getInstance(context);
    i18n = I18nSupport.getInstance(context);
  }

  /* (non-Javadoc)
   * @see de.odysseus.calyxo.control.Dispatcher#dispatch(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, de.odysseus.calyxo.control.conf.DispatchConfig)
   */
  public void dispatch(
    HttpServletRequest request,
    HttpServletResponse response,
    DispatchConfig dispatch)
    throws IOException, ServletException {

    if (dispatch.getPath() != null && !dispatch.isRedirect()) {
      Locale locale = i18n.getLocale(request);

      // lookup panel
      PanelConfig panel = support.findPanelConfig(dispatch.getPath(), locale);
      if (panel != null) {
        if (log.isTraceEnabled())
          log.trace("panel " + panel.getName());

        String template = panel.findTemplate(locale);
        if (template == null) {
          throw new ServletException("Could not find path for panel " + panel.toInlineString());
        }
        template = addParams(template, dispatch, "UTF-8");
//        log.debug("path " + path);

        PanelsContext context = support.getOrCreateContext(request, locale);

//        log.debug("push " + panel.getName());
        context.push(panel);

        // add dispatch parameters to current panel
//        Iterator params = dispatch.getParamConfigs();
//        while (params.hasNext()) {
//          ParamConfig param = (ParamConfig)params.next();
//          context.addParamConfig(
//            new DynamicParamConfig(param.getName(), param.getValue())
//          );
//        }

        try {
          dispatch(request, response, template, false);
        } finally {
//          log.debug("pop " + panel.getName());
          context.pop();
        }
        return;
      }
    }
    super.dispatch(request, response, dispatch);
  }
}
TOP

Related Classes of de.odysseus.calyxo.panels.control.PanelsDispatcher

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.