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.IQueueRegion;
020import org.apache.wicket.markup.IMarkupFragment;
021import org.apache.wicket.markup.html.MarkupUtil;
022import org.apache.wicket.markup.html.WebMarkupContainer;
023import org.apache.wicket.model.IModel;
024
025/**
026 * A panel is a reusable component that holds markup and other components.
027 * <p>
028 * Whereas WebMarkupContainer is an inline container like
029 * 
030 * <pre>
031 *  ...
032 *  &lt;span wicket:id=&quot;xxx&quot;&gt;
033 *    &lt;span wicket:id=&quot;mylabel&quot;&gt;My label&lt;/span&gt;
034 *    ....
035 *  &lt;/span&gt;
036 *  ...
037 * </pre>
038 * 
039 * a Panel has its own associated markup file and the container content is taken from that file,
040 * like:
041 * 
042 * <pre>
043 *  &lt;span wicket:id=&quot;mypanel&quot;/&gt;
044 * 
045 *  TestPanel.html
046 *  &lt;wicket:panel&gt;
047 *    &lt;span wicket:id=&quot;mylabel&quot;&gt;My label&lt;/span&gt;
048 *    ....
049 *  &lt;/wicket:panel&gt;
050 * </pre>
051 * 
052 * @author Jonathan Locke
053 * @author Juergen Donnerstag
054 */
055public abstract class Panel extends WebMarkupContainer implements IQueueRegion
056{
057        private static final long serialVersionUID = 1L;
058
059        /** */
060        public static final String PANEL = "panel";
061
062        /**
063         * @see org.apache.wicket.Component#Component(String)
064         */
065        public Panel(final String id)
066        {
067                super(id);
068        }
069
070        /**
071         * @see org.apache.wicket.Component#Component(String, IModel)
072         */
073        public Panel(final String id, final IModel<?> model)
074        {
075                super(id, model);
076        }
077
078        /**
079         * {@inheritDoc}
080         */
081        @Override
082        protected IMarkupSourcingStrategy newMarkupSourcingStrategy()
083        {
084                return PanelMarkupSourcingStrategy.get(false);
085        }
086        
087        /**
088         * Returns the markup inside &lt;wicket:panel&gt; tag.
089         * If such tag is not found, all the markup is returned.
090         * 
091         * @see IQueueRegion#getRegionMarkup() 
092         */
093        @Override
094        public IMarkupFragment getRegionMarkup()
095        {
096                IMarkupFragment markup = super.getRegionMarkup();
097                
098                if (markup == null)
099                {
100                        return markup;
101                }
102                
103                IMarkupFragment panelMarkup = MarkupUtil.findStartTag(markup, PANEL);
104                
105                return panelMarkup != null ? panelMarkup : markup;
106        }
107}