001    // Copyright 2004, 2005 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;
016    
017    import org.apache.hivemind.Resource;
018    
019    /**
020     * Defines methods needed by a {@link org.apache.tapestry.IScript}to execute.
021     * 
022     * @author Howard Lewis Ship
023     * @since 3.0
024     * @see org.apache.tapestry.html.Body
025     */
026    
027    public interface IScriptProcessor
028    {
029        /**
030         * Adds scripting code to the main body. During the render, multiple scripts may render multiple
031         * bodies; all are concatinated together to form a single block. The
032         * {@link org.apache.tapestry.html.Body} component will write the body script contents
033         * just inside the <code>&lt;body&gt;</code> tag.
034         * 
035         * @deprecated To be removed sometime after 4.1.
036         * @see {@link #addBodyScript(IComponent, String)}
037         */
038    
039        void addBodyScript(String script);
040    
041        /**
042         * Adds scripting code to the main body. During the render, multiple scripts may render multiple
043         * bodies; all are concatinated together to form a single block. The
044         * {@link org.apache.tapestry.html.Body}&nbsp;component will write the body script contents
045         * just inside the <code>&lt;body&gt;</code> tag.
046         * 
047         * @param target
048         *          The component this script is being added for.
049         * @param script
050         *          The script to add to the body response.
051         */
052        void addBodyScript(IComponent target, String script);
053        
054        /**
055         * Adds initialization script. Initialization script is executed once, when the containing page
056         * loads. Initialization script content is written only after all HTML content that could be
057         * referenced from the script (in effect, just before the <code>&lt/body&gt;</code> tag).
058         * 
059         * @deprecated To be removed sometime after 4.1.
060         * @see {@link #addInitializationScript(IComponent, String)}
061         */
062        void addInitializationScript(String script);
063    
064        /**
065         * Adds initialization script. Initialization script is executed once, when the containing page
066         * loads. Initialization script content is written only after all HTML content that could be
067         * referenced from the script (in effect, just before the <code>&lt/body&gt;</code> tag).
068         * 
069         * @param target
070         *          The component the script is being added for.
071         * @param script
072         *          The script to add.
073         */
074        void addInitializationScript(IComponent target, String script);
075        
076        /**
077         * Adds an external script. The processor is expected to ensure that external scripts are only
078         * loaded a single time per page.
079         * 
080         * @deprecated To be removed sometime after 4.1
081         * @see {@link #addExternalScript(IComponent, Resource)}
082         */
083    
084        void addExternalScript(Resource resource);
085    
086        /**
087         * Adds an external script. The processor is expected to ensure that external scripts are only
088         * loaded a single time per page. The target will be checked to filter the scripts
089         * added for those types of responses that require them.
090         * 
091         * @param target
092         *          The component the script is being added for.
093         * @param resource
094         *          The external script to add.
095         */
096        void addExternalScript(IComponent target, Resource resource);
097        
098        /**
099         * Determines if the specified component should have its javascript 
100         * body added to the response.
101         * 
102         * @param target
103         *          The component to allow/disallow body script content from.
104         * @return True if the component script should be allowed.
105         */
106        boolean isBodyScriptAllowed(IComponent target);
107        
108        /**
109         * Determines if the specified component should have its javascript 
110         * initialization added to the response.
111         * 
112         * @param target
113         *          The component to allow/disallow initialization script content from.
114         * @return True if the component script should be allowed.
115         */
116        boolean isInitializationScriptAllowed(IComponent target);
117        
118        /**
119         * Determines if the specified component should have its javascript 
120         * external resource scripts added to the response.
121         * 
122         * @param target
123         *          The component to check for inclusion/exclusion.
124         * @return True if external scripts from this component should be added to
125         *          the response.
126         */
127        boolean isExternalScriptAllowed(IComponent target);
128        
129        /**
130         * Ensures that the given string is unique. The string is either returned unchanged, or a suffix
131         * is appended to ensure uniqueness.
132         */
133    
134        String getUniqueString(String baseValue);
135    }