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;
026import org.ametys.web.repository.page.PageDataTypeExtensionPoint;
027
028/**
029 * {@link AmetysObjectFactory} handling {@link PostZone}.
030 */
031public class PostZoneFactory implements AmetysObjectFactory<PostZone>, Serviceable
032{
033    AmetysObjectResolver _resolver;
034    private PageDataTypeExtensionPoint _pageDataTypeExtensionPoint;
035    
036    @Override
037    public void service(ServiceManager manager) throws ServiceException
038    {
039        _resolver = (AmetysObjectResolver) manager.lookup(AmetysObjectResolver.ROLE);
040        _pageDataTypeExtensionPoint = (PageDataTypeExtensionPoint) manager.lookup(PageDataTypeExtensionPoint.ROLE);
041    }
042    
043    @Override
044    public String getScheme()
045    {
046        return "postZone";
047    }
048    
049    @Override
050    public PostZone getAmetysObjectById(String id) throws AmetysRepositoryException
051    {
052        int i = id.indexOf('?');
053        String pageId = id.substring(i + "?pageId=".length());
054        
055        VirtualPostPage page = _resolver.resolveById(pageId);
056        
057        return new PostZone(page, _pageDataTypeExtensionPoint, _pageDataTypeExtensionPoint);
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}