001 package org.apache.myfaces.tobago.context; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one or more 005 * contributor license agreements. See the NOTICE file distributed with 006 * this work for additional information regarding copyright ownership. 007 * The ASF licenses this file to You under the Apache License, Version 2.0 008 * (the "License"); you may not use this file except in compliance with 009 * the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019 020 import org.apache.commons.logging.Log; 021 import org.apache.commons.logging.LogFactory; 022 023 import java.util.Map; 024 import java.util.HashMap; 025 import java.util.Collection; 026 import java.io.Serializable; 027 028 /* 029 * Date: Sep 24, 2006 030 * Time: 3:46:11 PM 031 */ 032 public class RenderersConfigImpl implements RenderersConfig, Serializable { 033 034 private static final long serialVersionUID = 1L; 035 036 private static final Log LOG = LogFactory.getLog(RenderersConfigImpl.class); 037 038 private Map<String, RendererConfig> renderer = new HashMap<String, RendererConfig>(); 039 040 private boolean merged = false; 041 042 public boolean isMerged() { 043 return merged; 044 } 045 046 public void setMerged(boolean merged) { 047 this.merged = merged; 048 } 049 050 public Collection<RendererConfig> getRendererConfigs() { 051 return renderer.values(); 052 } 053 054 public void addRenderer(RendererConfig rendererConfig) { 055 addRenderer(rendererConfig, false); 056 } 057 058 public void addRenderer(RendererConfig rendererConfig, boolean override) { 059 if (override || !renderer.containsKey(rendererConfig.getName())) { 060 renderer.put(rendererConfig.getName(), rendererConfig); 061 } 062 } 063 064 public boolean isMarkupSupported(String rendererName, String markup) { 065 if (LOG.isDebugEnabled()) { 066 LOG.debug("calling isMarkupSupported " + rendererName + " " +markup); 067 } 068 RendererConfig rendererConfig = renderer.get(rendererName); 069 if (rendererConfig != null) { 070 return rendererConfig.contains(markup); 071 } else { 072 LOG.error("Calling isMarkupSupported " + rendererName + " " +markup + " but no configuration found."); 073 return false; 074 } 075 } 076 077 void merge(RenderersConfig renderersConfig, boolean override) { 078 Collection<RendererConfig> renderers = renderersConfig.getRendererConfigs(); 079 for (RendererConfig rendererConfig : renderers) { 080 addRenderer(rendererConfig, override); 081 } 082 } 083 084 public String toString() { 085 return renderer.toString(); 086 } 087 }