Class CMSMediaResource
- Author:
- Florian Alpers
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateMediaItem(Path filePath) createMediaItem.voidvoidgetAllFiles(int first, int count) List all uploaded media files, optionally paginated.getAllMedia(String tags, Integer maxItems, Integer prioritySlots, Boolean random) Returns all CMS media items, optionally filtered by the given category tags.static StreamingOutputgetIcoContent(String filename, HttpServletResponse response) getInvalidFilename(String filename) Fallback GET handler for filenames that do NOT match the image extension pattern handled byCMSMediaImageResource.getMediaItem(Long id) static StringgetMediaItemContent(String filename) getMediaItemContent.getMediaOfCategories(String tags, Integer maxItems, Integer prioritySlots, Boolean random) Returns the CMS media items associated with the given category tags.static StreamingOutputgetPDFMediaItemContent(String filename, HttpServletResponse response) getPDFMediaItemContent.static StreamingOutputgetSvgContent(String filename, HttpServletResponse response) static StreamingOutputgetWebpContent(String filename, HttpServletResponse response) Serves a CMS media WebP file as-is.static voidremoveFromImageCache(CMSMediaItem item, de.unigoettingen.sub.commons.cache.ContentServerCacheManager cacheManager) voidserveAudioContent(String filename) voidserveVideoContent(String filename) uploadMediaFiles(boolean enabled, String filename, InputStream uploadedInputStream, org.glassfish.jersey.media.multipart.FormDataContentDisposition fileDetail) May receive a file from a multipart form and saves the file in the cms media folder.validateUploadMediaFiles(String filename) Return the media item for the given filename.
-
Field Details
-
servletRequest
-
servletResponse
-
-
Constructor Details
-
CMSMediaResource
public CMSMediaResource() -
CMSMediaResource
-
-
Method Details
-
getMediaOfCategories
@GET @Produces("application/json") @Path("/category/{tags}") public MediaList getMediaOfCategories(@PathParam("tags") String tags, @QueryParam("max") Integer maxItems, @QueryParam("prioritySlots") Integer prioritySlots, @QueryParam("random") Boolean random) throws DAOException, de.unigoettingen.sub.commons.contentlib.exceptions.IllegalRequestException Returns the CMS media items associated with the given category tags.Requires at least one non-blank category tag: a blank or missing
tagsvalue returns an empty list rather than falling back to all media items, unlikegetAllMedia(java.lang.String, java.lang.Integer, java.lang.Integer, java.lang.Boolean). Category names are matched case-insensitively.- Parameters:
tags- category name(s) separated by '...'maxItems- maximum number of items to returnprioritySlots- number of high-priority items guaranteed in resultrandom- if true, return items in random order- Returns:
- a MediaList containing the CMS media items matching the given category tags
- Throws:
DAOException- if any.de.unigoettingen.sub.commons.contentlib.exceptions.IllegalRequestException
-
getAllMedia
@GET @Produces("application/json") public MediaList getAllMedia(@QueryParam("tags") String tags, @QueryParam("max") Integer maxItems, @QueryParam("prioritySlots") Integer prioritySlots, @QueryParam("random") Boolean random) throws DAOException Returns all CMS media items, optionally filtered by the given category tags.The comma-separated
tagsparameter is optional: a blank or missing value returns all media items instead of an empty list, unlikegetMediaOfCategories(java.lang.String, java.lang.Integer, java.lang.Integer, java.lang.Boolean). Unlike that endpoint, this operation also requires a validwebapi.authorization.tokensent in thetokenrequest header.- Parameters:
tags- comma-separated list of category tag namesmaxItems- maximum number of items to returnprioritySlots- number of high-priority items guaranteed in resultrandom- if true, return items in random order- Returns:
- a MediaList containing all CMS media items optionally filtered by the given tags
- Throws:
DAOException- if any.
-
getMediaItem
@GET @Path("/{id: \\d+}") @Produces("application/json") public MediaItem getMediaItem(@PathParam("id") Long id) throws DAOException, de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException - Throws:
DAOExceptionde.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException
-
getPDFMediaItemContent
@GET @Path("/files/{filename: [^\\/]*\\.([pP][dD][fF])}") @Produces("application/pdf") public static StreamingOutput getPDFMediaItemContent(@PathParam("filename") String filename, @Context HttpServletResponse response) throws de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException getPDFMediaItemContent.- Parameters:
filename- name of the PDF file to serveresponse- HTTP response used to set headers- Returns:
- File contents as HTML
- Throws:
de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException- if any.DAOException- if any.
-
getSvgContent
@GET @Path("/files/{filename: [^\\/]*\\.([sS][vV][gG])}") @Produces("image/svg+xml") public static StreamingOutput getSvgContent(@PathParam("filename") String filename, @Context HttpServletResponse response) throws de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException - Throws:
de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException
-
getIcoContent
@GET @Path("/files/{filename: [^\\/]*\\.([iI][cC][oO])}") @Produces("image/x-icon") public static StreamingOutput getIcoContent(@PathParam("filename") String filename, @Context HttpServletResponse response) throws de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException - Throws:
de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException
-
getWebpContent
@GET @Path("/files/{filename: [^\\/]*\\.([wW][eE][bB][pP])}") @Produces("image/webp") public static StreamingOutput getWebpContent(@PathParam("filename") String filename, @Context HttpServletResponse response) throws de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException Serves a CMS media WebP file as-is. WebP is not supported by the IIIF image server, so these files bypassCMSMediaImageResource.- Parameters:
filename- name of the WebP file in the CMS media folderresponse- servlet response- Returns:
StreamingOutputwriting the file content- Throws:
de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException- if the file does not exist
-
serveVideoContent
@GET @Path("/files/{filename: .*\\.([mM][pP]4|[mM][pP][eE][gG]4|[aA][vV][iI]|[mM][oO][vV]|[wW][mM][vV])}") public void serveVideoContent(@PathParam("filename") String filename) throws PresentationException, WebApplicationException -
serveAudioContent
@GET @Path("/files/{filename: .*\\.([mM][pP]3|[mM][pP][eE][gG]|[wW][aA][vV]|[oO][gG][gG]|[wW][mM][aA])}") public void serveAudioContent(@PathParam("filename") String filename) throws PresentationException, WebApplicationException -
getMediaItemContent
@GET @Path("/files/{filename: [^\\/]*\\.([hH][tT][mM][lL])}") @Produces("text/html") public static String getMediaItemContent(@PathParam("filename") String filename) throws de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException getMediaItemContent.- Parameters:
filename- name of the HTML file to serve- Returns:
- File contents as HTML
- Throws:
de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException- if any.DAOException- if any.
-
validateUploadMediaFiles
@GET @Path("/{filename: [^\\/]*\\.\\w{1,4}}") @Produces("application/json") public Response validateUploadMediaFiles(@PathParam("filename") String filename) throws DAOException Return the media item for the given filename. If no matching media item exists, return a not-found status code- Parameters:
filename- name of the CMS media file to look up- Returns:
- an HTTP response containing the CMS media item metadata as JSON, or a 404 response if no item was found for the given filename
- Throws:
DAOException- if any.
-
getAllFiles
@GET @Path("/files") @Produces("application/json") public List<String> getAllFiles(@QueryParam("first") @DefaultValue("0") int first, @QueryParam("count") @DefaultValue("2147483647") int count) throws PresentationException List all uploaded media files, optionally paginated.The default values keep the endpoint backwards-compatible with existing consumers that fetched the unbounded list: when no parameters are supplied, the full list is returned. Clients that opt in by sending
first/countget a paginated slice.Note:
Files.list(Path)returns entries in an undefined order, so a slice is not guaranteed to be stable across calls. The pagination here protects against unbounded responses, not against ordering changes.- Parameters:
first- zero-based index of the first entry to return; must be>= 0count- maximum number of entries to return; must be>= 0- Returns:
- paginated list of CMS media file names
- Throws:
PresentationException- when the media folder cannot be read
-
deleteAllFiles
@DELETE @Path("/files") @Produces("application/json") public void deleteAllFiles() throws de.unigoettingen.sub.commons.contentlib.exceptions.IllegalRequestException- Throws:
de.unigoettingen.sub.commons.contentlib.exceptions.IllegalRequestException
-
deleteFile
@DELETE @Path("/files/{filename}") @Produces("application/json") public void deleteFile() throws de.unigoettingen.sub.commons.contentlib.exceptions.IllegalRequestException- Throws:
de.unigoettingen.sub.commons.contentlib.exceptions.IllegalRequestException
-
getInvalidFilename
@GET @Path("/files/{filename}") @Produces("application/json") public Response getInvalidFilename(@PathParam("filename") String filename) throws de.unigoettingen.sub.commons.contentlib.exceptions.IllegalRequestException Fallback GET handler for filenames that do NOT match the image extension pattern handled byCMSMediaImageResource. CMSMediaImageResource only matches filenames with image extensions (jpg, png, tif, gif, jp2); any other filename reaches this handler.Returns 400 so that schemathesis receives the correct error code instead of 405 Method Not Allowed (which JAX-RS would return if no GET handler existed for this path).
- Parameters:
filename- the requested filename- Returns:
- never returns normally; always throws
IllegalRequestException - Throws:
de.unigoettingen.sub.commons.contentlib.exceptions.IllegalRequestException
-
uploadMediaFiles
@POST @Path("/files") @Consumes("multipart/form-data") @Produces("application/json") public Response uploadMediaFiles(@DefaultValue("true") boolean enabled, String filename, InputStream uploadedInputStream, org.glassfish.jersey.media.multipart.FormDataContentDisposition fileDetail) throws DAOException May receive a file from a multipart form and saves the file in the cms media folder.- Parameters:
enabled- whether the uploaded media item should be enabledfilename- target filename for the uploaded fileuploadedInputStream- input stream carrying the file contentfileDetail- multipart form metadata for the uploaded file- Returns:
- an ACCEPTED response if the upload was successful, a FORBIDDEN response if no user is registered in the html session or the user does not have rights to upload media, or a CONFLICT response if a file of the same name already exists in the cms media foler
- Throws:
DAOException- if any.
-
removeFromImageCache
public static void removeFromImageCache(CMSMediaItem item, de.unigoettingen.sub.commons.cache.ContentServerCacheManager cacheManager) - Parameters:
item- the CMS media item to evict from cachecacheManager- the content server cache manager to use
-
createMediaItem
createMediaItem.- Parameters:
filePath- path to the uploaded media file- Returns:
- a new CMSMediaItem initialized with the filename and empty metadata for all configured locales
-