001    // Copyright 2007 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.javascript;
016    
017    import java.util.List;
018    
019    import org.apache.tapestry.IAsset;
020    import org.apache.tapestry.IMarkupWriter;
021    import org.apache.tapestry.IRequestCycle;
022    
023    /**
024     * Manages javascript files of 3rd party libraries.
025     */
026    public interface JavascriptManager
027    {
028        /**
029         * The javascript files that should always be included.
030         *
031         * @return A not-null (but possibly empty) list of {@link IAsset}s.
032         */
033        List getAssets();
034    
035        IAsset getFirstAsset();
036    
037        /**
038         * The javascript files that provide form-related functionality.
039         * They're dynamically included when the page contains forms.
040         *
041         * @return A not-null (but possibly empty) list of {@link IAsset}s.
042         */
043        List getFormAssets();
044        
045        IAsset getFirstFormAsset();
046    
047        /**
048         * The javascript files that provide widget-related functionality.
049         * They're dynamically included when the page contains widgets.
050         *
051         * @return A not-null (but possibly empty) list of {@link IAsset}s.
052         */
053        List getWidgetAssets();
054    
055        IAsset getFirstWidgetAsset();
056    
057        /**
058         * The base path to the javascript files.
059         *
060         * @return if null, it is left unused.
061         */
062        IAsset getPath();
063    
064        /**
065         * The tapestry js file.
066         *
067         * @return if null then no tapestry file is included.
068         */
069        IAsset getTapestryAsset();
070    
071        /**
072         * The base path to the tapestry js files.
073         * 
074         * @return if null, it is left unused.
075         */
076        IAsset getTapestryPath();
077        
078        /**
079         * Output the resources (could be .js, .css, e.t.c. files) needed for the current javascript library.
080         * 
081         * @param writer
082         * @param cycle
083         * @param hasForm true if current page includes forms.
084         * @param hasWidget true if current page includes widgets.
085         */
086        void renderLibraryResources(IMarkupWriter writer, IRequestCycle cycle, boolean hasForm, boolean hasWidget);
087        
088        /**
089         * Output the resources needed for tapestry in order to use the current 
090         * javascript library.
091         * 
092         * @param writer
093         * @param cycle
094         */
095        void renderLibraryAdaptor(IMarkupWriter writer, IRequestCycle cycle);
096    }