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 */
016package org.ametys.web.skin.generators;
017
018import java.io.IOException;
019import java.util.HashMap;
020import java.util.Set;
021
022import org.apache.avalon.framework.service.ServiceException;
023import org.apache.avalon.framework.service.ServiceManager;
024import org.apache.cocoon.ProcessingException;
025import org.apache.cocoon.generation.ServiceableGenerator;
026import org.apache.cocoon.xml.XMLUtils;
027import org.xml.sax.SAXException;
028
029import org.ametys.core.ui.ClientSideElement;
030import org.ametys.core.ui.SAXClientSideElementHelper;
031import org.ametys.web.skin.AdminSkinActionExtensionPoint;
032
033/**
034 * SAX available JavaScript actions on skins
035 *
036 */
037public class AdminSkinActionsGenerator extends ServiceableGenerator
038{
039    private SAXClientSideElementHelper _saxClientSideElementHelper;
040    private AdminSkinActionExtensionPoint _skinActionEP;
041    
042    @Override
043    public void service(ServiceManager smanager) throws ServiceException
044    {
045        super.service(smanager);
046        _saxClientSideElementHelper = (SAXClientSideElementHelper) smanager.lookup(SAXClientSideElementHelper.ROLE);
047        _skinActionEP = (AdminSkinActionExtensionPoint) smanager.lookup(AdminSkinActionExtensionPoint.ROLE);
048    }
049    
050    @Override
051    public void generate() throws IOException, SAXException, ProcessingException
052    {
053        contentHandler.startDocument();
054        XMLUtils.startElement(contentHandler, "View");
055        
056        Set<String> extensionsIds = _skinActionEP.getExtensionsIds();
057        for (String id : extensionsIds)
058        {
059            ClientSideElement element = _skinActionEP.getExtension(id);
060            _saxClientSideElementHelper.saxDefinition("action", element, AdminSkinActionExtensionPoint.ROLE, contentHandler, new HashMap<String, Object>());
061        }
062        
063        XMLUtils.endElement(contentHandler, "View");
064        contentHandler.endDocument();
065    }
066}