Path: blob/master/src/java.base/share/classes/jdk/internal/util/xml/XMLStreamWriter.java
41161 views
/*1* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package jdk.internal.util.xml;2627import java.nio.charset.Charset;28import java.nio.charset.StandardCharsets;2930/**31* Basic XMLStreamWriter for writing simple XML files such as those32* defined in java.util.Properties33*34* This is a subset of javax.xml.stream.XMLStreamWriter35*36* @author Joe Wang37*/38public interface XMLStreamWriter {3940//Defaults the XML version to 1.0, and the encoding to utf-841public static final String DEFAULT_XML_VERSION = "1.0";42public static final String DEFAULT_ENCODING = "UTF-8";43public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;4445/**46* Writes a start tag to the output. All writeStartElement methods47* open a new scope in the internal namespace context. Writing the48* corresponding EndElement causes the scope to be closed.49* @param localName local name of the tag, may not be null50* @throws XMLStreamException51*/52public void writeStartElement(String localName) throws XMLStreamException;5354/**55* Writes an empty element tag to the output56* @param localName local name of the tag, may not be null57* @throws XMLStreamException58*/59public void writeEmptyElement(String localName) throws XMLStreamException;6061/**62* Writes an end tag to the output relying on the internal63* state of the writer to determine the prefix and local name64* of the event.65* @throws XMLStreamException66*/67public void writeEndElement() throws XMLStreamException;6869/**70* Closes any start tags and writes corresponding end tags.71* @throws XMLStreamException72*/73public void writeEndDocument() throws XMLStreamException;7475/**76* Close this writer and free any resources associated with the77* writer. This must not close the underlying output stream.78* @throws XMLStreamException79*/80public void close() throws XMLStreamException;8182/**83* Write any cached data to the underlying output mechanism.84* @throws XMLStreamException85*/86public void flush() throws XMLStreamException;8788/**89* Writes an attribute to the output stream without90* a prefix.91* @param localName the local name of the attribute92* @param value the value of the attribute93* @throws IllegalStateException if the current state does not allow Attribute writing94* @throws XMLStreamException95*/96public void writeAttribute(String localName, String value)97throws XMLStreamException;9899/**100* Writes a CData section101* @param data the data contained in the CData Section, may not be null102* @throws XMLStreamException103*/104public void writeCData(String data) throws XMLStreamException;105106/**107* Write a DTD section. This string represents the entire doctypedecl production108* from the XML 1.0 specification.109*110* @param dtd the DTD to be written111* @throws XMLStreamException112*/113public void writeDTD(String dtd) throws XMLStreamException;114115/**116* Write the XML Declaration. Defaults the XML version to 1.0, and the encoding to utf-8117* @throws XMLStreamException118*/119public void writeStartDocument() throws XMLStreamException;120121/**122* Write the XML Declaration. Defaults the encoding to utf-8123* @param version version of the xml document124* @throws XMLStreamException125*/126public void writeStartDocument(String version) throws XMLStreamException;127128/**129* Write the XML Declaration. Note that the encoding parameter does130* not set the actual encoding of the underlying output. That must131* be set when the instance of the XMLStreamWriter is created using the132* XMLOutputFactory133* @param encoding encoding of the xml declaration134* @param version version of the xml document135* @throws XMLStreamException If given encoding does not match encoding136* of the underlying stream137*/138public void writeStartDocument(String encoding, String version)139throws XMLStreamException;140141/**142* Write text to the output143* @param text the value to write144* @throws XMLStreamException145*/146public void writeCharacters(String text) throws XMLStreamException;147148/**149* Write text to the output150* @param text the value to write151* @param start the starting position in the array152* @param len the number of characters to write153* @throws XMLStreamException154*/155public void writeCharacters(char[] text, int start, int len)156throws XMLStreamException;157}158159160