    001    // Copyright 2006, 2009, 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
    015    package org.apache.tapestry5.internal.parser;
    016
    017    import org.apache.tapestry5.MarkupWriter;
    018    import org.apache.tapestry5.ioc.Location;
    019    import org.apache.tapestry5.runtime.RenderCommand;
    020    import org.apache.tapestry5.runtime.RenderQueue;
    021
    022    /**
    023     * The start of an ordinary element within the template (as opposed to {@link org.apache.tapestry5.internal.parser.StartComponentToken},
    024     * which represents an active Tapestry token. A start element token may be immediately followed by {@link
    025     * org.apache.tapestry5.internal.parser.AttributeToken}s that represents the attributes associated with the element. A
    026     * start element token will always be balanced by a {@link org.apache.tapestry5.internal.parser.EndElementToken} (though
    027     * there will likely be some amount of intermediate tokens).
    028     */
    029    public class StartElementToken extends TemplateToken implements RenderCommand
    030    {
    031        public final String namespaceURI;
    032
    033        public final String name;
    034
    035        public StartElementToken(String namespaceURI, String name, Location location)
    036        {
    037            super(TokenType.START_ELEMENT, location);
    038
    039            this.namespaceURI = namespaceURI;
    040            this.name = name;
    041        }
    042
    043        @Override
    044        public String toString()
    045        {
    046            StringBuilder builder = new StringBuilder("Start[");
    047
    048            if (namespaceURI != null && namespaceURI.length() > 0) builder.append(namespaceURI).append(" ");
    049
    050            builder.append(name).append("]");
    051
    052            return builder.toString();
    053        }
    054
    055        public void render(MarkupWriter writer, RenderQueue queue)
    056        {
    057            writer.elementNS(namespaceURI, name);
    058        }
    059    }