Coverage Report - org.jaxen.XPathFunctionContext

Classes in this Package Line Coverage Branch Coverage Complexity
XPathFunctionContext
100% 
N/A 
1

 1  
 /*
 2  
  * $Header: /home/projects/jaxen/scm/jaxen/src/java/main/org/jaxen/XPathFunctionContext.java,v 1.24 2005/05/08 18:51:49 elharo Exp $
 3  
  * $Revision: 1.24 $
 4  
  * $Date: 2005/05/08 18:51:49 $
 5  
  *
 6  
  * ====================================================================
 7  
  *
 8  
  * Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
 9  
  * All rights reserved.
 10  
  *
 11  
  * Redistribution and use in source and binary forms, with or without
 12  
  * modification, are permitted provided that the following conditions
 13  
  * are met:
 14  
  * 
 15  
  * 1. Redistributions of source code must retain the above copyright
 16  
  *    notice, this list of conditions, and the following disclaimer.
 17  
  *
 18  
  * 2. Redistributions in binary form must reproduce the above copyright
 19  
  *    notice, this list of conditions, and the disclaimer that follows 
 20  
  *    these conditions in the documentation and/or other materials 
 21  
  *    provided with the distribution.
 22  
  *
 23  
  * 3. The name "Jaxen" must not be used to endorse or promote products
 24  
  *    derived from this software without prior written permission.  For
 25  
  *    written permission, please contact license@jaxen.org.
 26  
  * 
 27  
  * 4. Products derived from this software may not be called "Jaxen", nor
 28  
  *    may "Jaxen" appear in their name, without prior written permission
 29  
  *    from the Jaxen Project Management (pm@jaxen.org).
 30  
  * 
 31  
  * In addition, we request (but do not require) that you include in the 
 32  
  * end-user documentation provided with the redistribution and/or in the 
 33  
  * software itself an acknowledgement equivalent to the following:
 34  
  *     "This product includes software developed by the
 35  
  *      Jaxen Project (http://www.jaxen.org/)."
 36  
  * Alternatively, the acknowledgment may be graphical using the logos 
 37  
  * available at http://www.jaxen.org/
 38  
  *
 39  
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 40  
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 41  
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 42  
  * DISCLAIMED.  IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
 43  
  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 44  
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 45  
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 46  
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 47  
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 48  
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 49  
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 50  
  * SUCH DAMAGE.
 51  
  *
 52  
  * ====================================================================
 53  
  * This software consists of voluntary contributions made by many 
 54  
  * individuals on behalf of the Jaxen Project and was originally 
 55  
  * created by bob mcwhirter <bob@werken.com> and 
 56  
  * James Strachan <jstrachan@apache.org>.  For more information on the 
 57  
  * Jaxen Project, please see <http://www.jaxen.org/>.
 58  
  * 
 59  
  * $Id: XPathFunctionContext.java,v 1.24 2005/05/08 18:51:49 elharo Exp $
 60  
  */
 61  
 
 62  
 
 63  
 package org.jaxen;
 64  
 
 65  
 import org.jaxen.function.BooleanFunction;
 66  
 import org.jaxen.function.CeilingFunction;
 67  
 import org.jaxen.function.ConcatFunction;
 68  
 import org.jaxen.function.ContainsFunction;
 69  
 import org.jaxen.function.CountFunction;
 70  
 import org.jaxen.function.FalseFunction;
 71  
 import org.jaxen.function.FloorFunction;
 72  
 import org.jaxen.function.IdFunction;
 73  
 import org.jaxen.function.LangFunction;
 74  
 import org.jaxen.function.LastFunction;
 75  
 import org.jaxen.function.LocalNameFunction;
 76  
 import org.jaxen.function.NameFunction;
 77  
 import org.jaxen.function.NamespaceUriFunction;
 78  
 import org.jaxen.function.NormalizeSpaceFunction;
 79  
 import org.jaxen.function.NotFunction;
 80  
 import org.jaxen.function.NumberFunction;
 81  
 import org.jaxen.function.PositionFunction;
 82  
 import org.jaxen.function.RoundFunction;
 83  
 import org.jaxen.function.StartsWithFunction;
 84  
 import org.jaxen.function.StringFunction;
 85  
 import org.jaxen.function.StringLengthFunction;
 86  
 import org.jaxen.function.SubstringAfterFunction;
 87  
 import org.jaxen.function.SubstringBeforeFunction;
 88  
 import org.jaxen.function.SubstringFunction;
 89  
 import org.jaxen.function.SumFunction;
 90  
 import org.jaxen.function.TranslateFunction;
 91  
 import org.jaxen.function.TrueFunction;
 92  
 import org.jaxen.function.ext.EndsWithFunction;
 93  
 import org.jaxen.function.ext.EvaluateFunction;
 94  
 import org.jaxen.function.ext.LowerFunction;
 95  
 import org.jaxen.function.ext.MatrixConcatFunction;
 96  
 import org.jaxen.function.ext.UpperFunction;
 97  
 import org.jaxen.function.xslt.DocumentFunction;
 98  
 
 99  
 /** A <code>FunctionContext</code> implementing the core XPath
 100  
  *  function library, with extensions.
 101  
  *
 102  
  *  <p>
 103  
  *  The core XPath function library is provided through this
 104  
  *  implementation of <code>FunctionContext</code>.  Additionally,
 105  
  *  extension functions have been provided, as enumerated below.
 106  
  *  </p>
 107  
  *
 108  
  *  <p>
 109  
  *  This class is re-entrant and thread-safe.  If using the
 110  
  *  default instance, it is inadvisable to call 
 111  
  *  {@link #registerFunction(String, String, Function)}
 112  
  *  as that will extend the global function context, affecting other
 113  
  *  users.  But that's your call, really, now isn't
 114  
  *  it?  That may be what you really want to do.
 115  
  *  </p>
 116  
  *
 117  
  *  <p>
 118  
  *  Extension functions:
 119  
  *
 120  
  *  <ul>
 121  
  *     <li>matrix-concat(..)</li>
 122  
  *     <li>evaluate(..)</li>
 123  
  *     <li>upper-case(..)</li>
 124  
  *     <li>lower-case(..)</li>
 125  
  *     <li>ends-with(..)</li>
 126  
  *  </ul>
 127  
  *
 128  
  *  @see FunctionContext
 129  
  *  @see org.jaxen.function
 130  
  *  @see org.jaxen.function.xslt
 131  
  *  @see org.jaxen.function.ext
 132  
  *
 133  
  *  @author <a href="mailto:bob@werken.com">bob mcwhirter</a>
 134  
  */
 135  
 public class XPathFunctionContext extends SimpleFunctionContext
 136  
 {
 137  41
     private static XPathFunctionContext instance = new XPathFunctionContext();
 138  
 
 139  
     /** Retrieve the default function context
 140  
      *
 141  
      *  @return the default function context
 142  
      */
 143  
     public static FunctionContext getInstance()
 144  
     {
 145  240
         return instance;
 146  
     }
 147  
 
 148  
     /** Create a new XPath function context.
 149  
      *  All core XPath and Jaxen extension functions are registered.
 150  
      */
 151  
     public XPathFunctionContext()
 152  41
     {
 153  41
         registerFunction( null,  // namespace URI
 154  
                           "boolean",
 155  
                           new BooleanFunction() );
 156  
 
 157  41
         registerFunction( null,  // namespace URI
 158  
                           "ceiling",
 159  
                           new CeilingFunction() );
 160  
 
 161  41
         registerFunction( null,  // namespace URI
 162  
                           "concat",
 163  
                           new ConcatFunction() );
 164  
 
 165  41
         registerFunction( null,  // namespace URI
 166  
                           "contains",
 167  
                           new ContainsFunction() );
 168  
         
 169  41
         registerFunction( null,  // namespace URI
 170  
                           "count",
 171  
                           new CountFunction() );
 172  
 
 173  41
         registerFunction( null,  // namespace URI
 174  
                           "false",
 175  
                           new FalseFunction() );
 176  
 
 177  41
         registerFunction( null,  // namespace URI
 178  
                           "floor",
 179  
                           new FloorFunction() );
 180  
 
 181  41
         registerFunction( null,  // namespace URI
 182  
                           "id",
 183  
                           new IdFunction() );
 184  
 
 185  41
         registerFunction( null,  // namespace URI
 186  
                           "lang",
 187  
                           new LangFunction() );
 188  
 
 189  41
         registerFunction( null,  // namespace URI
 190  
                           "last",
 191  
                           new LastFunction() );
 192  
 
 193  41
         registerFunction( null,  // namespace URI
 194  
                           "local-name",
 195  
                           new LocalNameFunction() );
 196  
 
 197  41
         registerFunction( null,  // namespace URI
 198  
                           "name",
 199  
                           new NameFunction() );
 200  
 
 201  41
         registerFunction( null,  // namespace URI
 202  
                           "namespace-uri",
 203  
                           new NamespaceUriFunction() );
 204  
 
 205  41
         registerFunction( null,  // namespace URI
 206  
                           "normalize-space",
 207  
                           new NormalizeSpaceFunction() );
 208  
 
 209  41
         registerFunction( null,  // namespace URI
 210  
                           "not",
 211  
                           new NotFunction() );
 212  
 
 213  41
         registerFunction( null,  // namespace URI
 214  
                           "number",
 215  
                           new NumberFunction() );
 216  
 
 217  41
         registerFunction( null,  // namespace URI
 218  
                           "position",
 219  
                           new PositionFunction() );
 220  
 
 221  41
         registerFunction( null,  // namespace URI
 222  
                           "round",
 223  
                           new RoundFunction() );
 224  
 
 225  41
         registerFunction( null,  // namespace URI
 226  
                           "starts-with",
 227  
                           new StartsWithFunction() );
 228  
 
 229  41
         registerFunction( null,  // namespace URI
 230  
                           "string",
 231  
                           new StringFunction() );
 232  
 
 233  41
         registerFunction( null,  // namespace URI
 234  
                           "string-length",
 235  
                           new StringLengthFunction() );
 236  
 
 237  41
         registerFunction( null,  // namespace URI
 238  
                           "substring-after",
 239  
                           new SubstringAfterFunction() );
 240  
 
 241  41
         registerFunction( null,  // namespace URI
 242  
                           "substring-before",
 243  
                           new SubstringBeforeFunction() );
 244  
 
 245  41
         registerFunction( null,  // namespace URI
 246  
                           "substring",
 247  
                           new SubstringFunction() );
 248  
 
 249  41
         registerFunction( null,  // namespace URI
 250  
                           "sum",
 251  
                           new SumFunction() );
 252  
 
 253  41
         registerFunction( null,  // namespace URI
 254  
                           "true",
 255  
                           new TrueFunction() );
 256  
         
 257  41
         registerFunction( null,  // namespace URI
 258  
                           "translate",
 259  
                           new TranslateFunction() );
 260  
         
 261  
         // XSLT extension function
 262  41
         registerFunction( null,  // namespace URI
 263  
                           "document",
 264  
                           new DocumentFunction() );
 265  
 
 266  
         // register extension functions
 267  
         // extension functions should go into a namespace, but which one?
 268  
         // for now, keep them in default namespace to not break any code
 269  
 
 270  41
         registerFunction( null,  // namespace URI
 271  
                           "matrix-concat",
 272  
                           new MatrixConcatFunction() );
 273  
 
 274  41
         registerFunction( null,  // namespace URI
 275  
                           "evaluate",
 276  
                           new EvaluateFunction() );
 277  
         
 278  41
         registerFunction( null,  // namespace URI
 279  
                           "lower-case",
 280  
                           new LowerFunction() );
 281  
         
 282  41
         registerFunction( null,  // namespace URI
 283  
                           "upper-case",
 284  
                           new UpperFunction() );
 285  
         
 286  41
         registerFunction( null,  // namespace URI
 287  
                           "ends-with",
 288  
                           new EndsWithFunction() );
 289  
         
 290  41
     }
 291  
 }