001/*
002 * (C) Copyright 2006-2008 Nuxeo SA (http://nuxeo.com/) and others.
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 * Contributors:
017 *     bstefanescu
018 *
019 * $Id$
020 */
021
022package org.nuxeo.ecm.webengine.rendering;
023
024import java.util.Arrays;
025import java.util.Collection;
026import java.util.Comparator;
027
028import org.nuxeo.ecm.core.schema.DocumentType;
029import org.nuxeo.ecm.core.schema.SchemaManager;
030import org.nuxeo.runtime.api.Framework;
031import org.nuxeo.runtime.model.ComponentName;
032import org.nuxeo.runtime.model.RegistrationInfo;
033import org.osgi.framework.Bundle;
034
035/**
036 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
037 */
038public class APIHelper implements RenderingExtensionFactory {
039
040    public static final APIHelper INSTANCE = new APIHelper();
041
042    public static final Comparator<DocumentType> DOCTYPE_COMPARATOR = new Comparator<DocumentType>() {
043        public int compare(DocumentType o1, DocumentType o2) {
044            return o1.getName().compareTo(o2.getName());
045        }
046    };
047
048    public Object createTemplate() {
049        return this;
050    }
051
052    public static DocumentType[] getSortedDocumentTypes() {
053        DocumentType[] doctypes = Framework.getService(SchemaManager.class).getDocumentTypes();
054        Arrays.sort(doctypes, DOCTYPE_COMPARATOR);
055        return doctypes;
056    }
057
058    public static Bundle[] getBundles() {
059        return Framework.getRuntime().getContext().getBundle().getBundleContext().getBundles();
060    }
061
062    public static Collection<RegistrationInfo> getComponents() {
063        return Framework.getRuntime().getComponentManager().getRegistrations();
064    }
065
066    public static Collection<ComponentName> getPendingComponents() {
067        return Framework.getRuntime().getComponentManager().getPendingRegistrations().keySet();
068    }
069
070}