    001// Copyright 2008, 2009 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
    015package org.apache.tapestry5.internal.services;
    016
    017import org.apache.tapestry5.Link;
    018import org.apache.tapestry5.services.Ajax;
    019import org.apache.tapestry5.services.ComponentEventResultProcessor;
    020
    021import java.io.IOException;
    022
    023/**
    024 * A {@link org.apache.tapestry5.services.ComponentEventResultProcessor}, used for Ajax requests, for a String value
    025 * that is interpreted as a logical page name.
    026 *
    027 * @see org.apache.tapestry5.internal.services.PageNameComponentEventResultProcessor
    028 */
    029@SuppressWarnings("all")
    030public class AjaxPageNameComponentEventResultProcessor implements ComponentEventResultProcessor<String>
    031{
    032    private final ComponentEventResultProcessor masterProcessor;
    033
    034    private final LinkSource linkSource;
    035
    036    public AjaxPageNameComponentEventResultProcessor(@Ajax
    037    ComponentEventResultProcessor masterProcessor, LinkSource linkSource)
    038    {
    039        this.masterProcessor = masterProcessor;
    040        this.linkSource = linkSource;
    041    }
    042
    043    /**
    044     * Obtains a page render {@link org.apache.tapestry5.Link} for the named, then builds a JSON response for the
    045     * client.
    046     *
    047     * @param value
    048     *            page name
    049     * @throws IOException
    050     */
    051    public void processResultValue(String value) throws IOException
    052    {
    053        Link link = linkSource.createPageRenderLink(value, false);
    054
    055        masterProcessor.processResultValue(link);
    056    }
    057}