Java Code Examples for javax.xml.stream.events.StartDocument#getVersion()

The following examples show how to use javax.xml.stream.events.StartDocument#getVersion() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XmlFilterReader.java    From knox with Apache License 2.0 5 votes vote down vote up
private void processStartDocument( StartDocument event ) throws ParserConfigurationException {
  String s;

  document = XmlUtils.createDocument( false );
  pushLevel( null, document, document, config );

  writer.write( "<?xml" );

  s = event.getVersion();
  if( s == null ) {
    s = DEFAULT_XML_VERSION;
  }
  writer.write( " version=\"");
  writer.write( s );
  writer.write( "\"" );

  s = event.getCharacterEncodingScheme();
  if( s != null ) {
    writer.write( " encoding=\"");
    writer.write( s );
    writer.write( "\"" );
  }

  writer.write( " standalone=\"");
  writer.write( event.isStandalone() ? "yes" : "no" );
  writer.write( "\"" );

  writer.write( "?>" );
}
 
Example 2
Source File: StaxEventXMLReader.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private void handleStartDocument(final XMLEvent event) throws SAXException {
	if (event.isStartDocument()) {
		StartDocument startDocument = (StartDocument) event;
		String xmlVersion = startDocument.getVersion();
		if (StringUtils.hasLength(xmlVersion)) {
			this.xmlVersion = xmlVersion;
		}
		if (startDocument.encodingSet()) {
			this.encoding = startDocument.getCharacterEncodingScheme();
		}
	}
	if (getContentHandler() != null) {
		final Location location = event.getLocation();
		getContentHandler().setDocumentLocator(new Locator2() {
			@Override
			public int getColumnNumber() {
				return (location != null ? location.getColumnNumber() : -1);
			}
			@Override
			public int getLineNumber() {
				return (location != null ? location.getLineNumber() : -1);
			}
			@Override
			@Nullable
			public String getPublicId() {
				return (location != null ? location.getPublicId() : null);
			}
			@Override
			@Nullable
			public String getSystemId() {
				return (location != null ? location.getSystemId() : null);
			}
			@Override
			public String getXMLVersion() {
				return xmlVersion;
			}
			@Override
			@Nullable
			public String getEncoding() {
				return encoding;
			}
		});
		getContentHandler().startDocument();
	}
}
 
Example 3
Source File: StaxEventXMLReader.java    From java-technology-stack with MIT License 4 votes vote down vote up
private void handleStartDocument(final XMLEvent event) throws SAXException {
	if (event.isStartDocument()) {
		StartDocument startDocument = (StartDocument) event;
		String xmlVersion = startDocument.getVersion();
		if (StringUtils.hasLength(xmlVersion)) {
			this.xmlVersion = xmlVersion;
		}
		if (startDocument.encodingSet()) {
			this.encoding = startDocument.getCharacterEncodingScheme();
		}
	}
	if (getContentHandler() != null) {
		final Location location = event.getLocation();
		getContentHandler().setDocumentLocator(new Locator2() {
			@Override
			public int getColumnNumber() {
				return (location != null ? location.getColumnNumber() : -1);
			}
			@Override
			public int getLineNumber() {
				return (location != null ? location.getLineNumber() : -1);
			}
			@Override
			@Nullable
			public String getPublicId() {
				return (location != null ? location.getPublicId() : null);
			}
			@Override
			@Nullable
			public String getSystemId() {
				return (location != null ? location.getSystemId() : null);
			}
			@Override
			public String getXMLVersion() {
				return xmlVersion;
			}
			@Override
			@Nullable
			public String getEncoding() {
				return encoding;
			}
		});
		getContentHandler().startDocument();
	}
}
 
Example 4
Source File: StaxEventXMLReader.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private void handleStartDocument(final XMLEvent event) throws SAXException {
	if (event.isStartDocument()) {
		StartDocument startDocument = (StartDocument) event;
		String xmlVersion = startDocument.getVersion();
		if (StringUtils.hasLength(xmlVersion)) {
			this.xmlVersion = xmlVersion;
		}
		if (startDocument.encodingSet()) {
			this.encoding = startDocument.getCharacterEncodingScheme();
		}
	}
	if (getContentHandler() != null) {
		final Location location = event.getLocation();
		getContentHandler().setDocumentLocator(new Locator2() {
			@Override
			public int getColumnNumber() {
				return (location != null ? location.getColumnNumber() : -1);
			}
			@Override
			public int getLineNumber() {
				return (location != null ? location.getLineNumber() : -1);
			}
			@Override
			public String getPublicId() {
				return (location != null ? location.getPublicId() : null);
			}
			@Override
			public String getSystemId() {
				return (location != null ? location.getSystemId() : null);
			}
			@Override
			public String getXMLVersion() {
				return xmlVersion;
			}
			@Override
			public String getEncoding() {
				return encoding;
			}
		});
		getContentHandler().startDocument();
	}
}
 
Example 5
Source File: StaxEventXMLReader.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
private void handleStartDocument(final XMLEvent event) throws SAXException {
	if (event.isStartDocument()) {
		StartDocument startDocument = (StartDocument) event;
		String xmlVersion = startDocument.getVersion();
		if (StringUtils.hasLength(xmlVersion)) {
			this.xmlVersion = xmlVersion;
		}
		if (startDocument.encodingSet()) {
			this.encoding = startDocument.getCharacterEncodingScheme();
		}
	}
	if (getContentHandler() != null) {
		final Location location = event.getLocation();
		getContentHandler().setDocumentLocator(new Locator2() {
			@Override
			public int getColumnNumber() {
				return (location != null ? location.getColumnNumber() : -1);
			}
			@Override
			public int getLineNumber() {
				return (location != null ? location.getLineNumber() : -1);
			}
			@Override
			public String getPublicId() {
				return (location != null ? location.getPublicId() : null);
			}
			@Override
			public String getSystemId() {
				return (location != null ? location.getSystemId() : null);
			}
			@Override
			public String getXMLVersion() {
				return xmlVersion;
			}
			@Override
			public String getEncoding() {
				return encoding;
			}
		});
		getContentHandler().startDocument();
	}
}