001 // Copyright May 8, 2006 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 package org.apache.tapestry.services.impl;
015
016 import java.io.IOException;
017 import java.util.ArrayList;
018 import java.util.List;
019
020 import org.apache.tapestry.IRequestCycle;
021 import org.apache.tapestry.markup.MarkupWriterSource;
022 import org.apache.tapestry.services.RequestLocaleManager;
023 import org.apache.tapestry.services.ResponseBuilder;
024 import org.apache.tapestry.services.ResponseContributor;
025 import org.apache.tapestry.web.WebRequest;
026 import org.apache.tapestry.web.WebResponse;
027
028
029 /**
030 * Handles determining dojo ajax requests.
031 *
032 * @author jkuhnert
033 */
034 public class DojoAjaxResponseContributorImpl implements ResponseContributor
035 {
036 public static final String DOJO_AJAX_HEADER = "dojo-ajax-request";
037
038 private RequestLocaleManager _localeManager;
039
040 private MarkupWriterSource _markupWriterSource;
041
042 private WebResponse _webResponse;
043
044 private WebRequest _webRequest;
045
046 private String _exceptionPageName;
047
048 private String _staleSessionPageName;
049
050 private String _staleLinkPageName;
051
052 /**
053 * {@inheritDoc}
054 */
055 public ResponseBuilder createBuilder(IRequestCycle cycle)
056 throws IOException
057 {
058 List errorPages = new ArrayList();
059 errorPages.add(_exceptionPageName);
060 errorPages.add(_staleSessionPageName);
061 errorPages.add(_staleLinkPageName);
062
063 return new DojoAjaxResponseBuilder(cycle, _localeManager,
064 _markupWriterSource,
065 _webResponse, errorPages);
066 }
067
068 /**
069 * {@inheritDoc}
070 */
071 public boolean handlesResponse(IRequestCycle cycle)
072 {
073 return _webRequest.getHeader(DOJO_AJAX_HEADER) != null;
074 }
075
076 public void setLocaleManager(RequestLocaleManager localeManager)
077 {
078 _localeManager = localeManager;
079 }
080
081 public void setMarkupWriterSource(MarkupWriterSource markupWriterSource)
082 {
083 _markupWriterSource = markupWriterSource;
084 }
085
086 public void setWebResponse(WebResponse webResponse)
087 {
088 _webResponse = webResponse;
089 }
090
091 public void setWebRequest(WebRequest webRequest)
092 {
093 _webRequest = webRequest;
094 }
095
096 public void setExceptionPageName(String name)
097 {
098 _exceptionPageName = name;
099 }
100
101 public void setStaleSessionPageName(String name)
102 {
103 _staleSessionPageName = name;
104 }
105
106 public void setStaleLinkPageName(String name)
107 {
108 _staleLinkPageName = name;
109 }
110 }