Class MarkdownParserSession
- All Implemented Interfaces:
BeanSession,ConverterSession,RecordReadable
- Direct Known Subclasses:
MarkdownDocParserSession
MarkdownParser.
Parses Markdown tables and bulleted lists into Java objects.
Notes:
- This class is not thread safe and is typically discarded after one use.
-
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
ConstructorsModifierConstructorDescriptionprotectedMarkdownParserSession(MarkdownParserSession.Builder<?> builder) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic MarkdownParserSession.Builder<?>create(MarkdownParser ctx) Creates a new builder for this object.protected <T> TdoRead(ParserPipe pipe, ClassMeta<T> type) Workhorse method.booleanStreaming-quality signal queryable before opening a cursor.protected booleanisSeparatorRow(String line) Returns whether a table row is a separator row (e.g.Reads all lines from the given reader.protected <T> TreadAnything(List<String> lines, ClassMeta<T> eType, Object outer, BeanPropertyMeta pMeta) Main parse dispatch method.protected ObjectreadBulletList(List<String> lines, ClassMeta<?> eType, Object outer) Parses a Markdown bulleted list into a collection or array.protected <T> TreadCellValue(String val, ClassMeta<T> eType, Object outer) Converts a raw Markdown table cell string to the target type.protected ObjectParses a 2-column key/value Markdown table.protected ObjectreadMultiColumnTable(List<String> headers, List<String> dataLines, ClassMeta<?> eType, Object outer) Parses a multi-column Markdown table (N columns).readRecords(Object input) Opens a low-levelRecordReadercursor over the specified input.protected ObjectParses a single data row into the specified element type.protected ObjectParses a Markdown table (either 2-column key/value or multi-column).splitTableRow(String line) Splits a Markdown table row into its cell values, stripping leading/trailing whitespace and pipes.protected StringUnescapes Markdown table cell escape sequences.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, doReadIntoCollection, doReadIntoMap, 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
-
MarkdownParserSession
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.
-
readRecords
Description copied from interface:RecordReadableOpens a low-levelRecordReadercursor over the specified input.When invoked on a convenience
Parserthe cursor is opened with default session args (mirroringread(...)). Callers that need request-derived configuration (locale, timezone, schema, swaps) should instead callcreateSession(args).build()and invoke this method on the resultingParserSession(which is also aRecordReadable).- Specified by:
readRecordsin interfaceRecordReadable- Parameters:
input- The input. Subtypes define the supported types (typicallyReader/CharSequence/InputStream/byte[]/File).- Returns:
- A new
RecordReadercursor. - Throws:
IOException- If a problem occurred reading the underlying input.
-
isRecordStreaming
Description copied from interface:RecordReadableStreaming-quality signal queryable before opening a cursor.- Specified by:
isRecordStreamingin interfaceRecordReadable- Returns:
true ifRecordReadable.readRecords(Object)returns an O(1)-memory streaming cursor;false for buffered (whole-value) formats backed byRecordAdapter.
-
doRead
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.
-
readAnything
protected <T> T readAnything(List<String> lines, ClassMeta<T> eType, Object outer, BeanPropertyMeta pMeta) throws IOException, ParseException Main parse dispatch method.- Type Parameters:
T- The target type.- Parameters:
lines- All input lines.eType- The expected type.outer- The outer object (for inner class instantiation).pMeta- The parent bean property meta (may be null).- Returns:
- The parsed object.
- Throws:
IOException- Thrown by underlying stream.ParseException- If parsing fails.
-
readTable
protected Object readTable(List<String> lines, ClassMeta<?> eType, Object outer) throws ParseException Parses a Markdown table (either 2-column key/value or multi-column).- Parameters:
lines- All input lines.eType- The expected type.outer- The outer object.- Returns:
- The parsed object.
- Throws:
ParseException- If parsing fails.
-
readKeyValueTable
protected Object readKeyValueTable(List<String> headers, List<String> dataLines, ClassMeta<?> eType, Object outer) throws ParseException Parses a 2-column key/value Markdown table.- Parameters:
headers- The header names.dataLines- The data row lines.eType- The expected type.outer- The outer object.- Returns:
- The parsed bean, map, or other object.
- Throws:
ParseException- If parsing fails.
-
readMultiColumnTable
protected Object readMultiColumnTable(List<String> headers, List<String> dataLines, ClassMeta<?> eType, Object outer) throws ParseException Parses a multi-column Markdown table (N columns).- Parameters:
headers- The column header names.dataLines- The data row lines.eType- The expected type.outer- The outer object.- Returns:
- The parsed list of beans, maps, or other objects.
- Throws:
ParseException- If parsing fails.
-
readRow
protected Object readRow(List<String> headers, List<String> cells, ClassMeta<?> eType, Object outer) throws ParseException Parses a single data row into the specified element type.- Parameters:
headers- The column header names.cells- The cell values for this row.eType- The element type.outer- The outer object.- Returns:
- The parsed element.
- Throws:
ParseException- If parsing fails.
-
readBulletList
protected Object readBulletList(List<String> lines, ClassMeta<?> eType, Object outer) throws ParseException Parses a Markdown bulleted list into a collection or array.- Parameters:
lines- All input lines.eType- The expected type.outer- The outer object.- Returns:
- The parsed collection, array, or single element.
- Throws:
ParseException- If parsing fails.
-
readCellValue
Converts a raw Markdown table cell string to the target type.If the cell matches the configured null value, returns
null. If the cell is backtick-wrapped JSON5, parses viaJson5Parser. Otherwise, attempts numeric/boolean auto-detection when the target type isObject.- Type Parameters:
T- The target type.- Parameters:
val- The raw cell string (already unescaped).eType- The target type.outer- The outer object (parent bean) for @ParentProperty support.- Returns:
- The parsed value.
- Throws:
ParseException- If parsing fails.
-
splitTableRow
Splits a Markdown table row into its cell values, stripping leading/trailing whitespace and pipes.- Parameters:
line- The raw table row line.- Returns:
- The list of trimmed cell values.
-
isSeparatorRow
Returns whether a table row is a separator row (e.g.|---|---|).- Parameters:
line- The table row line.- Returns:
- Whether it is a separator row.
-
readAllLines
Reads all lines from the given reader.- Parameters:
r- The reader.
Must not benull .- Returns:
- All lines.
- Throws:
IOException- Thrown by underlying stream.
-
unescapeCell
Unescapes Markdown table cell escape sequences.- Parameters:
s- The escaped cell value.
Can benull (returnsnull ).- Returns:
- The unescaped value. Returns
null if the input wasnull .
-