Package de.odysseus.calyxo.panels.misc

Source Code of de.odysseus.calyxo.panels.misc.PanelsAccessor

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

import javax.servlet.http.HttpServletRequest;

import de.odysseus.calyxo.base.ModuleContext;
import de.odysseus.calyxo.base.access.AccessException;
import de.odysseus.calyxo.base.access.DynamicMapAccessor;
import de.odysseus.calyxo.base.access.AccessorMap;
import de.odysseus.calyxo.panels.PanelsContext;
import de.odysseus.calyxo.panels.PanelsSupport;
import de.odysseus.calyxo.panels.conf.ParamConfig;

/**
* This accessor contains a <code>param</code> child to access
* panel parameters.
*
* @author Christoph Beck
*/
public class PanelsAccessor extends AccessorMap {
  /**
   * Lookup parameter within current panels context stack.
   *
   * @author Christoph Beck
   */
  public class ParamAccessor extends DynamicMapAccessor {
    /**
     * Lookup parameter.
     */
    protected Object get(HttpServletRequest request, Object key) {
      PanelsContext context = support.getContext(request);
      ParamConfig param = context.lookupParamConfig(key.toString());
      if (param == null) {
        throw new AccessException("Unknown panel parameter '" + key + "'");
      }
      if (!param.isDefined()) {
        throw new AccessException("Undefined value for panel parameter '" + key + "'");
      }
      return param.getValue();
    }
  } 

  final PanelsSupport support;

  public PanelsAccessor(ModuleContext context) {
    super();

    support = PanelsSupport.getInstance(context);

    put("param", new ParamAccessor());
  }
}
TOP

Related Classes of de.odysseus.calyxo.panels.misc.PanelsAccessor

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.
ww.google-analytics.com/analytics.js','ga'); ga('create', 'UA-20639858-1', 'auto'); ga('send', 'pageview');