Class PathResolver
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.plugins.extraction.execution.PathResolver
-
- All Implemented Interfaces:
LogEnabled
,Component
,Serviceable
public class PathResolver extends AbstractLogEnabled implements Component, Serviceable
The resolver for string paths which can contain variables (format isfoo/a_${meta1/meta2/meta3}_m_${meta4}_z/bar\qux/${meta5}
) and need to be resolved against some given contents.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
PathResolver.PathWrapper
-
Field Summary
Fields Modifier and Type Field Description private static String
__NO_VALUE_OR_BLANK_FOLDER_NAME
private static List<Character>
__PATH_SEPARATORS
private static Pattern
__VARIABLE_REGEXP_PATTERN
private ContentValuesExtractorFactory
_contentValuesExtractorFactory
private EditExtractionNodeManager
_editExtractionNodeManager
static String
ROLE
The Avalon role.
-
Constructor Summary
Constructors Constructor Description PathResolver()
-
Method Summary
-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
__PATH_SEPARATORS
private static final List<Character> __PATH_SEPARATORS
-
__VARIABLE_REGEXP_PATTERN
private static final Pattern __VARIABLE_REGEXP_PATTERN
-
__NO_VALUE_OR_BLANK_FOLDER_NAME
private static final String __NO_VALUE_OR_BLANK_FOLDER_NAME
- See Also:
- Constant Field Values
-
_contentValuesExtractorFactory
private ContentValuesExtractorFactory _contentValuesExtractorFactory
-
_editExtractionNodeManager
private EditExtractionNodeManager _editExtractionNodeManager
-
-
Constructor Detail
-
PathResolver
public PathResolver()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
hasVariable
public boolean hasVariable(String path)
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
public boolean isFolder(String path)
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)
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.
-
_validPath
private PathResolver.PathWrapper _validPath(PathResolver.PathWrapper pathWithNoVar)
-
_toPath
private Path _toPath(PathResolver.PathWrapper resolvedPath, Path basePath)
-
_splitPathElements
private PathResolver.PathWrapper _splitPathElements(String path)
-
_fillVariableNames
private void _fillVariableNames(String element, Set<String> variableNames)
-
_getFirstLevelContentTypes
private Collection<String> _getFirstLevelContentTypes(Extraction extraction)
-
_getContentTypes
private Collection<String> _getContentTypes(ExtractionComponent component)
-
_pathByContent
private Map<Content,Set<PathResolver.PathWrapper>> _pathByContent(PathResolver.PathWrapper unresolvedPath, List<Content> contents, ContentValuesExtractorFactory.SimpleContentValuesExtractor valuesExtractor)
-
_resolvePath
private List<Set<String>> _resolvePath(PathResolver.PathWrapper unresolvedPath, Content content, ContentValuesExtractorFactory.SimpleContentValuesExtractor valuesExtractor)
-
_resolvePathElement
private Set<String> _resolvePathElement(String unresolvedElement, Map<String,Object> values)
-
_getStringValues
private Set<String> _getStringValues(Object value)
-
_replace
private Set<String> _replace(String toReplace, Set<String> replaceBy, Set<String> uncompleteElements)
-
_validPathElementNames
private Set<String> _validPathElementNames(Set<String> elements)
-
_validPathElementName
private String _validPathElementName(String element)
-
_getAllPaths
private Set<PathResolver.PathWrapper> _getAllPaths(List<Set<String>> pathElements)
-
_getAllPathsInCurrentLevel
private Set<PathResolver.PathWrapper> _getAllPathsInCurrentLevel(Set<String> possibleElementsInCurrentLevel, Set<PathResolver.PathWrapper> computedPathsInPreviousLevel)
-
_contentsByPath
private Map<PathResolver.PathWrapper,List<Content>> _contentsByPath(Map<Content,Set<PathResolver.PathWrapper>> pathByContent)
-
-