View Javadoc

1   /*   Copyright 2004 BEA Systems, Inc.
2    *
3    *   Licensed under the Apache License, Version 2.0 (the "License");
4    *   you may not use this file except in compliance with the License.
5    *   You may obtain a copy of the License at
6    *
7    *       http://www.apache.org/licenses/LICENSE-2.0
8    *
9    *   Unless required by applicable law or agreed to in writing, software
10   *   distributed under the License is distributed on an "AS IS" BASIS,
11   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   *   See the License for the specific language governing permissions and
13   *   limitations under the License.
14   */
15  
16  package com.bea.xml.stream.events;
17  import javax.xml.stream.events.StartDocument;
18  import javax.xml.stream.events.XMLEvent;
19  public class StartDocumentEvent 
20    extends BaseEvent 
21    implements StartDocument 
22  {
23    protected String systemId="";
24    protected String publicId="";
25    protected String encodingScheme="UTF-8";
26    protected boolean standalone=true;
27    protected String version="1.0";
28    private boolean encodingSchemeSet = false;
29    private boolean standaloneSet = false;
30  
31    public StartDocumentEvent(){super();init();}
32    protected void init() {setEventType(XMLEvent.START_DOCUMENT); }
33    public String getSystemId() { return systemId; }
34    //  public String getPublicId() { return publicId; }
35    public String getCharacterEncodingScheme() { return encodingScheme; }
36    public boolean isStandalone(){ return standalone; }
37    public String getVersion() { return version; }
38    public void setStandalone(boolean standalone) {
39      standaloneSet = true;
40      this.standalone = standalone;
41    }
42    public void setStandalone(String standalone) {
43      standaloneSet = true;
44      if (standalone == null) {this.standalone = true; return;}
45      if (standalone.equals("yes")) this.standalone = true;
46      else
47        this.standalone = false;
48    }
49    public boolean encodingSet() { return encodingSchemeSet; }
50    public boolean standaloneSet() { return standaloneSet; }
51    public void setEncoding(String encoding) {
52      encodingScheme = encoding;
53      encodingSchemeSet = true;
54    }
55    public void setVersion(String version) {
56      this.version = version;
57    }
58    public void clear() {
59      encodingScheme = "UTF-8";
60      standalone = true;
61      version = "1.0";
62      encodingSchemeSet = false;
63      standaloneSet=false;
64    }
65    public String toString() {
66      String val = "<?xml version=\""+version+"\"";
67      val = val + " encoding='"+encodingScheme+"'";
68      if (standaloneSet) {
69        if (standalone) val = val+  " standalone='yes'?>";
70        else
71          val = val + " standalone='no'?>";
72      } else {
73        val = val +"?>";
74      }
75      return val;
76    }
77  }
78  
79  
80