/** * @see org.opencms.search.extractors.A_CmsTextExtractor#extractText(java.io.InputStream, java.lang.String) */ @Override public I_CmsExtractionResult extractText(InputStream in, String encoding) throws Exception { ZipInputStream zin = new ZipInputStream(in); ZipEntry ze; boolean FOUND_CONTENT = false; String result = ""; while (!FOUND_CONTENT) { ze = zin.getNextEntry(); FOUND_CONTENT = ze.getName().equalsIgnoreCase("content.xml"); if (FOUND_CONTENT) { result = readContent(zin); try { zin.close(); } catch (Exception e) { e.printStackTrace(System.err); } } } result = removeControlChars(result); return new CmsExtractionResult(result); }
/** * @see org.opencms.search.extractors.A_CmsTextExtractor#extractText(java.io.InputStream, java.lang.String) */ @Override public I_CmsExtractionResult extractText(InputStream in, String encoding) throws Exception { ZipInputStream zin = new ZipInputStream(in); ZipEntry ze; boolean FOUND_CONTENT = false; String result = ""; while (!FOUND_CONTENT) { ze = zin.getNextEntry(); FOUND_CONTENT = ze.getName().equalsIgnoreCase("content.xml"); if (FOUND_CONTENT) { result = readContent(zin); try { zin.close(); } catch (Exception e) { e.printStackTrace(System.err); } } } result = removeControlChars(result); return new CmsExtractionResult(result); }
/** * @see org.opencms.search.extractors.I_CmsExtractionResult#merge(java.util.List) */ public I_CmsExtractionResult merge(List<I_CmsExtractionResult> extractionResults) { //prepare copy Map<Locale, LinkedHashMap<String, String>> contentItems = new HashMap<Locale, LinkedHashMap<String, String>>( m_locales.size()); for (Locale locale : m_locales) { LinkedHashMap<String, String> originalLocalValues = m_contentItems.get(locale); LinkedHashMap<String, String> localeValues = new LinkedHashMap<String, String>(originalLocalValues); contentItems.put(locale, localeValues); } HashMap<String, String> fieldMappings = new HashMap<String, String>(m_fieldMappings.size()); for (String fieldMapping : m_fieldMappings.keySet()) { fieldMappings.put(fieldMapping, m_fieldMappings.get(fieldMapping)); } //merge content from the other extraction results for (Locale locale : m_locales) { Map<String, String> localeValues = contentItems.get(locale); for (I_CmsExtractionResult result : extractionResults) { if (result.getLocales().contains(locale)) { Map<String, String> resultLocaleValues = result.getContentItems(locale); for (String item : Arrays.asList(ITEMS_TO_MERGE)) { localeValues = mergeItem(item, localeValues, resultLocaleValues); } } } } return new CmsExtractionResult(m_defaultLocale, contentItems, fieldMappings); }
/** * @see org.opencms.search.extractors.I_CmsTextExtractor#extractText(byte[], java.lang.String) */ @Override public I_CmsExtractionResult extractText(byte[] content, String encoding) throws Exception { String result = ""; try { // RTF always uses ASCII, so we don't need to care about the encoding String input = new String(content); // workaround to remove RTF keywords that cause a NPE in Java 1.4 // this is a known bug in Java 1.4 that was fixed in 1.5 // please see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5042109 for the official bug report input = TS_REMOVE_PATTERN.matcher(input).replaceAll(""); // use build in RTF parser from Swing API RTFEditorKit rtfEditor = new RTFEditorKit(); Document doc = rtfEditor.createDefaultDocument(); rtfEditor.read(new StringReader(input), doc, 0); result = doc.getText(0, doc.getLength()); result = removeControlChars(result); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error(Messages.get().container(Messages.LOG_EXTRACT_TEXT_ERROR_0), e); } } return new CmsExtractionResult(result); }
/** * Just returns an empty extraction result since the content can't be extracted form a generic resource.<p> * * @see org.opencms.search.documents.I_CmsSearchExtractor#extractContent(CmsObject, CmsResource, CmsSearchIndex) */ public I_CmsExtractionResult extractContent(CmsObject cms, CmsResource resource, CmsSearchIndex index) throws CmsIndexException { if (resource == null) { throw new CmsIndexException(Messages.get().container(Messages.ERR_NO_RAW_CONTENT_1, index.getLocale())); } // just return an empty result set return new CmsExtractionResult(""); }
/** * Just returns an empty extraction result since the content can't be extracted form a generic resource.<p> * * @see org.opencms.search.documents.I_CmsSearchExtractor#extractContent(CmsObject, CmsResource, CmsSearchIndex) */ public I_CmsExtractionResult extractContent(CmsObject cms, CmsResource resource, CmsSearchIndex index) throws CmsIndexException { if (resource == null) { throw new CmsIndexException(Messages.get().container(Messages.ERR_NO_RAW_CONTENT_1, index.getLocale())); } // just return an empty result set return new CmsExtractionResult(""); }
/** * @see org.opencms.search.extractors.I_CmsTextExtractor#extractText(java.io.InputStream, java.lang.String) */ @Override public I_CmsExtractionResult extractText(InputStream in, String encoding) throws Exception { String result = ""; try { if (CmsStringUtil.isEmpty(encoding)) { encoding = OpenCms.getSystemInfo().getDefaultEncoding(); } result = CmsHtmlExtractor.extractText(in, encoding); result = removeControlChars(result); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error(Messages.get().container(Messages.LOG_EXTRACT_TEXT_ERROR_0), e); } } return new CmsExtractionResult(result); } }
return new CmsExtractionResult(content.toString(), items);
/** * @see org.opencms.search.extractors.I_CmsTextExtractor#extractText(java.io.InputStream, java.lang.String) */ @Override public I_CmsExtractionResult extractText(InputStream in, String encoding) throws Exception { String result = ""; try { if (CmsStringUtil.isEmpty(encoding)) { encoding = OpenCms.getSystemInfo().getDefaultEncoding(); } result = CmsHtmlExtractor.extractText(in, encoding); result = removeControlChars(result); } catch (Exception e) { if (LOG.isErrorEnabled()) { LOG.error(Messages.get().container(Messages.LOG_EXTRACT_TEXT_ERROR_0), e); } } return new CmsExtractionResult(result); } }
return new CmsExtractionResult(content.toString(), items); } catch (Exception e) { throw new CmsIndexException(
return new CmsExtractionResult(content.toString(), items);
/** * Returns the raw text content of a given vfs resource containing plain text data.<p> * * @see org.opencms.search.documents.I_CmsSearchExtractor#extractContent(CmsObject, CmsResource, CmsSearchIndex) */ public I_CmsExtractionResult extractContent(CmsObject cms, CmsResource resource, CmsSearchIndex index) throws CmsException { CmsFile file = readFile(cms, resource); try { CmsProperty encProp = cms.readPropertyObject( resource, CmsPropertyDefinition.PROPERTY_CONTENT_ENCODING, true); String encoding = encProp.getValue(OpenCms.getSystemInfo().getDefaultEncoding()); return new CmsExtractionResult(new String(file.getContents(), encoding)); } catch (Exception e) { throw new CmsIndexException( Messages.get().container(Messages.ERR_TEXT_EXTRACTION_1, resource.getRootPath()), e); } }
return new CmsExtractionResult(content.toString(), items);
/** * Returns the raw text content of a given vfs resource containing plain text data.<p> * * @see org.opencms.search.documents.I_CmsSearchExtractor#extractContent(CmsObject, CmsResource, CmsSearchIndex) */ public I_CmsExtractionResult extractContent(CmsObject cms, CmsResource resource, CmsSearchIndex index) throws CmsException { logContentExtraction(resource, index); CmsFile file = readFile(cms, resource); try { CmsProperty encProp = cms.readPropertyObject( resource, CmsPropertyDefinition.PROPERTY_CONTENT_ENCODING, true); String encoding = encProp.getValue(OpenCms.getSystemInfo().getDefaultEncoding()); return new CmsExtractionResult(new String(file.getContents(), encoding)); } catch (Exception e) { throw new CmsIndexException( Messages.get().container(Messages.ERR_TEXT_EXTRACTION_1, resource.getRootPath()), e); } }
return new CmsExtractionResult(resourceLocale, items, fieldMappings);
return new CmsExtractionResult(content.toString(), contentItems);
return new CmsExtractionResult(content.toString(), contentItems);
? forceLocale : index.getLocaleForResource(cms, resource, containerPage.getLocales()); ex = new CmsExtractionResult(locale, multilingualValues, fieldMappings); ex = ex.merge(all); return ex;
return new CmsExtractionResult(content.toString(), items);
return new CmsExtractionResult(content.toString(), contentItems);