1 23 24 package org.enhydra.xml.xmlc.metadata; 25 26 import java.util.ArrayList ; 27 28 import org.enhydra.xml.io.Encodings; 29 import org.enhydra.xml.xmlc.XMLCException; 30 import org.w3c.dom.Document ; 31 import org.w3c.dom.Node ; 32 33 36 public class HTMLSection extends MetaDataElement { 37 40 public static final String TAG_NAME = "html"; 41 42 45 private static final String ENCODING_ATTR = "encoding"; 46 47 50 private String defaultFileEncoding = System.getProperty("file.encoding"); 51 52 55 public HTMLSection(Document ownerDoc) { 56 super(ownerDoc, TAG_NAME); 57 } 58 59 64 private String getDefaultEncoding() { 65 if (defaultFileEncoding == null) { 66 return Encodings.ISO_8859_1; 67 } 68 Encodings encodings = Encodings.getEncodings(); 69 String encoding = encodings.getMIMEPreferred(defaultFileEncoding); 70 if (encoding != null) { 71 if (encodings.sameEncodings(encoding, Encodings.US_ASCII)) { 72 return Encodings.ISO_8859_1; 73 } 74 return encoding; 75 } else { 76 return Encodings.ISO_8859_1; 77 } 78 } 79 80 83 public String getEncoding() { 84 String encoding = getAttributeNull(ENCODING_ATTR); 85 if (encoding == null) { 86 encoding = getDefaultEncoding(); 87 } 88 return encoding; 89 } 90 91 94 public void setEncoding(String value) { 95 setRemoveAttribute(ENCODING_ATTR, value); 96 } 97 98 101 public HTMLTagSet[] getHTMLTagSets() { 102 return (HTMLTagSet[])getChildren(HTMLTagSet.class); 103 } 104 105 108 public void addHTMLTagSet(HTMLTagSet htmlTagSet) { 109 appendChild(htmlTagSet); 110 } 111 112 115 public HTMLTagSet addHTMLTagSet() { 116 HTMLTagSet htmlTagSet = new HTMLTagSet(getOwnerDocument()); 117 appendChild(htmlTagSet); 118 return htmlTagSet; 119 } 120 121 124 public void deleteTagSet(HTMLTagSet htmlTagSet) { 125 removeChild(htmlTagSet); 126 } 127 128 131 public HTMLTag[] getHTMLTags() { 132 return (HTMLTag[])getChildren(HTMLTag.class); 133 } 134 135 138 public void addHTMLTag(HTMLTag htmlTag) { 139 appendChild(htmlTag); 140 } 141 142 145 public HTMLTag addHTMLTag() { 146 HTMLTag htmlTag = new HTMLTag(getOwnerDocument()); 147 appendChild(htmlTag); 148 return htmlTag; 149 } 150 151 154 public void deleteHTMLTag(HTMLTag htmlTag) { 155 removeChild(htmlTag); 156 } 157 158 161 public HTMLAttr[] getHTMLAttr() { 162 return (HTMLAttr[])getChildren(HTMLAttr.class); 163 } 164 165 168 public void addHTMLAttr(HTMLAttr htmlAttr) { 169 appendChild(htmlAttr); 170 } 171 172 175 public HTMLAttr addHTMLAttr() { 176 HTMLAttr htmlAttr = new HTMLAttr(getOwnerDocument()); 177 appendChild(htmlAttr); 178 return htmlAttr; 179 } 180 181 184 public void deleteHTMLAttr(HTMLAttr htmlAttr) { 185 removeChild(htmlAttr); 186 } 187 188 191 private void addTagSetTagDefs(HTMLTagSetDef tagSet, 192 ArrayList tagDefs) { 193 HTMLTagDef[] defs = tagSet.getTagDefs(); 194 for (int idx = 0; idx < defs.length; idx++) { 195 tagDefs.add(defs[idx]); 196 } 197 } 198 199 202 public HTMLTagDef[] getHTMLTagDefs() { 203 ArrayList tagDefs = new ArrayList (); 204 205 HTMLTagSet[] tagSets = getHTMLTagSets(); 206 for (int idx = 0; idx < tagSets.length; idx++) { 207 addTagSetTagDefs(tagSets[idx].getTagSetDef(), tagDefs); 208 } 209 210 HTMLTag[] tags = getHTMLTags(); 211 for (int idx = 0; idx < tags.length; idx++) { 212 tagDefs.add(tags[idx]); 213 } 214 return (HTMLTagDef[])tagDefs.toArray(new HTMLTagDef[tagDefs.size()]); 215 } 216 217 220 private void addTagSetAttrDefs(HTMLTagSetDef tagSet, 221 ArrayList attrDefs) { 222 HTMLAttrDef[] defs = tagSet.getAttrDefs(); 223 for (int idx = 0; idx < defs.length; idx++) { 224 attrDefs.add(defs[idx]); 225 } 226 } 227 228 231 public HTMLAttrDef[] getHTMLAttrDefs() { 232 ArrayList attrDefs = new ArrayList (); 233 234 HTMLTagSet[] tagSets = getHTMLTagSets(); 235 for (int idx = 0; idx < tagSets.length; idx++) { 236 addTagSetAttrDefs(tagSets[idx].getTagSetDef(), attrDefs); 237 } 238 239 HTMLAttr[] attrs = getHTMLAttr(); 240 for (int idx = 0; idx < attrs.length; idx++) { 241 attrDefs.add(attrs[idx]); 242 } 243 return (HTMLAttrDef[])attrDefs.toArray(new HTMLAttrDef[attrDefs.size()]); 244 } 245 246 249 public HTMLCompatibility getCompatibility() { 250 return (HTMLCompatibility)getChild(HTMLCompatibility.class); 251 } 252 253 256 public HTMLCompatibility getCreateCompatibility() { 257 return (HTMLCompatibility)getCreateChild(HTMLCompatibility.class); 258 } 259 260 263 public void setCompatibility(HTMLCompatibility compatibility) { 264 setChild(compatibility); 265 } 266 267 271 protected void completeModifications() throws XMLCException { 272 super.completeModifications(); 273 } 274 275 278 protected void mergeElement(MetaDataElement srcElement) { 279 mergeAttributes(srcElement); 280 mergeSingletonChild(HTMLCompatibility.class, srcElement); 281 282 Document document = getOwnerDocument(); 284 for (Node child = srcElement.getFirstChild(); 285 child != null; 286 child = child.getNextSibling()) { 287 if (!(child instanceof HTMLCompatibility)) { 288 appendChild(document.importNode(child, true)); 289 } 290 } 291 } 292 } 293 | Popular Tags |