Class DocService

java.lang.Object
org.ctan.site.services.DocService

public class DocService extends Object
The class 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.

  • Constructor Details

    • DocService

      public DocService(File base)
      This is the constructor for DocService.
      Parameters:
      base - the base directory
  • Method Details

    • analyse

      public DocService.DocInfo analyse(File file)
      The method analyse provides means to TODO gene.
      Parameters:
      file - the input file
      Returns:
      the info instance or NO_INFO
    • analyse

      public DocService.DocInfo analyse(String path)
      Analyses the document at the given path and returns its metadata.

      The prefixes http://mirrors.ctan.org/ and http://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_INFO is returned.

      Parameters:
      path - the path to the document, relative to the base directory; must not be null
      Returns:
      a DocService.DocInfo with the extracted metadata; never null
    • analyseHtml

      public DocService.DocInfo analyseHtml(File file)
      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 be null.

      Parameters:
      file - the HTML file to analyse; must not be null
      Returns:
      a DocService.DocInfo with the title, or NO_INFO if no <title> element was found or an I/O error occurred
    • analyseMarkdown

      public DocService.DocInfo analyseMarkdown(File file)
      Extracts metadata from a Markdown file.

      If the file begins with a YAML front-matter block (delimited by ---), the title and author keys 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 be null.

      Parameters:
      file - the Markdown file to analyse; must not be null
      Returns:
      a DocService.DocInfo with the extracted metadata, or NO_INFO if nothing could be extracted or an I/O error occurred
    • analysePdf

      public DocService.DocInfo analysePdf(File file)
      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 null is returned.

      Parameters:
      file - the PDF file to analyse; must not be null
      Returns:
      a DocService.DocInfo with the extracted metadata
    • analysePs

      public DocService.DocInfo analysePs(File file)
      Extracts metadata from a Postscript file.

      If the file begins with a comments block (lines starting with %%), the Title key is read from it. Author and possibly page count are not available in the comments block and will be null then.

      Parameters:
      file - the Postscript file to analyse; must not be null
      Returns:
      a DocService.DocInfo with the extracted metadata, or NO_INFO if nothing could be extracted or an I/O error occurred