001/* 002 * Copyright 2021 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 */ 016 017package org.ametys.plugins.ugc.page; 018 019import org.apache.avalon.framework.service.ServiceException; 020import org.apache.avalon.framework.service.ServiceManager; 021import org.apache.avalon.framework.service.Serviceable; 022import org.apache.commons.lang3.StringUtils; 023 024import org.ametys.plugins.repository.AmetysObjectFactory; 025import org.ametys.plugins.repository.AmetysObjectResolver; 026import org.ametys.plugins.repository.AmetysRepositoryException; 027import org.ametys.web.repository.page.PageDataTypeExtensionPoint; 028import org.ametys.web.service.ServiceExtensionPoint; 029 030/** 031 * {@link AmetysObjectFactory} handling {@link UGCTransitionalZoneItem}. 032 */ 033public class UGCTransitionalZoneItemFactory implements AmetysObjectFactory<UGCTransitionalZoneItem>, Serviceable 034{ 035 AmetysObjectResolver _resolver; 036 ServiceExtensionPoint _serviceExtensionPoint; 037 PageDataTypeExtensionPoint _pageDataTypeExtensionPoint; 038 039 @Override 040 public void service(ServiceManager manager) throws ServiceException 041 { 042 _resolver = (AmetysObjectResolver) manager.lookup(AmetysObjectResolver.ROLE); 043 _serviceExtensionPoint = (ServiceExtensionPoint) manager.lookup(ServiceExtensionPoint.ROLE); 044 _pageDataTypeExtensionPoint = (PageDataTypeExtensionPoint) manager.lookup(PageDataTypeExtensionPoint.ROLE); 045 } 046 047 @Override 048 public UGCTransitionalZoneItem getAmetysObjectById(String id) throws AmetysRepositoryException 049 { 050 String pageId = StringUtils.substringAfter(id, "?pageId="); 051 UGCTransitionalPage page = _resolver.resolveById(pageId); 052 053 return new UGCTransitionalZoneItem(page, _pageDataTypeExtensionPoint, _serviceExtensionPoint, _pageDataTypeExtensionPoint); 054 } 055 056 @Override 057 public String getScheme() 058 { 059 return "ugctransionalzoneitem"; 060 } 061 062 @Override 063 public boolean hasAmetysObjectForId(String id) throws AmetysRepositoryException 064 { 065 String pageId = StringUtils.substringAfter(id, "?pageId="); 066 return _resolver.hasAmetysObjectForId(pageId); 067 } 068}