Class DocService
DocService analyses document files and extracts
metadata such as title, author, and page count.
Supported formats are PDF (.pdf), Markdown (.md), and HTML
(.html, .htm). All paths are resolved relative to the
texarchive base directory supplied at construction time.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe classDocInfocontains the transport object for the document meta data. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionThe methodanalyseprovides means to TODO gene.Analyses the document at the given path and returns its metadata.analyseHtml(File file) Extracts metadata from a HTML file.analyseMarkdown(File file) Extracts metadata from a Markdown file.analysePdf(File file) Extracts metadata from a PDF document using Apache PDFBox.Extracts metadata from a Postscript file.
-
Constructor Details
-
DocService
This is the constructor forDocService.- Parameters:
base- the base directory
-
-
Method Details
-
analyse
The methodanalyseprovides means to TODO gene.- Parameters:
file- the input file- Returns:
- the info instance or
NO_INFO
-
analyse
Analyses the document at the given path and returns its metadata.The prefixes
http://mirrors.ctan.org/andhttp://mirrors.ctan.org/of the path are stripped.The file type is determined by the path suffix. If the file cannot be read, or the suffix is not recognised,
NO_INFOis returned.- Parameters:
path- the path to the document, relative to the base directory; must not benull- Returns:
- a
DocService.DocInfowith the extracted metadata; nevernull
-
analyseHtml
Extracts metadata from a HTML file.Scans the file line by line for a
<title>element and returns its text content as the document title. Author and page count are not extracted from HTML and will benull.- Parameters:
file- the HTML file to analyse; must not benull- Returns:
- a
DocService.DocInfowith the title, orNO_INFOif no<title>element was found or an I/O error occurred
-
analyseMarkdown
Extracts metadata from a Markdown file.If the file begins with a YAML front-matter block (delimited by
---), thetitleandauthorkeys are read from it. Otherwise the first ATX level-1 heading (# …) is used as the title. Author and page count are not available outside of front matter and will benull.- Parameters:
file- the Markdown file to analyse; must not benull- Returns:
- a
DocService.DocInfowith the extracted metadata, orNO_INFOif nothing could be extracted or an I/O error occurred
-
analysePdf
Extracts metadata from a PDF document using Apache PDFBox.Reads title, author, and page count from the PDF document information dictionary. Any I/O failure is logged at error level and
nullis returned.- Parameters:
file- the PDF file to analyse; must not benull- Returns:
- a
DocService.DocInfowith the extracted metadata
-
analysePs
Extracts metadata from a Postscript file.If the file begins with a comments block (lines starting with
%%), theTitlekey is read from it. Author and possibly page count are not available in the comments block and will benullthen.- Parameters:
file- the Postscript file to analyse; must not benull- Returns:
- a
DocService.DocInfowith the extracted metadata, orNO_INFOif nothing could be extracted or an I/O error occurred
-