📄 staxeventreader.java
字号:
* Constructs a DOM4J Attribute from the provided event stream. The stream
* must be positioned before an {@link Attribute}event.
*
* @param reader
* The event stream from which to read the Attribute.
*
* @return The Attribute that was read from the stream.
*
* @throws XMLStreamException
* If an error occured reading events from the stream, or the
* stream was not positioned before an {@linkAttribute}event.
*/
public org.dom4j.Attribute readAttribute(XMLEventReader reader)
throws XMLStreamException {
XMLEvent event = reader.peek();
if (event.isAttribute()) {
Attribute attr = (Attribute) reader.nextEvent();
return createAttribute(null, attr);
} else {
throw new XMLStreamException("Expected Attribute event, found: "
+ event);
}
}
/**
* Constructs a DOM4J Namespace from the provided event stream. The stream
* must be positioned before a {@link Namespace}event.
*
* @param reader
* The event stream from which to read the Namespace.
*
* @return The Namespace that was read from the stream.
*
* @throws XMLStreamException
* If an error occured reading events from the stream, or the
* stream was not positioned before a {@linkNamespace}event.
*/
public org.dom4j.Namespace readNamespace(XMLEventReader reader)
throws XMLStreamException {
XMLEvent event = reader.peek();
if (event.isNamespace()) {
Namespace ns = (Namespace) reader.nextEvent();
return createNamespace(ns);
} else {
throw new XMLStreamException("Expected Namespace event, found: "
+ event);
}
}
/**
* Constructs a DOM4J Text or CDATA section from the provided event stream.
* The stream must be positioned before a {@link Characters}event.
*
* @param reader
* The event stream from which to read the Text or CDATA.
*
* @return The Text or CDATA that was read from the stream.
*
* @throws XMLStreamException
* If an error occured reading events from the stream, or the
* stream was not positioned before a {@linkCharacters}event.
*/
public CharacterData readCharacters(XMLEventReader reader)
throws XMLStreamException {
XMLEvent event = reader.peek();
if (event.isCharacters()) {
Characters characters = reader.nextEvent().asCharacters();
return createCharacterData(characters);
} else {
throw new XMLStreamException("Expected Characters event, found: "
+ event);
}
}
/**
* Constructs a DOM4J Comment from the provided event stream. The stream
* must be positioned before a {@link Comment}event.
*
* @param reader
* The event stream from which to read the Comment.
*
* @return The Comment that was read from the stream.
*
* @throws XMLStreamException
* If an error occured reading events from the stream, or the
* stream was not positioned before a {@linkComment}event.
*/
public org.dom4j.Comment readComment(XMLEventReader reader)
throws XMLStreamException {
XMLEvent event = reader.peek();
if (event instanceof Comment) {
return createComment((Comment) reader.nextEvent());
} else {
throw new XMLStreamException("Expected Comment event, found: "
+ event);
}
}
/**
* Constructs a DOM4J Entity from the provided event stream. The stream must
* be positioned before an {@link EntityReference}event.
*
* @param reader
* The event stream from which to read the {@link
* EntityReference}.
*
* @return The {@link org.dom4j.Entity}that was read from the stream.
*
* @throws XMLStreamException
* If an error occured reading events from the stream, or the
* stream was not positioned before an {@linkEntityReference}
* event.
*/
public Entity readEntityReference(XMLEventReader reader)
throws XMLStreamException {
XMLEvent event = reader.peek();
if (event.isEntityReference()) {
EntityReference entityRef = (EntityReference) reader.nextEvent();
return createEntity(entityRef);
} else {
throw new XMLStreamException("Expected EntityRef event, found: "
+ event);
}
}
/**
* Constructs a DOM4J ProcessingInstruction from the provided event stream.
* The stream must be positioned before a {@link ProcessingInstruction}
* event.
*
* @param reader
* The event stream from which to read the ProcessingInstruction.
*
* @return The ProcessingInstruction that was read from the stream.
*
* @throws XMLStreamException
* If an error occured reading events from the stream, or the
* stream was not positioned before a {@link
* ProcessingInstruction} event.
*/
public org.dom4j.ProcessingInstruction readProcessingInstruction(
XMLEventReader reader) throws XMLStreamException {
XMLEvent event = reader.peek();
if (event.isProcessingInstruction()) {
ProcessingInstruction pi = (ProcessingInstruction) reader
.nextEvent();
return createProcessingInstruction(pi);
} else {
throw new XMLStreamException("Expected PI event, found: " + event);
}
}
/**
* Constructs a new DOM4J Element from the provided StartElement event. All
* attributes and namespaces will be added to the returned element.
*
* @param startEvent
* The StartElement event from which to construct the new DOM4J
* Element.
*
* @return The Element constructed from the provided StartElement event.
*/
public Element createElement(StartElement startEvent) {
QName qname = startEvent.getName();
org.dom4j.QName elemName = createQName(qname);
Element elem = factory.createElement(elemName);
// create attributes
for (Iterator i = startEvent.getAttributes(); i.hasNext();) {
Attribute attr = (Attribute) i.next();
elem.addAttribute(createQName(attr.getName()), attr.getValue());
}
// create namespaces
for (Iterator i = startEvent.getNamespaces(); i.hasNext();) {
Namespace ns = (Namespace) i.next();
elem.addNamespace(ns.getPrefix(), ns.getNamespaceURI());
}
return elem;
}
/**
* Constructs a new DOM4J Attribute from the provided StAX Attribute event.
*
* @param elem
* DOCUMENT ME!
* @param attr
* The Attribute event from which to construct the new DOM4J
* Attribute.
*
* @return The Attribute constructed from the provided Attribute event.
*/
public org.dom4j.Attribute createAttribute(Element elem, Attribute attr) {
return factory.createAttribute(elem, createQName(attr.getName()), attr
.getValue());
}
/**
* Constructs a new DOM4J Namespace from the provided StAX Namespace event.
*
* @param ns
* The Namespace event from which to construct the new DOM4J
* Namespace.
*
* @return The Namespace constructed from the provided Namespace event.
*/
public org.dom4j.Namespace createNamespace(Namespace ns) {
return factory.createNamespace(ns.getPrefix(), ns.getNamespaceURI());
}
/**
* Constructs a new DOM4J Text or CDATA object from the provided Characters
* event.
*
* @param characters
* The Characters event from which to construct the new DOM4J
* Text or CDATA object.
*
* @return The Text or CDATA object constructed from the provided Characters
* event.
*/
public CharacterData createCharacterData(Characters characters) {
String data = characters.getData();
if (characters.isCData()) {
return factory.createCDATA(data);
} else {
return factory.createText(data);
}
}
/**
* Constructs a new DOM4J Comment from the provided StAX Comment event.
*
* @param comment
* The Comment event from which to construct the new DOM4J
* Comment.
*
* @return The Comment constructed from the provided Comment event.
*/
public org.dom4j.Comment createComment(Comment comment) {
return factory.createComment(comment.getText());
}
/**
* Constructs a new DOM4J Entity from the provided StAX EntityReference
* event.
*
* @param entityRef
* The EntityReference event from which to construct the new
* DOM4J Entity.
*
* @return The Entity constructed from the provided EntityReference event.
*/
public org.dom4j.Entity createEntity(EntityReference entityRef) {
return factory.createEntity(entityRef.getName(), entityRef
.getDeclaration().getReplacementText());
}
/**
* Constructs a new DOM4J ProcessingInstruction from the provided StAX
* ProcessingInstruction event.
*
* @param pi
* The ProcessingInstruction event from which to construct the
* new DOM4J ProcessingInstruction.
*
* @return The ProcessingInstruction constructed from the provided
* ProcessingInstruction event.
*/
public org.dom4j.ProcessingInstruction createProcessingInstruction(
ProcessingInstruction pi) {
return factory
.createProcessingInstruction(pi.getTarget(), pi.getData());
}
/**
* Constructs a new DOM4J QName from the provided JAXP QName.
*
* @param qname
* The JAXP QName from which to create a DOM4J QName.
*
* @return The newly constructed DOM4J QName.
*/
public org.dom4j.QName createQName(QName qname) {
return factory.createQName(qname.getLocalPart(), qname.getPrefix(),
qname.getNamespaceURI());
}
}
/*
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain copyright statements and
* notices. Redistributions must also contain a copy of this document.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name "DOM4J" must not be used to endorse or promote products derived
* from this Software without prior written permission of MetaStuff, Ltd. For
* written permission, please contact dom4j-info@metastuff.com.
*
* 4. Products derived from this Software may not be called "DOM4J" nor may
* "DOM4J" appear in their names without prior written permission of MetaStuff,
* Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
*
* 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
*
* THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -