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 */ 017package org.apache.wicket.markup.html.panel; 018 019import org.apache.wicket.Component; 020import org.apache.wicket.MarkupContainer; 021import org.apache.wicket.markup.ComponentTag; 022import org.apache.wicket.markup.IMarkupFragment; 023import org.apache.wicket.markup.MarkupStream; 024import org.slf4j.Logger; 025import org.slf4j.LoggerFactory; 026 027/** 028 * This is a no-op sourcing strategy implementing the default behavior for most components. 029 * 030 * @author Juergen Donnerstag 031 */ 032public final class DefaultMarkupSourcingStrategy extends AbstractMarkupSourcingStrategy 033{ 034 /** Log for reporting. */ 035 private static final Logger log = LoggerFactory.getLogger(DefaultMarkupSourcingStrategy.class); 036 037 private static final DefaultMarkupSourcingStrategy instance = new DefaultMarkupSourcingStrategy(); 038 039 /** 040 * 041 * @return A singleton of the strategy 042 */ 043 public static DefaultMarkupSourcingStrategy get() 044 { 045 return instance; 046 } 047 048 /** 049 * Construct. Please use {@link #get()} instead. 050 */ 051 private DefaultMarkupSourcingStrategy() 052 { 053 } 054 055 /** 056 * Nothing to add to the response by default 057 */ 058 @Override 059 public void onComponentTag(final Component component, final ComponentTag tag) 060 { 061 } 062 063 /** 064 * Invoke the component's onComponentTagBody(). 065 */ 066 @Override 067 public void onComponentTagBody(final Component component, final MarkupStream markupStream, 068 final ComponentTag openTag) 069 { 070 component.onComponentTagBody(markupStream, openTag); 071 } 072 073 /** 074 * Get the markup for the child component, which is assumed to be a child of 'container'. 075 */ 076 @Override 077 public IMarkupFragment getMarkup(final MarkupContainer container, final Component child) 078 { 079 // If the sourcing strategy did not provide one, then ask the component. 080 // Get the markup for the container 081 IMarkupFragment containerMarkup = container.getMarkup(); 082 if (containerMarkup == null) 083 { 084 return null; 085 } 086 087 if (child == null) 088 { 089 return containerMarkup; 090 } 091 092 // Find the child's markup 093 IMarkupFragment childMarkup = containerMarkup.find(child.getId()); 094 if (childMarkup != null) 095 { 096 return childMarkup; 097 } 098 099 return searchMarkupInTransparentResolvers(container, containerMarkup, child); 100 } 101}