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;
018
019import org.apache.wicket.markup.html.border.Border;
020import org.apache.wicket.markup.html.panel.Panel;
021import org.apache.wicket.markup.parser.XmlTag;
022import org.apache.wicket.markup.parser.filter.EnclosureHandler;
023import org.apache.wicket.markup.parser.filter.WicketLinkTagHandler;
024import org.apache.wicket.markup.parser.filter.WicketRemoveTagHandler;
025import org.apache.wicket.markup.parser.filter.WicketTagIdentifier;
026import org.apache.wicket.markup.resolver.HtmlHeaderResolver;
027import org.apache.wicket.markup.resolver.WicketContainerResolver;
028import org.apache.wicket.markup.resolver.WicketMessageResolver;
029
030/**
031 * WicketTag extends ComponentTag and will be created by a MarkupParser whenever it parses a tag in
032 * the wicket namespace. By default, this namespace is "wicket", so wicket tags are then of the form
033 * <wicket:*>
034 * <p>
035 * Note 1: you need to add an XHTML doctype to your markup and use <html xmlns:wicket> to
036 * create a XHTML conform namespace for such tags.
037 * <p>
038 * Note 2: The namespace name is configurable. E.g. <html xmlns:wcn="http://wicket">
039 * 
040 * @author Juergen Donnerstag
041 */
042public class WicketTag extends ComponentTag
043{
044        /**
045         * Constructor
046         * 
047         * @param tag
048         *            The XML tag which this wicket tag is based upon.
049         */
050        public WicketTag(final XmlTag tag)
051        {
052                super(tag);
053        }
054
055        /**
056         * Constructor
057         * 
058         * @param tag
059         *            The ComponentTag tag which this wicket tag is based upon.
060         */
061        public WicketTag(final ComponentTag tag)
062        {
063                super(tag.getXmlTag());
064                tag.copyPropertiesTo(this);
065        }
066
067        /**
068         * @return True, if tag name equals 'wicket:container'
069         */
070        public final boolean isContainerTag()
071        {
072                return WicketContainerResolver.CONTAINER.equalsIgnoreCase(getName());
073        }
074
075        /**
076         * @return True, if tag name equals 'wicket:link'
077         */
078        public final boolean isLinkTag()
079        {
080                return WicketLinkTagHandler.LINK.equalsIgnoreCase(getName());
081        }
082
083        /**
084         * @return True, if tag name equals 'wicket:remove'
085         */
086        public final boolean isRemoveTag()
087        {
088                return WicketRemoveTagHandler.REMOVE.equalsIgnoreCase(getName());
089        }
090
091        /**
092         * @return True, if tag name equals 'wicket:body'
093         */
094        public final boolean isBodyTag()
095        {
096                return Border.BODY.equalsIgnoreCase(getName());
097        }
098
099        /**
100         * @return True, if tag name equals 'wicket:child'
101         */
102        public final boolean isChildTag()
103        {
104                return WicketTagIdentifier.CHILD.equalsIgnoreCase(getName());
105        }
106
107        /**
108         * @return True, if tag name equals 'wicket:extend'
109         */
110        public final boolean isExtendTag()
111        {
112                return WicketTagIdentifier.EXTEND.equalsIgnoreCase(getName());
113        }
114
115        /**
116         * @return True, if tag name equals 'wicket:head'
117         */
118        public final boolean isHeadTag()
119        {
120                return HtmlHeaderResolver.HEAD.equalsIgnoreCase(getName());
121        }
122
123        /**
124         * @return True, if tag name equals 'wicket:header-items'
125         */
126        public final boolean isHeaderItemsTag()
127        {
128                return HtmlHeaderResolver.HEADER_ITEMS.equalsIgnoreCase(getName());
129        }
130
131        /**
132         * @return True, if tag name equals 'wicket:message'
133         */
134        public final boolean isMessageTag()
135        {
136                return WicketMessageResolver.MESSAGE.equalsIgnoreCase(getName());
137        }
138
139        /**
140         * @return True, if tag name equals 'wicket:panel'
141         */
142        public final boolean isPanelTag()
143        {
144                return Panel.PANEL.equalsIgnoreCase(getName());
145        }
146
147        /**
148         * @return True, if tag name equals 'wicket:border'
149         */
150        public final boolean isBorderTag()
151        {
152                return Border.BORDER.equalsIgnoreCase(getName());
153        }
154
155        /**
156         * @return True if <wicket:fragment>
157         */
158        public final boolean isFragmentTag()
159        {
160                return WicketTagIdentifier.FRAGMENT.equalsIgnoreCase(getName());
161        }
162
163        /**
164         * @return true if <wicket:enclosure>
165         */
166        public final boolean isEnclosureTag()
167        {
168                return EnclosureHandler.ENCLOSURE.equalsIgnoreCase(getName());
169        }
170
171        /**
172         * @return True if <wicket:panel>, <wicket:border>, <wicket:extend>
173         */
174        public final boolean isMajorWicketComponentTag()
175        {
176                return isPanelTag() || isBorderTag() || isExtendTag();
177        }
178
179        /**
180         * Gets this tag if it is already mutable, or a mutable copy of this tag if it is immutable.
181         * 
182         * @return This tag if it is already mutable, or a mutable copy of this tag if it is immutable.
183         */
184        @Override
185        public ComponentTag mutable()
186        {
187                if (xmlTag.isMutable())
188                {
189                        return this;
190                }
191                else
192                {
193                        final WicketTag tag = new WicketTag(xmlTag.mutable());
194                        copyPropertiesTo(tag);
195
196                        return tag;
197                }
198        }
199}