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