All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opencms.search.solr.CmsSolrDocumentContainerPage Maven / Gradle / Ivy

Go to download

OpenCms is an enterprise-ready, easy to use website content management system based on Java and XML technology. Offering a complete set of features, OpenCms helps content managers worldwide to create and maintain beautiful websites fast and efficiently.

There is a newer version: 18.0
Show newest version
/*
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software GmbH & Co. KG, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.search.solr;

import org.opencms.ade.configuration.CmsADEConfigData;
import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.main.CmsException;
import org.opencms.main.OpenCms;
import org.opencms.search.CmsIndexException;
import org.opencms.search.CmsSearchIndex;
import org.opencms.search.documents.Messages;
import org.opencms.search.extractors.CmsExtractionResult;
import org.opencms.search.extractors.I_CmsExtractionResult;
import org.opencms.xml.containerpage.CmsContainerElementBean;
import org.opencms.xml.containerpage.CmsContainerPageBean;
import org.opencms.xml.containerpage.CmsFormatterConfiguration;
import org.opencms.xml.containerpage.CmsXmlContainerPage;
import org.opencms.xml.containerpage.CmsXmlContainerPageFactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

/**
 * Lucene document factory class to extract index data from a resource
 * of type CmsResourceTypeContainerPage.

* * @since 8.5.0 */ public class CmsSolrDocumentContainerPage extends CmsSolrDocumentXmlContent { /** The solr document type name for xml-contents. */ public static final String TYPE_CONTAINERPAGE_SOLR = "containerpage-solr"; /** * Creates a new instance of this lucene document factory.

* * @param name name of the document type */ public CmsSolrDocumentContainerPage(String name) { super(name); } /** * Returns the raw text content of a VFS resource of type CmsResourceTypeContainerPage.

* * @see org.opencms.search.documents.I_CmsSearchExtractor#extractContent(CmsObject, CmsResource, CmsSearchIndex) */ @Override public I_CmsExtractionResult extractContent(CmsObject cms, CmsResource resource, CmsSearchIndex index) throws CmsException { return extractContent(cms, resource, index, null); } /** * Extracts the content of a given index resource according to the resource file type and the * configuration of the given index.

* * @param cms the cms object * @param resource the resource to extract the content from * @param index the index to extract the content for * @param forceLocale if set, only the content values for the given locale will be extracted * * @return the extracted content of the resource * * @throws CmsException if something goes wrong */ public I_CmsExtractionResult extractContent( CmsObject cms, CmsResource resource, CmsSearchIndex index, Locale forceLocale) throws CmsException { logContentExtraction(resource, index); I_CmsExtractionResult ex = null; try { CmsFile file = readFile(cms, resource); CmsXmlContainerPage containerPage = CmsXmlContainerPageFactory.unmarshal(cms, file); List all = new ArrayList(); CmsContainerPageBean containerBean = containerPage.getContainerPage(cms); if (containerBean != null) { for (CmsContainerElementBean element : containerBean.getElements()) { // check all elements in this container // get the formatter configuration for this element element.initResource(cms); CmsADEConfigData adeConfig = OpenCms.getADEManager().lookupConfiguration(cms, file.getRootPath()); CmsFormatterConfiguration formatters = adeConfig.getFormatters(cms, element.getResource()); if ((formatters != null) && (element.getFormatterId() != null) && formatters.isSearchContent(element.getFormatterId())) { // the content of this element must be included for the container page element.initResource(cms); all.add( CmsSolrDocumentXmlContent.extractXmlContent( cms, element.getResource(), index, forceLocale)); } } } // we have to overwrite the resource and content locales with the one from this container page // TODO: Is this really the wanted behavior? It seems to be done like this before. Map fieldMappings = new HashMap(1); // Add to each container page the contents in all available locales, // in case one containerpage is used in multiple languages. List localesAvailable = OpenCms.getLocaleManager().getAvailableLocales(cms, resource); Map> multilingualValues = new HashMap>( localesAvailable.size()); for (Locale localeAvailable : localesAvailable) { multilingualValues.put(localeAvailable, new LinkedHashMap()); } Locale locale = forceLocale != null ? forceLocale : index.getLocaleForResource(cms, resource, containerPage.getLocales()); ex = new CmsExtractionResult(locale, multilingualValues, fieldMappings); ex = ex.merge(all); return ex; } catch (Exception e) { throw new CmsIndexException( Messages.get().container(Messages.ERR_TEXT_EXTRACTION_1, resource.getRootPath()), e); } } /** * @see org.opencms.search.documents.I_CmsDocumentFactory#isLocaleDependend() */ @Override public boolean isLocaleDependend() { return true; } /** * @see org.opencms.search.documents.I_CmsDocumentFactory#isUsingCache() */ @Override public boolean isUsingCache() { return true; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy