diff --git a/src/main/java/Bundle.properties b/src/main/java/Bundle.properties index 7c778761088..5a6d571d06e 100755 --- a/src/main/java/Bundle.properties +++ b/src/main/java/Bundle.properties @@ -803,6 +803,7 @@ dataset.cite.standards.tip=If you use these data, please add this citation to yo dataset.cite.downloadBtn=Download Citation dataset.cite.downloadBtn.xml=EndNote XML dataset.cite.downloadBtn.ris=RIS Format +dataset.cite.downloadBtn.bib=BibTeX Format dataset.create.authenticatedUsersOnly=Only authenticated users can create datasets. dataset.deaccession.reason=Deaccession Reason dataset.beAccessedAt=The dataset can now be accessed at: diff --git a/src/main/java/Bundle_zh_CN.properties b/src/main/java/Bundle_zh_CN.properties index 7ec37ba606f..d2a8589d2e7 100644 --- a/src/main/java/Bundle_zh_CN.properties +++ b/src/main/java/Bundle_zh_CN.properties @@ -328,6 +328,7 @@ dataset.cite.whyCite=\u4e3a\u4ec0\u4e48\u8981\u5f15\u7528\uff1f dataset.cite.downloadBtn=\u4e0b\u8f7d\u5f15\u7528 dataset.cite.downloadBtn.xml=EndNote XML dataset.cite.downloadBtn.ris=RIS\u683c\u5f0f +dataset.cite.downloadBtn.bib=BibTeX\u683c\u5f0f dataset.deaccession.reason=Deaccession\u539f\u56e0\uff1a dataset.beAccessedAt=\u8be5\u6570\u636e\u96c6\u73b0\u5728\u53ef\u4ee5\u5728{0}\u8bbf\u95ee dataset.noTemplate.label=\u6ca1\u6709\u6a21\u677f - \u6e05\u6670\u7684\u9ed8\u8ba4\u503c diff --git a/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java b/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java index d785c82213a..2c460fcb486 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java +++ b/src/main/java/edu/harvard/iq/dataverse/DatasetPage.java @@ -3311,7 +3311,44 @@ public void downloadCitationRIS(FileMetadata fileMetadata) { } } - + + public void downloadDatasetCitationBibtex() { + + downloadCitationBibtex(null); + + } + + public void downloadDatafileCitationBibtex(FileMetadata fileMetadata) { + downloadCitationBibtex(fileMetadata); + } + + public void downloadCitationBibtex(FileMetadata fileMetadata) { + + String bibFormatDowload = datasetService.createCitationBibtex(workingVersion, fileMetadata); + FacesContext ctx = FacesContext.getCurrentInstance(); + HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse(); + response.setContentType("application/download"); + + String fileNameString = ""; + if (fileMetadata == null || fileMetadata.getLabel() == null) { + // Dataset-level citation: + fileNameString = "attachment;filename=" + getFileNameDOI() + ".bib"; + } else { + // Datafile-level citation: + fileNameString = "attachment;filename=" + getFileNameDOI() + "-" + fileMetadata.getLabel().replaceAll("\\.tab$", ".bib"); + } + response.setHeader("Content-Disposition", fileNameString); + + try { + ServletOutputStream out = response.getOutputStream(); + out.write(bibFormatDowload.getBytes()); + out.flush(); + ctx.responseComplete(); + } catch (Exception e) { + + } + } + public String getDatasetPublishCustomText(){ String datasetPublishCustomText = settingsService.getValueForKey(SettingsServiceBean.Key.DatasetPublishPopupCustomText); if( datasetPublishCustomText!= null && !datasetPublishCustomText.isEmpty()){ diff --git a/src/main/java/edu/harvard/iq/dataverse/DatasetServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/DatasetServiceBean.java index 8596ba9dcc8..6fb072f2903 100644 --- a/src/main/java/edu/harvard/iq/dataverse/DatasetServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/DatasetServiceBean.java @@ -106,7 +106,7 @@ public List findAll() { /** * For docs, see the equivalent method on the DataverseServiceBean. - * @see DataverseServiceBean#findAllOrSubset(long, long) + * @see DataverseServiceBean#findAllOrSubset(long, long, boolean) */ public List findAllOrSubset(long numPartitions, long partitionId, boolean skipIndexed) { if (numPartitions < 1) { @@ -265,6 +265,36 @@ public String createCitationRIS(DatasetVersion version, FileMetadata fileMetadat return retString; } + public String createCitationBibtex(DatasetVersion version) { + return createCitationBibtex(version, null); + } + + public String createCitationBibtex(DatasetVersion version, FileMetadata fileMetadata) { + String publisher = version.getRootDataverseNameforCitation(); + List authorList = version.getDatasetAuthors(); + List authorDisplayList = new ArrayList<>(); + + for (DatasetAuthor author : authorList) { + authorDisplayList.add(author.getName().getDisplayValue()); + } + + String retString = "@data{"; + retString += version.getDataset().getIdentifier() + "_" + version.getVersionYear() + "," + "\r\n"; + retString += "author = {"; + retString += String.join("; ", authorDisplayList); + retString += "}," + "\r\n"; + retString += "publisher = {" + publisher + "}," + "\r\n"; + retString += "title = {" + version.getTitle() + "}," + "\r\n"; + retString += "year = {" + version.getVersionYear() + "}," + "\r\n"; + retString += "doi = {" + version.getDataset().getAuthority() + + version.getDataset().getDoiSeparator() + + version.getDataset().getIdentifier() + "}," + "\r\n"; + retString += "url = {" + version.getDataset().getPersistentURL() + "}" + "\r\n"; + retString += "}"; + + return retString; + } + private XMLOutputFactory xmlOutputFactory = null; public String createCitationXML(DatasetVersion datasetVersion, FileMetadata fileMetadata) { diff --git a/src/main/java/edu/harvard/iq/dataverse/api/Access.java b/src/main/java/edu/harvard/iq/dataverse/api/Access.java index 5e2d834272b..522a28362f7 100644 --- a/src/main/java/edu/harvard/iq/dataverse/api/Access.java +++ b/src/main/java/edu/harvard/iq/dataverse/api/Access.java @@ -143,7 +143,8 @@ public BundleDownloadInstance datafileBundle(@PathParam("fileId") Long fileId, @ downloadInstance.setFileCitationEndNote(datasetService.createCitationXML(datasetVersion, fileMetadata)); downloadInstance.setFileCitationRIS(datasetService.createCitationRIS(datasetVersion, fileMetadata)); - + downloadInstance.setFileCitationBibtex(datasetService.createCitationBibtex(datasetVersion, fileMetadata)); + ByteArrayOutputStream outStream = null; outStream = new ByteArrayOutputStream(); diff --git a/src/main/java/edu/harvard/iq/dataverse/api/BundleDownloadInstance.java b/src/main/java/edu/harvard/iq/dataverse/api/BundleDownloadInstance.java index 31c895f29fe..b44434107ca 100644 --- a/src/main/java/edu/harvard/iq/dataverse/api/BundleDownloadInstance.java +++ b/src/main/java/edu/harvard/iq/dataverse/api/BundleDownloadInstance.java @@ -6,8 +6,6 @@ package edu.harvard.iq.dataverse.api; -import java.util.List; - /** * * @author Leonid Andreev @@ -19,6 +17,7 @@ public class BundleDownloadInstance { private String fileCitationEndNote = ""; private String fileCitationRIS = ""; private String fileDDIXML = ""; + private String fileCitationBibtex = ""; public BundleDownloadInstance() { @@ -59,4 +58,13 @@ public String getFileDDIXML() { public void setFileDDIXML(String fileDDIXML) { this.fileDDIXML = fileDDIXML; } + + public String getFileCitationBibtex() { + return fileCitationBibtex; + } + + public void setFileCitationBibtex(String fileCitationBibtex) { + this.fileCitationBibtex = fileCitationBibtex; + } + } diff --git a/src/main/java/edu/harvard/iq/dataverse/api/BundleDownloadInstanceWriter.java b/src/main/java/edu/harvard/iq/dataverse/api/BundleDownloadInstanceWriter.java index 32967b58a1c..2c1ee91b687 100644 --- a/src/main/java/edu/harvard/iq/dataverse/api/BundleDownloadInstanceWriter.java +++ b/src/main/java/edu/harvard/iq/dataverse/api/BundleDownloadInstanceWriter.java @@ -186,6 +186,14 @@ public void writeTo(BundleDownloadInstance di, Class clazz, Type type, Annota zout.closeEntry(); } + if (di.getFileCitationBibtex() != null) { + e = new ZipEntry(fileName.replaceAll("\\.tab$","citation-bib.bib")); + + zout.putNextEntry(e); + zout.write(di.getFileCitationBibtex().getBytes()); + zout.closeEntry(); + } + zout.close(); return; } diff --git a/src/main/webapp/dataset.xhtml b/src/main/webapp/dataset.xhtml index 72fda13a700..0642a52fe21 100755 --- a/src/main/webapp/dataset.xhtml +++ b/src/main/webapp/dataset.xhtml @@ -322,6 +322,11 @@ #{bundle['dataset.cite.downloadBtn.ris']} +
  • + + #{bundle['dataset.cite.downloadBtn.bib']} + +
  • diff --git a/src/main/webapp/filesFragment.xhtml b/src/main/webapp/filesFragment.xhtml index 680a8713659..4603d57a863 100644 --- a/src/main/webapp/filesFragment.xhtml +++ b/src/main/webapp/filesFragment.xhtml @@ -491,6 +491,12 @@ +
  • + + + +
  • +