Coverage report

  %line %branch
org.apache.commons.jelly.tags.jetty.ResourceHandlerTag
95% 
100% 

 1  
 /*
 2  
  * Copyright 2002,2004 The Apache Software Foundation.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package org.apache.commons.jelly.tags.jetty;
 18  
 
 19  
 import org.apache.commons.jelly.JellyTagException;
 20  
 import org.apache.commons.jelly.TagSupport;
 21  
 import org.apache.commons.jelly.XMLOutput;
 22  
 
 23  
 import org.mortbay.http.handler.ResourceHandler;
 24  
 
 25  
 import java.util.StringTokenizer;
 26  
 
 27  
 /**
 28  
  * Declare a static file resource handler for a Jetty http server
 29  
  *
 30  
  * @author  rtl
 31  
  * @version $Id: ResourceHandlerTag.java,v 1.3 2002/07/14 12:38:22 dion Exp $
 32  
  */
 33  1
 public class ResourceHandlerTag extends TagSupport {
 34  
 
 35  
     /** parameter allowed methods */
 36  
     private String _allowedMethods;
 37  
 
 38  
     /** Creates a new instance of ResourceHandlerTag */
 39  4
     public ResourceHandlerTag() {
 40  4
     }
 41  
 
 42  
     /**
 43  
      * Perform the tag functionality. In this case, add a resource handler
 44  
      * to the parent context, setting the allowed methods if required
 45  
      *
 46  
      * @param xmlOutput where to send output
 47  
      * @throws Exception when an error occurs
 48  
      */
 49  
     public void doTag(XMLOutput xmlOutput) throws JellyTagException {
 50  4
         HttpContextTag httpContext = (HttpContextTag) findAncestorWithClass(
 51  
             HttpContextTag.class);
 52  4
         if ( httpContext == null ) {
 53  0
             throw new JellyTagException( "<resourceHandler> tag must be enclosed inside a <httpContext> tag" );
 54  
         }
 55  4
         ResourceHandler resourceHandler = new ResourceHandler();
 56  4
         if (getAllowedMethods() != null) {
 57  
             // split comma-separated list up into tokens and convert to an array
 58  1
             StringTokenizer tokenizer =
 59  
                 new StringTokenizer( getAllowedMethods(), " ," );
 60  1
             String[] allowedMethods = new String[tokenizer.countTokens()];
 61  4
             for (int i = 0; i < allowedMethods.length; i++) {
 62  3
                 allowedMethods[i] = tokenizer.nextToken();
 63  
             }
 64  1
             resourceHandler.setAllowedMethods(allowedMethods);
 65  
         }
 66  4
         httpContext.addHandler(resourceHandler);
 67  4
         invokeBody(xmlOutput);
 68  4
     }
 69  
 
 70  
     //--------------------------------------------------------------------------
 71  
     // Property accessors/mutators
 72  
     //--------------------------------------------------------------------------
 73  
 
 74  
     /**
 75  
      * Getter for property allowedMethods.
 76  
      *
 77  
      * @return value of property allowedMethods.
 78  
      */
 79  
     public String getAllowedMethods() {
 80  5
         return _allowedMethods;
 81  
     }
 82  
 
 83  
     /**
 84  
      * Setter for property allowedMethods.
 85  
      *
 86  
      * @param allowedMethods Comma separated list of allowed methods.
 87  
      */
 88  
     public void setAllowedMethods(String allowedMethods) {
 89  1
         _allowedMethods = allowedMethods;
 90  1
     }
 91  
 
 92  
 
 93  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.