1 16 package org.apache.cocoon.components.elementprocessor.types; 17 18 import java.io.IOException ; 19 20 27 public class BooleanConverter 28 { 29 private static final String _true_values[] = 30 { 31 "1", "true" 32 }; 33 private static final String _false_values[] = 34 { 35 "0", "false" 36 }; 37 private static final BooleanResult _true_result = 38 new BooleanResult(true); 39 private static final BooleanResult _false_result = 40 new BooleanResult(false); 41 42 private BooleanConverter() { 43 } 44 45 55 56 public static BooleanResult extractBoolean(final String value) { 57 String input = (value == null) ? "" : value.trim(); 58 BooleanResult result = null; 59 60 for (int k = 0; k < _true_values.length; k++) { 61 if (_true_values[k].equalsIgnoreCase(input)) { 62 result = _true_result; 63 break; 64 } 65 } 66 if (result == null) { 67 for (int k = 0; k < _false_values.length; k++) { 68 if (_false_values[k].equalsIgnoreCase(input)) { 69 result = _false_result; 70 break; 71 } 72 } 73 } 74 if (result == null) { 75 result = new BooleanResult( 76 new IOException ("\"" + input + "\" is not a boolean value")); 77 } 78 return result; 79 } 80 } | Popular Tags |