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.web.indexing.solr; 017 018import java.util.Collections; 019import java.util.Set; 020 021import org.apache.avalon.framework.context.Context; 022import org.apache.avalon.framework.context.ContextException; 023import org.apache.avalon.framework.context.Contextualizable; 024import org.apache.avalon.framework.service.ServiceException; 025import org.apache.avalon.framework.service.ServiceManager; 026import org.apache.avalon.framework.service.Serviceable; 027 028import org.ametys.cms.content.ContentHelper; 029import org.ametys.cms.content.indexing.solr.SolrContentRightIndexerExtension; 030import org.ametys.cms.repository.Content; 031import org.ametys.web.repository.content.WebContent; 032 033/** 034 * Implementation for {@link WebContent}s 035 */ 036public class SolrWebContentRightIndexerExtension implements SolrContentRightIndexerExtension, Serviceable, Contextualizable 037{ 038 /** The helper for contents */ 039 protected ContentHelper _contentHelper; 040 041 /** The avalon context */ 042 protected Context _context; 043 044 public void contextualize(Context context) throws ContextException 045 { 046 _context = context; 047 } 048 049 public void service(ServiceManager manager) throws ServiceException 050 { 051 _contentHelper = (ContentHelper) manager.lookup(ContentHelper.ROLE); 052 } 053 054 public Set<Object> getParents(Object context) 055 { 056 if (context instanceof WebContent) 057 { 058 return Collections.singleton(((Content) context).getParent()); 059 } 060 else 061 { 062 return null; 063 } 064 } 065}