001/*
002 * (C) Copyright 2016 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 *     Nuxeo
018 */
019package org.nuxeo.ecm.admin;
020
021import org.nuxeo.connect.client.ui.SharedPackageListingsSettings;
022import org.nuxeo.connect.client.ui.SharedPackageListingsSettings.RequestResolver;
023import org.nuxeo.runtime.model.ComponentContext;
024import org.nuxeo.runtime.model.DefaultComponent;
025
026import javax.faces.context.FacesContext;
027import javax.servlet.http.HttpServletRequest;
028
029public class AdminJSFComponent extends DefaultComponent {
030
031    static RequestResolver resolver = new RequestResolver() {
032        @Override
033        public boolean isActive() {
034            return FacesContext.getCurrentInstance() != null;
035        }
036
037        @Override
038        public HttpServletRequest resolve() {
039            return (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
040        }
041
042        @Override
043        public String getId() {
044            return "jsf";
045        }
046    };
047
048    @Override
049    public void activate(ComponentContext context) {
050        super.activate(context);
051        SharedPackageListingsSettings.addRequestResolver(resolver);
052    }
053
054    @Override
055    public void deactivate(ComponentContext context) {
056        super.deactivate(context);
057        SharedPackageListingsSettings.removeRequestResolver(resolver.getId());
058    }
059}