001/*
002 *  Copyright 2017 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.plugins.extraction.component;
017
018import java.util.Map;
019
020import org.apache.avalon.framework.configuration.Configuration;
021import org.apache.avalon.framework.configuration.ConfigurationException;
022import org.apache.commons.lang.StringUtils;
023import org.xml.sax.ContentHandler;
024
025import org.ametys.cms.repository.Content;
026import org.ametys.plugins.extraction.ExtractionConstants;
027import org.ametys.plugins.extraction.execution.ExtractionExecutionContext;
028import org.ametys.plugins.extraction.execution.ExtractionExecutionContextHierarchyElement;
029
030/**
031 * This class represents a mapping query component of the extraction module
032 */
033public class MappingQueryExtractionComponent extends AbstractSolrExtractionComponent
034{
035    @Override
036    public void configure(Configuration configuration) throws ConfigurationException
037    {
038        String tagName = configuration.getAttribute("tagName", null);
039        if (tagName != null && !StringUtils.isEmpty(tagName))
040        {
041            throw new IllegalArgumentException(getLogsPrefix() + "a maping query component can't have a tagName attribute");
042        }
043        
044        super.configure(configuration);
045    }
046
047    @Override
048    protected void processContents(Iterable<Content> contents, ContentHandler contentHandler, ExtractionExecutionContext context) throws Exception
049    {
050        if (contents.iterator().hasNext())
051        {
052            ExtractionExecutionContextHierarchyElement currentContext = new ExtractionExecutionContextHierarchyElement(this, contents);
053            executeSubComponents(contentHandler, context, currentContext);
054        }
055    }
056    
057    @Override
058    public Map<String, Object> getComponentDetailsForTree()
059    {
060        Map<String, Object> details = super.getComponentDetailsForTree();
061        details.put("text", "mapping-query");
062        details.put("tag", ExtractionConstants.MAPPING_QUERY_COMPONENT_TAG);
063        details.put("iconCls", "ametysicon-squares");
064        return details;
065    }
066
067    @Override
068    protected String getDefaultTagName()
069    {
070        return null;
071    }
072    
073    @Override
074    protected String getLogsPrefix()
075    {
076        return "Mapping-query component: ";
077    }
078}