Class RecordFileResource
- Author:
- Florian Alpers
-
Constructor Summary
ConstructorsConstructorDescriptionRecordFileResource(HttpServletRequest request, HttpServletResponse response, String pi) -
Method Summary
Modifier and TypeMethodDescriptionprotected booleancheckMediaFileAccess(String filename) Returns the ALTO document for a single page.Returns the CMDI metadata document for a record file.getDownloadedResource(String taskId, String path) Downloads a file from a previously completed external resource download task.getMediaFile(String filename) Returns a media file (e.g. audio, video, 3D model or web archive) of the record.getMEI()Returns the MEI (Music Encoding Initiative) document for the record.getPlaintext(String filename) Returns the plain text content of a single page.getSourceFile(String filename) Returns a source metadata file (e.g.Returns the fulltext of a single page converted to TEI format.
-
Constructor Details
-
RecordFileResource
public RecordFileResource(@Context HttpServletRequest request, @Context HttpServletResponse response, @PathParam("pi") String pi) - Parameters:
request- the http requestresponse- the http responsepi- the requested indentifier
-
-
Method Details
-
getAlto
@GET @Path("/alto/{filename}") @Produces("text/xml") public String getAlto(@PathParam("filename") String filename) throws PresentationException, IndexUnreachableException, de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException, de.unigoettingen.sub.commons.contentlib.exceptions.ServiceNotAllowedException Returns the ALTO document for a single page.The file is looked up first in the crowdsourced ALTO folder and, if not found there, in the record's regular ALTO folder, so corrections made through crowdsourcing take precedence over the originally indexed file. Access requires the fulltext view permission for the requested page.
- Parameters:
filename- filename of the alto document- Returns:
- the ALTO document as an XML string
- Throws:
de.unigoettingen.sub.commons.contentlib.exceptions.ServiceNotAllowedException- if the fulltext view permission is not grantedde.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException- if no ALTO file exists for the given filenamePresentationExceptionIndexUnreachableException
-
getPlaintext
@GET @Path("/plaintext/{filename}") @Produces("text/plain") public String getPlaintext(@PathParam("filename") String filename) throws de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException, PresentationException, IndexUnreachableException, de.unigoettingen.sub.commons.contentlib.exceptions.ServiceNotAllowedException Returns the plain text content of a single page.The text is looked up first in the crowdsourced plaintext folder and then in the regular plaintext folder; if neither contains a matching file, the page's ALTO file is converted to plain text on the fly instead. Access requires the fulltext view permission for the requested page.
- Parameters:
filename- filename containing the text- Returns:
- the plain text content of the page
- Throws:
de.unigoettingen.sub.commons.contentlib.exceptions.ServiceNotAllowedException- if the fulltext view permission is not grantedde.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException- if no plaintext or ALTO file exists for the filenamePresentationExceptionIndexUnreachableException
-
getTEI
@GET @Path("/tei/{filename}") @Produces("text/xml") public String getTEI(@PathParam("filename") String filename) throws PresentationException, IndexUnreachableException, de.unigoettingen.sub.commons.contentlib.exceptions.ContentLibException Returns the fulltext of a single page converted to TEI format.The plain text of the page (falling back to a converted ALTO file, as for the plaintext endpoint) is wrapped in a generated TEI header built from the record's indexed metadata. Access requires the fulltext view permission for the requested page.
- Parameters:
filename- filename containing the text- Returns:
- the page fulltext as a TEI XML document
- Throws:
de.unigoettingen.sub.commons.contentlib.exceptions.ServiceNotAllowedException- if the fulltext view permission is not grantedde.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException- if no record is found for the given identifier, or if no plaintext or ALTO file exists for the filenamePresentationExceptionIndexUnreachableExceptionde.unigoettingen.sub.commons.contentlib.exceptions.ContentLibException
-
getMEI
@GET @Path("/mei") @Produces("text/xml") public String getMEI() throws de.unigoettingen.sub.commons.contentlib.exceptions.ContentLibException, DAOException, IOException, IndexUnreachableException, PresentationExceptionReturns the MEI (Music Encoding Initiative) document for the record.The file name is read from the record's indexed metadata; if the record has no MEI file associated, the response body is empty. Access requires the download-metadata privilege for the record.
- Returns:
- the MEI document as a string, or null if the record has no associated MEI file
- Throws:
de.unigoettingen.sub.commons.contentlib.exceptions.ServiceNotAllowedException- if the download-metadata privilege is not grantedde.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException- if no record is found for the given identifierde.unigoettingen.sub.commons.contentlib.exceptions.ContentLibExceptionDAOExceptionIOExceptionIndexUnreachableExceptionPresentationException
-
getSourceFile
@GET @Path("/source/{filename}") public Response getSourceFile(@PathParam("filename") String filename) throws de.unigoettingen.sub.commons.contentlib.exceptions.ContentLibException, PresentationException, IndexUnreachableException, DAOException Returns a source metadata file (e.g. METS/LIDO) of the record.The requested file is resolved beneath the record's configured source folder and rejected as invalid if the resolved path would escape that folder. The content type is probed from the file name, falling back to a generic binary stream. Access requires the download-original-content privilege for the record.
- Parameters:
filename- source file name- Returns:
- the source file content as a binary stream
- Throws:
de.unigoettingen.sub.commons.contentlib.exceptions.IllegalRequestException- if the filename is invalid or would resolve outside the record's source folderde.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException- if no such file existsde.unigoettingen.sub.commons.contentlib.exceptions.ServiceNotAllowedException- if the download-original-content privilege is not grantedde.unigoettingen.sub.commons.contentlib.exceptions.ContentLibExceptionPresentationExceptionIndexUnreachableExceptionDAOException
-
getMediaFile
@GET @Path("/media/{filename}") public Response getMediaFile(@PathParam("filename") String filename) throws de.unigoettingen.sub.commons.contentlib.exceptions.ContentLibException, PresentationException, IndexUnreachableException, DAOException Returns a media file (e.g. audio, video, 3D model or web archive) of the record.The requested file is resolved beneath the record's configured media folder and rejected as invalid if the resolved path would escape that folder. Whether access is granted depends on the file's mime type: image files require the download-images privilege, every other file requires the download-born-digital-files privilege.
A 3D model file whose sibling model folder exists is delivered together with the other files found in that folder, packed into a zip archive generated on the fly. A ".wacz", ".warc" or ".warc.gz" file is streamed through the web archive delivery service instead of being returned directly. The request is recorded for the file-download usage statistics.
- Parameters:
filename- media file name- Returns:
- the media file content as a binary stream, or no entity if the file is a web archive delivered through the web archive delivery service
- Throws:
de.unigoettingen.sub.commons.contentlib.exceptions.IllegalRequestException- if the filename is invalid or would resolve outside the record's media folderde.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException- if no such file existsde.unigoettingen.sub.commons.contentlib.exceptions.ServiceNotAllowedException- if the required download privilege is not grantedde.unigoettingen.sub.commons.contentlib.exceptions.ContentLibExceptionPresentationExceptionIndexUnreachableExceptionDAOException
-
checkMediaFileAccess
protected boolean checkMediaFileAccess(String filename) throws IndexUnreachableException, DAOException -
getCMDI
@GET @Path("/cmdi/{filename}") @Produces("application/octet-stream") public String getCMDI(@PathParam("filename") String filename, @QueryParam("lang") String lang) throws de.unigoettingen.sub.commons.contentlib.exceptions.ContentLibException, PresentationException, IndexUnreachableException, IOException Returns the CMDI metadata document for a record file.The requested language defaults to the current user's locale if not given. The record's CMDI folder is searched for a file whose name matches "
_<isoCode>.xml" for that language's ISO-3 code, falling back to the ISO-2 code if no ISO-3 match exists. Access requires the fulltext view permission for the given filename.- Parameters:
filename- image file name for cmdilang- language for CMDI- Returns:
- the CMDI document as an XML string
- Throws:
de.unigoettingen.sub.commons.contentlib.exceptions.ServiceNotAllowedException- if the fulltext view permission is not grantedde.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException- if no matching CMDI file existsde.unigoettingen.sub.commons.contentlib.exceptions.ContentLibExceptionPresentationExceptionIndexUnreachableExceptionIOException
-
getDownloadedResource
@GET @Path("/resources/{taskId}/{path: .+}") public Response getDownloadedResource(@PathParam("taskId") String taskId, @PathParam("path") String path) throws PresentationException, IndexUnreachableException, de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException, de.unigoettingen.sub.commons.contentlib.exceptions.IllegalRequestException, DAOException, RecordNotFoundException, de.unigoettingen.sub.commons.contentlib.exceptions.ServiceNotAllowedException Downloads a file from a previously completed external resource download task.The path is resolved beneath the given task's own folder inside the record's configured download folder; a path that would escape that folder is rejected as invalid. Access requires the download-born-digital-files privilege for the record. The request is recorded for the file-download usage statistics.
- Parameters:
taskId- download resource task idpath- file path relative to the download directory- Returns:
- the downloaded resource file content as a binary stream
- Throws:
de.unigoettingen.sub.commons.contentlib.exceptions.IllegalRequestException- if the path would resolve outside the task's folderde.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException- if no such file existsde.unigoettingen.sub.commons.contentlib.exceptions.ServiceNotAllowedException- if the download-born-digital-files privilege is not grantedPresentationExceptionIndexUnreachableExceptionDAOExceptionRecordNotFoundException
-