001    /*
002     *  Copyright 2012 GWT-Bootstrap
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    package com.github.gwtbootstrap.datepicker.client.ui.resources;
017    
018    import com.github.gwtbootstrap.client.ui.resources.JavaScriptInjector;
019    import com.github.gwtbootstrap.client.ui.resources.ResourceInjector;
020    import com.github.gwtbootstrap.datepicker.client.ui.util.LocaleUtil;
021    import com.google.gwt.resources.client.TextResource;
022    
023    /**
024     * Utility class to inject our resources into modules page. Use it to inject
025     * JavaScript and CSS files.
026     *
027     * @author Carlos Alexandro Becker
028     * @since 2.0.4.0
029     */
030    public class DatepickerResourceInjector {
031    
032        /**
033         * Injects the required CSS styles and JavaScript files into the document header.
034         * <pre>
035         * It's for NoStyle Module.
036         * </pre>
037         */
038        public static void configureWithCssFile() {
039            
040            ResourceInjector.injectResourceCssAsFile("datepicker.css");
041            configure();
042            
043        }
044    
045    
046        /**
047         * Injects the required CSS styles and JavaScript files into the document
048         * header.
049         */
050        public static void configure() {
051            Resources r = Resources.RESOURCES;
052            injectJs(r.datepickerJs());
053    
054            TextResource locale = LocaleUtil.getLocaleJsResource();
055            if (locale != null) {
056                JavaScriptInjector.inject(locale.getText());
057            }
058        }
059    
060        private static void injectJs(TextResource r) {
061            JavaScriptInjector.inject(r.getText());
062        }
063    }