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    
015    package org.apache.tapestry5.internal.services;
016    
017    import org.apache.tapestry5.Link;
018    import org.apache.tapestry5.services.Ajax;
019    import org.apache.tapestry5.services.ComponentEventResultProcessor;
020    
021    import 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    public class AjaxPageNameComponentEventResultProcessor implements ComponentEventResultProcessor<String>
030    {
031        private final ComponentEventResultProcessor masterProcessor;
032    
033        private final LinkSource linkSource;
034    
035        public AjaxPageNameComponentEventResultProcessor(@Ajax ComponentEventResultProcessor masterProcessor,
036                                                         LinkSource linkSource)
037        {
038            this.masterProcessor = masterProcessor;
039            this.linkSource = linkSource;
040        }
041    
042        /**
043         * Obtains a page render {@link org.apache.tapestry5.Link} for the named, then builds a JSON reponse for the
044         * client.
045         *
046         * @param value page name
047         * @throws IOException
048         */
049        public void processResultValue(String value) throws IOException
050        {
051            Link link = linkSource.createPageRenderLink(value, false);
052    
053            masterProcessor.processResultValue(link);
054        }
055    }