01: // Copyright 2006 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.dom;
16:
17: import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newSet;
18:
19: import java.util.Set;
20:
21: /**
22: * Default implementation of {@link org.apache.tapestry.dom.MarkupModel} that is appropriate for
23: * traditional HTML markup. This conforms to the SGML HTML definition, including some things that
24: * are not well formed XML-style markup. Assumes that all tags are lowercase.
25: */
26: public class DefaultMarkupModel implements MarkupModel {
27: private final Set<String> EMPTY_ELEMENTS = newSet("base", "br",
28: "col", "frame", "hr", "img", "input", "link", "meta",
29: "option", "param");
30:
31: /** Passes all characters but '<', '>' and '&' through unchanged. */
32: public void encode(String content, StringBuilder buffer) {
33: char[] array = content.toCharArray();
34:
35: for (char ch : array) {
36: switch (ch) {
37: case '<':
38: buffer.append("<");
39: continue;
40:
41: case '>':
42: buffer.append(">");
43: continue;
44:
45: case '&':
46: buffer.append("&");
47: continue;
48:
49: default:
50: buffer.append(ch);
51: }
52: }
53: }
54:
55: public EndTagStyle getEndTagStyle(String element) {
56: boolean isEmpty = EMPTY_ELEMENTS.contains(element);
57:
58: return isEmpty ? EndTagStyle.OMIT : EndTagStyle.REQUIRE;
59: }
60:
61: }
|