Coverage Report - org.apache.tapestry.engine.encoders.ServiceExtensionEncoder
 
Classes in this File Line Coverage Branch Coverage Complexity
ServiceExtensionEncoder
0%
0/14
0%
0/2
1.667
 
 1  
 // Copyright 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  
 
 15  
 package org.apache.tapestry.engine.encoders;
 16  
 
 17  
 import org.apache.tapestry.engine.ServiceEncoder;
 18  
 import org.apache.tapestry.engine.ServiceEncoding;
 19  
 import org.apache.tapestry.services.ServiceConstants;
 20  
 
 21  
 /**
 22  
  * Encodes the service name, typical output is "/page.svc" where "page" is a
 23  
  * service name. This is useful for the home and restart services, for example.
 24  
  * This encoder should be prioritized very low so that it doesn't prevent other
 25  
  * encoders from doing their work.
 26  
  * 
 27  
  * @author Howard M. Lewis Ship
 28  
  * @since 4.0
 29  
  */
 30  0
 public class ServiceExtensionEncoder implements ServiceEncoder
 31  
 {
 32  
 
 33  
     private String _extension;
 34  
 
 35  
     public void setExtension(String extension)
 36  
     {
 37  0
         _extension = extension;
 38  0
     }
 39  
 
 40  
     public void encode(ServiceEncoding encoding)
 41  
     {
 42  0
         String service = encoding.getParameterValue(ServiceConstants.SERVICE);
 43  
 
 44  
         // Can assume this is never null.
 45  
 
 46  0
         encoding.setServletPath("/" + service + "." + _extension);
 47  0
         encoding.setParameterValue(ServiceConstants.SERVICE, null);
 48  0
     }
 49  
 
 50  
     public void decode(ServiceEncoding encoding)
 51  
     {
 52  0
         String servletPath = encoding.getServletPath();
 53  
 
 54  0
         int dotx = servletPath.lastIndexOf('.');
 55  
 
 56  0
         String extension = servletPath.substring(dotx + 1);
 57  
 
 58  0
         if (!extension.equals(_extension)) return;
 59  
 
 60  
         // The first character should be a slash, then the service name, then
 61  
         // the dot.
 62  
 
 63  0
         String service = servletPath.substring(1, dotx);
 64  
 
 65  0
         encoding.setParameterValue(ServiceConstants.SERVICE, service);
 66  0
     }
 67  
 
 68  
 }