Skip to content
Snippets Groups Projects

refacto: move file quality control into a service implementing an interface

Merged Nicolas.Rod requested to merge rodn-file-metadata-interface into master
2 unresolved threads

Merge request reports

Approved by

Merged by Homada.BoumedaneHomada.Boumedane 4 years ago (Jan 20, 2021 12:23pm UTC)

Merge details

  • Changes merged into master with ecc44dbf.
  • Deleted the source branch.

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
7 import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException;
8 import org.apache.pdfbox.text.PDFTextStripper;
9 import org.springframework.stereotype.Service;
10
11 import ch.unige.aou.model.publication.DocumentFile;
12
13 /**
14 * FileMetadataExtractor implementation that supports only PDF files
15 */
16 @Service
17 public class PdfBoxMetadataExtractor implements FileMetadataExtractor {
18
19 @Override
20 public boolean isPasswordProtected(DocumentFile pdfDocumentFile) throws IOException {
21 PDDocument doc = null;
22 try {
  • 23 doc = PDDocument.load(new File(pdfDocumentFile.getFinalData()));
    24 return false;
    25 } catch (InvalidPasswordException invalidPasswordException) {
    26 return true;
    27 } finally {
    28 if (doc != null) {
    29 doc.close();
    30 }
    31 }
    32 }
    33
    34 @Override
    35 public String getText(DocumentFile pdfDocumentFile) throws IOException {
    36 if (!this.isPasswordProtected(pdfDocumentFile)) {
    37 PDDocument doc = null;
    38 try {
  • Nicolas.Rod added 3 commits

    added 3 commits

    • 43cf55b3...702249ab - 2 commits from branch master
    • ed5de69e - refacto: move file quality control into a service implementing an interface

    Compare with previous version

  • Nicolas.Rod added 1 commit

    added 1 commit

    • ecc44dbf - refacto(PdfBoxMetadataExtractor): open file by using try-with-resources

    Compare with previous version

  • Homada.Boumedane approved this merge request

    approved this merge request

  • Please register or sign in to reply
    Loading