001// Copyright 2007, 2011 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
015package org.apache.tapestry5.internal.parser;
016
017import org.apache.tapestry5.MarkupWriter;
018import org.apache.tapestry5.ioc.Location;
019import org.apache.tapestry5.runtime.RenderCommand;
020import org.apache.tapestry5.runtime.RenderQueue;
021
022/**
023 * A token from a template that defines a namespace prefix. This will always follow a {@link
024 * org.apache.tapestry5.internal.parser.StartComponentToken} or {@link org.apache.tapestry5.internal.parser.StartElementToken}
025 * (and come before {@link org.apache.tapestry5.internal.parser.AttributeToken}) and applies to the component or
026 * element.
027 *
028 * @see org.apache.tapestry5.dom.Element#defineNamespace(String, String)
029 */
030public class DefineNamespacePrefixToken extends TemplateToken implements RenderCommand
031{
032    public final String namespaceURI;
033
034    public final String namespacePrefix;
035
036    public DefineNamespacePrefixToken(String namespaceURI, String namespacePrefix, Location location)
037    {
038        super(TokenType.DEFINE_NAMESPACE_PREFIX, location);
039
040        this.namespacePrefix = namespacePrefix;
041        this.namespaceURI = namespaceURI;
042    }
043
044    @Override
045    public String toString()
046    {
047        return String.format("DefineNamespacePrefix[%s=%s]", namespacePrefix, namespaceURI);
048    }
049
050    public void render(MarkupWriter writer, RenderQueue queue)
051    {
052        writer.defineNamespace(namespaceURI, namespacePrefix);
053    }
054
055}