1 31 32 package org.opencms.search.documents; 33 34 import org.opencms.file.CmsFile; 35 import org.opencms.file.CmsObject; 36 import org.opencms.file.CmsResource; 37 import org.opencms.main.CmsException; 38 import org.opencms.search.A_CmsIndexResource; 39 import org.opencms.search.CmsIndexException; 40 import org.opencms.search.extractors.CmsExtractorPdf; 41 import org.opencms.search.extractors.I_CmsExtractionResult; 42 43 import org.pdfbox.exceptions.CryptographyException; 44 import org.pdfbox.exceptions.InvalidPasswordException; 45 46 56 public class CmsDocumentPdf extends A_CmsVfsDocument { 57 58 63 public CmsDocumentPdf(String name) { 64 65 super(name); 66 } 67 68 73 public I_CmsExtractionResult extractContent(CmsObject cms, A_CmsIndexResource indexResource, String language) 74 throws CmsIndexException, CmsException { 75 76 CmsResource resource = (CmsResource)indexResource.getData(); 77 CmsFile file = readFile(cms, resource); 78 79 try { 80 return CmsExtractorPdf.getExtractor().extractText(file.getContents()); 81 } catch (Exception e) { 82 if (e instanceof CryptographyException) { 83 throw new CmsIndexException(Messages.get().container( 84 Messages.ERR_DECRYPTING_RESOURCE_1, 85 resource.getRootPath()), e); 86 } 87 if (e instanceof InvalidPasswordException) { 88 throw new CmsIndexException(Messages.get().container( 90 Messages.ERR_PWD_PROTECTED_1, 91 resource.getRootPath()), e); 92 } 93 throw new CmsIndexException( 94 Messages.get().container(Messages.ERR_TEXT_EXTRACTION_1, resource.getRootPath()), 95 e); 96 } 97 } 98 } | Popular Tags |