Class PathResolver
java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.plugins.extraction.execution.PathResolver
- All Implemented Interfaces:
LogEnabled
,Component
,Serviceable
The resolver for string paths which can contain variables (format is
foo/a_${meta1/meta2/meta3}_m_${meta4}_z/bar\qux/${meta5}
)
and need to be resolved against some given contents.-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
hasVariable
(String path) Returnstrue
if the path contains variables to be resolved.boolean
Returnstrue
if the unresolved path represents a folder, i.e.resolvePath
(String path, List<Content> contents, Extraction extraction, Path basePath) Resolve the given path, which can contain variables, with the values for the given contents.void
service
(ServiceManager manager) Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
Field Details
-
ROLE
The Avalon role.
-
-
Constructor Details
-
PathResolver
public PathResolver()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
hasVariable
Returnstrue
if the path contains variables to be resolved.
If it returnsfalse
, thenresolvePath(String, List, Extraction, Path)
can be called withnull
parameters for contents and extraction.- Parameters:
path
- The relative path to resolve- Returns:
true
if the path contains variables to be resolved
-
isFolder
Returnstrue
if the unresolved path represents a folder, i.e. its last element does not contain a '.' character.- Parameters:
path
- The relative path to resolve- Returns:
true
if the unresolved path represents a folder
-
resolvePath
public Map<Path,List<Content>> resolvePath(String path, List<Content> contents, Extraction extraction, Path basePath) throws IllegalArgumentException Resolve the given path, which can contain variables, with the values for the given contents.
Thus, the result is aMap
of resolvedPaths
, each value containg the list of contents for its associated resolved path key.
If a variable is multivalued, a content can be in several paths at the same time in the result.
For instance,foo/a_${meta1/meta2/meta3}_m_${meta4}_z/bar\qux/${meta5}
could be resolved to the pathfoo / a_val1_m_val2_z / bar / qux / val3
for some contents.- Parameters:
path
- The relative path to resolve. It must not start, nor end with a '/' or a '\' charactercontents
- The contents. Can be null ifhasVariable(String)
was called before and returned false.extraction
- The extraction. Can be null ifhasVariable(String)
was called before and returned false.basePath
- The base absolute path- Returns:
- The absolute resolved paths mapped with their matching contents.
If the returned map contains only one path with a null list, it means that all contents match for that given single path. - Throws:
IllegalArgumentException
- If the path contains variables that are not in the extracted contents' model
-