Coverage report

  %line %branch
org.apache.commons.jelly.tags.jetty.RealmTag
85% 
95% 

 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.HashUserRealm;
 24  
 
 25  
 import java.io.IOException;
 26  
 import java.net.URL;
 27  
 
 28  
 /**
 29  
  * Declare a user realm for a Jetty http server
 30  
  *
 31  
  * @author  rtl
 32  
  * @version $Id: RealmTag.java,v 1.3 2002/07/14 12:38:22 dion Exp $
 33  
  */
 34  1
 public class RealmTag extends TagSupport {
 35  
 
 36  
     /** parameter name with default*/
 37  
     private String _name;
 38  
 
 39  
     /** parameter config, with default */
 40  
     private String _config;
 41  
 
 42  
     /** Creates a new instance of RealmTag */
 43  1
     public RealmTag() {
 44  1
     }
 45  
 
 46  
     /**
 47  
      * Perform the tag functionality. In this case, add a realm with the
 48  
      * specified name using the specified config (preperties) file to the
 49  
      * parent server,
 50  
      *
 51  
      * @param xmlOutput where to send output
 52  
      * @throws Exception when an error occurs
 53  
      */
 54  
     public void doTag(XMLOutput xmlOutput) throws JellyTagException {
 55  1
         JettyHttpServerTag httpserver = (JettyHttpServerTag) findAncestorWithClass(
 56  
             JettyHttpServerTag.class);
 57  1
         if ( httpserver == null ) {
 58  0
             throw new JellyTagException( "<realm> tag must be enclosed inside a <server> tag" );
 59  
         }
 60  1
         if (null == getName() || class="keyword">null == getConfig()) {
 61  0
             throw new JellyTagException( "<realm> tag must have a name and a config" );
 62  
         }
 63  
 
 64  
         // convert the config string to a URL
 65  
         // (this makes URL's relative to the location of the script
 66  
         try {
 67  1
             URL configURL = getContext().getResource(getConfig());
 68  1
             httpserver.addRealm( new HashUserRealm(getName(), configURL.toString() ) );
 69  1
         } catch (IOException e) {
 70  0
             throw new JellyTagException(e);
 71  
         }
 72  
 
 73  1
         invokeBody(xmlOutput);
 74  1
     }
 75  
 
 76  
     //--------------------------------------------------------------------------
 77  
     // Property accessors/mutators
 78  
     //--------------------------------------------------------------------------
 79  
 
 80  
     /**
 81  
      * Getter for property name.
 82  
      *
 83  
      * @return value of property name.
 84  
      */
 85  
     public String getName() {
 86  2
         return _name;
 87  
     }
 88  
 
 89  
     /**
 90  
      * Setter for property name.
 91  
      *
 92  
      * @param name New value of property name.
 93  
      */
 94  
     public void setName(String name) {
 95  1
         _name = name;
 96  1
     }
 97  
 
 98  
     /**
 99  
      * Getter for property config.
 100  
      *
 101  
      * @return value of property config.
 102  
      */
 103  
     public String getConfig() {
 104  2
         return _config;
 105  
     }
 106  
 
 107  
     /**
 108  
      * Setter for property config.
 109  
      *
 110  
      * @param config New value of property config.
 111  
      */
 112  
     public void setConfig(String config) {
 113  1
         _config = config;
 114  1
     }
 115  
 
 116  
 }

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