Class MarkdownDocParserSession
java.lang.Object
org.apache.juneau.marshall.ContextSession
org.apache.juneau.marshall.MarshallingSession
org.apache.juneau.marshall.parser.ParserSession
org.apache.juneau.marshall.parser.ReaderParserSession
org.apache.juneau.marshall.markdown.MarkdownParserSession
org.apache.juneau.marshall.markdown.MarkdownDocParserSession
- All Implemented Interfaces:
BeanSession,ConverterSession,RecordReadable
Session object for
MarkdownDocParser.
Parses Markdown documents (headings + tables) produced by MarkdownDocSerializer
into Java objects by mapping heading sections to nested bean properties.
Notes:
- This class is not thread safe and is typically discarded after one use.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.apache.juneau.marshall.markdown.MarkdownParserSession
MarkdownParserSession.DefaultBuilder -
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
ConstructorsModifierConstructorDescriptionprotectedConstructor. -
Method Summary
Modifier and TypeMethodDescriptioncreate(MarkdownDocParser ctx) Creates a new builder for this object.protected <T> TdoRead(ParserPipe pipe, ClassMeta<T> type) Workhorse method.protected StringgetHeadingText(String line, int level) Returns the heading text if the given line is a heading at the specified level, else null.protected booleanisBulletLine(String line) Returns whether a line is a bullet list item.protected booleanisHeadingLine(String line, int level) Returns whether the given line is a heading at the specified level.protected ObjectreadBeanFromDoc(List<String> lines, ClassMeta<?> sType, Object outer, int level) Parses a bean from Markdown document structure (headings + tables).protected <T> TreadDocAnything(List<String> lines, ClassMeta<T> eType, Object outer, int level) Main document-mode parse dispatch.protected ObjectreadMapFromDoc(List<String> lines, ClassMeta<?> sType, Object outer, int level) Parses a map from Markdown document structure.segmentBySections(List<String> lines, int sectionLevel) Segments document lines into sections by heading level.Methods inherited from class org.apache.juneau.marshall.markdown.MarkdownParserSession
create, isRecordStreaming, isSeparatorRow, readAllLines, readAnything, readBulletList, readCellValue, readKeyValueTable, readMultiColumnTable, readRecords, readRow, readTable, splitTableRow, unescapeCellMethods 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
-
MarkdownDocParserSession
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.
-
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 classMarkdownParserSession- 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.
-
readDocAnything
protected <T> T readDocAnything(List<String> lines, ClassMeta<T> eType, Object outer, int level) throws IOException, ParseException Main document-mode parse dispatch.- Type Parameters:
T- The target type.- Parameters:
lines- All input lines.eType- The expected type.outer- The outer object.level- The expected heading level for the top-level section.- Returns:
- The parsed object.
- Throws:
IOException- Thrown by underlying stream.ParseException- If parsing fails.
-
readBeanFromDoc
protected Object readBeanFromDoc(List<String> lines, ClassMeta<?> sType, Object outer, int level) throws IOException, ParseException Parses a bean from Markdown document structure (headings + tables).The top-level heading (title) is ignored. Inline key/value tables at the current heading level populate simple properties. Sub-headings at
level+1map to nested bean properties.- Parameters:
lines- All document lines.sType- The bean type.outer- The outer object.level- The current heading level.- Returns:
- The parsed bean.
- Throws:
ParseException- If parsing fails.IOException
-
readMapFromDoc
protected Object readMapFromDoc(List<String> lines, ClassMeta<?> sType, Object outer, int level) throws IOException, ParseException Parses a map from Markdown document structure.- Parameters:
lines- All document lines.sType- The map type.outer- The outer object.level- The current heading level.- Returns:
- The parsed map.
- Throws:
ParseException- If parsing fails.IOException
-
segmentBySections
Segments document lines into sections by heading level.Returns a map where the key is the heading text and the value is the lines in that section. The empty-string key maps to content before the first sub-heading (root content).
- Parameters:
lines- All document lines.sectionLevel- The heading level that defines section boundaries.- Returns:
- Map of section name → section lines.
-
getHeadingText
Returns the heading text if the given line is a heading at the specified level, else null.- Parameters:
line- The input line.level- The heading level to check.- Returns:
- The heading text or null.
-
isHeadingLine
Returns whether the given line is a heading at the specified level.- Parameters:
line- The input line.level- The heading level.- Returns:
- Whether it is a heading at that level.
-
isBulletLine
Returns whether a line is a bullet list item.- Parameters:
line- The input line.- Returns:
- Whether it is a bullet item.
-