Package org.ametys.cms.transformation
Class MetadataURIResolver
- java.lang.Object
-
- org.ametys.cms.transformation.MetadataURIResolver
-
- All Implemented Interfaces:
URIResolver
,Contextualizable
,Serviceable
- Direct Known Subclasses:
MetadataURIResolver
public class MetadataURIResolver extends Object implements URIResolver, Serviceable, Contextualizable
URIResolver
for type "metadata".
These links or images point to a file from the metadata of the current Content.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
MetadataURIResolver.MetaInfo
Metadata information.
-
Field Summary
Fields Modifier and Type Field Description private static Pattern
_CONTENT_URI_PATTERN
protected Context
_context
The contextprivate static Pattern
_OBJECT_URI_PATTERN
protected AmetysObjectResolver
_resolver
The ametys object resolver
-
Constructor Summary
Constructors Constructor Description MetadataURIResolver()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected MetadataURIResolver.MetaInfo
_getMetaInfo(String uri, Request request)
Get metadata name and content.protected String
_resolveImage(String uri, String uriArgument, boolean download, boolean absolute, boolean internal)
Resolves a link URI for rendering image.
The output must be a properly encoded path, relative to the webapp context, accessible from a browser.ConsistencyChecker.CHECK
checkLink(String uri, boolean shortTest)
Tests if the URI is not broken.void
contextualize(Context context)
protected BinaryMetadata
getBinaryMetadata(MetadataAwareAmetysObject content, String path)
Get the binary metadataI18nizableText
getLabel(String uri)
Get an URI label.String
getType()
Returns the type of links handled by thisURIResolver
.protected String
getUri(String path, MetadataAwareAmetysObject object, boolean download, boolean absolute, boolean internal)
Get the URI prefixString
resolve(String uri, boolean download, boolean absolute, boolean internal)
Resolves a link URI for rendering purposes.
The output must be a properly encoded path, relative to the webapp context, accessible from a browser.String
resolveBoundedImage(String uri, int maxHeight, int maxWidth, boolean download, boolean absolute, boolean internal)
Resolves a link URI for rendering image.
The output must be a properly encoded path, relative to the webapp context, accessible from a browser.String
resolveBoundedImageAsBase64(String uri, int maxHeight, int maxWidth)
Resolve an image and return it as a base64-encoded string.String
resolveCroppedImage(String uri, int cropHeight, int cropWidth, boolean download, boolean absolute, boolean internal)
Resolves a link URI for rendering image.
The output must be a properly encoded path, relative to the webapp context, accessible from a browser.String
resolveCroppedImageAsBase64(String uri, int cropHeight, int cropWidth)
Resolve an image and return it as a base64-encoded string.String
resolveImage(String uri, int height, int width, boolean download, boolean absolute, boolean internal)
Resolves a link URI for rendering image.
The output must be a properly encoded path, relative to the webapp context, accessible from a browser.String
resolveImageAsBase64(String uri, int height, int width)
Resolve an image and return it as a base64-encoded string.protected String
resolveImageAsBase64(String uri, int height, int width, int maxHeight, int maxWidth, int cropHeight, int cropWidth)
Get an image's bytes encoded as base64, optionally resized.void
service(ServiceManager manager)
-
-
-
Field Detail
-
_OBJECT_URI_PATTERN
private static final Pattern _OBJECT_URI_PATTERN
-
_CONTENT_URI_PATTERN
private static final Pattern _CONTENT_URI_PATTERN
-
_resolver
protected AmetysObjectResolver _resolver
The ametys object resolver
-
-
Constructor Detail
-
MetadataURIResolver
public MetadataURIResolver()
-
-
Method Detail
-
contextualize
public void contextualize(Context context) throws ContextException
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
getType
public String getType()
Description copied from interface:URIResolver
Returns the type of links handled by thisURIResolver
.- Specified by:
getType
in interfaceURIResolver
- Returns:
- the type of links handled by this
URIResolver
.
-
resolve
public String resolve(String uri, boolean download, boolean absolute, boolean internal)
Description copied from interface:URIResolver
Resolves a link URI for rendering purposes.
The output must be a properly encoded path, relative to the webapp context, accessible from a browser.- Specified by:
resolve
in interfaceURIResolver
- Parameters:
uri
- the link URI.download
- true if the pointed resource is to be downloaded.absolute
- true if the url must be absoluteinternal
- true to get an internal URI.- Returns:
- the path to the resource.
-
resolveImage
public String resolveImage(String uri, int height, int width, boolean download, boolean absolute, boolean internal)
Description copied from interface:URIResolver
Resolves a link URI for rendering image.
The output must be a properly encoded path, relative to the webapp context, accessible from a browser.- Specified by:
resolveImage
in interfaceURIResolver
- Parameters:
uri
- the link URI.height
- the height of the image.width
- the width of the imagedownload
- true if the pointed resource is to be downloaded.absolute
- true if the url must be absoluteinternal
- true to get an internal URI.- Returns:
- the path to the image.
-
resolveImageAsBase64
public String resolveImageAsBase64(String uri, int height, int width)
Description copied from interface:URIResolver
Resolve an image and return it as a base64-encoded string.- Specified by:
resolveImageAsBase64
in interfaceURIResolver
- Parameters:
uri
- the link URI.height
- the height of the image.width
- the width of the image- Returns:
- a base64-encoded string representing the image.
-
resolveBoundedImage
public String resolveBoundedImage(String uri, int maxHeight, int maxWidth, boolean download, boolean absolute, boolean internal)
Description copied from interface:URIResolver
Resolves a link URI for rendering image.
The output must be a properly encoded path, relative to the webapp context, accessible from a browser.- Specified by:
resolveBoundedImage
in interfaceURIResolver
- Parameters:
uri
- the link URI.maxHeight
- the max heightmaxWidth
- the max widthdownload
- true if the pointed resource is to be downloaded.absolute
- true if the url must be absoluteinternal
- true to get an internal URI.- Returns:
- the path to the image.
-
resolveCroppedImage
public String resolveCroppedImage(String uri, int cropHeight, int cropWidth, boolean download, boolean absolute, boolean internal)
Description copied from interface:URIResolver
Resolves a link URI for rendering image.
The output must be a properly encoded path, relative to the webapp context, accessible from a browser.- Specified by:
resolveCroppedImage
in interfaceURIResolver
- Parameters:
uri
- the link URI.cropHeight
- the crop heightcropWidth
- the crop widthdownload
- true if the pointed resource is to be downloaded.absolute
- true if the url must be absoluteinternal
- true to get an internal URI.- Returns:
- the path to the image.
-
resolveCroppedImageAsBase64
public String resolveCroppedImageAsBase64(String uri, int cropHeight, int cropWidth)
Description copied from interface:URIResolver
Resolve an image and return it as a base64-encoded string.- Specified by:
resolveCroppedImageAsBase64
in interfaceURIResolver
- Parameters:
uri
- the link URI.cropHeight
- the crop heightcropWidth
- the crop width- Returns:
- a base64-encoded string representing the image.
-
_resolveImage
protected String _resolveImage(String uri, String uriArgument, boolean download, boolean absolute, boolean internal)
Resolves a link URI for rendering image.
The output must be a properly encoded path, relative to the webapp context, accessible from a browser.- Parameters:
uri
- the link URI.uriArgument
- the argument to append to the uridownload
- true if the pointed resource is to be downloaded.absolute
- true if the url must be absoluteinternal
- true to get an internal URI.- Returns:
- the path to the image.
-
resolveBoundedImageAsBase64
public String resolveBoundedImageAsBase64(String uri, int maxHeight, int maxWidth)
Description copied from interface:URIResolver
Resolve an image and return it as a base64-encoded string.- Specified by:
resolveBoundedImageAsBase64
in interfaceURIResolver
- Parameters:
uri
- the link URI.maxHeight
- the max heightmaxWidth
- the max width- Returns:
- a base64-encoded string representing the image.
-
resolveImageAsBase64
protected String resolveImageAsBase64(String uri, int height, int width, int maxHeight, int maxWidth, int cropHeight, int cropWidth)
Get an image's bytes encoded as base64, optionally resized.- Parameters:
uri
- the image URI.height
- the specified height. Ignored if negative.width
- the specified width. Ignored if negative.maxHeight
- the maximum image height. Ignored if height or width is specified.maxWidth
- the maximum image width. Ignored if height or width is specified.cropHeight
- The cropping height. Ignored if negative.cropWidth
- The cropping width. Ignored if negative.- Returns:
- the image bytes encoded as base64.
-
getUri
protected String getUri(String path, MetadataAwareAmetysObject object, boolean download, boolean absolute, boolean internal)
Get the URI prefix- Parameters:
path
- the resource pathobject
- The objectdownload
- true if the pointed resource is to be downloaded.absolute
- true if the url must be absoluteinternal
- true to get an internal URI.- Returns:
- the URI prefix
-
checkLink
public ConsistencyChecker.CHECK checkLink(String uri, boolean shortTest)
Description copied from interface:URIResolver
Tests if the URI is not broken.- Specified by:
checkLink
in interfaceURIResolver
- Parameters:
uri
- The uri to testshortTest
- If shortTest is to true, only fast check should be done. If false, complete test (even if long) should be done.- Returns:
- SUCCESS if the test was done and ok, FAILURE if the test was done and ko, UNKNOWN if the test was not done (because too long). UNKNOWN can not be returned when shortTest is set to false
-
getLabel
public I18nizableText getLabel(String uri)
Description copied from interface:URIResolver
Get an URI label.- Specified by:
getLabel
in interfaceURIResolver
- Parameters:
uri
- the uri which label to get.- Returns:
- the label.
-
getBinaryMetadata
protected BinaryMetadata getBinaryMetadata(MetadataAwareAmetysObject content, String path)
Get the binary metadata- Parameters:
content
- the contentpath
- the metadata path- Returns:
- the binary metadata
-
_getMetaInfo
protected MetadataURIResolver.MetaInfo _getMetaInfo(String uri, Request request)
Get metadata name and content.- Parameters:
uri
- the metadata URI.request
- the request.- Returns:
- the metadata info.
-
-