Interface ResourcePath
public sealed interface ResourcePath
Represents a module name and a URI used for loading a document's resources.
Page paths are made up of 3 elements: the module name, the path and the query.
Module Name
Name of a specific directory/zip archive in theDelphiResources.getModuleDirectory()
directory.
Path
The file path of a file/directory in the directory/zip archive the module name points to.Query
Optional search parameters that scripts can use.-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionaddAllElements(@NotNull ResourcePath path) Adds all elements from the specified path.addElement(@NotNull String element) Adds an element to the path's filepath.Clears all of this path's file elements.static ResourcePathCreates a page path with a specifiedmoduleNameintGets the amount of elements in the pathelements()Gets the file path of this page path combined with the query parameters.@NotNull StringgetElement(int index) Gets an element at a specific indexGets an unmodifiable list of the path's elements@NotNull StringGets the module name element of the path.@Nullable StringGets the value of a queryGets an unmodifiable set of the query keys.@NotNull Stringpath()Gets the file path part of this page path.@NotNull Stringquery()Gets the query part of this path as a string.removeElement(int index) Removes a path elementsetElement(int index, @NotNull String element) Sets the element at a specific index.setElements(ResourcePath path) Sets the elements of this pathsetModuleName(@NotNull String moduleName) Sets the module name.Sets a query value.toString()Combines the module name, elements and queries into a string that can be given toDelphi.parsePath(String)to parse.static voidvalidateFilename(String element) Validates a filename.static voidvalidateQuery(String query) Validates a query key/value.
-
Field Details
-
VALID_ELEMENT
-
VALID_QUERY
-
-
Method Details
-
create
Creates a page path with a specifiedmoduleName- Parameters:
moduleName- Path Module name- Returns:
- Created path
-
validateFilename
Validates a filename.For a filename to be "valid" it must not be null and match the
VALID_ELEMENTregex pattern.- Parameters:
element- Element to validate- Throws:
NullPointerException- If theelementisnullIllegalArgumentException- If theelementis an invalid filename.
-
validateQuery
Validates a query key/value.For a query key or value to be "valid" it must not be null and must match the
VALID_QUERYregex pattern.- Parameters:
query- Query element to validate.- Throws:
NullPointerException- If thequeryis null.IllegalArgumentException- If thequeryis invalid.
-
getModuleName
Gets the module name element of the path.- Returns:
- Module name
-
setModuleName
Sets the module name.- Parameters:
moduleName- New module name- Returns:
- A copy of this path with the specified module name
- Throws:
NullPointerException- If the module name is nullIllegalArgumentException- If the module name failsvalidateQuery(String)
-
addElement
Adds an element to the path's filepath.- Parameters:
element- Filename- Returns:
- A copy of this path with the specified element added
- Throws:
NullPointerException- If theelementisnullIllegalArgumentException- If the element failsvalidateFilename(String)
-
setElement
ResourcePath setElement(int index, @NotNull @NotNull String element) throws IndexOutOfBoundsException Sets the element at a specific index.- Parameters:
index- Element indexelement- New element- Returns:
- A copy of this path with the specified element changed
- Throws:
IndexOutOfBoundsException- If the index is less than 0 or greater/equal toelementCount().NullPointerException- If theelementisnullIllegalArgumentException- If the element failsvalidateFilename(String)
-
setQuery
Sets a query value.- Parameters:
key- Query keyvalue- Query value- Returns:
- A copy of this path with the specified query changed
- Throws:
NullPointerException- If thekeyis nullIllegalArgumentException- If thekeyorvalue(if not null) failsvalidateQuery(String).
-
addAllElements
Adds all elements from the specified path.- Parameters:
path- Path to copy elements from- Returns:
- A copy of this path with all the elements of the specified path added
-
setElements
Sets the elements of this path- Parameters:
path- Path elements- Returns:
- A copy of this path with the elements of the specified path
-
removeElement
Removes a path element- Parameters:
index- Index of the element to remove- Returns:
- A copy of this path with the specified element removed
-
clearElements
ResourcePath clearElements()Clears all of this path's file elements.- Returns:
- A copy of this path with no elements
-
getQuery
-
getQueryKeys
-
getElements
-
elementCount
int elementCount()Gets the amount of elements in the path- Returns:
- Element count
-
getElement
Gets an element at a specific indexAssume we have the path
foobar/filepath/filename.ext, these would be the indexes:Index Element 0 foobar1 filepath2 filename.ext- Parameters:
index- Element index- Returns:
- Element
- Throws:
IndexOutOfBoundsException- Ifindexis less than 0, or greater/equal toelementCount().
-
path
Gets the file path part of this page path.Example:
foo/bar/foobar.json- Returns:
- File path string, or
"", if no file elements were specified
-
query
Gets the query part of this path as a string.Example:
?foo=bar&bar=foo- Returns:
- Query string, or
""if there are no query elements.
-
elements
String elements()Gets the file path of this page path combined with the query parameters.Example:
dir/file.xml?foo=bar- Returns:
- File path + query parameters.
- See Also:
-
toString
String toString()Combines the module name, elements and queries into a string that can be given toDelphi.parsePath(String)to parse.Examples:
modulemodule:file.extmodule:'file with space.ext'module:'dir with space'/file.xmlmodule:foobar/file.extmodule:foobar/file.ext?foo=bar&bar=foomodule:foobar/file.ext?foo&bar=falsemodule:?foo=bar&bar=foo
-