Refine search
protected static XMLStreamReader getFastinfoSetXMLStreamReader(InputStream entityStream) { InputStream in = new BufferedInputStream(entityStream, 2048); XMLStreamReader streamReader = new StAXDocumentParser(in); return streamReader; }
/** {@inheritDoc} */ @Override protected XMLStreamReader createStreamReader(InputStream input) throws XMLStreamException { StAXDocumentParser parser = new StAXDocumentParser(input); parser.setStringInterning(true); parser.setParseFragments(true); return parser; } }
int event = fastInfosetStreamReader.getEventType(); if(event == XMLStreamConstants.START_DOCUMENT) { while( !fastInfosetStreamReader.isStartElement() ) event = fastInfosetStreamReader.next(); handleStartDocument(fastInfosetStreamReader.getNamespaceContext()); event = fastInfosetStreamReader.peekNext(); if (event == XMLStreamConstants.END_ELEMENT) processNonIgnorableText(); event=fastInfosetStreamReader.next(); fastInfosetStreamReader.next(); // move beyond the end tag. throw new XMLStreamException(e);
public void set() { ch = fastInfosetStreamReader.getTextCharacters(); start = fastInfosetStreamReader.getTextStart(); length = fastInfosetStreamReader.getTextLength(); }
private void handleStartElement() throws SAXException { processUnreportedText(); for (int i = 0; i < fastInfosetStreamReader.accessNamespaceCount(); i++) { visitor.startPrefixMapping(fastInfosetStreamReader.getNamespacePrefix(i), fastInfosetStreamReader.getNamespaceURI(i)); } tagName.uri = fastInfosetStreamReader.accessNamespaceURI(); tagName.local = fastInfosetStreamReader.accessLocalName(); tagName.atts = fastInfosetStreamReader.getAttributesHolder(); visitor.startElement(tagName); }
private void handleFragmentedCharacters() throws XMLStreamException, SAXException { buffer.setLength(0); // Append characters of first character event buffer.append(fastInfosetStreamReader.getTextCharacters(), fastInfosetStreamReader.getTextStart(), fastInfosetStreamReader.getTextLength()); // Consume all character while(true) { switch(fastInfosetStreamReader.peekNext()) { case XMLStreamConstants.START_ELEMENT : processBufferedText(true); return; case XMLStreamConstants.END_ELEMENT : processBufferedText(false); return; case XMLStreamConstants.CHARACTERS : case XMLStreamConstants.CDATA : case XMLStreamConstants.SPACE : // Append characters of second and subsequent character events fastInfosetStreamReader.next(); buffer.append(fastInfosetStreamReader.getTextCharacters(), fastInfosetStreamReader.getTextStart(), fastInfosetStreamReader.getTextLength()); break; default: fastInfosetStreamReader.next(); } } }
throw new XMLStreamException( CommonResourceBundle.getInstance().getString("message.mustBeOnSTARTELEMENT"), getLocation()); int eventType = getEventType(); StringBuilder content = new StringBuilder(); while(eventType != END_ELEMENT ) { || eventType == SPACE || eventType == ENTITY_REFERENCE) { content.append(getText()); } else if(eventType == PROCESSING_INSTRUCTION || eventType == COMMENT) { throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.unexpectedEOF")); } else if(eventType == START_ELEMENT) { throw new XMLStreamException( CommonResourceBundle.getInstance().getString("message.getElementTextExpectTextOnly"), getLocation()); } else { throw new XMLStreamException( CommonResourceBundle.getInstance().getString("message.unexpectedEventType")+ getEventTypeString(eventType), getLocation()); eventType = next();
/** Reads the content of a text-only element. Precondition: * the current event is START_ELEMENT. Postcondition: * The current event is the corresponding END_ELEMENT. * @throws XMLStreamException if the current event is not a START_ELEMENT or if * a non text element is encountered */ public final String getElementText() throws XMLStreamException { if(getEventType() != START_ELEMENT) { throw new XMLStreamException( CommonResourceBundle.getInstance().getString("message.mustBeOnSTARTELEMENT"), getLocation()); } //current is StartElement, move to the next next(); return getElementText(true); } /**
/** if the current tag has already read, such as in the case EventReader's * peek() has been called, the current cursor should not move before the loop */ public final int nextTag(boolean currentTagRead) throws XMLStreamException { int eventType = getEventType(); if (!currentTagRead) { eventType = next(); } while((eventType == CHARACTERS && isWhiteSpace()) // skip whitespace || (eventType == CDATA && isWhiteSpace()) || eventType == SPACE || eventType == PROCESSING_INSTRUCTION || eventType == COMMENT) { eventType = next(); } if (eventType != START_ELEMENT && eventType != END_ELEMENT) { throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.expectedStartOrEnd"), getLocation()); } return eventType; }
/** Test if the current event is of the given type and if the namespace and name match the current namespace and name of the current event. * If the namespaceURI is null it is not checked for equality, if the localName is null it is not checked for equality. * @param type the event type * @param namespaceURI the uri of the event, may be null * @param localName the localName of the event, may be null * @throws XMLStreamException if the required values are not matched. */ public final void require(int type, String namespaceURI, String localName) throws XMLStreamException { if( type != _eventType) throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.eventTypeNotMatch", new Object[]{getEventTypeString(type)})); if( namespaceURI != null && !namespaceURI.equals(getNamespaceURI()) ) throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.namespaceURINotMatch", new Object[]{namespaceURI})); if(localName != null && !localName.equals(getLocalName())) throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.localNameNotMatch", new Object[]{localName})); return; }
private StAXDocumentParser getParser(InputStream in) { StAXDocumentParser parser = new StAXDocumentParser(in); parser.setStringInterning(true); parser.setForceStreamClose(true); parser.setInputStream(in); return parser; }
private void processNonIgnorableText() throws SAXException { textReported = true; boolean isTextAlgorithmAplied = (fastInfosetStreamReader.getTextAlgorithmBytes() != null); if (isTextAlgorithmAplied && fastInfosetStreamReader.getTextAlgorithmIndex() == EncodingAlgorithmIndexes.BASE64) { base64Data.set(fastInfosetStreamReader.getTextAlgorithmBytesClone(),null); visitor.text(base64Data); } else { if (isTextAlgorithmAplied) { fastInfosetStreamReader.getText(); } charArray.set(); visitor.text(charArray); } }
/** * Create a new (@link StAXDocumentParser} instance. * * @param in the InputStream to parse from. * @param retainState if true the parser should retain the state of * vocabulary tables for multiple parses. * @return a new {@link StAXDocumentParser} instance. */ /* package */ static StAXDocumentParser createNewStreamReader(InputStream in, boolean retainState) { StAXDocumentParser parser = new StAXDocumentParser(in); parser.setStringInterning(true); if (retainState) { /** * Create a parser vocabulary external to the parser. * This will ensure that the vocabulary will never be cleared * for each parse and will be retained (and will grow) * for each parse. */ ParserVocabulary vocabulary = new ParserVocabulary(); parser.setVocabulary(vocabulary); } return parser; }
@Override protected final XMLStreamReader getXMLStreamReader(Class<?> elementType, MediaType mediaType, Unmarshaller u, InputStream entityStream) throws XMLStreamException { StAXDocumentParser parser = new StAXDocumentParser(entityStream); // jaxb needs interning doc parser, see http://java.net/jira/browse/JERSEY-320 parser.setStringInterning(true); return parser; }
/** * @param inputstream * @throws XMLStreamException * @return */ XMLStreamReader getXMLStreamReader(Reader xmlfile) throws XMLStreamException{ ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); BufferedOutputStream bufferedStream = new BufferedOutputStream(byteStream); StAXDocumentParser sr = null; try { XML_SAX_FI convertor = new XML_SAX_FI(); convertor.convert(xmlfile, bufferedStream); ByteArrayInputStream byteInputStream = new ByteArrayInputStream(byteStream.toByteArray()); InputStream document = new BufferedInputStream(byteInputStream); sr = new StAXDocumentParser(); sr.setInputStream(document); sr.setManager(_manager); return sr; //return new StAXDocumentParser(document, _manager); } catch (Exception e) { return null; } }
public void parse(InputStream document, OutputStream events) throws Exception { if (!document.markSupported()) { document = new BufferedInputStream(document); } document.mark(4); boolean isFastInfosetDocument = Decoder.isFastInfosetDocument(document); document.reset(); if (isFastInfosetDocument) { StAXDocumentParser parser = new StAXDocumentParser(); parser.setInputStream(document); SAXEventSerializer ses = new SAXEventSerializer(events); StAX2SAXReader reader = new StAX2SAXReader(parser, ses); reader.setLexicalHandler(ses); reader.adapt(); } else { SAXParserFactory parserFactory = SAXParserFactory.newInstance(); parserFactory.setNamespaceAware(true); SAXParser parser = parserFactory.newSAXParser(); SAXEventSerializer ses = new SAXEventSerializer(events); parser.setProperty(Properties.LEXICAL_HANDLER_PROPERTY, ses); parser.parse(document, ses); } }
/** * Returns true if the cursor points to a character data event that consists of all whitespace * Application calling this method needs to cache the value and avoid calling this method again * for the same event. * @return true if the cursor points to all whitespace, false otherwise */ public final boolean isWhiteSpace() { if(isCharacters() || (_eventType == CDATA)){ char [] ch = this.getTextCharacters(); int start = this.getTextStart(); int length = this.getTextLength(); for (int i=start; i< length;i++){ if(!XMLChar.isSpace(ch[i])){ return false; } } return true; } return false; }
/** * Create a new (@link StAXDocumentParser} recyclable instance. * * @param in the InputStream to parse from. * @param retainState if true the parser should retain the state of * vocabulary tables for multiple parses. * @return a new recyclable {@link StAXDocumentParser} instance. */ /* package */ static StAXDocumentParser createNewStreamReaderRecyclable(InputStream in, boolean retainState) { StAXDocumentParser parser = new FastInfosetStreamReaderRecyclable(in); parser.setStringInterning(true); parser.setForceStreamClose(true); if (retainState) { /** * Create a parser vocabulary external to the parser. * This will ensure that the vocabulary will never be cleared * for each parse and will be retained (and will grow) * for each parse. */ ParserVocabulary vocabulary = new ParserVocabulary(); parser.setVocabulary(vocabulary); } return parser; }
public FastInfosetConnector(StAXDocumentParser fastInfosetStreamReader, XmlVisitor visitor) { super(visitor); fastInfosetStreamReader.setStringInterning(true); this.fastInfosetStreamReader = fastInfosetStreamReader; }
/** * Creates a new {@link StAXDocumentParser} (Fast Infoset {@link XMLStreamReader}) instance. * * @param is * binary stream to read from, must not be <code>null</code> * @param voc * vocabulary to use, must not be <code>null</code> * @param vocUri * uri used for declaring the external vocabulary, must not be <code>null</code> or empty * @return binary XML reader, never <code>null</code> */ public static StAXDocumentParser getFIReader( InputStream is, ParserVocabulary voc, String vocUri ) { Map<String, ParserVocabulary> externalVocabularies = new HashMap<String, ParserVocabulary>(); externalVocabularies.put( vocUri, voc ); StAXDocumentParser reader = new StAXDocumentParser( is ); reader.setExternalVocabularies( externalVocabularies ); return reader; } }