org.apache.cxf.staxutils.W3CDOMStreamReader Maven / Gradle / Ivy
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cxf.staxutils;
import java.util.ArrayList;
import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.stream.Location;
import javax.xml.stream.XMLStreamException;
import org.w3c.dom.Attr;
import org.w3c.dom.Comment;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.Text;
import org.w3c.dom.TypeInfo;
import org.apache.cxf.helpers.DOMUtils;
public class W3CDOMStreamReader extends AbstractDOMStreamReader {
private Node content;
private Document document;
private W3CNamespaceContext context;
private String sysId;
/**
* @param element
*/
public W3CDOMStreamReader(Element element) {
super(new ElementFrame(element, null));
content = element;
newFrame(getCurrentFrame());
this.document = element.getOwnerDocument();
}
public W3CDOMStreamReader(Element element, String systemId) {
this(element);
sysId = systemId;
}
public W3CDOMStreamReader(Document doc) {
super(new ElementFrame(doc, false) {
public boolean isDocument() {
return true;
}
});
this.document = doc;
}
public W3CDOMStreamReader(DocumentFragment docfrag) {
super(new ElementFrame(docfrag, true) {
public boolean isDocumentFragment() {
return true;
}
});
this.document = docfrag.getOwnerDocument();
}
/**
* Get the document associated with this stream.
*/
public Document getDocument() {
return document;
}
public String getSystemId() {
return sysId == null ? document.getDocumentURI() : sysId;
}
/**
* Find name spaces declaration in atrributes and move them to separate
* collection.
*/
@Override
protected final void newFrame(ElementFrame frame) {
Node element = getCurrentNode();
frame.uris = new ArrayList();
frame.prefixes = new ArrayList();
frame.attributes = new ArrayList