Package org.dspace.disseminate
Class CitationDocumentServiceImpl
- java.lang.Object
-
- org.dspace.disseminate.CitationDocumentServiceImpl
-
- All Implemented Interfaces:
CitationDocumentService,org.springframework.beans.factory.InitializingBean
public class CitationDocumentServiceImpl extends Object implements CitationDocumentService, org.springframework.beans.factory.InitializingBean
The Citation Document produces a dissemination package (DIP) that is different that the archival package (AIP). In this case we append the descriptive metadata to the end (configurable) of the document. i.e. last page of PDF. So instead of getting the original PDF, you get a cPDF (with citation information added).- Author:
- Peter Dietz (peter@longsight.com)
-
-
Field Summary
Fields Modifier and Type Field Description protected AuthorizeServiceauthorizeServiceprotected BitstreamServicebitstreamServiceprotected BooleancitationAsFirstPageShould the citation page be the first page of the document, or the last page? default = true.protected List<String>citationEnabledCollectionsListList of all enabled collections, inherited/determined for those under communities.protected BooleancitationEnabledGloballyBoolean to determine is citation-functionality is enabled globally for entire site.protected org.apache.pdfbox.pdmodel.common.PDRectanglecitationPageFormatCitation page formatprotected CommunityServicecommunityServiceprotected ConfigurationServiceconfigurationServiceprotected String[]fieldsprotected Stringfooterprotected HandleServicehandleServiceprotected String[]header1protected String[]header2protected ItemServiceitemServiceprotected Set<String>PDF_MIMESA set of MIME types that refer to a PDFprotected Set<String>RASTER_MIMESA set of MIME types that refer to a JPEG, PNG, or GIFprotected Set<String>SVG_MIMESA set of MIME types that refer to a SVGprotected FiletempDirprotected Set<String>VALID_TYPESA set of MIME types that can have a citation page added to them.
-
Constructor Summary
Constructors Modifier Constructor Description protectedCitationDocumentServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddCoverPageToDocument(org.apache.pdfbox.pdmodel.PDDocument document, org.apache.pdfbox.pdmodel.PDDocument sourceDocument, org.apache.pdfbox.pdmodel.PDPage coverPage)voidafterPropertiesSet()booleancanGenerateCitationVersion(Context context, Bitstream bitstream)intdrawStringWordWrap(org.apache.pdfbox.pdmodel.PDPage page, org.apache.pdfbox.pdmodel.PDPageContentStream contentStream, String text, int startX, int startY, org.apache.pdfbox.pdmodel.font.PDFont pdfFont, float fontSize)voiddrawTable(org.apache.pdfbox.pdmodel.PDPage page, org.apache.pdfbox.pdmodel.PDPageContentStream contentStream, float y, float margin, String[][] content, org.apache.pdfbox.pdmodel.font.PDFont font, int fontSize, boolean cellBorders)protected voidgenerateCoverPage(Context context, org.apache.pdfbox.pdmodel.PDDocument document, org.apache.pdfbox.pdmodel.PDPage coverPage, Item item)StringgetAllMetadataSeparated(Item item, String metadataKey)Get metadata separated by value separator (semicolon)StringgetOwningCollection(Item item)Get name of owning collectionStringgetOwningCommunity(Context context, Item item)Get name of owning communityBooleanisCitationEnabledForBitstream(Bitstream bitstream, Context context)Repository policy can specify to have a custom citation cover/tail page to the document, which embeds metadata.protected booleanisCitationEnabledGlobally()protected booleanisCitationEnabledThroughCollection(Context context, Bitstream bitstream)protected BooleanisCitationFirstPage()org.apache.commons.lang3.tuple.Pair<byte[],Long>makeCitedDocument(Context context, Bitstream bitstream)Creates a cited document from the given bitstream of the given item.
-
-
-
Field Detail
-
VALID_TYPES
protected final Set<String> VALID_TYPES
A set of MIME types that can have a citation page added to them. That is, MIME types in this set can be converted to a PDF which is then prepended with a citation page.
-
RASTER_MIMES
protected final Set<String> RASTER_MIMES
A set of MIME types that refer to a JPEG, PNG, or GIF
-
citationEnabledCollectionsList
protected List<String> citationEnabledCollectionsList
List of all enabled collections, inherited/determined for those under communities.
-
tempDir
protected File tempDir
-
header1
protected String[] header1
-
header2
protected String[] header2
-
fields
protected String[] fields
-
footer
protected String footer
-
citationPageFormat
protected org.apache.pdfbox.pdmodel.common.PDRectangle citationPageFormat
Citation page format
-
authorizeService
@Autowired(required=true) protected AuthorizeService authorizeService
-
bitstreamService
@Autowired(required=true) protected BitstreamService bitstreamService
-
communityService
@Autowired(required=true) protected CommunityService communityService
-
itemService
@Autowired(required=true) protected ItemService itemService
-
configurationService
@Autowired(required=true) protected ConfigurationService configurationService
-
handleService
@Autowired(required=true) protected HandleService handleService
-
citationEnabledGlobally
protected Boolean citationEnabledGlobally
Boolean to determine is citation-functionality is enabled globally for entire site. config/module/citation-page: enable_globally, default false. true=on, false=off
-
citationAsFirstPage
protected Boolean citationAsFirstPage
Should the citation page be the first page of the document, or the last page? default = true. true = first page, false = last page citation_as_first_page=true
-
-
Method Detail
-
afterPropertiesSet
public void afterPropertiesSet() throws Exception- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception
-
isCitationEnabledGlobally
protected boolean isCitationEnabledGlobally()
-
isCitationEnabledThroughCollection
protected boolean isCitationEnabledThroughCollection(Context context, Bitstream bitstream) throws SQLException
- Throws:
SQLException
-
isCitationEnabledForBitstream
public Boolean isCitationEnabledForBitstream(Bitstream bitstream, Context context) throws SQLException
Description copied from interface:CitationDocumentServiceRepository policy can specify to have a custom citation cover/tail page to the document, which embeds metadata. We need to determine if we will intercept this bitstream download, and give out a citation dissemination rendition. What will trigger a redirect/intercept? Citation enabled globally (all citable bitstreams will get "watermarked") modules/disseminate-citation: enable_globally OR The container is this object is "allow list" enabled. - community: modules/disseminate-citation: enabled_communities - collection: modules/disseminate-citation: enabled_collections AND This User is not an admin. (Admins need to be able to view the "raw" original instead.) AND This object is citation-able (presently, just PDF) The module must be enabled, before the permission level checks happen.- Specified by:
isCitationEnabledForBitstreamin interfaceCitationDocumentService- Parameters:
bitstream- DSpace bitstreamcontext- DSpace context- Returns:
- true or false
- Throws:
SQLException- if error
-
isCitationFirstPage
protected Boolean isCitationFirstPage()
-
canGenerateCitationVersion
public boolean canGenerateCitationVersion(Context context, Bitstream bitstream) throws SQLException
- Specified by:
canGenerateCitationVersionin interfaceCitationDocumentService- Parameters:
context- DSpace Contextbitstream- DSpace Bitstream- Returns:
- true or false
- Throws:
SQLException- if error
-
makeCitedDocument
public org.apache.commons.lang3.tuple.Pair<byte[],Long> makeCitedDocument(Context context, Bitstream bitstream) throws IOException, SQLException, AuthorizeException
Description copied from interface:CitationDocumentServiceCreates a cited document from the given bitstream of the given item. This requires that bitstream is contained in item.The Process for adding a cover page is as follows:
- Load source file into PdfReader and create a Document to put our cover page into.
- Create cover page and add content to it.
- Concatenate the coverpage and the source document.
- Specified by:
makeCitedDocumentin interfaceCitationDocumentService- Parameters:
context- DSpace contextbitstream- The source bitstream being cited. This must be a PDF.- Returns:
- The temporary File that is the finished, cited document.
- Throws:
IOException- if IO errorSQLException- if database errorAuthorizeException- if authorization error
-
generateCoverPage
protected void generateCoverPage(Context context, org.apache.pdfbox.pdmodel.PDDocument document, org.apache.pdfbox.pdmodel.PDPage coverPage, Item item) throws IOException
- Throws:
IOException
-
addCoverPageToDocument
protected void addCoverPageToDocument(org.apache.pdfbox.pdmodel.PDDocument document, org.apache.pdfbox.pdmodel.PDDocument sourceDocument, org.apache.pdfbox.pdmodel.PDPage coverPage)
-
drawStringWordWrap
public int drawStringWordWrap(org.apache.pdfbox.pdmodel.PDPage page, org.apache.pdfbox.pdmodel.PDPageContentStream contentStream, String text, int startX, int startY, org.apache.pdfbox.pdmodel.font.PDFont pdfFont, float fontSize) throws IOException- Specified by:
drawStringWordWrapin interfaceCitationDocumentService- Parameters:
page- pagecontentStream- content streamtext- text to drawstartX- x-coordinate of wordstartY- y-coordinate of wordpdfFont- fontfontSize- size of font- Returns:
- integer
- Throws:
IOException- if IO error
-
getOwningCommunity
public String getOwningCommunity(Context context, Item item)
Description copied from interface:CitationDocumentServiceGet name of owning community- Specified by:
getOwningCommunityin interfaceCitationDocumentService- Parameters:
context- DSpace contextitem- DSpace Item- Returns:
- name
-
getOwningCollection
public String getOwningCollection(Item item)
Description copied from interface:CitationDocumentServiceGet name of owning collection- Specified by:
getOwningCollectionin interfaceCitationDocumentService- Parameters:
item- DSpace Item- Returns:
- owning collection name
-
getAllMetadataSeparated
public String getAllMetadataSeparated(Item item, String metadataKey)
Description copied from interface:CitationDocumentServiceGet metadata separated by value separator (semicolon)- Specified by:
getAllMetadataSeparatedin interfaceCitationDocumentService- Parameters:
item- DSpace ItemmetadataKey- metadata string- Returns:
- string
- See Also:
DSpaceObjectService.getMetadataByMetadataString(org.dspace.content .DSpaceObject, java.lang.String)
-
drawTable
public void drawTable(org.apache.pdfbox.pdmodel.PDPage page, org.apache.pdfbox.pdmodel.PDPageContentStream contentStream, float y, float margin, String[][] content, org.apache.pdfbox.pdmodel.font.PDFont font, int fontSize, boolean cellBorders) throws IOException- Specified by:
drawTablein interfaceCitationDocumentService- Parameters:
page- pagecontentStream- content streamy- the y-coordinate of the first rowmargin- the padding on left and right of tablecontent- a 2d array containing the table datafont- PDFontfontSize- size of font (int)cellBorders- whether to include cellBorders- Throws:
IOException- if error
-
-