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.CmsProperty; 37 import org.opencms.file.CmsPropertyDefinition; 38 import org.opencms.file.CmsResource; 39 import org.opencms.main.CmsException; 40 import org.opencms.main.OpenCms; 41 import org.opencms.search.A_CmsIndexResource; 42 import org.opencms.search.CmsIndexException; 43 import org.opencms.search.extractors.CmsExtractionResult; 44 import org.opencms.search.extractors.I_CmsExtractionResult; 45 46 56 public class CmsDocumentPlainText extends A_CmsVfsDocument { 57 58 63 public CmsDocumentPlainText(String name) { 64 65 super(name); 66 } 67 68 73 public I_CmsExtractionResult extractContent(CmsObject cms, A_CmsIndexResource indexResource, String language) 74 throws CmsException { 75 76 CmsResource resource = (CmsResource)indexResource.getData(); 77 String result = null; 78 79 try { 80 String path = cms.getRequestContext().removeSiteRoot(resource.getRootPath()); 81 CmsProperty extractionClass = cms.readPropertyObject( 82 path, 83 CmsPropertyDefinition.PROPERTY_SEARCH_EXTRACTIONCLASS, 84 true); 85 if (extractionClass != CmsProperty.getNullProperty()) { 86 Object ext = Class.forName(extractionClass.getValue()).newInstance(); 87 88 if (ext instanceof I_CmsSearchExtractor) { 89 90 I_CmsSearchExtractor extractor = (I_CmsSearchExtractor)ext; 91 return extractor.extractContent(cms, indexResource, language); 92 } else { 93 throw new CmsIndexException(Messages.get().container( 94 Messages.ERR_EXTRACTION_CLASS_2, 95 resource.getRootPath(), 96 ext.getClass().getName())); 97 98 } 99 } else { 100 CmsProperty encoding = cms.readPropertyObject( 101 path, 102 CmsPropertyDefinition.PROPERTY_CONTENT_ENCODING, 103 true); 104 CmsFile file = readFile(cms, resource); 105 result = new String (file.getContents(), encoding.getValue(OpenCms.getSystemInfo().getDefaultEncoding())); 106 return new CmsExtractionResult(result); 107 } 108 } catch (Exception e) { 109 throw new CmsIndexException( 110 Messages.get().container(Messages.ERR_TEXT_EXTRACTION_1, resource.getRootPath()), 111 e); 112 } 113 } 114 } | Popular Tags |