001// Copyright 2006, 2007, 2008, 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 015package org.apache.tapestry5.dom; 016 017import org.apache.tapestry5.ioc.internal.util.CollectionFactory; 018 019import java.util.Set; 020 021/** 022 * Default implementation of {@link org.apache.tapestry5.dom.MarkupModel} that is appropriate for traditional (X)HTML 023 * markup. Assumes that all tags are lower-case. The majority of elements will be "expanded" (meaning a complete start 024 * and end tag); this is for compatibility with web browsers, especially when the content type of a response indicates 025 * HTML, not true XML. Only the "hr", "br","img", "link", and "meta" tags will be rendered abbreviated (i.e., "lt;img/>"). 026 */ 027public class DefaultMarkupModel extends AbstractMarkupModel 028{ 029 private final Set<String> ALWAYS_EMPTY = CollectionFactory.newSet("hr", "br", "img", "link", "meta"); 030 031 public DefaultMarkupModel() 032 { 033 this(false); 034 } 035 036 public DefaultMarkupModel(boolean useApostropheForAttributes) 037 { 038 super(useApostropheForAttributes); 039 } 040 041 public EndTagStyle getEndTagStyle(String element) 042 { 043 boolean alwaysEmpty = ALWAYS_EMPTY.contains(element); 044 045 return alwaysEmpty ? EndTagStyle.ABBREVIATE : EndTagStyle.REQUIRE; 046 } 047 048 /** 049 * Returns false. 050 */ 051 public boolean isXML() 052 { 053 return false; 054 } 055}