KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > CaseTransform


1 /*
2  * Copyright 2001-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 /**
18  * An implementation of the Transform interface which converts all
19  * input text to either upper or lower case.
20  * <p>
21  * Note that because it doesn't use any nested tags for configuration,
22  * just xml attributes which map 1:1 onto bean property-setter methods,
23  * there is no need to define any custom addRules method to use this
24  * as a Digester plugin class.
25  */

26
27 public class CaseTransform implements Transform {
28     private boolean toLower = true;
29     
30     public void setCase(String JavaDoc caseType) {
31         if (caseType.equalsIgnoreCase("upper"))
32             toLower = false;
33         else
34             toLower = true;
35     }
36     
37     public String JavaDoc transform(String JavaDoc s) {
38         if (toLower)
39             return s.toLowerCase();
40         else
41             return s.toUpperCase();
42     }
43 }
44
Popular Tags