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.dom.Document;
019import org.apache.tapestry5.ioc.Location;
020import org.apache.tapestry5.runtime.RenderCommand;
021import org.apache.tapestry5.runtime.RenderQueue;
022
023/**
024 * Represents the presence of a Document Type declaration within a template. The Document type declaration will be
025 * output to the client. In the event that multiple declarations are encountered (a page and one or more nested
026 * components all declare a document type), the first document type declared will be used.
027 */
028public class DTDToken extends TemplateToken implements RenderCommand
029{
030    public final String name;
031
032    public final String publicId;
033
034    public final String systemId;
035
036    public DTDToken(String name, String publicId, String systemId, Location location)
037    {
038        super(TokenType.DTD, location);
039
040        this.name = name;
041        this.publicId = publicId;
042        this.systemId = systemId;
043    }
044
045    public void render(MarkupWriter writer, RenderQueue queue)
046    {
047        Document document = writer.getDocument();
048
049        if (!document.hasDTD())
050        {
051            document.dtd(name, publicId, systemId);
052        }
053    }
054
055    @Override
056    public String toString()
057    {
058        return String.format("DTD[name=%s; publicId=%s; systemId=%s]", name, publicId, systemId);
059    }
060}