Coverage Report - org.apache.tapestry.services.impl.JSONResponseContributorImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
JSONResponseContributorImpl
0%
0/18
0%
0/6
1.714
 
 1  
 // Copyright 2004, 2005 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 package org.apache.tapestry.services.impl;
 15  
 
 16  
 import org.apache.tapestry.IRequestCycle;
 17  
 import org.apache.tapestry.asset.AssetFactory;
 18  
 import org.apache.tapestry.markup.MarkupWriterSource;
 19  
 import org.apache.tapestry.services.RequestLocaleManager;
 20  
 import org.apache.tapestry.services.ResponseBuilder;
 21  
 import org.apache.tapestry.services.ResponseContributor;
 22  
 import org.apache.tapestry.web.WebRequest;
 23  
 import org.apache.tapestry.web.WebResponse;
 24  
 
 25  
 import java.io.IOException;
 26  
 
 27  
 /**
 28  
  * Determines if incoming request is a valid json request via the "json" http header
 29  
  * or the "json" = "true" request parameter.
 30  
  * 
 31  
  * @author jkuhnert
 32  
  */
 33  0
 public class JSONResponseContributorImpl implements ResponseContributor
 34  
 {
 35  
     
 36  
     public static final String JSON_HEADER = "json";
 37  
     
 38  
     private RequestLocaleManager _localeManager;
 39  
     
 40  
     private MarkupWriterSource _markupWriterSource;
 41  
     
 42  
     private WebResponse _webResponse;
 43  
     
 44  
     private WebRequest _webRequest;
 45  
     
 46  
     private AssetFactory _assetFactory;
 47  
     
 48  
     /**
 49  
      * {@inheritDoc}
 50  
      */
 51  
     public ResponseBuilder createBuilder(IRequestCycle cycle)
 52  
     throws IOException
 53  
     {
 54  0
         return new JSONResponseBuilder(cycle, _localeManager, _markupWriterSource,
 55  
                 _webResponse, _webRequest, _assetFactory, _webResponse.getNamespace());
 56  
     }
 57  
     
 58  
     /**
 59  
      * {@inheritDoc}
 60  
      */
 61  
     public boolean handlesResponse(IRequestCycle cycle)
 62  
     {
 63  0
         String parm = cycle.getParameter(JSON_HEADER);
 64  
         
 65  0
         if (parm != null && Boolean.valueOf(parm).booleanValue())
 66  0
             return true;
 67  0
         if (_webRequest.getHeader(JSON_HEADER) != null)
 68  0
             return true;
 69  
         
 70  0
         return false;
 71  
     }
 72  
     
 73  
     public void setLocaleManager(RequestLocaleManager localeManager)
 74  
     {
 75  0
         _localeManager = localeManager;
 76  0
     }
 77  
     
 78  
     public void setMarkupWriterSource(MarkupWriterSource markupWriterSource)
 79  
     {
 80  0
         _markupWriterSource = markupWriterSource;
 81  0
     }
 82  
     
 83  
     public void setWebResponse(WebResponse webResponse)
 84  
     {
 85  0
         _webResponse = webResponse;
 86  0
     }
 87  
     
 88  
     public void setWebRequest(WebRequest webRequest)
 89  
     {
 90  0
         _webRequest  = webRequest;
 91  0
     }
 92  
     
 93  
     public void setAssetFactory(AssetFactory factory)
 94  
     {
 95  0
         _assetFactory = factory;
 96  0
     }
 97  
 }