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; 026 027/** 028 * {@link AmetysObjectFactory} handling {@link UserZone}. 029 */ 030public class UserZoneFactory implements AmetysObjectFactory<UserZone>, Serviceable 031{ 032 AmetysObjectResolver _resolver; 033 034 @Override 035 public void service(ServiceManager manager) throws ServiceException 036 { 037 _resolver = (AmetysObjectResolver) manager.lookup(AmetysObjectResolver.ROLE); 038 } 039 040 @Override 041 public UserZone getAmetysObjectById(String id) throws AmetysRepositoryException 042 { 043 int i = id.indexOf('?'); 044 String pageId = id.substring(i + "?pageId=".length()); 045 046 UserPage page = _resolver.resolveById(pageId); 047 048 return new UserZone(page); 049 } 050 051 @Override 052 public String getScheme() 053 { 054 return "uduserzone"; 055 } 056 057 @Override 058 public boolean hasAmetysObjectForId(String id) throws AmetysRepositoryException 059 { 060 int i = id.indexOf('?'); 061 String pageId = id.substring(i + "?pageId=".length()); 062 063 return _resolver.hasAmetysObjectForId(pageId); 064 } 065}