Package org.apache.tapestry.engine

Source Code of org.apache.tapestry.engine.TagSupportService

/* $$ 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.engine;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.tapestry.IComponent;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.Tapestry;
import org.apache.tapestry.html.HTMLWriter;
import org.apache.tapestry.request.RequestContext;
import org.apache.tapestry.request.ResponseOutputStream;

/**
*  A very specialized service used by JSPs to access Tapestry URLs.
*  This is used by the Tapestry JSP tags, such as
{@link org.apache.tapestry.jsp.PageTag}.
*
@author Howard Lewis Ship
@since 3.0
@see org.apache.tapestry.jsp.URLRetriever
*
**/

public class TagSupportService implements IEngineService
{public static com.cortexeb.tools.clover.d __CLOVER_105_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 static final Log LOG = LogFactory.getLog(TagSupportService.class);

    /**
     *  Not to be invoked; this service is different than the others.
     *
     *  @throws ApplicationRuntimeException always
     *
     **/

    public ILink getLink(IRequestCycle cycle, IComponent component, Object[] parameters)
    {try { __CLOVER_105_0.M[584]++;
        __CLOVER_105_0.S[2492]++;throw new ApplicationRuntimeException(
            Tapestry.getMessage("TagSupportService.service-only"));
    } finally { }}

    public void service(
        IEngineServiceView engine,
        IRequestCycle cycle,
        ResponseOutputStream output)
        throws ServletException, IOException
    {try { __CLOVER_105_0.M[585]++;
        __CLOVER_105_0.S[2493]++;RequestContext context = cycle.getRequestContext();
        __CLOVER_105_0.S[2494]++;HttpServletRequest request = context.getRequest();

        __CLOVER_105_0.S[2495]++;String serviceName = getAttribute(request, Tapestry.TAG_SUPPORT_SERVICE_ATTRIBUTE);

        __CLOVER_105_0.S[2496]++;Object raw = request.getAttribute(Tapestry.TAG_SUPPORT_PARAMETERS_ATTRIBUTE);
        __CLOVER_105_0.S[2497]++;Object[] parameters = null;

        __CLOVER_105_0.S[2498]++;try
        {
            __CLOVER_105_0.S[2499]++;parameters = (Object[]) raw;
        }
        catch (ClassCastException ex)
        {
            __CLOVER_105_0.S[2500]++;throw new ServletException(
                Tapestry.format(
                    "TagSupportService.attribute-not-array",
                    Tapestry.TAG_SUPPORT_PARAMETERS_ATTRIBUTE,
                    Tapestry.getClassName(raw.getClass())));
        }

        __CLOVER_105_0.S[2501]++;IEngineService service = cycle.getEngine().getService(serviceName);

        __CLOVER_105_0.S[2502]++;ILink link = service.getLink(cycle, null, parameters);

        __CLOVER_105_0.S[2503]++;String URI = link.getURL();

        __CLOVER_105_0.S[2504]++;if ((((LOG.isDebugEnabled()) && (++__CLOVER_105_0.CT[464] != 0)) || (++__CLOVER_105_0.CF[464] == 0))){
        {
          __CLOVER_105_0.S[2505]++;LOG.debug("Request servlet path = " + request.getServletPath());
         
            __CLOVER_105_0.S[2506]++;Enumeration e = request.getParameterNames();
            __CLOVER_105_0.S[2507]++;while ((((e.hasMoreElements()) && (++__CLOVER_105_0.CT[465] != 0)) || (++__CLOVER_105_0.CF[465] == 0))){
            {
                __CLOVER_105_0.S[2508]++;String name = (String) e.nextElement();
                __CLOVER_105_0.S[2509]++;LOG.debug("Request parameter " + name + " = " + request.getParameter(name));
            }}
            __CLOVER_105_0.S[2510]++;e = request.getAttributeNames();
            __CLOVER_105_0.S[2511]++;while ((((e.hasMoreElements()) && (++__CLOVER_105_0.CT[466] != 0)) || (++__CLOVER_105_0.CF[466] == 0))){
            {
                __CLOVER_105_0.S[2512]++;String name = (String) e.nextElement();
                __CLOVER_105_0.S[2513]++;LOG.debug("Request attribute " + name + " = " + request.getAttribute(name));
            }}

            __CLOVER_105_0.S[2514]++;LOG.debug("Result URI: " + URI);
        }}

        __CLOVER_105_0.S[2515]++;HttpServletResponse response = context.getResponse();
        __CLOVER_105_0.S[2516]++;PrintWriter servletWriter = response.getWriter();

        __CLOVER_105_0.S[2517]++;IMarkupWriter writer = new HTMLWriter(servletWriter);

        __CLOVER_105_0.S[2518]++;writer.print(URI);

        __CLOVER_105_0.S[2519]++;writer.flush();
    } finally { }}

    private String getAttribute(HttpServletRequest request, String name) throws ServletException
    {try { __CLOVER_105_0.M[586]++;
        __CLOVER_105_0.S[2520]++;Object result = request.getAttribute(name);

        __CLOVER_105_0.S[2521]++;if ((((result == null) && (++__CLOVER_105_0.CT[467] != 0)) || (++__CLOVER_105_0.CF[467] == 0))){
            __CLOVER_105_0.S[2522]++;throw new ServletException(Tapestry.format("TagSupportService.null-attribute", name));}

        __CLOVER_105_0.S[2523]++;try
        {
            __CLOVER_105_0.S[2524]++;return (String) result;
        }
        catch (ClassCastException ex)
        {
            __CLOVER_105_0.S[2525]++;throw new ServletException(
                Tapestry.format(
                    "TagSupportService.attribute-not-string",
                    name,
                    Tapestry.getClassName(result.getClass())));

        }
    } finally { }}

    /**
     *  @return {@link org.apache.tapestry.Tapestry#TAGSUPPORT_SERVICE}.
     *
     **/

    public String getName()
    {try { __CLOVER_105_0.M[587]++;
        __CLOVER_105_0.S[2526]++;return Tapestry.TAGSUPPORT_SERVICE;
    } finally { }}

}
TOP

Related Classes of org.apache.tapestry.engine.TagSupportService

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.