44 |
import java.net.URL; |
import java.net.URL; |
45 |
import java.util.Collections; |
import java.util.Collections; |
46 |
import java.util.HashMap; |
import java.util.HashMap; |
47 |
|
import java.util.HashSet; |
48 |
import java.util.Map; |
import java.util.Map; |
49 |
|
import java.util.Set; |
50 |
import org.w3c.dom.DOMException; |
import org.w3c.dom.DOMException; |
51 |
import org.w3c.dom.Element; |
import org.w3c.dom.Element; |
52 |
import org.w3c.dom.Node; |
import org.w3c.dom.Node; |
141 |
ELEMENT_CLASSES = Collections.unmodifiableMap(map); |
ELEMENT_CLASSES = Collections.unmodifiableMap(map); |
142 |
} |
} |
143 |
|
|
144 |
|
private static Set HTML_NS_URIS; |
145 |
|
static |
146 |
|
{ |
147 |
|
Set set = new HashSet(); |
148 |
|
set.add("http://www.w3.org/TR/html4/strict"); |
149 |
|
set.add("http://www.w3.org/TR/html4/loose"); |
150 |
|
set.add("http://www.w3.org/TR/html4/frameset"); |
151 |
|
set.add("http://www.w3.org/1999/xhtml"); |
152 |
|
set.add("http://www.w3.org/TR/xhtml1/strict"); |
153 |
|
set.add("http://www.w3.org/TR/xhtml1/loose"); |
154 |
|
set.add("http://www.w3.org/TR/xhtml1/frameset"); |
155 |
|
HTML_NS_URIS = Collections.unmodifiableSet(set); |
156 |
|
} |
157 |
|
|
158 |
|
/** |
159 |
|
* Convenience constructor. |
160 |
|
*/ |
161 |
|
public DomHTMLDocument() |
162 |
|
{ |
163 |
|
this(new DomHTMLImpl()); |
164 |
|
} |
165 |
|
|
166 |
/** |
/** |
167 |
* Constructor. |
* Constructor. |
168 |
* This is called by the implementation. |
* This is called by the DOMImplementation. |
169 |
*/ |
*/ |
170 |
protected DomHTMLDocument(DomHTMLImpl impl) |
public DomHTMLDocument(DomHTMLImpl impl) |
171 |
{ |
{ |
172 |
super(impl); |
super(impl); |
173 |
} |
} |
390 |
|
|
391 |
public Element createElementNS(String uri, String qName) |
public Element createElementNS(String uri, String qName) |
392 |
{ |
{ |
393 |
|
/* If a non-HTML element, use the default implementation. */ |
394 |
|
if (uri != null && !HTML_NS_URIS.contains(uri)) |
395 |
|
{ |
396 |
|
return super.createElementNS(uri, qName); |
397 |
|
} |
398 |
String localName = qName.toLowerCase(); |
String localName = qName.toLowerCase(); |
399 |
int ci = qName.indexOf(':'); |
int ci = qName.indexOf(':'); |
400 |
if (ci != -1) |
if (ci != -1) |
402 |
localName = qName.substring(ci + 1); |
localName = qName.substring(ci + 1); |
403 |
} |
} |
404 |
Class t = (Class) ELEMENT_CLASSES.get(localName); |
Class t = (Class) ELEMENT_CLASSES.get(localName); |
405 |
|
/* If a non-HTML element, use the default implementation. */ |
406 |
if (t == null) |
if (t == null) |
407 |
{ |
{ |
408 |
return super.createElementNS(uri, qName); |
return super.createElementNS(uri, qName); |
409 |
} |
} |
410 |
try |
try |
411 |
{ |
{ |
412 |
Constructor c = t.getConstructor(ELEMENT_PT); |
Constructor c = t.getDeclaredConstructor(ELEMENT_PT); |
413 |
Object[] args = new Object[] { this, uri, qName }; |
Object[] args = new Object[] { this, uri, qName }; |
414 |
return (Element) c.newInstance(args); |
return (Element) c.newInstance(args); |
415 |
} |
} |