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.cms.content; 017 018import org.apache.avalon.framework.component.Component; 019import org.apache.avalon.framework.service.ServiceException; 020import org.apache.avalon.framework.service.ServiceManager; 021import org.apache.avalon.framework.service.Serviceable; 022 023import org.ametys.cms.repository.Content; 024import org.ametys.plugins.repository.AmetysObjectResolver; 025import org.ametys.plugins.repository.RepositoryConstants; 026import org.ametys.plugins.repository.collection.AmetysObjectCollection; 027 028/** 029 * Helper for retrieving root of contents 030 */ 031public class RootContentHelper implements Component, Serviceable 032{ 033 /** The component role. */ 034 public static final String ROLE = RootContentHelper.class.getName(); 035 036 /** Ametys object resolver */ 037 protected AmetysObjectResolver _resolver; 038 039 @Override 040 public void service(ServiceManager manager) throws ServiceException 041 { 042 _resolver = (AmetysObjectResolver) manager.lookup(AmetysObjectResolver.ROLE); 043 } 044 045 /** 046 * Gets the root of contents 047 * @return the root of contents 048 */ 049 public AmetysObjectCollection getRootContent() 050 { 051 return _resolver.resolveByPath("/" + RepositoryConstants.NAMESPACE_PREFIX + ":contents"); 052 } 053 054 /** 055 * Tests if the given content is child of the root of contents, i.e. the given content is managed by the CMS workspace 056 * @param content The content to test 057 * @return true if the given content is child of the root of contents 058 */ 059 public boolean isChildOfRootContent(Content content) 060 { 061 return getRootContent().equals(content.getParent()); 062 } 063}