/** * Returns the locale (language) of the given resource based on the resource root path.<p> * * @param rootPath the resource name to check for the locale information * * @return the locale of the given resource based on the resource root path */ public static Locale getLocale(String rootPath) { return (new CmsDocumentDependency(null, rootPath)).getLocale(); }
/** * Cleans up the extraction result cache.<p> */ protected void cleanExtractionCache() { // clean up the extraction result cache m_extractionResultCache.cleanCache(m_extractionCacheMaxAge); }
/** * @see org.opencms.main.CmsException#createException(org.opencms.i18n.CmsMessageContainer, java.lang.Throwable) */ @Override public CmsException createException(CmsMessageContainer container, Throwable cause) { return new CmsIndexNoContentException(container, cause); } }
/** * Adds the given document dependency to this document.<p> * * @param cms the current CmsObject * @param resDeps the dependency */ public void addDocumentDependency(CmsObject cms, CmsDocumentDependency resDeps) { if (resDeps != null) { m_doc.addField(CmsSearchField.FIELD_DEPENDENCY_TYPE, resDeps.getType()); if ((resDeps.getMainDocument() != null) && (resDeps.getType() != null)) { m_doc.addField( CmsSearchField.FIELD_PREFIX_DEPENDENCY + resDeps.getType().toString(), resDeps.getMainDocument().toDependencyString(cms)); } for (CmsDocumentDependency dep : resDeps.getVariants()) { m_doc.addField( CmsSearchField.FIELD_PREFIX_DEPENDENCY + dep.getType().toString(), dep.toDependencyString(cms)); } for (CmsDocumentDependency dep : resDeps.getAttachments()) { m_doc.addField( CmsSearchField.FIELD_PREFIX_DEPENDENCY + dep.getType().toString(), dep.toDependencyString(cms)); } } }
/** * Loads or creates a dependency object for the given parameters.<p> * * @param cms the current OpenCms user context * @param pubRes the published resource to get the dependency object for * * @return a dependency object for the given parameters */ public static CmsDocumentDependency load(CmsObject cms, CmsPublishedResource pubRes) { CmsDocumentDependency result = readFromContext(cms, pubRes.getRootPath()); if (result == null) { result = new CmsDocumentDependency(pubRes); result.readDependencies(cms); } return result; }
/** * Returns the raw text content of a given vfs resource containing MS Word data.<p> * * @see org.opencms.search.documents.I_CmsSearchExtractor#extractContent(CmsObject, CmsResource, CmsSearchIndex) */ public I_CmsExtractionResult extractContent(CmsObject cms, CmsResource resource, CmsSearchIndex index) throws CmsIndexException, CmsException { logContentExtraction(resource, index); CmsFile file = readFile(cms, resource); try { return CmsExtractorMsOfficeOOXML.getExtractor().extractText(file.getContents()); } catch (Exception e) { throw new CmsIndexException( Messages.get().container(Messages.ERR_TEXT_EXTRACTION_1, resource.getRootPath()), e); } }
/** * Returns the raw text content of a given vfs resource containing RTF 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 { return CmsExtractorRtf.getExtractor().extractText(file.getContents()); } catch (Exception e) { throw new CmsIndexException( Messages.get().container(Messages.ERR_TEXT_EXTRACTION_1, resource.getRootPath()), e); } }
/** * Returns the raw text content of a given vfs resource containing MS Word data.<p> * * @see org.opencms.search.documents.I_CmsSearchExtractor#extractContent(CmsObject, CmsResource, CmsSearchIndex) */ public I_CmsExtractionResult extractContent(CmsObject cms, CmsResource resource, CmsSearchIndex index) throws CmsIndexException, CmsException { CmsFile file = readFile(cms, resource); try { return CmsExtractorOpenOffice.getExtractor().extractText(file.getContents()); } catch (Exception e) { throw new CmsIndexException( Messages.get().container(Messages.ERR_TEXT_EXTRACTION_1, resource.getRootPath()), e); } }
/** * Adds another language version document dependency to this document.<p> * * @param dep the language version document dependency to add */ public void addVariant(CmsDocumentDependency dep) { // check if already exists for (CmsDocumentDependency lang : m_variants) { if (lang.getLocale().equals(dep.getLocale())) { return; } } dep.setType(DependencyType.variant); m_variants.add(dep); addDependency(dep); }
/** * Upgrades the given resource to a {@link CmsFile} with content.<p> * * @param cms the current users OpenCms context * @param resource the resource to upgrade * * @return the given resource upgraded to a {@link CmsFile} with content * * @throws CmsException if the resource could not be read * @throws CmsIndexNoContentException if the resource has no content */ protected CmsFile readFile(CmsObject cms, CmsResource resource) throws CmsException, CmsIndexNoContentException { CmsFile file = cms.readFile(resource); if (file.getLength() <= 0) { throw new CmsIndexNoContentException( Messages.get().container(Messages.ERR_NO_CONTENT_1, resource.getRootPath())); } return file; } }
/** * Returns the raw text content of a given vfs resource containing MS PowerPoint data.<p> * * @see org.opencms.search.documents.I_CmsSearchExtractor#extractContent(CmsObject, CmsResource, CmsSearchIndex) */ public I_CmsExtractionResult extractContent(CmsObject cms, CmsResource resource, CmsSearchIndex index) throws CmsIndexException, CmsException { CmsFile file = readFile(cms, resource); try { return CmsExtractorMsPowerPoint.getExtractor().extractText(file.getContents()); } catch (Exception e) { throw new CmsIndexException( Messages.get().container(Messages.ERR_TEXT_EXTRACTION_1, resource.getRootPath()), e); } }
/** * Returns a lucene document factory for given resource type and MIME type.<p> * * The type of the document factory is selected according to the configuration * in <code>opencms-search.xml</code>.<p> * * @param resourceType the resource type name * @param mimeType the MIME type * * @return a lucene document factory or null in case no matching factory was found */ public I_CmsDocumentFactory getDocumentFactory(String resourceType, String mimeType) { I_CmsDocumentFactory result = null; if (resourceType != null) { // create the factory lookup key for the document String documentTypeKey = A_CmsVfsDocument.getDocumentKey(resourceType, mimeType); // check if a setting is available for this specific MIME type result = m_documentTypes.get(documentTypeKey); if (result == null) { // no setting is available, try to use a generic setting without MIME type result = m_documentTypes.get(A_CmsVfsDocument.getDocumentKey(resourceType, null)); // please note: the result may still be null } } return result; }
/** * Stores this dependency object for a published resource in the OpenCms runtime context.<p> * * This done to optimize indexing speed. When the index update information is calculated, * all dependencies for a resource must be calculated also. The same information is later needed when * the Lucene document is created, for example in order to store the list of other available languages.<p> * * @param cms the current OpenCms user context */ public void storeInContext(CmsObject cms) { cms.getRequestContext().setAttribute(getAttributeKey(getResource().getRootPath()), this); }
/** * Creates a dependency object for the given root path, to be used only for test cases.<p> * * @param rootPath the root path to create the dependency object for * * @return a dependency object for the given parameters */ protected static CmsDocumentDependency loadForTest(String rootPath) { return new CmsDocumentDependency(null, rootPath); }
/** * @see java.lang.Object#hashCode() */ @Override public int hashCode() { return getResource().hashCode(); }
/** * Reads the dependency object for the given root path in the OpenCms runtime context.<p> * * @param cms the current OpenCms user context * @param rootPath the root path to look up the dependency object for * * @return the deps */ private static CmsDocumentDependency readFromContext(CmsObject cms, String rootPath) { return (CmsDocumentDependency)cms.getRequestContext().getAttribute(getAttributeKey(rootPath)); }
/** * * @see org.opencms.search.documents.A_CmsVfsDocument#createDocument(org.opencms.file.CmsObject, org.opencms.file.CmsResource, org.opencms.search.CmsSearchIndex) */ @Override public I_CmsSearchDocument createDocument(CmsObject cms, CmsResource resource, CmsSearchIndex index) throws CmsException { CmsXmlContentDefinition def = CmsXmlContentDefinition.getContentDefinitionForResource(cms, resource); if (def.getContentHandler().isContainerPageOnly()) { return null; } return super.createDocument(cms, resource, index); }
/** * Loads or creates a dependency object for the given parameters.<p> * * @param cms the current OpenCms user context * @param res the VFS resource to get the dependency object for * * @return a dependency object for the given parameters */ public static CmsDocumentDependency load(CmsObject cms, CmsResource res) { CmsDocumentDependency result = readFromContext(cms, res.getRootPath()); if (result == null) { result = new CmsDocumentDependency(res); result.readDependencies(cms); } return result; }
/** * Cleans up the extraction result cache.<p> */ protected void cleanExtractionCache() { // clean up the extraction result cache m_extractionResultCache.cleanCache(m_extractionCacheMaxAge); }
/** * Loads or creates a dependency object for the given parameters.<p> * * @param cms the current OpenCms user context * @param res the VFS resource to get the dependency object for * @param resources the resource folder data to check for dependencies * * @return a dependency object for the given parameters */ public static CmsDocumentDependency load(CmsObject cms, CmsResource res, List<CmsResource> resources) { CmsDocumentDependency result = readFromContext(cms, res.getRootPath()); if (result == null) { result = new CmsDocumentDependency(res); result.readDependencies(cms, resources); } return result; }