Source code: com/webobjects/woextensions/_WOJExtensionsUtil.java
1 /*
2 * _WOJExtensionsUtil.java
3 * © Copyright 2001 Apple Computer, Inc. All rights reserved.
4 * This a modified version.
5 * Original license: http://www.opensource.apple.com/apsl/
6 */
7
8 package com.webobjects.woextensions;
9
10 import com.webobjects.appserver.*;
11 import com.webobjects.foundation.*;
12 import com.webobjects.eocontrol.*;
13
14 public class _WOJExtensionsUtil extends Object {
15
16 public static boolean booleanValue(Object associationValue) {
17 boolean associationEvaluation = true;
18 if (associationValue!=null) {
19 // is this a number. If it is, evaluate it.
20 if (associationValue instanceof Number) {
21 if (((Number) associationValue).intValue()==0) {
22 associationEvaluation = false;
23 }
24 } else if (associationValue instanceof String) {
25 String associationValueString = (String)associationValue;
26 // is this no or false ?
27 if (associationValueString.equalsIgnoreCase("no") || associationValueString.equalsIgnoreCase("false")) {
28 associationEvaluation = false;
29 } else {
30 // is this a string representing a number ? Try to evaluate it.
31 try {
32 if (Integer.parseInt(associationValueString)==0) {
33 associationEvaluation = false;
34 }
35 } catch (NumberFormatException e) {
36 throw new RuntimeException("error parsing boolean from value "+ associationValueString);
37 }
38 }
39 } else if (associationValue instanceof Boolean) {
40 associationEvaluation = ((Boolean) associationValue).booleanValue();
41 } else {
42 // do nothing, it's non-null, so it's true !
43 }
44 } else {
45 associationEvaluation = false;
46 }
47
48 return associationEvaluation;
49 }
50
51 protected static void _sortEOsUsingSingleKey(NSMutableArray array, String aKey) throws NSComparator.ComparisonException {
52
53 NSArray orderings = new NSArray(EOSortOrdering.sortOrderingWithKey(aKey, EOSortOrdering.CompareAscending));
54
55 EOSortOrdering.sortArrayUsingKeyOrderArray(array, orderings);
56 }
57
58 protected static Object valueForBindingOrNull(String binding,WOComponent component) {
59 // wod bindings of the type binding = null are converted to False Boolean
60 // associations, which isn't always what we want. This utility method
61 // assumes that a Boolean value means the binding value was intented to
62 // be null
63 if (binding == null) {
64 return null;
65 }
66 Object result = component.valueForBinding(binding);
67 if (result instanceof Boolean) {
68 result = null;
69 }
70 return result;
71 }
72 }
73