Package sk.iway.iwcm.rag.service
Class MarkdownSourceService
java.lang.Object
sk.iway.iwcm.rag.service.MarkdownSourceService
Resolves explicitly configured documentation roots in the web application or local filesystem.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordDescribes one directory node in the lazy-loaded Markdown folder selector. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondetectLanguage(String root, String sourcePath) Finds the nearest supported language directory in the configured root and root-relative source path.getDirectories(String folder, String selectedDirectory) Lists immediate eligible child directories for lazy loading in the folder selector.Lists eligible language-classified Markdown files recursively without following symbolic links.Lists selected eligible files while retaining paths relative to the configured root.Returns normalized shared language codes, including the standard documentation folder languages.getRelativePath(String configuredRoot, String fullPath) Returns an indexable path below a normalized configured root without requiring the source to exist.getRoots()Reads and normalizes the globally configured documentation roots.Builds a Docsify hash URL, or returns null for filesystem roots without a public web address.booleanisExcludedDirectory(String name) booleanisFileSystemRoot(String root) Distinguishes explicit filesystem roots from application-relative paths without checking disk state.booleanisIndexable(String sourcePath) booleanisInDirectory(String sourcePath, String directory, boolean includeSubfolders) Matches a root-relative source against a selected directory without touching the filesystem.requireDirectory(String directory) Validates a root-relative directory without requiring it to exist, allowing removal of deleted sources.requireLanguage(String language) Validates and normalizes a documentation language used for retrieval or chunk metadata.requireRoot(String folder) Returns a normalized root only when it exactly matches the configured allowlist.resolveFile(String folder, String sourcePath) Revalidates a queued source path and rejects symlinks, including links in intermediate directories.resolveRoot(String folder) Resolves an existing directory, confining virtual roots to the deployed web application.
-
Constructor Details
-
MarkdownSourceService
public MarkdownSourceService()
-
-
Method Details
-
getRoots
Reads and normalizes the globally configured documentation roots.- Returns:
- distinct roots in configuration order, or an empty list when none are configured
-
requireRoot
Returns a normalized root only when it exactly matches the configured allowlist.- Parameters:
folder- requested documentation root- Returns:
- normalized configured root
- Throws:
IllegalArgumentException- if the root is missing, invalid, or not configured
-
getRelativePath
Returns an indexable path below a normalized configured root without requiring the source to exist.- Parameters:
configuredRoot- normalized configured rootfullPath- full logical source path- Returns:
- eligible root-relative path, or
nullwhen outside the root or ineligible
-
resolveRoot
Resolves an existing directory, confining virtual roots to the deployed web application.- Parameters:
folder- configured virtual or filesystem documentation root- Returns:
- canonical directory path
- Throws:
IOException- if the root cannot be resolved to an allowed existing directory
-
getFiles
Lists eligible language-classified Markdown files recursively without following symbolic links.- Parameters:
folder- configured documentation root- Returns:
- sorted root-relative source paths
- Throws:
IOException- if the root or its files cannot be scanned
-
getFiles
public List<String> getFiles(String folder, String selectedDirectory, boolean includeSubfolders) throws IOException Lists selected eligible files while retaining paths relative to the configured root.- Parameters:
folder- configured documentation rootselectedDirectory- root-relative directory, empty or null for the rootincludeSubfolders- whether to scan descendant directories- Returns:
- sorted root-relative source paths
- Throws:
IOException- if the selected directory or its files cannot be scanned
-
getDirectories
public List<MarkdownSourceService.DirectoryNode> getDirectories(String folder, String selectedDirectory) throws IOException Lists immediate eligible child directories for lazy loading in the folder selector.- Parameters:
folder- configured documentation rootselectedDirectory- root-relative directory, empty or null for the root- Returns:
- child nodes sorted by name, excluding symbolic links and excluded directories
- Throws:
IOException- if the selected directory or its children cannot be inspected
-
requireDirectory
Validates a root-relative directory without requiring it to exist, allowing removal of deleted sources.- Parameters:
directory- root-relative directory, empty or null for the root- Returns:
- validated directory, or an empty string for the root
- Throws:
IllegalArgumentException- if the relative path is invalid or includes excluded segments
-
isInDirectory
Matches a root-relative source against a selected directory without touching the filesystem.- Parameters:
sourcePath- root-relative source pathdirectory- selected root-relative directoryincludeSubfolders- whether descendants also match- Returns:
truewhen the source is indexable and lies in the selected scope
-
resolveFile
Revalidates a queued source path and rejects symlinks, including links in intermediate directories.- Parameters:
folder- configured documentation rootsourcePath- root-relative Markdown path- Returns:
- resolved path, which may refer to a deleted source
- Throws:
IOException- if the root is unavailable, a path contains a symlink, or confinement fails
-
isFileSystemRoot
Distinguishes explicit filesystem roots from application-relative paths without checking disk state.- Parameters:
root- logical root, possiblynull- Returns:
truewhen the root starts withfile:
-
isExcludedDirectory
-
getLanguages
Returns normalized shared language codes, including the standard documentation folder languages.- Returns:
- configured language codes plus
sk,en, andcs, without duplicates
-
detectLanguage
Finds the nearest supported language directory in the configured root and root-relative source path.- Parameters:
root- documentation rootsourcePath- root-relative Markdown path- Returns:
- nearest recognized language code, or
nullfor an ineligible or unclassified source
-
requireLanguage
Validates and normalizes a documentation language used for retrieval or chunk metadata.- Parameters:
language- language code with an optional regional suffix- Returns:
- trimmed lowercase language code
- Throws:
IllegalArgumentException- if the language code is missing or has invalid syntax
-
isIndexable
-
getUrl
Builds a Docsify hash URL, or returns null for filesystem roots without a public web address.- Parameters:
root- documentation rootsourcePath- indexable root-relative Markdown path- Returns:
- encoded context-relative viewer URL, or
nullfor filesystem roots
-