public abstract class ALfnHierarchicalResourceLocation extends Object implements ILfnResourceLocation
This base class assumes that hierarchical components are separated by a fixed separator and that the encoded location starts with a fixed prefix.
Modifier | Constructor and Description |
---|---|
protected |
ALfnHierarchicalResourceLocation(String aPrefix,
String aSeparator)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
protected abstract ILfnResourceLocation |
createResolvedLocation(List<String> aResolvedComponents)
Creates a new resource location from the hierarchical components determined by
resolve(String) . |
boolean |
equals(Object aObject) |
int |
hashCode() |
String |
relativize(ILfnResourceLocation aTarget)
Generates a "relative" location for the given target, using this location as a base.
|
ILfnResourceLocation |
resolve(String aRelative)
Resolve a "relative" location against this resource location.
|
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getFileName, getLocation, getParent
protected ALfnHierarchicalResourceLocation(String aPrefix, String aSeparator)
aPrefix
- the fixed prefix (for instance http://
for web resources)aSeparator
- the separator used to separate hierarchical components (for instance /
for URI paths)public String relativize(ILfnResourceLocation aTarget)
The relative location is often encoded using elements like ..
to denote a parent and
/name
to denote a child named name
. However, implementations are free to encode the relative
location in any way they please.
The only requirement is that base.resolve(base.relativize(aTarget)).equals(aTarget)
.
If there is no ancestry relationship between the target and this location,
implementations must return the full encoded form
of the target.
The implementation in ALfnHierarchicalResourceLocation
finds a common ancestor between this location
and aTarget
.
If there is no common ancestor, aTarget
's location is returned.
If there is a common ancestor, the returned value starts with a number of ".."
components equal to the
number of times the ILfnResourceLocation.getParent()
has to be used to get from this location to the common ancestor.
Then the hierarchical components from the common ancestor to aTarget
are added.
The components are separated using the separator provided to the constructor.
relativize
in interface ILfnResourceLocation
aTarget
- the location to provide a relative location forPath.relativize(Path)
public ILfnResourceLocation resolve(String aRelative)
The relative location was either produced by ILfnResourceLocation.relativize(ILfnResourceLocation)
or a manipulation of another resource location's file name
.
Note that this means that the "relative" location may actually be the full encoded form of a resource location.
If the relative location cannot be resolved, implementations should throw IllegalArgumentException
.
The returned resource location must be compatible with this location.
The implementation in ALfnHierarchicalResourceLocation
uses the prefix provided to the constructor
to determine whether aRelative
is actually an absolute encoded location.
If it is absolute, resolution is done on only aRelative
.
If it is not absolute, resolution is done on the combination of this location's encoded form and the aRelative
.
Resolution is performed by removing the prefix and splitting the remainder by the separator provided to the constructor.
Empty components and "."
components are considered redundant and removed.
Then, consecutive name
and ".."
components are removed.
If at any point the list of hierarchical components starts with ".."
, this is considered invalid and an exception is thrown.
Finally, a new resolved location is constructed using the resulting list of components and returned.
resolve
in interface ILfnResourceLocation
aRelative
- the resource location to resolvecreateResolvedLocation(List)
protected abstract ILfnResourceLocation createResolvedLocation(List<String> aResolvedComponents)
resolve(String)
.aResolvedComponents
- the hierarchical components