Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: juju/reattore/util/Toolbox.java


1   /*  Reattore HTTP Server
2   
3       Copyright (C) 2002 Michael Hope <michaelh@juju.net.nz>
4   
5       This program is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published by
7       the Free Software Foundation; either version 2 of the License, or
8       (at your option) any later version.
9   
10      This program is distributed in the hope that it will be useful,
11      but WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13      GNU General Public License for more details.
14  
15      You should have received a copy of the GNU General Public License
16      along with this program; if not, write to the Free Software
17      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  
19      $Id: Toolbox.java,v 1.2 2003/03/05 05:06:16 michaelh Exp $
20  */
21  package juju.reattore.util;
22  
23  import java.util.*;
24  import java.util.regex.*;
25  
26  /** Toolbox of methods for use from Velocity.
27   */
28  public class Toolbox {
29      /** Create a new MapOfLists
30  
31         @return The new object.
32      */
33      public MapOfLists createMapOfLists() {
34          return new MapOfLists();
35      }
36  
37      /** Check if the named method is a Bean setter.
38  
39          @param name  Method name to check.
40          @return      true if it is a setter.
41       */ 
42      public boolean isSetter(String name) {
43          return name.startsWith("set");
44      }
45  
46      /** Turn a method name into a Bean property name.
47  
48          @param name Method name
49          @return The property name
50      */
51      public String getPropertyName(String name) {
52          if (isSetter(name)) {
53              char[] prop = name.substring(3).toCharArray();
54  
55              if (prop.length > 1
56                  && Character.isUpperCase(prop[1])) {
57  
58                  prop[1] = Character.toUpperCase(prop[1]);
59              }
60              else {
61                  prop[0] = Character.toLowerCase(prop[0]);
62              }
63  
64              return new String(prop);
65          }
66          else {
67              return null;
68          }
69      }
70  
71      /* Match the last word in a string */
72      private static Pattern shortClassPattern = Pattern.compile("^.*?(\\w+)$");
73  
74      /** Turn a fully qualified class name into the base name.
75  
76          @param name  The name to convert
77          @return The short name.
78       */
79      public String getShortClassName(String name) {
80          Matcher match = shortClassPattern.matcher(name);
81  
82          if (match.matches()) {
83              return match.group(1);
84          }
85          else {
86              return name;
87          }
88      }
89  }
90