001/*
002 *  Copyright 2010 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.odfweb.repository;
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 ProgramZoneItem}.
029 */
030public class ProgramZoneItemFactory implements AmetysObjectFactory<ProgramZoneItem>, 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 ProgramZoneItem getAmetysObjectById(String id) throws AmetysRepositoryException
042    {
043        int i = id.indexOf('?');
044        String pageId = id.substring(i + "?pageId=".length());
045        
046        ProgramPage page = _resolver.resolveById(pageId);
047        
048        return new ProgramZoneItem(page);
049    }
050
051    @Override
052    public String getScheme()
053    {
054        return "programZoneItem";
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}