(final SgmlPage page, final Node source, final boolean handleXHTMLAsHTML)
| 227 | } |
| 228 | |
| 229 | private static DomNode createFrom(final SgmlPage page, final Node source, final boolean handleXHTMLAsHTML) { |
| 230 | if (source.getNodeType() == Node.TEXT_NODE) { |
| 231 | return new DomText(page, source.getNodeValue()); |
| 232 | } |
| 233 | if (source.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { |
| 234 | return new DomProcessingInstruction(page, source.getNodeName(), source.getNodeValue()); |
| 235 | } |
| 236 | if (source.getNodeType() == Node.COMMENT_NODE) { |
| 237 | return new DomComment(page, source.getNodeValue()); |
| 238 | } |
| 239 | if (source.getNodeType() == Node.DOCUMENT_TYPE_NODE) { |
| 240 | final DocumentType documentType = (DocumentType) source; |
| 241 | return new DomDocumentType(page, documentType.getName(), documentType.getPublicId(), |
| 242 | documentType.getSystemId()); |
| 243 | } |
| 244 | final String ns = source.getNamespaceURI(); |
| 245 | String localName = source.getLocalName(); |
| 246 | if (handleXHTMLAsHTML && Html.XHTML_NAMESPACE.equals(ns)) { |
| 247 | final ElementFactory factory = page.getWebClient().getPageCreator().getHtmlParser().getFactory(localName); |
| 248 | return factory.createElementNS(page, ns, localName, |
| 249 | namedNodeMapToSaxAttributes(source.getAttributes())); |
| 250 | } |
| 251 | final NamedNodeMap nodeAttributes = source.getAttributes(); |
| 252 | if (page != null && page.isHtmlPage()) { |
| 253 | localName = localName.toUpperCase(Locale.ROOT); |
| 254 | } |
| 255 | final String qualifiedName; |
| 256 | if (source.getPrefix() == null) { |
| 257 | qualifiedName = localName; |
| 258 | } |
| 259 | else { |
| 260 | qualifiedName = source.getPrefix() + ':' + localName; |
| 261 | } |
| 262 | |
| 263 | final String namespaceURI = source.getNamespaceURI(); |
| 264 | if (Html.SVG_NAMESPACE.equals(namespaceURI)) { |
| 265 | return page.getWebClient().getPageCreator().getHtmlParser().getSvgFactory() |
| 266 | .createElementNS(page, namespaceURI, qualifiedName, |
| 267 | namedNodeMapToSaxAttributes(nodeAttributes)); |
| 268 | } |
| 269 | |
| 270 | final OrderedFastHashMap<String, DomAttr> attributes = new OrderedFastHashMap<>(); |
| 271 | for (int i = 0; i < nodeAttributes.getLength(); i++) { |
| 272 | final Attr attribute = (Attr) nodeAttributes.item(i); |
| 273 | final String attributeNamespaceURI = attribute.getNamespaceURI(); |
| 274 | final String attributeQualifiedName; |
| 275 | if (attribute.getPrefix() == null) { |
| 276 | attributeQualifiedName = attribute.getLocalName(); |
| 277 | } |
| 278 | else { |
| 279 | attributeQualifiedName = attribute.getPrefix() + ':' + attribute.getLocalName(); |
| 280 | } |
| 281 | final String value = attribute.getNodeValue(); |
| 282 | final boolean specified = attribute.getSpecified(); |
| 283 | final DomAttr xmlAttribute = |
| 284 | new DomAttr(page, attributeNamespaceURI, attributeQualifiedName, value, specified); |
| 285 | attributes.put(attribute.getNodeName(), xmlAttribute); |
| 286 | } |
no test coverage detected