Class PlannedAssetPaths
For example, page 42 stages /images/photo.webp at
/files/protected/planned-changes/42/images/photo.webp. These helpers
rewrite paths and validate their syntax and destinations without accessing the filesystem.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancontainsPlannedPath(String value) Detects a planned-directory reference anywhere in a URL or text.static StringgetPublicPath(String plannedPath, int docId) Resolves a planned file or folder to the public path used when publishing its page.static StringExtracts and decodes a root-relative path while rejecting unsafe path syntax.static StringremovePlannedPrefix(String value) Converts a planned file or folder reference to its validated public path.static StringReplaces a page's planned asset prefix with the public root in URLs or page content.static StringrewriteToProtectedFolder(int docId, String target) Prepends a page's protected planned-directory prefix to a public file or folder path.
-
Field Details
-
ROOT
- See Also:
-
-
Method Details
-
rewrite
Replaces a page's planned asset prefix with the public root in URLs or page content.This literal replacement preserves surrounding HTML, URL encoding, query strings and fragments. It does not validate paths or change prefixes belonging to other pages.
- Parameters:
value- URL or content containing planned asset references; may benulldocId- page ID identifying the planned prefix to replace- Returns:
- content with each matching prefix replaced by
/, ornullfor null input
-
containsPlannedPath
Detects a planned-directory reference anywhere in a URL or text.The check decodes URL escapes and ignores case. If decoding fails, it checks for
planned-changesin the original text so malformed references still receive access checks. A match does not mean the path or page ID is valid.- Parameters:
value- URL or text to inspect; may benull- Returns:
trueif a planned-directory reference is detected;falsefor null input
-
localPath
Extracts and decodes a root-relative path while rejecting unsafe path syntax.Query strings and fragments are discarded, URL escapes are decoded as UTF-8, and literal
+characters are preserved. The path must start with/and must not contain traversal segments, backslashes, repeated slashes, semicolons, remaining percent signs, control characters, or segments ending in a dot or space.A URL's scheme and authority are ignored. This method does not verify the origin, require a planned prefix, check permissions or inspect the filesystem.
- Parameters:
value- non-null path or URL; literal spaces are accepted- Returns:
- decoded root-relative path, suitable for directory permission checks
- Throws:
IllegalArgumentException- if the URI is malformed, has no path, or has unsafe path syntax
-
getPublicPath
Resolves a planned file or folder to the public path used when publishing its page.For example,
/files/protected/planned-changes/42/images/photo.webpbecomes/images/photo.webpwhendocIdis42. The source is decoded and checked bylocalPath(String), its page ID must matchdocId, and the resulting public path must passvalidatePublicPath(String). No files are copied or modified.- Parameters:
plannedPath- non-null planned asset path or URLdocId- ID of the page whose planned directory must contain the asset, not a user ID- Returns:
- decoded public path without the planned prefix, query string or fragment
- Throws:
IllegalArgumentException- if the source path is invalid, belongs to another page, or maps to an unsupported public destination
-
removePlannedPrefix
Converts a planned file or folder reference to its validated public path.The owning page ID is read from the path. Planned references are decoded and lose their URL authority, query string and fragment. Values without a planned reference are returned unchanged, without validation.
- Parameters:
value- path or URL to convert; may benull- Returns:
- validated public path for a planned reference, or the original value otherwise
- Throws:
IllegalArgumentException- if a detected planned reference has an invalid path, page ID or public destination
-
rewriteToProtectedFolder
Prepends a page's protected planned-directory prefix to a public file or folder path.For example, page
42and/files/catalog.pdfproduce/files/protected/planned-changes/42/files/catalog.pdf. The decoded target is validated, but the original target is appended unchanged, preserving its URL encoding, query string and fragment. No directories are created.- Parameters:
docId- page ID to place in the prefix; expected to be positive but not validated heretarget- non-null root-relative public file or folder path- Returns:
- protected planned path containing the page ID and the original target
- Throws:
IllegalArgumentException- if the target has invalid path syntax or an unsupported destination
-