Class XmlParserSession
- All Implemented Interfaces:
BeanSession,ConverterSession,ArrayRecordReadable,RecordReadable
- Direct Known Subclasses:
HtmlParserSession
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder class.static final classConcrete default builder leaf for the non-subclassedcreate()path (CRTP terminal). -
Field Summary
Fields inherited from class org.apache.juneau.marshall.parser.ParserSession
DEFAULT_MAX_PARSE_DEPTHFields inherited from class org.apache.juneau.marshall.MarshallingSession
NAME_PROPERTY_NAME -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedXmlParserSession(XmlParserSession.Builder<?> builder) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic XmlParserSession.Builder<?>Creates a new builder for this object.protected final StringDecodes and trims the specified string.protected <T> TdoRead(ParserPipe pipe, ClassMeta<T> type) Workhorse method.protected <E> Collection<E>doReadIntoCollection(ParserPipe pipe, Collection<E> c, Type elementType) Implementation method.protected <K,V> Map<K, V> doReadIntoMap(ParserPipe pipe, Map<K, V> m, Type keyType, Type valueType) Implementation method.protected StringReturns the text content of the current XML element.protected final XMLEventAllocatorXML event allocator.protected final XMLReporterXML reporter.protected final XMLResolverXML resolver.protected XmlBeanMetagetXmlBeanMeta(BeanMeta<?> bm) Returns the language-specific metadata on the specified bean.protected XmlBeanPropertyMetaReturns the language-specific metadata on the specified bean property.protected XmlClassMetagetXmlClassMeta(ClassMeta<?> cm) Returns the language-specific metadata on the specified class.protected final XmlReadergetXmlReader(ParserPipe pipe) Wrap the specified reader in a STAX reader based on settings in this context.booleanThe XML array-record cursor is buffered/RecordAdapter-backed, not O(1) streaming.protected final booleanPreserve root element during generalized parsing.booleanThe XML record cursor is buffered/RecordAdapter-backed, not O(1) streaming.protected final booleanEnable validation.protected booleanReturnstrue if the current element is a whitespace element.protected <T> TreadAnything(ClassMeta<T> eType, String currAttr, XmlReader r, Object outer, boolean isRoot, BeanPropertyMeta pMeta) Workhorse method.readArrayRecords(Object input) Buffered array-elementRecordReaderfor XML, bound to this live session.readArrayRecords(Object input, String rootElementName) Buffered array-elementRecordReaderthat honors the caller-specified root element name.readRecords(Object input) Opens a whole-value pull-parser cursor over an XML document, bound to this live session.protected StringParses the current element as text.protected StringParses the current whitespace element.Methods inherited from class org.apache.juneau.marshall.parser.ReaderParserSession
create, createPipe, getStreamCharset, isReaderParser, propertiesMethods inherited from class org.apache.juneau.marshall.parser.ParserSession
allocateLocal, cast, checkRequired, convertAttrToType, create, doReadToBeanConsumer, enterParseDepth, exitParseDepth, getCalendarFormat, getClassMeta, getDateFormat, getDebugOutputLines, getDurationFormat, getInputAsString, getJavaMethod, getLastLocation, getListener, getListener, getListenerClass, getLocaleFormat, getNulls, getOuter, getPeriodFormat, getPosition, getSchema, getStringBuilder, getTemporalFormat, getTimeZoneFormat, isAutoCloseStreams, isTrimStrings, isUnbuffered, mark, onBeanSetterException, onUnknownProperty, parentBean, read, read, read, read, read, read, readArgs, readCalendar, readDate, readDuration, readIntoCollection, readIntoMap, readPeriod, readTemporal, readToBeanConsumer, returnStringBuilder, setCurrentClass, setCurrentProperty, setName, setParent, setPipe, swapParentBean, trim, trim, unmark, unswapMethods inherited from class org.apache.juneau.marshall.MarshallingSession
addWarning, convertToMemberType, convertToMemberType, convertToMemberType, convertToType, convertToType, convertToType, convertToType, create, get, getActiveView, getAnnotationProvider, getArgsClassMeta, getBeanClassVisibility, getBeanConstructorVisibility, getBeanDictionary, getBeanFieldVisibility, getBeanMeta, getBeanMethodVisibility, getBeanRegistry, getBeanTypePropertyName, getBeanTypePropertyName, getClassLoader, getClassMeta, getClassMeta, getClassMetaForObject, getClassMetaForObject, getLocale, getMarshallingContext, getMediaType, getNotBeanClasses, getNotBeanPackagesNames, getPropertyNamer, getSwaps, getTimeZone, getTimeZoneId, isBean, isBean, isBeanMapPutReturnsOldValue, isBeansRequireDefaultConstructor, isBeansRequireSerializable, isBeansRequireSettersForGetters, isBeansRequireSomeProperties, isFindFluentSetters, isIgnoreInvocationExceptionsOnGetters, isIgnoreInvocationExceptionsOnSetters, isIgnoreMissingSetters, isIgnoreUnknownBeanProperties, isIgnoreUnknownNullBeanProperties, isPropertyInActiveView, isRecordComponentOrder, isUnsortedProperties, isUseInterfaceProxies, isUseJavaBeanIntrospector, isValidateSchema, newBean, newBean, newBeanMap, newBeanMap, newGenericList, newGenericMap, newGenericMap, object, parseToList, parseToMap, string, toArray, toBeanMap, toBeanMap, toBeanMapMethods inherited from class org.apache.juneau.marshall.ContextSession
checkForWarnings, getContext, getSessionProperties, getWarnings, isDebug, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.juneau.commons.conversion.ConverterSession
get
-
Constructor Details
-
XmlParserSession
Constructor.- Parameters:
builder- The builder for this object.
-
-
Method Details
-
create
Creates a new builder for this object.- Parameters:
ctx- The context creating this session.
Cannot benull .- Returns:
- A new builder.
-
decodeString
Decodes and trims the specified string.Any
'_x####_' sequences in the string will be decoded.- Parameters:
s- The string to be decoded.
Can benull (returnsnull ).- Returns:
- The decoded string, or
null if the input wasnull .
-
doRead
protected <T> T doRead(ParserPipe pipe, ClassMeta<T> type) throws IOException, ParseException, ExecutableException Description copied from class:ParserSessionWorkhorse method.Subclasses are expected to implement this method or
Parser.doRead(ParserSession,ParserPipe,ClassMeta).The default implementation of this method simply calls
Parser.doRead(ParserSession,ParserPipe,ClassMeta).- Overrides:
doReadin classParserSession- Type Parameters:
T- The class type of the object to create.- Parameters:
pipe- Where to get the input from.type- The class type of the object to create. Ifnull orObject., object type is based on what's being parsed. For example, when parsing JSON text, it may return aclass String ,Number ,JsonMap , etc...- Returns:
- The parsed object.
- Throws:
IOException- Thrown by underlying stream.ParseException- Malformed input encountered.ExecutableException- Exception occurred on invoked constructor/method/field.
-
doReadIntoCollection
protected <E> Collection<E> doReadIntoCollection(ParserPipe pipe, Collection<E> c, Type elementType) throws Exception Description copied from class:ParserSessionImplementation method.Default implementation throws an
UnsupportedOperationException.- Overrides:
doReadIntoCollectionin classParserSession- Type Parameters:
E- The element type.- Parameters:
pipe- The parser input.c- The collection being loaded.elementType- The class type of the elements, ornull to default to whatever is being parsed.- Returns:
- The same collection that was passed in to allow this method to be chained.
- Throws:
Exception- If thrown from underlying stream, or if the input contains a syntax error or is malformed.
-
doReadIntoMap
protected <K,V> Map<K,V> doReadIntoMap(ParserPipe pipe, Map<K, V> m, Type keyType, Type valueType) throws ExceptionDescription copied from class:ParserSessionImplementation method.Default implementation throws an
UnsupportedOperationException.- Overrides:
doReadIntoMapin classParserSession- Type Parameters:
K- The key type.V- The value type.- Parameters:
pipe- The parser input.m- The map being loaded.keyType- The class type of the keys, ornull to default toString..class valueType- The class type of the values, ornull to default to whatever is being parsed.- Returns:
- The same map that was passed in to allow this method to be chained.
- Throws:
Exception- If thrown from underlying stream, or if the input contains a syntax error or is malformed.
-
readRecords
Opens a whole-value pull-parser cursor over an XML document, bound to this live session.Because XML's wire format (attributes, namespaces, mixed content) is non-trivial to expose as a fine-grained token cursor, this implementation supports only the cursor-level POJO bridge —
read(...)delegates to the polymorphicParserSession.read(Object, Class)entry point.- Specified by:
readRecordsin interfaceRecordReadable- Parameters:
input- The input.- Returns:
- A new
RecordReadercursor. - Throws:
IOException- If a problem occurred opening the underlying input.
-
readArrayRecords
Buffered array-elementRecordReaderfor XML, bound to this live session. Callsparse(input, List.class, Object.class)once and iterates the result.For caller-specified-root semantics use
readArrayRecords(Object, String).- Specified by:
readArrayRecordsin interfaceArrayRecordReadable- Parameters:
input- The input.- Returns:
- A buffered
RecordReader. - Throws:
IOException- If a problem occurred reading the input.
-
readArrayRecords
Buffered array-elementRecordReaderthat honors the caller-specified root element name.The document is parsed once into a generic structure and the records to yield are selected by the supplied
rootElementName:- If the document root is a wrapper element (parses to a
Map) that contains a child namedrootElementName, that child's value supplies the records (a repeated child element parses to aList; a single occurrence yields one record). Sibling elements with other names are ignored. - If the document root is an array wrapper (parses to a
List, e.g. Juneau's<array>envelope), its already-unwrapped elements are the records and the hint is a no-op. - A scalar root yields a single record.
A
null rootElementNameis equivalent toreadArrayRecords(Object). The cursor is buffered (RecordReader.isStreaming()==false ); see175abItem 3 for why true element-at-a-time XML streaming is left for a demand-driven StAX cursor.- Specified by:
readArrayRecordsin interfaceArrayRecordReadable- Parameters:
input- The input.rootElementName- The name of the wrapping/child element whose occurrences are the records.null defers toreadArrayRecords(Object).- Returns:
- A buffered
RecordReader. - Throws:
IOException- If a problem occurred reading the input.
- If the document root is a wrapper element (parses to a
-
isRecordStreaming
The XML record cursor is buffered/RecordAdapter-backed, not O(1) streaming.- Specified by:
isRecordStreamingin interfaceRecordReadable- Returns:
- Always
false .
-
isArrayRecordStreaming
The XML array-record cursor is buffered/RecordAdapter-backed, not O(1) streaming.- Specified by:
isArrayRecordStreamingin interfaceArrayRecordReadable- Returns:
- Always
false .
-
getElementText
Returns the text content of the current XML element.Any
'_x####_' sequences in the string will be decoded.Leading and trailing whitespace (unencoded) will be trimmed from the result.
- Parameters:
r- The reader to read the element text from.
Must not benull .- Returns:
- The decoded text.
null if the text consists of the sequence'_x0000_' . - Throws:
XMLStreamException- Thrown by underlying reader.IOException- Thrown by underlying stream.ParseException- Malformed input encountered.
-
getEventAllocator
XML event allocator.- Returns:
- The
XMLEventAllocatorassociated with this parser, ornull if there isn't one. - See Also:
-
getReporter
XML reporter.- Returns:
- The
XMLReporterassociated with this parser, ornull if there isn't one. - See Also:
-
getResolver
XML resolver.- Returns:
- The
XMLResolverassociated with this parser, ornull if there isn't one. - See Also:
-
getXmlBeanMeta
Returns the language-specific metadata on the specified bean.- Parameters:
bm- The bean to return the metadata on.- Returns:
- The metadata.
-
getXmlBeanPropertyMeta
Returns the language-specific metadata on the specified bean property.- Parameters:
bpm- The bean property to return the metadata on.- Returns:
- The metadata.
-
getXmlClassMeta
Returns the language-specific metadata on the specified class.- Parameters:
cm- The class to return the metadata on.- Returns:
- The metadata.
-
getXmlReader
Wrap the specified reader in a STAX reader based on settings in this context.- Parameters:
pipe- The parser input.
Must not benull .- Returns:
- The new STAX reader.
- Throws:
IOException- Thrown by underlying stream.XMLStreamException- Unexpected XML processing error.
-
isPreserveRootElement
Preserve root element during generalized parsing.- Returns:
true if when parsing into a genericJsonMap, the map will contain a single entry whose key is the root element name.- See Also:
-
isValidating
Enable validation.- Returns:
true if XML document will be validated.- See Also:
-
isWhitespaceElement
Returnstrue if the current element is a whitespace element.For the XML parser, this always returns
false . However, the HTML parser defines various whitespace elements such as"br" and"sp" .- Parameters:
r- The XML stream reader to read the current event from.- Returns:
true if the current element is a whitespace element.
-
readAnything
protected <T> T readAnything(ClassMeta<T> eType, String currAttr, XmlReader r, Object outer, boolean isRoot, BeanPropertyMeta pMeta) throws IOException, ParseException, ExecutableException, XMLStreamException Workhorse method.- Type Parameters:
T- The expected type of object.- Parameters:
eType- The expected type of object.
Can benull , in which case the genericObjecttype is used and the actual type is auto-detected from the XML.currAttr- The current bean property name.
Can benull if not being parsed as a named bean property (e.g. the root value).r- The reader.
Must not benull .outer- The outer object.
Can benull if there is no enclosing (outer) object; the parsed object is then not linked to a parent.isRoot- Iftrue , then we're serializing a root element in the document.pMeta- The bean property metadata.
Can benull if no bean property metadata applies (e.g. the root value or an unknown property).- Returns:
- The parsed object, or
null if the element represents anull value. - Throws:
IOException- Thrown by underlying stream.ParseException- Malformed input encountered.ExecutableException- Exception occurred on invoked constructor/method/field.XMLStreamException- Malformed XML encountered.
-
readText
Parses the current element as text.- Parameters:
r- The input reader.
Must not benull .- Returns:
- The parsed text.
- Throws:
XMLStreamException- Thrown by underlying reader.IOException- Thrown by underlying stream.ParseException- Malformed input encountered.
-
readWhitespaceElement
protected String readWhitespaceElement(XmlReader r) throws IOException, XMLStreamException, ParseException Parses the current whitespace element.For the XML parser, this always returns
null since there is no concept of a whitespace element. However, the HTML parser defines various whitespace elements such as"br" and"sp" .- Parameters:
r- The XML stream reader to read the current event from.- Returns:
- The whitespace character or characters.
- Throws:
XMLStreamException- Thrown by underlying reader.IOException- Thrown by underlying stream.ParseException- Malformed input encountered.
-