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 */ 016 017package org.ametys.plugins.userdirectory.page; 018 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.plugins.repository.AmetysObjectFactory; 024import org.ametys.plugins.repository.AmetysObjectResolver; 025import org.ametys.plugins.repository.AmetysRepositoryException; 026import org.ametys.web.data.type.ModelItemTypeExtensionPoint; 027 028/** 029 * {@link AmetysObjectFactory} handling {@link UserZoneItem}. 030 */ 031public class UserZoneItemFactory implements AmetysObjectFactory<UserZoneItem>, Serviceable 032{ 033 AmetysObjectResolver _resolver; 034 ModelItemTypeExtensionPoint _pageDataTypeExtensionPoint; 035 036 @Override 037 public void service(ServiceManager manager) throws ServiceException 038 { 039 _resolver = (AmetysObjectResolver) manager.lookup(AmetysObjectResolver.ROLE); 040 _pageDataTypeExtensionPoint = (ModelItemTypeExtensionPoint) manager.lookup(ModelItemTypeExtensionPoint.ROLE_PAGE_DATA); 041 } 042 043 @Override 044 public UserZoneItem getAmetysObjectById(String id) throws AmetysRepositoryException 045 { 046 int i = id.indexOf('?'); 047 String pageId = id.substring(i + "?pageId=".length()); 048 049 UserPage page = _resolver.resolveById(pageId); 050 051 return new UserZoneItem(page, _pageDataTypeExtensionPoint, _pageDataTypeExtensionPoint); 052 } 053 054 @Override 055 public String getScheme() 056 { 057 return "uduserzoneitem"; 058 } 059 060 @Override 061 public boolean hasAmetysObjectForId(String id) throws AmetysRepositoryException 062 { 063 int i = id.indexOf('?'); 064 String pageId = id.substring(i + "?pageId=".length()); 065 066 return _resolver.hasAmetysObjectForId(pageId); 067 } 068}