1 /* 2 * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 * 25 * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC. 26 */ 27 28 package com.sun.xml.internal.fastinfoset.stax.events ; 29 30 import javax.xml.stream.XMLStreamConstants; 31 import javax.xml.stream.events.StartDocument; 32 33 34 public class StartDocumentEvent extends EventBase implements StartDocument { 35 36 protected String _systemId; 37 protected String _encoding = XMLConstants.ENCODING; //default 38 protected boolean _standalone = true; 39 protected String _version = XMLConstants.XMLVERSION; 40 private boolean _encodingSet = false; 41 private boolean _standaloneSet = false; 42 reset()43 public void reset() { 44 _encoding = XMLConstants.ENCODING; 45 _standalone = true; 46 _version = XMLConstants.XMLVERSION; 47 _encodingSet = false; 48 _standaloneSet=false; 49 } StartDocumentEvent()50 public StartDocumentEvent() { 51 this(null ,null); 52 } 53 StartDocumentEvent(String encoding)54 public StartDocumentEvent(String encoding){ 55 this(encoding, null); 56 } 57 StartDocumentEvent(String encoding, String version)58 public StartDocumentEvent(String encoding, String version){ 59 if (encoding != null) { 60 _encoding = encoding; 61 _encodingSet = true; 62 } 63 if (version != null) 64 _version = version; 65 setEventType(XMLStreamConstants.START_DOCUMENT); 66 } 67 68 69 // ------------------- methods defined in StartDocument ------------------------- 70 /** 71 * Returns the system ID of the XML data 72 * @return the system ID, defaults to "" 73 */ getSystemId()74 public String getSystemId() { 75 return super.getSystemId(); 76 } 77 78 /** 79 * Returns the encoding style of the XML data 80 * @return the character encoding, defaults to "UTF-8" 81 */ getCharacterEncodingScheme()82 public String getCharacterEncodingScheme() { 83 return _encoding; 84 } 85 /** 86 * Returns true if CharacterEncodingScheme was set in 87 * the encoding declaration of the document 88 */ encodingSet()89 public boolean encodingSet() { 90 return _encodingSet; 91 } 92 93 94 /** 95 * Returns if this XML is standalone 96 * @return the standalone state of XML, defaults to "no" 97 */ isStandalone()98 public boolean isStandalone() { 99 return _standalone; 100 } 101 /** 102 * Returns true if the standalone attribute was set in 103 * the encoding declaration of the document. 104 */ standaloneSet()105 public boolean standaloneSet() { 106 return _standaloneSet; 107 } 108 109 /** 110 * Returns the version of XML of this XML stream 111 * @return the version of XML, defaults to "1.0" 112 */ getVersion()113 public String getVersion() { 114 return _version; 115 } 116 // ------------------- end of methods defined in StartDocument ------------------------- 117 setStandalone(boolean standalone)118 public void setStandalone(boolean standalone) { 119 _standaloneSet = true; 120 _standalone = standalone; 121 } 122 setStandalone(String s)123 public void setStandalone(String s) { 124 _standaloneSet = true; 125 if(s == null) { 126 _standalone = true; 127 return; 128 } 129 if(s.equals("yes")) 130 _standalone = true; 131 else 132 _standalone = false; 133 } 134 135 setEncoding(String encoding)136 public void setEncoding(String encoding) { 137 _encoding = encoding; 138 _encodingSet = true; 139 } 140 setDeclaredEncoding(boolean value)141 void setDeclaredEncoding(boolean value){ 142 _encodingSet = value; 143 } 144 setVersion(String s)145 public void setVersion(String s) { 146 _version = s; 147 } 148 clear()149 void clear() { 150 _encoding = "UTF-8"; 151 _standalone = true; 152 _version = "1.0"; 153 _encodingSet = false; 154 _standaloneSet = false; 155 } 156 toString()157 public String toString() { 158 String s = "<?xml version=\"" + _version + "\""; 159 s = s + " encoding='" + _encoding + "'"; 160 if(_standaloneSet) { 161 if(_standalone) 162 s = s + " standalone='yes'?>"; 163 else 164 s = s + " standalone='no'?>"; 165 } else { 166 s = s + "?>"; 167 } 168 return s; 169 } 170 isStartDocument()171 public boolean isStartDocument() { 172 return true; 173 } 174 } 175