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