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.resolver; 018 019import org.apache.wicket.Component; 020import org.apache.wicket.MarkupContainer; 021import org.apache.wicket.markup.ComponentTag; 022import org.apache.wicket.markup.MarkupStream; 023import org.apache.wicket.markup.WicketTag; 024import org.slf4j.Logger; 025import org.slf4j.LoggerFactory; 026 027 028/** 029 * This is a tag resolver which handles <wicket:container> 030 * 031 * Sometimes adding components in certain ways may lead to output of invalid markup. For example, 032 * lets pretend we output table rows two at a time using a repeater. The markup would look something 033 * like this: 034 * 035 * <code> 036 * <table> 037 * <span wicket:id="repeater"> 038 * <tr><td>...</td></tr> 039 * <tr><td>...</td></tr> 040 * </span> 041 * </table> 042 * </code> 043 * 044 * Notice that we had to attach the repeater to a component tag - in this case a <code>span</code>, 045 * but a span is not a legal tag to nest under <code>table</code>. So we can rewrite the example as 046 * following: 047 * 048 * <code> 049 * <table> 050 * <wicket:container wicket:id="repeater"> 051 * <tr><td>...</td></tr> 052 * <tr><td>...</td></tr> 053 * </wicket:container> 054 * </table> 055 * </code> 056 * 057 * The above is valid markup because wicket namespaced tags are allowed anywhere 058 * 059 * @author Igor Vaynberg (ivaynberg) 060 */ 061public class WicketContainerResolver implements IComponentResolver 062{ 063 private static final Logger log = LoggerFactory.getLogger(WicketContainerResolver.class); 064 065 private static final long serialVersionUID = 1L; 066 067 /** */ 068 public static final String CONTAINER = "container"; 069 070 @Override 071 public Component resolve(final MarkupContainer container, final MarkupStream markupStream, 072 final ComponentTag tag) 073 { 074 if (tag instanceof WicketTag && ((WicketTag)tag).isContainerTag()) 075 { 076 return container.get(tag.getId()); 077 } 078 return null; 079 } 080}