Package org.apache.tapestry.html

Source Code of org.apache.tapestry.html.Script

/* $$ Clover has instrumented this file $$ */// Copyright 2004 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.apache.tapestry.html;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.Resource;
import org.apache.tapestry.AbstractComponent;
import org.apache.tapestry.IBinding;
import org.apache.tapestry.IEngine;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.IScript;
import org.apache.tapestry.Tapestry;
import org.apache.tapestry.engine.IScriptSource;

/**
*  Works with the {@link Body} component to add a script (and perhaps some initialization)
*  to the HTML response.
*
*  [<a href="../../../../../ComponentReference/Script.html">Component Reference</a>]
*
@author Howard Lewis Ship
*
**/

public abstract class Script extends AbstractComponent
{public static com.cortexeb.tools.clover.d __CLOVER_162_0 = com.cortexeb.tools.clover.aq.getRecorder(new char[] {67,58,92,119,111,114,107,115,112,97,99,101,92,106,97,107,97,114,116,97,45,116,97,112,101,115,116,114,121,92,102,114,97,109,101,119,111,114,107,92,116,97,114,103,101,116,92,99,108,111,118,101,114,45,100,98},1096998272901L);
    private Map _baseSymbols;

    /**
     *  A Map of input and output symbols visible to the body of the Script.
     *
     *  @since 2.2
     *
     **/

    private Map _symbols;

    /**
     *  Constructs the symbols {@link Map}.  This starts with the
     *  contents of the symbols parameter (if specified) to which is added
     *  any informal parameters.  If both a symbols parameter and informal
     *  parameters are bound, then a copy of the symbols parameter's value is made
     *  (that is, the {@link Map} provided by the symbols parameter is read, but not modified).
     *
     **/

    private Map getInputSymbols()
    {try { __CLOVER_162_0.M[826]++;
        __CLOVER_162_0.S[3964]++;Map result = new HashMap();

        __CLOVER_162_0.S[3965]++;if ((((_baseSymbols != null) && (++__CLOVER_162_0.CT[743] != 0)) || (++__CLOVER_162_0.CF[743] == 0))){
            __CLOVER_162_0.S[3966]++;result.putAll(_baseSymbols);}

        // Now, iterate through all the binding names (which includes both
        // formal and informal parmeters).  Skip the formal ones and
        // access the informal ones.

        __CLOVER_162_0.S[3967]++;Iterator i = getBindingNames().iterator();
        __CLOVER_162_0.S[3968]++;while ((((i.hasNext()) && (++__CLOVER_162_0.CT[744] != 0)) || (++__CLOVER_162_0.CF[744] == 0))){
        {
            __CLOVER_162_0.S[3969]++;String bindingName = (String) i.next();

            // Skip formal parameters

            __CLOVER_162_0.S[3970]++;if ((((getSpecification().getParameter(bindingName) != null) && (++__CLOVER_162_0.CT[745] != 0)) || (++__CLOVER_162_0.CF[745] == 0))){
                __CLOVER_162_0.S[3971]++;continue;}

            __CLOVER_162_0.S[3972]++;IBinding binding = getBinding(bindingName);

            __CLOVER_162_0.S[3973]++;Object value = binding.getObject();

            __CLOVER_162_0.S[3974]++;result.put(bindingName, value);
        }}

        __CLOVER_162_0.S[3975]++;return result;
    } finally { }}

    /**
     *  Gets the {@link IScript} for the correct script.
     *
     *
     **/

    private IScript getParsedScript(IRequestCycle cycle)
    {try { __CLOVER_162_0.M[827]++;
        __CLOVER_162_0.S[3976]++;String scriptPath = getScriptPath();

        __CLOVER_162_0.S[3977]++;if ((((scriptPath == null) && (++__CLOVER_162_0.CT[746] != 0)) || (++__CLOVER_162_0.CF[746] == 0))){
            __CLOVER_162_0.S[3978]++;throw Tapestry.createRequiredParameterException(this, "scriptPath");}

        __CLOVER_162_0.S[3979]++;IEngine engine = cycle.getEngine();
        __CLOVER_162_0.S[3980]++;IScriptSource source = engine.getScriptSource();

        // If the script path is relative, it should be relative to the Script component's
        // container (i.e., relative to a page in the application).

        __CLOVER_162_0.S[3981]++;Resource rootLocation =
            getContainer().getSpecification().getSpecificationLocation();
        __CLOVER_162_0.S[3982]++;Resource scriptLocation = rootLocation.getRelativeResource(scriptPath);

        __CLOVER_162_0.S[3983]++;try
        {
            __CLOVER_162_0.S[3984]++;return source.getScript(scriptLocation);
        }
        catch (RuntimeException ex)
        {
            __CLOVER_162_0.S[3985]++;throw new ApplicationRuntimeException(ex.getMessage(), this, null, ex);
        }

    } finally { }}

    protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
    {try { __CLOVER_162_0.M[828]++;
        __CLOVER_162_0.S[3986]++;if ((((!cycle.isRewinding()) && (++__CLOVER_162_0.CT[747] != 0)) || (++__CLOVER_162_0.CF[747] == 0))){
        {
            __CLOVER_162_0.S[3987]++;Body body = Body.get(cycle);

            __CLOVER_162_0.S[3988]++;if ((((body == null) && (++__CLOVER_162_0.CT[748] != 0)) || (++__CLOVER_162_0.CF[748] == 0))){
                __CLOVER_162_0.S[3989]++;throw new ApplicationRuntimeException(
                    Tapestry.getMessage("Script.must-be-contained-by-body"),
                    this,
                    null,
                    null);}

            __CLOVER_162_0.S[3990]++;_symbols = getInputSymbols();

            __CLOVER_162_0.S[3991]++;getParsedScript(cycle).execute(cycle, body, _symbols);
        }}

        // Render the body of the Script;
        __CLOVER_162_0.S[3992]++;renderBody(writer, cycle);
    } finally { }}

    public abstract String getScriptPath();

    public Map getBaseSymbols()
    {try { __CLOVER_162_0.M[829]++;
        __CLOVER_162_0.S[3993]++;return _baseSymbols;
    } finally { }}

    public void setBaseSymbols(Map baseSymbols)
    {try { __CLOVER_162_0.M[830]++;
        __CLOVER_162_0.S[3994]++;_baseSymbols = baseSymbols;
    } finally { }}

    /**
     *  Returns the complete set of symbols (input and output)
     *  from the script execution.  This is visible to the body
     *  of the Script, but is cleared after the Script
     *  finishes rendering.
     *
     *  @since 2.2
     **/

    public Map getSymbols()
    {try { __CLOVER_162_0.M[831]++;
        __CLOVER_162_0.S[3995]++;return _symbols;
    } finally { }}

    protected void cleanupAfterRender(IRequestCycle cycle)
    {try { __CLOVER_162_0.M[832]++;
        __CLOVER_162_0.S[3996]++;_symbols = null;

        __CLOVER_162_0.S[3997]++;super.cleanupAfterRender(cycle);
    } finally { }}

}
TOP

Related Classes of org.apache.tapestry.html.Script

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.