001/*
002 * Copyright 2014 Atteo.
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.atteo.moonshine.webjars;
018
019import javax.xml.bind.annotation.XmlElement;
020import javax.xml.bind.annotation.XmlRootElement;
021
022import org.atteo.moonshine.TopLevelService;
023import org.atteo.moonshine.services.ImportService;
024import org.atteo.moonshine.webserver.ServletContainer;
025
026import com.google.inject.Module;
027import com.google.inject.PrivateModule;
028
029@XmlRootElement(name = "webjars")
030public class WebJarsService extends TopLevelService {
031    @ImportService
032    private ServletContainer servletContainer;
033
034    @XmlElement
035    private String prefix = "/webjars";
036
037    @XmlElement
038    private String destination = "/META-INF/resources/webjars";
039
040    @Override
041    public Module configure() {
042        return new PrivateModule() {
043            @Override
044            protected void configure() {
045                bind(WebJarsServlet.class).toInstance(new WebJarsServlet(destination));
046
047                servletContainer.addServlet(getProvider(WebJarsServlet.class), prefix + "/*");
048                
049            }
050        };
051    }
052
053}