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: */
017: package org.apache.wicket.markup;
018:
019: import org.apache.wicket.markup.parser.XmlTag;
020:
021: /**
022: * WicketTag extends ComponentTag and will be created by a MarkupParser whenever
023: * it parses a tag in the wicket namespace. By default, this namespace is
024: * "wicket", so wicket tags are then of the form <wicket:*>
025: * <p>
026: * Note 1: you need to add an XHTML doctype to your markup and use <html
027: * xmlns:wicket> to create a XHTML conformant namespace for such tags.
028: * <p>
029: * Note 2: The namespace name is configurable. E.g. <html
030: * xmlns:wcn="http://wicket">
031: *
032: * @author Juergen Donnerstag
033: */
034: public class WicketTag extends ComponentTag {
035: /**
036: * Constructor
037: *
038: * @param tag
039: * The XML tag which this wicket tag is based upon.
040: */
041: public WicketTag(final XmlTag tag) {
042: super (tag);
043: }
044:
045: /**
046: * Constructor
047: *
048: * @param tag
049: * The ComponentTag tag which this wicket tag is based upon.
050: */
051: public WicketTag(final ComponentTag tag) {
052: super (tag.getXmlTag());
053: tag.copyPropertiesTo(this );
054: }
055:
056: /**
057: * Get the tag's name attribute: e.g. <wicket:region name=panel>
058: *
059: * @return The tag's name attribute
060: */
061: public final String getNameAttribute() {
062: return getAttributes().getString("name");
063: }
064:
065: /**
066: * @return True, if tag name equals 'wicket:component'
067: */
068: public final boolean isComponentTag() {
069: return "component".equalsIgnoreCase(getName());
070: }
071:
072: /**
073: * @return True, if tag name equals 'wicket:link'
074: */
075: public final boolean isLinkTag() {
076: return "link".equalsIgnoreCase(getName());
077: }
078:
079: /**
080: * @return True, if tag name equals 'wicket:remove'
081: */
082: public final boolean isRemoveTag() {
083: return "remove".equalsIgnoreCase(getName());
084: }
085:
086: /**
087: * @return True, if tag name equals 'wicket:body'
088: */
089: public final boolean isBodyTag() {
090: return "body".equalsIgnoreCase(getName());
091: }
092:
093: /**
094: * @return True, if tag name equals 'wicket:child'
095: */
096: public final boolean isChildTag() {
097: return "child".equalsIgnoreCase(getName());
098: }
099:
100: /**
101: * @return True, if tag name equals 'wicket:extend'
102: */
103: public final boolean isExtendTag() {
104: return "extend".equalsIgnoreCase(getName());
105: }
106:
107: /**
108: * @return True, if tag name equals 'wicket:head'
109: */
110: public final boolean isHeadTag() {
111: return "head".equalsIgnoreCase(getName());
112: }
113:
114: /**
115: * @return True, if tag name equals 'wicket:message'
116: */
117: public final boolean isMessageTag() {
118: return "message".equalsIgnoreCase(getName());
119: }
120:
121: /**
122: * @return True, if tag name equals 'wicket:panel'
123: */
124: public final boolean isPanelTag() {
125: return "panel".equalsIgnoreCase(getName());
126: }
127:
128: /**
129: * @return True, if tag name equals 'wicket:border'
130: */
131: public final boolean isBorderTag() {
132: return "border".equalsIgnoreCase(getName());
133: }
134:
135: /**
136: * @return True if <wicket:fragment>
137: */
138: public final boolean isFragementTag() {
139: return "fragment".equalsIgnoreCase(getName());
140: }
141:
142: /**
143: * @return true if <wicket:enclsoure>
144: */
145: public final boolean isEnclosureTag() {
146: return "enclosure".equalsIgnoreCase(getName());
147: }
148:
149: /**
150: * @return True if <wicket:panel>, <wicket:border>, <wicket:ex
151: */
152: public final boolean isMajorWicketComponentTag() {
153: return isPanelTag() || isBorderTag() || isExtendTag();
154: }
155:
156: /**
157: * Gets this tag if it is already mutable, or a mutable copy of this tag if
158: * it is immutable.
159: *
160: * @return This tag if it is already mutable, or a mutable copy of this tag
161: * if it is immutable.
162: */
163: public ComponentTag mutable() {
164: if (xmlTag.isMutable()) {
165: return this ;
166: } else {
167: final WicketTag tag = new WicketTag(xmlTag.mutable());
168: tag.setId(getId());
169: tag.setAutoComponentTag(isAutoComponentTag());
170: return tag;
171: }
172: }
173: }
|