Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/com/sun/xml/internal/stream/events/StartDocumentEvent.java
86414 views
/*1* Copyright (c) 2005, 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 com.sun.xml.internal.stream.events ;2627import javax.xml.stream.events.StartDocument;28import javax.xml.stream.Location;29import javax.xml.stream.XMLStreamConstants;3031/** Implementation of StartDocumentEvent.32*33* @author Neeraj Bajaj Sun Microsystems,Inc.34* @author K.Venugopal Sun Microsystems,Inc.35*36*/3738public class StartDocumentEvent extends DummyEvent39implements StartDocument {4041protected String fSystemId;42protected String fEncodingScheam;43protected boolean fStandalone;44protected String fVersion;45private boolean fEncodingSchemeSet = false;46private boolean fStandaloneSet = false;47private boolean nestedCall = false;4849public StartDocumentEvent() {50init("UTF-8","1.0",true,null);51}5253public StartDocumentEvent(String encoding){54init(encoding,"1.0",true,null);55}5657public StartDocumentEvent(String encoding, String version){58init(encoding,version,true,null);59}6061public StartDocumentEvent(String encoding, String version, boolean standalone){62this.fStandaloneSet = true;63init(encoding,version,standalone,null);64}6566public StartDocumentEvent(String encoding, String version, boolean standalone,Location loc){67this.fStandaloneSet = true;68init(encoding, version, standalone, loc);69}70protected void init(String encoding, String version, boolean standalone,Location loc) {71setEventType(XMLStreamConstants.START_DOCUMENT);72this.fEncodingScheam = encoding;73this.fVersion = version;74this.fStandalone = standalone;75if (encoding != null && !encoding.equals(""))76this.fEncodingSchemeSet = true;77else {78this.fEncodingSchemeSet = false;79this.fEncodingScheam = "UTF-8";80}81this.fLocation = loc;82}8384public String getSystemId() {85if(fLocation == null )86return "";87else88return fLocation.getSystemId();89}909192public String getCharacterEncodingScheme() {93return fEncodingScheam;94}9596public boolean isStandalone() {97return fStandalone;98}99100public String getVersion() {101return fVersion;102}103104public void setStandalone(boolean flag) {105fStandaloneSet = true;106fStandalone = flag;107}108109public void setStandalone(String s) {110fStandaloneSet = true;111if(s == null) {112fStandalone = true;113return;114}115if(s.equals("yes"))116fStandalone = true;117else118fStandalone = false;119}120121public boolean encodingSet() {122return fEncodingSchemeSet;123}124125public boolean standaloneSet() {126return fStandaloneSet;127}128129public void setEncoding(String encoding) {130fEncodingScheam = encoding;131}132133void setDeclaredEncoding(boolean value){134fEncodingSchemeSet = value;135}136137public void setVersion(String s) {138fVersion = s;139}140141void clear() {142fEncodingScheam = "UTF-8";143fStandalone = true;144fVersion = "1.0";145fEncodingSchemeSet = false;146fStandaloneSet = false;147}148149public String toString() {150String s = "<?xml version=\"" + fVersion + "\"";151s = s + " encoding='" + fEncodingScheam + "'";152if(fStandaloneSet) {153if(fStandalone)154s = s + " standalone='yes'?>";155else156s = s + " standalone='no'?>";157} else {158s = s + "?>";159}160return s;161}162163public boolean isStartDocument() {164return true;165}166167protected void writeAsEncodedUnicodeEx(java.io.Writer writer)168throws java.io.IOException169{170writer.write(toString());171}172}173174175