java.fedora.server.journal.xmlhelpers.AbstractXmlWriter Maven / Gradle / Ivy
Show all versions of fcrepo-client Show documentation
/*
* -----------------------------------------------------------------------------
*
* License and Copyright: The contents of this file are subject to 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.fedora-commons.org/licenses.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The entire file consists of original code.
* Copyright © 2008 Fedora Commons, Inc.
*
Copyright © 2002-2007 The Rector and Visitors of the University of
* Virginia and Cornell University
* All rights reserved.
*
* -----------------------------------------------------------------------------
*/
package fedora.server.journal.xmlhelpers;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventFactory;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLStreamException;
import fedora.server.journal.JournalConstants;
/**
*
* Title: AbstractXmlWriter.java
*
*
* Description: An abstract base class that provides some useful methods
* for the XML writer classes.
*
*
* @author [email protected]
* @version $Id: AbstractXmlWriter.java 5025 2006-09-01 22:08:17 +0000 (Fri, 01
* Sep 2006) cwilper $
*/
public class AbstractXmlWriter
implements JournalConstants {
private final XMLEventFactory factory = XMLEventFactory.newInstance();
protected void putStartDocument(XMLEventWriter writer)
throws XMLStreamException {
writer.add(factory.createStartDocument(DOCUMENT_ENCODING,
DOCUMENT_VERSION));
}
protected void putStartTag(XMLEventWriter writer, QName tagName)
throws XMLStreamException {
writer.add(factory.createStartElement(tagName, null, null));
}
protected void putAttribute(XMLEventWriter writer, QName name, String value)
throws XMLStreamException {
writer.add(factory.createAttribute(name, value));
}
protected void putAttributeIfNotNull(XMLEventWriter writer,
QName attributeName,
String value)
throws XMLStreamException {
if (value != null) {
putAttribute(writer, attributeName, value);
}
}
protected void putCharacters(XMLEventWriter writer, String chars)
throws XMLStreamException {
writer.add(factory.createCharacters(chars));
}
protected void putEndTag(XMLEventWriter writer, QName tagName)
throws XMLStreamException {
writer.add(factory.createEndElement(tagName, null));
}
protected void putEndDocument(XMLEventWriter writer)
throws XMLStreamException {
writer.add(factory.createEndDocument());
}
}