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; 029import org.ametys.plugins.repository.AmetysObjectIterable; 030 031/** 032 * This class represents a mapping query component of the extraction module 033 */ 034public class MappingQueryExtractionComponent extends AbstractSolrExtractionComponent 035{ 036 @Override 037 public void configure(Configuration configuration) throws ConfigurationException 038 { 039 String tagName = configuration.getAttribute("tagName", null); 040 if (tagName != null && !StringUtils.isEmpty(tagName)) 041 { 042 throw new IllegalArgumentException(getLogsPrefix() + "a maping query component can't have a tagName attribute"); 043 } 044 045 super.configure(configuration); 046 } 047 048 @Override 049 protected void processContents(AmetysObjectIterable<Content> contents, ContentHandler contentHandler, ExtractionExecutionContext context) throws Exception 050 { 051 if (contents.getSize() > 0) 052 { 053 ExtractionExecutionContextHierarchyElement currentContext = new ExtractionExecutionContextHierarchyElement(this, contents); 054 executeSubComponents(contentHandler, context, currentContext); 055 } 056 } 057 058 @Override 059 public Map<String, Object> getComponentDetailsForTree() 060 { 061 Map<String, Object> details = super.getComponentDetailsForTree(); 062 details.put("text", "mapping-query"); 063 details.put("tag", ExtractionConstants.MAPPING_QUERY_COMPONENT_TAG); 064 details.put("iconCls", "ametysicon-squares"); 065 return details; 066 } 067 068 @Override 069 protected String getDefaultTagName() 070 { 071 return null; 072 } 073 074 @Override 075 protected String getLogsPrefix() 076 { 077 return "Mapping-query component: "; 078 } 079}