001 // Copyright 2009 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.tapestry5.dom;
016
017 import org.apache.tapestry5.internal.TapestryInternalUtils;
018
019 import java.util.Map;
020
021 /**
022 * An attribute within an {@link org.apache.tapestry5.dom.Element}. Each attribute has a namespace URI, a local name
023 * within the namespace, and a value.
024 *
025 * @since 5.1.0.2
026 */
027 public class Attribute
028 {
029 private final Element element;
030
031 private final String namespace;
032
033 private final String name;
034
035 String value;
036
037 Attribute nextAttribute;
038
039 Attribute(Element element, String namespace, String name, String value, Attribute nextAttribute)
040 {
041 this.element = element;
042 this.namespace = namespace;
043 this.name = name;
044 this.value = value;
045 this.nextAttribute = nextAttribute;
046 }
047
048 public String getName()
049 {
050 return name;
051 }
052
053 public String getNamespace()
054 {
055 return namespace;
056 }
057
058 public String getValue()
059 {
060 return value;
061 }
062
063 void render(MarkupModel model, StringBuilder builder, Map<String, String> namespaceURIToPrefix)
064 {
065 builder.append(" ");
066 builder.append(element.toPrefixedName(namespaceURIToPrefix, namespace, name));
067 builder.append("=");
068 builder.append(model.getAttributeQuote());
069 model.encodeQuoted(value, builder);
070 builder.append(model.getAttributeQuote());
071 }
072
073 boolean matches(String namespace, String name)
074 {
075 return TapestryInternalUtils.isEqual(this.namespace, namespace) &&
076 this.name.equalsIgnoreCase(name);
077 }
078 }