Java Code Examples for javax.xml.stream.XMLStreamReader#getCharacterEncodingScheme()
The following examples show how to use
javax.xml.stream.XMLStreamReader#getCharacterEncodingScheme() .
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: XmlEntityConsumer.java From cloud-odata-java with Apache License 2.0 | 6 votes |
private XMLStreamReader createStaxReader(final Object content) throws XMLStreamException, EntityProviderException { XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_VALIDATING, false); factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true); if (content == null) { throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT .addContent("Got not supported NULL object as content to de-serialize.")); } if (content instanceof InputStream) { XMLStreamReader streamReader = factory.createXMLStreamReader((InputStream) content, DEFAULT_CHARSET); // verify charset encoding set in content is supported (if not set UTF-8 is used as defined in 'http://www.w3.org/TR/2008/REC-xml-20081126/') String characterEncodingInContent = streamReader.getCharacterEncodingScheme(); if (characterEncodingInContent != null && !DEFAULT_CHARSET.equalsIgnoreCase(characterEncodingInContent)) { throw new EntityProviderException(EntityProviderException.UNSUPPORTED_CHARACTER_ENCODING.addContent(characterEncodingInContent)); } return streamReader; } throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT .addContent("Found not supported content of class '" + content.getClass() + "' to de-serialize.")); }
Example 2
Source File: EncodingDetector.java From Tomcat8-Source-Read with MIT License | 5 votes |
private String getPrologEncoding(InputStream stream) { String encoding = null; try { XMLStreamReader xmlStreamReader = XML_INPUT_FACTORY.createXMLStreamReader(stream); encoding = xmlStreamReader.getCharacterEncodingScheme(); } catch (XMLStreamException e) { // Ignore } return encoding; }
Example 3
Source File: XmlHelper.java From olingo-odata2 with Apache License 2.0 | 5 votes |
public static XMLStreamReader createStreamReader(final Object content) throws EntityProviderException { if (content == null) { throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT .addContent("Got not allowed NULL parameter for creation of XMLStreamReader.")); } XMLStreamReader streamReader; try { XMLInputFactory factory = getXMLInputFactory(); factory.setProperty(XMLInputFactory.IS_VALIDATING, false); factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true); factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); factory.setProperty(XMLInputFactory.SUPPORT_DTD, false); if (content instanceof InputStream) { streamReader = factory.createXMLStreamReader((InputStream) content, DEFAULT_CHARSET); // verify charset encoding set in content is supported (if not set UTF-8 is used as defined in // v'http://www.w3.org/TR/2008/REC-xml-20081126/') String characterEncodingInContent = streamReader.getCharacterEncodingScheme(); if (characterEncodingInContent != null && !DEFAULT_CHARSET.equalsIgnoreCase(characterEncodingInContent)) { throw new EntityProviderException(EntityProviderException .UNSUPPORTED_CHARACTER_ENCODING.addContent(characterEncodingInContent)); } } else { throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT .addContent("Found not supported content of class '" + content.getClass() + "' to de-serialize.")); } return streamReader; } catch (XMLStreamException e) { throw new EntityProviderException(EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getClass() .getSimpleName()), e); } }
Example 4
Source File: FileReaderFactory.java From analysis-model with MIT License | 5 votes |
@Nullable private Charset detectCharset(final InputStream inputStream) throws IOException { try (Reader reader = new InputStreamReader(inputStream, StandardCharsets.US_ASCII)) { XMLStreamReader xmlStreamReader = new SecureXmlParserFactory().createXmlStreamReader(reader); String encodingTitle = xmlStreamReader.getCharacterEncodingScheme(); if (encodingTitle != null) { return Charset.forName(encodingTitle); } } catch (IllegalArgumentException ignore) { // Ignore it the charset couldn't be detected } return null; }
Example 5
Source File: StAXEventAllocatorBase.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
XMLEvent getXMLEvent(XMLStreamReader reader){ XMLEvent event = null; //returns the current event int eventType = reader.getEventType(); //this needs to be set before creating events factory.setLocation(reader.getLocation()); switch(eventType){ case XMLEvent.START_ELEMENT: { StartElementEvent startElement = (StartElementEvent)factory.createStartElement(reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); addAttributes(startElement,reader); addNamespaces(startElement, reader); //need to fix it along with the Reader //setNamespaceContext(startElement,reader); event = startElement; break; } case XMLEvent.END_ELEMENT: { EndElementEvent endElement = (EndElementEvent)factory.createEndElement( reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); addNamespaces(endElement,reader); event = endElement ; break; } case XMLEvent.PROCESSING_INSTRUCTION: { event = factory.createProcessingInstruction(reader.getPITarget(),reader.getPIData()); break; } case XMLEvent.CHARACTERS: { if (reader.isWhiteSpace()) event = factory.createSpace(reader.getText()); else event = factory.createCharacters(reader.getText()); break; } case XMLEvent.COMMENT: { event = factory.createComment(reader.getText()); break; } case XMLEvent.START_DOCUMENT: { StartDocumentEvent docEvent = (StartDocumentEvent)factory.createStartDocument( reader.getVersion(), reader.getEncoding(), reader.isStandalone()); if(reader.getCharacterEncodingScheme() != null){ docEvent.setDeclaredEncoding(true); }else{ docEvent.setDeclaredEncoding(false); } event = docEvent ; break; } case XMLEvent.END_DOCUMENT:{ EndDocumentEvent endDocumentEvent = new EndDocumentEvent() ; event = endDocumentEvent ; break; } case XMLEvent.ENTITY_REFERENCE:{ event = factory.createEntityReference(reader.getLocalName(), new EntityDeclarationImpl(reader.getLocalName(),reader.getText())); break; } case XMLEvent.ATTRIBUTE:{ event = null ; break; } case XMLEvent.DTD:{ event = factory.createDTD(reader.getText()); break; } case XMLEvent.CDATA:{ event = factory.createCData(reader.getText()); break; } case XMLEvent.SPACE:{ event = factory.createSpace(reader.getText()); break; } } return event ; }
Example 6
Source File: StAXEventAllocatorBase.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
XMLEvent getXMLEvent(XMLStreamReader reader){ XMLEvent event = null; //returns the current event int eventType = reader.getEventType(); //this needs to be set before creating events factory.setLocation(reader.getLocation()); switch(eventType){ case XMLEvent.START_ELEMENT: { StartElementEvent startElement = (StartElementEvent)factory.createStartElement(reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); addAttributes(startElement,reader); addNamespaces(startElement, reader); //need to fix it along with the Reader //setNamespaceContext(startElement,reader); event = startElement; break; } case XMLEvent.END_ELEMENT: { EndElementEvent endElement = (EndElementEvent)factory.createEndElement( reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); addNamespaces(endElement,reader); event = endElement ; break; } case XMLEvent.PROCESSING_INSTRUCTION: { event = factory.createProcessingInstruction(reader.getPITarget(),reader.getPIData()); break; } case XMLEvent.CHARACTERS: { if (reader.isWhiteSpace()) event = factory.createSpace(reader.getText()); else event = factory.createCharacters(reader.getText()); break; } case XMLEvent.COMMENT: { event = factory.createComment(reader.getText()); break; } case XMLEvent.START_DOCUMENT: { StartDocumentEvent docEvent = (StartDocumentEvent)factory.createStartDocument( reader.getVersion(), reader.getEncoding(), reader.isStandalone()); if(reader.getCharacterEncodingScheme() != null){ docEvent.setDeclaredEncoding(true); }else{ docEvent.setDeclaredEncoding(false); } event = docEvent ; break; } case XMLEvent.END_DOCUMENT:{ EndDocumentEvent endDocumentEvent = new EndDocumentEvent() ; event = endDocumentEvent ; break; } case XMLEvent.ENTITY_REFERENCE:{ event = factory.createEntityReference(reader.getLocalName(), new EntityDeclarationImpl(reader.getLocalName(),reader.getText())); break; } case XMLEvent.ATTRIBUTE:{ event = null ; break; } case XMLEvent.DTD:{ event = factory.createDTD(reader.getText()); break; } case XMLEvent.CDATA:{ event = factory.createCData(reader.getText()); break; } case XMLEvent.SPACE:{ event = factory.createSpace(reader.getText()); break; } } return event ; }
Example 7
Source File: StAXEventAllocatorBase.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
XMLEvent getXMLEvent(XMLStreamReader reader){ XMLEvent event = null; //returns the current event int eventType = reader.getEventType(); //this needs to be set before creating events factory.setLocation(reader.getLocation()); switch(eventType){ case XMLEvent.START_ELEMENT: { StartElementEvent startElement = (StartElementEvent)factory.createStartElement(reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); addAttributes(startElement,reader); addNamespaces(startElement, reader); //need to fix it along with the Reader //setNamespaceContext(startElement,reader); event = startElement; break; } case XMLEvent.END_ELEMENT: { EndElementEvent endElement = (EndElementEvent)factory.createEndElement( reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); addNamespaces(endElement,reader); event = endElement ; break; } case XMLEvent.PROCESSING_INSTRUCTION: { event = factory.createProcessingInstruction(reader.getPITarget(),reader.getPIData()); break; } case XMLEvent.CHARACTERS: { if (reader.isWhiteSpace()) event = factory.createSpace(reader.getText()); else event = factory.createCharacters(reader.getText()); break; } case XMLEvent.COMMENT: { event = factory.createComment(reader.getText()); break; } case XMLEvent.START_DOCUMENT: { StartDocumentEvent docEvent = (StartDocumentEvent)factory.createStartDocument( reader.getVersion(), reader.getEncoding(), reader.isStandalone()); if(reader.getCharacterEncodingScheme() != null){ docEvent.setDeclaredEncoding(true); }else{ docEvent.setDeclaredEncoding(false); } event = docEvent ; break; } case XMLEvent.END_DOCUMENT:{ EndDocumentEvent endDocumentEvent = new EndDocumentEvent() ; event = endDocumentEvent ; break; } case XMLEvent.ENTITY_REFERENCE:{ event = factory.createEntityReference(reader.getLocalName(), new EntityDeclarationImpl(reader.getLocalName(),reader.getText())); break; } case XMLEvent.ATTRIBUTE:{ event = null ; break; } case XMLEvent.DTD:{ event = factory.createDTD(reader.getText()); break; } case XMLEvent.CDATA:{ event = factory.createCData(reader.getText()); break; } case XMLEvent.SPACE:{ event = factory.createSpace(reader.getText()); break; } } return event ; }
Example 8
Source File: StAXEventAllocatorBase.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
XMLEvent getXMLEvent(XMLStreamReader reader){ XMLEvent event = null; //returns the current event int eventType = reader.getEventType(); //this needs to be set before creating events factory.setLocation(reader.getLocation()); switch(eventType){ case XMLEvent.START_ELEMENT: { StartElementEvent startElement = (StartElementEvent)factory.createStartElement(reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); addAttributes(startElement,reader); addNamespaces(startElement, reader); //need to fix it along with the Reader //setNamespaceContext(startElement,reader); event = startElement; break; } case XMLEvent.END_ELEMENT: { EndElementEvent endElement = (EndElementEvent)factory.createEndElement( reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); addNamespaces(endElement,reader); event = endElement ; break; } case XMLEvent.PROCESSING_INSTRUCTION: { event = factory.createProcessingInstruction(reader.getPITarget(),reader.getPIData()); break; } case XMLEvent.CHARACTERS: { if (reader.isWhiteSpace()) event = factory.createSpace(reader.getText()); else event = factory.createCharacters(reader.getText()); break; } case XMLEvent.COMMENT: { event = factory.createComment(reader.getText()); break; } case XMLEvent.START_DOCUMENT: { StartDocumentEvent docEvent = (StartDocumentEvent)factory.createStartDocument( reader.getVersion(), reader.getEncoding(), reader.isStandalone()); if(reader.getCharacterEncodingScheme() != null){ docEvent.setDeclaredEncoding(true); }else{ docEvent.setDeclaredEncoding(false); } event = docEvent ; break; } case XMLEvent.END_DOCUMENT:{ EndDocumentEvent endDocumentEvent = new EndDocumentEvent() ; event = endDocumentEvent ; break; } case XMLEvent.ENTITY_REFERENCE:{ event = factory.createEntityReference(reader.getLocalName(), new EntityDeclarationImpl(reader.getLocalName(),reader.getText())); break; } case XMLEvent.ATTRIBUTE:{ event = null ; break; } case XMLEvent.DTD:{ event = factory.createDTD(reader.getText()); break; } case XMLEvent.CDATA:{ event = factory.createCData(reader.getText()); break; } case XMLEvent.SPACE:{ event = factory.createSpace(reader.getText()); break; } } return event ; }
Example 9
Source File: StAXEventAllocatorBase.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
XMLEvent getXMLEvent(XMLStreamReader reader){ XMLEvent event = null; //returns the current event int eventType = reader.getEventType(); //this needs to be set before creating events factory.setLocation(reader.getLocation()); switch(eventType){ case XMLEvent.START_ELEMENT: { StartElementEvent startElement = (StartElementEvent)factory.createStartElement(reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); addAttributes(startElement,reader); addNamespaces(startElement, reader); //need to fix it along with the Reader //setNamespaceContext(startElement,reader); event = startElement; break; } case XMLEvent.END_ELEMENT: { EndElementEvent endElement = (EndElementEvent)factory.createEndElement( reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); addNamespaces(endElement,reader); event = endElement ; break; } case XMLEvent.PROCESSING_INSTRUCTION: { event = factory.createProcessingInstruction(reader.getPITarget(),reader.getPIData()); break; } case XMLEvent.CHARACTERS: { if (reader.isWhiteSpace()) event = factory.createSpace(reader.getText()); else event = factory.createCharacters(reader.getText()); break; } case XMLEvent.COMMENT: { event = factory.createComment(reader.getText()); break; } case XMLEvent.START_DOCUMENT: { StartDocumentEvent docEvent = (StartDocumentEvent)factory.createStartDocument( reader.getVersion(), reader.getEncoding(), reader.isStandalone()); if(reader.getCharacterEncodingScheme() != null){ docEvent.setDeclaredEncoding(true); }else{ docEvent.setDeclaredEncoding(false); } event = docEvent ; break; } case XMLEvent.END_DOCUMENT:{ EndDocumentEvent endDocumentEvent = new EndDocumentEvent() ; event = endDocumentEvent ; break; } case XMLEvent.ENTITY_REFERENCE:{ event = factory.createEntityReference(reader.getLocalName(), new EntityDeclarationImpl(reader.getLocalName(),reader.getText())); break; } case XMLEvent.ATTRIBUTE:{ event = null ; break; } case XMLEvent.DTD:{ event = factory.createDTD(reader.getText()); break; } case XMLEvent.CDATA:{ event = factory.createCData(reader.getText()); break; } case XMLEvent.SPACE:{ event = factory.createSpace(reader.getText()); break; } } return event ; }
Example 10
Source File: StAXEventAllocatorBase.java From hottub with GNU General Public License v2.0 | 4 votes |
XMLEvent getXMLEvent(XMLStreamReader reader){ XMLEvent event = null; //returns the current event int eventType = reader.getEventType(); //this needs to be set before creating events factory.setLocation(reader.getLocation()); switch(eventType){ case XMLEvent.START_ELEMENT: { StartElementEvent startElement = (StartElementEvent)factory.createStartElement(reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); addAttributes(startElement,reader); addNamespaces(startElement, reader); //need to fix it along with the Reader //setNamespaceContext(startElement,reader); event = startElement; break; } case XMLEvent.END_ELEMENT: { EndElementEvent endElement = (EndElementEvent)factory.createEndElement( reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); addNamespaces(endElement,reader); event = endElement ; break; } case XMLEvent.PROCESSING_INSTRUCTION: { event = factory.createProcessingInstruction(reader.getPITarget(),reader.getPIData()); break; } case XMLEvent.CHARACTERS: { if (reader.isWhiteSpace()) event = factory.createSpace(reader.getText()); else event = factory.createCharacters(reader.getText()); break; } case XMLEvent.COMMENT: { event = factory.createComment(reader.getText()); break; } case XMLEvent.START_DOCUMENT: { StartDocumentEvent docEvent = (StartDocumentEvent)factory.createStartDocument( reader.getVersion(), reader.getEncoding(), reader.isStandalone()); if(reader.getCharacterEncodingScheme() != null){ docEvent.setDeclaredEncoding(true); }else{ docEvent.setDeclaredEncoding(false); } event = docEvent ; break; } case XMLEvent.END_DOCUMENT:{ EndDocumentEvent endDocumentEvent = new EndDocumentEvent() ; event = endDocumentEvent ; break; } case XMLEvent.ENTITY_REFERENCE:{ event = factory.createEntityReference(reader.getLocalName(), new EntityDeclarationImpl(reader.getLocalName(),reader.getText())); break; } case XMLEvent.ATTRIBUTE:{ event = null ; break; } case XMLEvent.DTD:{ event = factory.createDTD(reader.getText()); break; } case XMLEvent.CDATA:{ event = factory.createCData(reader.getText()); break; } case XMLEvent.SPACE:{ event = factory.createSpace(reader.getText()); break; } } return event ; }
Example 11
Source File: StAXEventAllocatorBase.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
XMLEvent getXMLEvent(XMLStreamReader reader){ XMLEvent event = null; //returns the current event int eventType = reader.getEventType(); //this needs to be set before creating events factory.setLocation(reader.getLocation()); switch(eventType){ case XMLEvent.START_ELEMENT: { StartElementEvent startElement = (StartElementEvent)factory.createStartElement(reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); addAttributes(startElement,reader); addNamespaces(startElement, reader); //need to fix it along with the Reader //setNamespaceContext(startElement,reader); event = startElement; break; } case XMLEvent.END_ELEMENT: { EndElementEvent endElement = (EndElementEvent)factory.createEndElement( reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); addNamespaces(endElement,reader); event = endElement ; break; } case XMLEvent.PROCESSING_INSTRUCTION: { event = factory.createProcessingInstruction(reader.getPITarget(),reader.getPIData()); break; } case XMLEvent.CHARACTERS: { if (reader.isWhiteSpace()) event = factory.createSpace(reader.getText()); else event = factory.createCharacters(reader.getText()); break; } case XMLEvent.COMMENT: { event = factory.createComment(reader.getText()); break; } case XMLEvent.START_DOCUMENT: { StartDocumentEvent docEvent = (StartDocumentEvent)factory.createStartDocument( reader.getVersion(), reader.getEncoding(), reader.isStandalone()); if(reader.getCharacterEncodingScheme() != null){ docEvent.setDeclaredEncoding(true); }else{ docEvent.setDeclaredEncoding(false); } event = docEvent ; break; } case XMLEvent.END_DOCUMENT:{ EndDocumentEvent endDocumentEvent = new EndDocumentEvent() ; event = endDocumentEvent ; break; } case XMLEvent.ENTITY_REFERENCE:{ event = factory.createEntityReference(reader.getLocalName(), new EntityDeclarationImpl(reader.getLocalName(),reader.getText())); break; } case XMLEvent.ATTRIBUTE:{ event = null ; break; } case XMLEvent.DTD:{ event = factory.createDTD(reader.getText()); break; } case XMLEvent.CDATA:{ event = factory.createCData(reader.getText()); break; } case XMLEvent.SPACE:{ event = factory.createSpace(reader.getText()); break; } } return event ; }
Example 12
Source File: StAXEventAllocatorBase.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
XMLEvent getXMLEvent(XMLStreamReader reader){ XMLEvent event = null; //returns the current event int eventType = reader.getEventType(); //this needs to be set before creating events factory.setLocation(reader.getLocation()); switch(eventType){ case XMLEvent.START_ELEMENT: { StartElementEvent startElement = (StartElementEvent)factory.createStartElement(reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); addAttributes(startElement,reader); addNamespaces(startElement, reader); //need to fix it along with the Reader //setNamespaceContext(startElement,reader); event = startElement; break; } case XMLEvent.END_ELEMENT: { EndElementEvent endElement = (EndElementEvent)factory.createEndElement( reader.getPrefix(), reader.getNamespaceURI(), reader.getLocalName()); addNamespaces(endElement,reader); event = endElement ; break; } case XMLEvent.PROCESSING_INSTRUCTION: { event = factory.createProcessingInstruction(reader.getPITarget(),reader.getPIData()); break; } case XMLEvent.CHARACTERS: { if (reader.isWhiteSpace()) event = factory.createSpace(reader.getText()); else event = factory.createCharacters(reader.getText()); break; } case XMLEvent.COMMENT: { event = factory.createComment(reader.getText()); break; } case XMLEvent.START_DOCUMENT: { StartDocumentEvent docEvent = (StartDocumentEvent)factory.createStartDocument( reader.getVersion(), reader.getEncoding(), reader.isStandalone()); if(reader.getCharacterEncodingScheme() != null){ docEvent.setDeclaredEncoding(true); }else{ docEvent.setDeclaredEncoding(false); } event = docEvent ; break; } case XMLEvent.END_DOCUMENT:{ EndDocumentEvent endDocumentEvent = new EndDocumentEvent() ; event = endDocumentEvent ; break; } case XMLEvent.ENTITY_REFERENCE:{ event = factory.createEntityReference(reader.getLocalName(), new EntityDeclarationImpl(reader.getLocalName(),reader.getText())); break; } case XMLEvent.ATTRIBUTE:{ event = null ; break; } case XMLEvent.DTD:{ event = factory.createDTD(reader.getText()); break; } case XMLEvent.CDATA:{ event = factory.createCData(reader.getText()); break; } case XMLEvent.SPACE:{ event = factory.createSpace(reader.getText()); break; } } return event ; }