1 23 24 package org.enhydra.xml.io; 25 26 import java.util.HashMap ; 27 28 import org.w3c.dom.Element ; 29 30 33 final public class HTMLElements { 34 37 public static final Integer BLOCK_FORMATTING = new Integer (1); 38 39 42 public static final Integer HEADER_FORMATTING = new Integer (2); 43 44 47 public static final Integer INLINE_FORMATTING = new Integer (3); 48 49 52 private static final String [] BLOCK_FORMATTED_ELEMENTS = { 53 "HTML", "HEAD", "BODY", "SCRIPT", "P", "UL", "OL", "DL", "DIR", 54 "MENU", "PRE", "LISTING", "XMP", "PLAINTEXT", "ADDRESS", "BLOCKQUOTE", 55 "FORM", "ISINDEX", "FIELDSET", "TABLE", "HR", "DIV", "NOSAVE", "LAYER", 56 "NOLAYER", "ALIGN", "CENTER", "INS", "DEL", "NOFRAMES", "NOSCRIPT", 57 "AREA" 58 }; 59 60 63 private static final String [] HEADER_FORMATTED_ELEMENTS = { 64 "TITLE", "H1", "H2", "H3", "H4", "H5", "H6" 65 }; 66 67 71 private static final HashMap fFormattingMap = new HashMap (); 72 73 78 private static final String [] NO_VALUE_ATTRS = { 79 "checked", "compact", "declare", "defer", "disabled", "ismap", 80 "nohref", "noresize", "noshade", "nowrap", "readonly", "selected" 81 }; 82 private static final HashMap fNoValueAttrs = new HashMap (); 83 84 88 private static final String [] NO_CLOSE_TAGS = { 89 "AREA", "BASE", "BASEFONT", "BR", "COL", "FRAME", "HR", "IMG", 90 "INPUT", "ISINDEX", "LINK", "META", "PARAM", "P" 91 }; 92 private static final HashMap fNoCloseTags = new HashMap (); 93 94 97 static { 98 for (int idx = 0; idx < NO_CLOSE_TAGS.length; idx++) { 99 fNoCloseTags.put(NO_CLOSE_TAGS[idx], NO_CLOSE_TAGS[idx]); 100 } 101 for (int idx = 0; idx < NO_VALUE_ATTRS.length; idx++) { 102 fNoValueAttrs.put(NO_VALUE_ATTRS[idx], NO_VALUE_ATTRS[idx]); 103 } 104 for (int idx = 0; idx < BLOCK_FORMATTED_ELEMENTS.length; idx++) { 105 fFormattingMap.put(BLOCK_FORMATTED_ELEMENTS[idx], 106 BLOCK_FORMATTING); 107 } 108 for (int idx = 0; idx < HEADER_FORMATTED_ELEMENTS.length; idx++) { 109 fFormattingMap.put(HEADER_FORMATTED_ELEMENTS[idx], 110 HEADER_FORMATTING); 111 } 112 } 113 114 117 private HTMLElements() { 118 } 119 120 124 public static boolean isBooleanAttr(String attrName) { 125 return fNoValueAttrs.containsKey(attrName); 126 } 127 128 135 public Integer getElementFormatting(String tagName) { 136 Integer formatting = (Integer )fFormattingMap.get(tagName); 137 if (formatting == null) { 138 return INLINE_FORMATTING; 139 } else { 140 return formatting; 141 } 142 } 143 144 148 public static boolean hasCloseTag(String tagName) { 149 return !fNoCloseTags.containsKey(tagName); 150 } 151 152 156 public static boolean isScriptStyle(Element element) { 157 String tagName = element.getTagName(); 158 return (tagName.equals("SCRIPT") || tagName.equals("STYLE")); 159 } 160 161 } 163 | Popular Tags |