public static String getDocumentCharset(final File f) throws IOException, XMLException { XMLEventReader reader = null; try { // using stax to get xml factory objects and read the input file XMLInputFactory inputFactory = XMLInputFactory.newInstance(); reader = inputFactory.createXMLEventReader(new FileInputStream(f)); XMLEvent event = reader.nextEvent(); // Always the first element is StartDocument // even if the XML does not have explicit declaration: StartDocument document = (StartDocument) event; return document.getCharacterEncodingScheme(); } catch (XMLStreamException ex) { throw new XMLException(ex.getMessage(), ex); } finally{ if(reader != null){ try{ reader.close(); } catch(XMLStreamException ex){ LOG.warning(ex.getMessage()); } } } }
this.encoding = startDocument.getCharacterEncodingScheme();
this.encoding = startDocument.getCharacterEncodingScheme();
this.encoding = startDocument.getCharacterEncodingScheme();
.getCharacterEncodingScheme(); doc = factory.createDocument(encodingScheme); } else {
document.setBaseURI(event.getLocation().getSystemId()); document.setProperty("ENCODING_SCHEME", ((javax.xml.stream.events.StartDocument)event).getCharacterEncodingScheme()); document.setProperty("STANDALONE", String.valueOf( ((javax.xml.stream.events.StartDocument)event).isStandalone()));
public void startDocument(StartDocument event) throws XMLStreamException { String version = event.getVersion(); String encoding = event.getCharacterEncodingScheme(); fStreamWriter.writeStartDocument(encoding != null ? encoding : "UTF-8", version != null ? version : "1.0"); }
public String getCharacterEncodingScheme() { requiredEventType(START_DOCUMENT); return ((StartDocument) current).getCharacterEncodingScheme(); }
public String getCharacterEncodingScheme() { requiredEventType(START_DOCUMENT); return ((StartDocument) current).getCharacterEncodingScheme(); }
private void procStartDoc(XMLEvent event) { javax.xml.stream.events.StartDocument startDoc = (javax.xml.stream.events.StartDocument) event; String xmlVersion = startDoc.getVersion(); if (xmlVersion != null && !xmlVersion.equals("1.0")) { logger.warn("Filter will use xml version 1.0"); } String xmlEnc = startDoc.getCharacterEncodingScheme(); if (xmlEnc != null && !xmlEnc.equalsIgnoreCase(encoding)) { logger.warn( "The xml encoding attribute value {} is different from " + "what was detected or specified in the settings. Encoding {} will be used.", xmlEnc, encoding); } }
public void addStartDocument(StartDocument sd) throws XMLStreamException { String encoding = sd.getCharacterEncodingScheme(); String version = sd.getVersion(); boolean standalone = sd.isStandalone(); writer.writeStartDocument(encoding,version); }
/** * Writes a {@link StartDocument} to the provided stream. * * @param start The {@link StartDocument} to write. * @param writer The destination stream. * @throws XMLStreamException If an error occurs writing to the stream. */ public static final void writeStartDocument(StartDocument start, XMLStreamWriter writer) throws XMLStreamException { String version = start.getVersion(); if (start.encodingSet()) { String encoding = start.getCharacterEncodingScheme(); writer.writeStartDocument(encoding, version); } else { writer.writeStartDocument(version); } }
private void processStartDocument( StartDocument event ) throws ParserConfigurationException { //System.out.println( "SD=" + event ); String s; document = XmlUtils.createDocument( false ); pushLevel( null, event, 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( "?>" ); }
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( "?>" ); }
/** * Compares two {@link StartDocument}s. This method will return * <code>true</code> only if the two events have identical encodings, versions, * and have the same standalone setting. * * @param a The first event. * @param b The second event. * @return <code>true</code> if the events match, <code>false</code> otherwise. */ public static boolean eventsMatch(StartDocument a, StartDocument b) { if (a == b) { return true; } else if (a == null || b == null) { return false; } if (!a.getCharacterEncodingScheme().equals( b.getCharacterEncodingScheme())) { return false; } else if (a.isStandalone() != b.isStandalone()) { return false; } else if (!a.getVersion().equals(b.getVersion())) { return false; } else { // TODO match the two system ID fields? return true; } }
StartDocument sd = (StartDocument)event; if (sd.encodingSet()) { encoding = sd.getCharacterEncodingScheme();
/** * Copy constructor. * * @param that The {@link StartDocument} event to copy. */ public StartDocumentEvent(StartDocument that) { super(that); // copy encoding if (that.encodingSet()) { this.encoding = that.getCharacterEncodingScheme(); } // copy standalone if (standaloneSet()) { this.standalone = that.isStandalone() ? Boolean.TRUE : Boolean.FALSE; } this.version = DEFAULT_VERSION.equals(that.getVersion()) ? null : that.getVersion(); }
/** * Writes a {@link StartDocument} to the provided stream. * * @param start The {@link StartDocument} to write. * @param writer The destination stream. * @throws IOException If an error occurs writing to the stream. */ public static final void writeStartDocument(StartDocument start, Writer writer) throws IOException { String version = start.getVersion(); String encoding = start.getCharacterEncodingScheme(); if (start.standaloneSet()) { writeStartDocument(version, encoding, start.isStandalone(), writer); } else { writeStartDocument(version, encoding, writer); } }
(start.getCharacterEncodingScheme())) return false; else if (start.getCharacterEncodingScheme() != null) return false;
public boolean equals(Object o) { if (o == this) return true; if (o == null) return false; if (!(o instanceof StartDocument)) return false; StartDocument other = (StartDocument) o; return (encodingSet() == other.encodingSet()) && (isStandalone() == other.isStandalone()) && (standaloneSet() == other.standaloneSet()) && stringsWithNullsEqual(getCharacterEncodingScheme(), other.getCharacterEncodingScheme()) && stringsWithNullsEqual(getSystemId(), other.getSystemId()) && stringsWithNullsEqual(getVersion(), other.getVersion()) ; }