001/* 002 * Copyright 2016 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.explorer; 017 018import org.ametys.cms.indexing.explorer.SolrIndexResourceObserver; 019import org.ametys.plugins.repository.AmetysObject; 020import org.ametys.plugins.repository.RepositoryConstants; 021import org.ametys.web.WebConstants; 022import org.ametys.web.explorer.ResourceHelper; 023import org.ametys.web.repository.site.Site; 024 025/** 026 * Observer in charge of indexing resources in web context when created, modified, moved... 027 */ 028public class SolrIndexWebResourceObserver extends SolrIndexResourceObserver 029{ 030 @Override 031 protected boolean isHandledResource(AmetysObject object) 032 { 033 if (object != null) 034 { 035 AmetysObject parent = object.getParent(); 036 while (parent != null) 037 { 038 String name = parent.getName(); 039 if ((RepositoryConstants.NAMESPACE_PREFIX_INTERNAL + ":resources").equals(name) && parent.getParent() instanceof Site // resource of a site 040 || "shared-resources".equals(name) && ResourceHelper.SHARED_RESOURCE_PATH.equals(parent.getPath()) // shared resource (first, check the name to avoid too much path computing) 041 || (RepositoryConstants.NAMESPACE_PREFIX + ":resources").equals(name) && ("/" + RepositoryConstants.NAMESPACE_PREFIX + ":resources").equals(parent.getPath())) // resource of CMS (first, check the name to avoid too much path computing) 042 { 043 // The given object is a resource handled by this observer 044 return true; 045 } 046 else if ((RepositoryConstants.NAMESPACE_PREFIX_INTERNAL + ":attachments").equals(name)) 047 { 048 // It is an attachment of a content or page, not handled 049 return false; 050 } 051 parent = parent.getParent(); 052 } 053 } 054 055 return false; 056 } 057 058 @Override 059 protected String[] getWorkspacesToIndex() 060 { 061 return new String[] {RepositoryConstants.DEFAULT_WORKSPACE, WebConstants.LIVE_WORKSPACE}; 062 } 063}