source: trunk/src/org/expeditee/gui/AttributeUtils.java@ 145

Last change on this file since 145 was 145, checked in by ra33, 16 years ago
File size: 22.9 KB
Line 
1package org.expeditee.gui;
2
3import java.awt.Color;
4import java.awt.Font;
5import java.awt.Point;
6import java.lang.reflect.InvocationTargetException;
7import java.lang.reflect.Method;
8import java.util.HashMap;
9import java.util.LinkedList;
10import java.util.List;
11
12import org.expeditee.io.Conversion;
13import org.expeditee.items.Item;
14import org.expeditee.items.Justification;
15import org.expeditee.items.Permission;
16import org.expeditee.items.Text;
17
18/**
19 * This class provides the methods to extract and set attributes of Items and
20 * Frames. These methods are called when a user merges a text item with
21 * <code>Attribute: Value</code> pairs.
22 *
23 * @author jdm18
24 *
25 */
26public class AttributeUtils {
27
28 public static final char SEPARATOR_CHAR = ':';
29
30 private static final String SEPARATOR_STRING = SEPARATOR_CHAR + " ";
31
32 private static final int GET_LENGTH = "get".length();
33
34 private static int SET_LENGTH = "set".length();
35
36 // List of method names to ignore when searching for a match
37 private static List<Method> _GetMethods = null;
38
39 private static HashMap<String, Method> _SetMethods = null;
40
41 // List of attributes which are ignored when copying.
42 private static List<String> _Ignore = null;
43
44 // List of method names to show in extraced lists even when they return
45 // null
46 // (Null is often used to indicate the default value is used)
47 private static List<Method> _AllowNull = null;
48
49 private static List<String> _ExtractIgnore = null;
50
51 // private static HashMap<String, String> _Abbreviations = null;
52
53 /**
54 * Initialises the _Ignore and _AllowNull lists.
55 */
56 private static void initLists() {
57
58 Class[] param = {};
59
60 try {
61 // TODO load these in with reflection...
62 // Set the shortcuts with annotation tags on the methods
63 _Ignore = new LinkedList<String>();
64 _Ignore.add("date");
65 _Ignore.add("datecreated");
66 _Ignore.add("d");
67 _Ignore.add("link");
68 _Ignore.add("l");
69 _Ignore.add("action");
70 _Ignore.add("a");
71 _Ignore.add("position");
72 _Ignore.add("pos");
73 _Ignore.add("p");
74 _Ignore.add("x");
75 _Ignore.add("y");
76
77 _ExtractIgnore = new LinkedList<String>();
78 _ExtractIgnore.add("x");
79 _ExtractIgnore.add("y");
80
81 _AllowNull = new LinkedList<Method>();
82 _AllowNull.add(Item.class.getMethod("getColor", param));
83 _AllowNull.add(Item.class.getMethod("getBackgroundColor", param));
84
85 _AllowNull.add(Frame.class.getMethod("getBackgroundColor", param));
86 _AllowNull.add(Frame.class.getMethod("getForegroundColor", param));
87
88 _GetMethods = new LinkedList<Method>();
89 _GetMethods.add(Item.class.getMethod("getDateCreated", param));
90
91 _GetMethods.add(Item.class.getMethod("getColor", param));
92 _GetMethods.add(Item.class.getMethod("getBackgroundColor", param));
93 _GetMethods.add(Item.class.getMethod("getAction", param));
94 _GetMethods.add(Item.class.getMethod("getData", param));
95 _GetMethods.add(Item.class.getMethod("getLink", param));
96 _GetMethods.add(Item.class.getMethod("getFillColor", param));
97 _GetMethods.add(Item.class.getMethod("getFillPattern", param));
98 _GetMethods.add(Item.class.getMethod("getThickness", param));
99
100 _GetMethods.add(Item.class.getMethod("getOwner", param));
101 _GetMethods.add(Item.class.getMethod("getLinkMark", param));
102 _GetMethods.add(Item.class.getMethod("getActionMark", param));
103
104 _GetMethods
105 .add(Item.class.getMethod("getActionCursorEnter", param));
106 _GetMethods
107 .add(Item.class.getMethod("getActionCursorLeave", param));
108 _GetMethods.add(Item.class.getMethod("getActionEnterFrame", param));
109 _GetMethods.add(Item.class.getMethod("getActionLeaveFrame", param));
110
111 _GetMethods.add(Item.class.getMethod("getTopShadowColor", param));
112 _GetMethods
113 .add(Item.class.getMethod("getBottomShadowColor", param));
114 _GetMethods.add(Item.class.getMethod("getArrow", param));
115
116 _GetMethods.add(Item.class.getMethod("getLinePattern", param));
117 _GetMethods.add(Item.class.getMethod("getLinkFrameset", param));
118 _GetMethods.add(Item.class.getMethod("getLinkTemplate", param));
119 _GetMethods.add(Item.class.getMethod("getPosition", param));
120 _GetMethods.add(Item.class.getMethod("getX", param));
121 _GetMethods.add(Item.class.getMethod("getY", param));
122
123 _GetMethods.add(Text.class.getMethod("getFamily", param));
124 _GetMethods.add(Text.class.getMethod("getFontStyle", param));
125 _GetMethods.add(Text.class.getMethod("getJustification", param));
126 _GetMethods.add(Text.class.getMethod("getWidth", param));
127 _GetMethods.add(Item.class.getMethod("getSize", param));
128
129 _GetMethods.add(Frame.class.getMethod("getOwner", param));
130 _GetMethods.add(Frame.class.getMethod("getPermission", param));
131 _GetMethods.add(Frame.class.getMethod("getDateCreated", param));
132 _GetMethods.add(Frame.class.getMethod("getLastModifyUser", param));
133 _GetMethods.add(Frame.class.getMethod("getLastModifyDate", param));
134 _GetMethods.add(Frame.class.getMethod("getForegroundColor", param));
135 _GetMethods.add(Frame.class.getMethod("getBackgroundColor", param));
136
137 Class[] pPoint = { Point.class };
138 Class[] pString = { String.class };
139 Class[] pInt = { int.class };
140 Class[] pFloat = { float.class };
141 Class[] pColor = { Color.class };
142 Class[] pBool = { boolean.class };
143 Class[] pArrow = { float.class, double.class };
144 Class[] pList = { List.class };
145 Class[] pIntArray = { int[].class };
146 Class[] pJustification = { Justification.class };
147 Class[] pPermission = { Permission.class };
148
149 _SetMethods = new HashMap<String, Method>();
150 _SetMethods.put("x", Item.class.getMethod("setX", pFloat));
151 _SetMethods.put("y", Item.class.getMethod("setY", pFloat));
152 _SetMethods.put("position", Item.class.getMethod("setPosition",
153 pPoint));
154 _SetMethods.put("p", Item.class.getMethod("setPosition", pPoint));
155 _SetMethods.put("pos", Item.class.getMethod("setPosition", pPoint));
156 _SetMethods.put("thickness", Item.class.getMethod("setThickness",
157 pFloat));
158 _SetMethods.put("t", Item.class.getMethod("setThickness", pFloat));
159
160 _SetMethods.put("color", Item.class.getMethod("setColor", pColor));
161 _SetMethods.put("c", Item.class.getMethod("setColor", pColor));
162
163 _SetMethods.put("backgroundcolor", Item.class.getMethod(
164 "setBackgroundColor", pColor));
165 _SetMethods.put("bgc", Item.class.getMethod("setBackgroundColor",
166 pColor));
167
168 _SetMethods
169 .put("action", Item.class.getMethod("setActions", pList));
170 _SetMethods.put("a", Item.class.getMethod("setActions", pList));
171 _SetMethods.put("d", Item.class.getMethod("setData", pList));
172 _SetMethods.put("data", Item.class.getMethod("setData", pList));
173
174 _SetMethods.put("link", Item.class.getMethod("setLink", pString));
175 _SetMethods.put("l", Item.class.getMethod("setLink", pString));
176
177 _SetMethods.put("fillcolor", Item.class.getMethod("setFillColor",
178 pColor));
179 _SetMethods.put("fc", Item.class.getMethod("setFillColor", pColor));
180 _SetMethods.put("gc", Item.class.getMethod("setGradientColor", pColor));
181 _SetMethods.put("gradientcolor", Item.class.getMethod("setGradientColor",
182 pColor));
183
184 _SetMethods.put("fillpattern", Item.class.getMethod(
185 "setFillPattern", pString));
186 _SetMethods.put("fp", Item.class.getMethod("setFillPattern",
187 pString));
188
189 _SetMethods.put("owner", Item.class.getMethod("setOwner", pString));
190 _SetMethods.put("linkmark", Item.class.getMethod("setLinkMark",
191 pBool));
192 _SetMethods.put("lm", Item.class.getMethod("setLinkMark", pBool));
193 _SetMethods.put("actionmark", Item.class.getMethod("setActionMark",
194 pBool));
195 _SetMethods.put("am", Item.class.getMethod("setActionMark", pBool));
196
197 _SetMethods.put("actioncursorenter", Item.class.getMethod(
198 "setActionCursorEnter", pList));
199 _SetMethods.put("actioncursorleave", Item.class.getMethod(
200 "setActionCursorLeave", pList));
201 _SetMethods.put("actionenterframe", Item.class.getMethod(
202 "setActionEnterFrame", pList));
203 _SetMethods.put("actionleaveframe", Item.class.getMethod(
204 "setActionLeaveFrame", pList));
205
206 _SetMethods.put("topshadow", Item.class.getMethod(
207 "setTopShadowColor", pColor));
208 _SetMethods.put("bottomshadow", Item.class.getMethod(
209 "setBottomShadowColor", pColor));
210 _SetMethods.put("arrow", Item.class.getMethod("setArrow", pArrow));
211
212 _SetMethods.put("linepattern", Item.class.getMethod(
213 "setLinePattern", pIntArray));
214 _SetMethods.put("lp", Item.class.getMethod("setLinePattern",
215 pIntArray));
216
217 _SetMethods.put("linkframeset", Item.class.getMethod(
218 "setLinkFrameset", pString));
219 _SetMethods.put("lf", Item.class.getMethod("setLinkFrameset",
220 pString));
221 _SetMethods.put("linktemplate", Item.class.getMethod(
222 "setLinkTemplate", pString));
223 _SetMethods.put("lt", Item.class.getMethod("setLinkTemplate",
224 pString));
225
226 _SetMethods.put("family", Text.class
227 .getMethod("setFamily", pString));
228 _SetMethods.put("face", Text.class.getMethod("setFontStyle",
229 pString));
230 _SetMethods.put("fontstyle", Text.class.getMethod("setFontStyle",
231 pString));
232 _SetMethods.put("justification", Text.class.getMethod(
233 "setJustification", pJustification));
234 _SetMethods.put("width", Text.class.getMethod("setWidth", pInt));
235 _SetMethods.put("size", Item.class.getMethod("setSize", pFloat));
236 _SetMethods.put("s", Item.class.getMethod("setSize", pFloat));
237
238 _SetMethods.put("foregroundcolor", Frame.class.getMethod(
239 "setForegroundColor", pColor));
240 _SetMethods.put("fgc", Frame.class.getMethod("setForegroundColor",
241 pColor));
242 _SetMethods.put("backgroundcolor0", Frame.class.getMethod(
243 "setBackgroundColor", pColor));
244 _SetMethods.put("bgc0", Frame.class.getMethod("setBackgroundColor",
245 pColor));
246 _SetMethods.put("permission", Frame.class.getMethod(
247 "setPermission", pPermission));
248
249 } catch (SecurityException e) {
250 // TODO Auto-generated catch block
251 e.printStackTrace();
252 } catch (NoSuchMethodException e) {
253 // TODO Auto-generated catch block
254 e.printStackTrace();
255 }
256 }
257
258 /**
259 * Extracts a list of attributes from the given Object. Any method that
260 * starts with <code>get</code>, takes no arguments and is not found in
261 * the Ignore list will be run, All the attributes are then put into a Text
262 * Item of the form <Name>:<Value> If the value returned by the get method
263 * is null, then the attribute will not be included, unless the name of the
264 * method is found in the AllowNull list.
265 *
266 * @param toExtract
267 * The Object from which to extract the attributes
268 * @return A Text Item containing the extracted Attributes.
269 */
270 public static Item extractAttributes(Object toExtract) {
271 if (toExtract == null)
272 return null;
273
274 // ensure the lists are populated
275 if (_Ignore == null)
276 initLists();
277
278 // StringBuffer to store all the extracted Attribute:Value pairs
279 StringBuffer attributes = new StringBuffer();
280
281 // iterate through the list of methods
282 for (Method m : _GetMethods) {
283
284 // Make sure the classes of the methods match the item
285 if (m.getDeclaringClass().isAssignableFrom(toExtract.getClass())) {
286 try {
287 Object o = m.invoke(toExtract, (Object[]) null);
288
289 if (o == null) {
290 // methods that return null are only included if they
291 // are in the AllowNull list
292 if (_AllowNull.contains(m)) {
293 String name = m.getName().substring(GET_LENGTH)
294 .toLowerCase();
295 if (name.equals("color"))
296 o = "default";
297 else if (name.equals("backgroundcolor"))
298 o = "transparent";
299 else if (name.equals("foregroundcolor"))
300 o = "auto";
301 else
302 o = "";
303 } else {
304 continue;
305 }
306 }
307 // skip methods that are in the ignore lists
308 if (_ExtractIgnore.contains(m.getName().substring(
309 GET_LENGTH).toLowerCase())) {
310 continue;
311 }
312
313 if (o instanceof Integer) {
314 Integer i = (Integer) o;
315 if (i == Item.DEFAULT_INTEGER)
316 continue;
317 if (m.getName().endsWith("Justification")
318 && ((Justification) o).toString() != null)
319 o = ((Justification) o).toString();
320 // -1 indicates default value
321 else
322 o = i;
323 } else if (o instanceof Float) {
324 // -1 indicates default value
325 if (((Float) o) < 0.0001)
326 continue;
327 o = Math.round((Float)o);
328 } else if (o instanceof Double) {
329 // -1 indicates default value
330 if (((Double) o) < 0.0001)
331 continue;
332 } else if (o instanceof Color) {
333 // converts the color to the Expeditee code
334 o = Conversion.getExpediteeColorCode((Color) o);
335 if (o == null)
336 continue;
337 } else if (o instanceof Point) {
338 Point p = (Point) o;
339 o = Math.round(p.getX()) + " " + Math.round(p.getY());
340 } else if (o instanceof Font) {
341 Font f = (Font) o;
342
343 String s = f.getName() + "-";
344 if (f.isPlain())
345 s += "Plain";
346
347 if (f.isBold())
348 s += "Bold";
349
350 if (f.isItalic())
351 s += "Italic";
352
353 s += "-" + f.getSize();
354 o = s;
355 } else if (o instanceof Text) {
356 o = ((Text) o).getFirstLine();
357 } else if (o instanceof List) {
358 List list = (List) o;
359 for (Object ob : list)
360 attributes
361 .append(m.getName().substring(GET_LENGTH))
362 .append(SEPARATOR_STRING).append(ob)
363 .append('\n');
364 continue;
365 } else if (o instanceof int[]) {
366 StringBuffer sb = new StringBuffer();
367 int[] values = (int[]) o;
368 for (int i = 0; i < values.length; i++) {
369 sb.append(values[i]).append(' ');
370 }
371 sb.deleteCharAt(attributes.length() - 1);
372 o = sb.toString();
373 } else if (o instanceof Boolean) {
374 // true is the default for boolean values
375 if (((Boolean) o).booleanValue())
376 continue;
377 }
378 // Append the attributes
379 attributes.append(m.getName().substring(GET_LENGTH))
380 .append(SEPARATOR_STRING).append(o).append('\n');
381 } catch (Exception e) {
382 // TODO Auto-generated catch block
383 e.printStackTrace();
384 }
385 }
386 }
387
388 // if no attributes were extracted
389 if (attributes.length() <= 0)
390 return null;
391
392 while (attributes. charAt(attributes.length() - 1) == '\n')
393 attributes.delete(attributes.length() - 1, attributes.length());
394
395 // create the text Item
396 Frame current = DisplayIO.getCurrentFrame();
397 Item attribs = current.getStatsTextItem(attributes.toString());
398 return attribs;
399 }
400
401 /**
402 * Attempts to set the attribute in the given attribute: value pair. The
403 * value string should be formatted as follows:
404 * <code> Attribute: Value </code> Multiple values can be used if they are
405 * separated by spaces
406 *
407 * @param toSet
408 * The Item or Frame to set the attribute of
409 * @param attribs
410 * The Text item that contains the list of attributes to set
411 * @return True if the attribute(s) were sucessfully set, false otherwise
412 */
413 public static boolean setAttribute(Object toSet, Text attribs) {
414 // error checking
415 if (toSet == null || attribs == null)
416 return false;
417
418 if (_Ignore == null)
419 initLists();
420
421 // get the list of attribute: value pairs
422 List<String> values = attribs.getTextList();
423 // if no pairs exist, we are done
424 if (values.size() == 0
425 || (values.size() == 1 && values.get(0).length() == 0)) {
426 return false;
427 }
428
429 // loop through all attribute: value pairs
430 for (int i = 0; i < values.size(); i++) {
431 StringBuffer v = new StringBuffer(values.get(i));
432
433 // remove the annotation mark (if applicable)
434 if (v.indexOf("@") == 0)
435 v = v.deleteCharAt(0);
436
437 // check if the next string is another attribute to merge or a
438 // continuation
439 while (i < values.size() - 1) {
440 StringBuffer next = new StringBuffer(values.get(i + 1));
441
442 // if the next String has a colon, then it may be another
443 // attribute
444 if (next.indexOf("" + SEPARATOR_CHAR) >= 0) {
445 // if the attribute is the same as v, then it is a
446 // continuation
447 if (v.indexOf(getAttribute(next.toString())) == 0) {
448 // strip the attribute from next
449 next = new StringBuffer(getValue(next.toString()));
450 // if the attribute is not the same, then it may be a
451 // new method
452 } else {
453 // if this is indeed a method, then leave the while loop
454 // if(_SetMethods.containsKey(StripFromColon(next.toString()).toLowerCase())){
455 break;
456 // }
457 }
458 }
459
460 v.append("\n").append(next);
461 i++;
462 }
463
464 if (v.length() > 0
465 && !setAttribute(toSet, v.toString(), values.size() > 1)) {
466 // if no other attributes have been set
467 if (i == 0)
468 return false;
469 // otherwise, this is a list of attributes, so continue
470 else {
471 String stripped = getAttribute(v.toString());
472 if (stripped == null) {
473 // This happens when there is an attribute at the start
474 // Then a bunch of plain text
475 return false;
476 } else if (_Ignore.contains(stripped)) {
477 return false;
478 } else if (!(_SetMethods.containsKey(stripped))) {
479 // Display an error message if its not in our list of
480 // attributes to ignore when copying
481 MessageBay.warningMessage("Attribute: '"
482 + getAttribute(v.toString())
483 + "' does not exist.");
484 } else {
485 String types = "";
486 for (Class c : _SetMethods.get(stripped)
487 .getParameterTypes())
488 types += c.getSimpleName() + " ";
489 MessageBay.warningMessage("Wrong arguments for: '"
490 + getAttribute(v.toString()) + "' expecting "
491 + types.trim() + " found '"
492 + getValue(v.toString()) + "'");
493 }
494 }
495 } else if (v.length() == 0)
496 return false;
497 }
498
499 return true;
500 }
501
502 private static boolean setAttribute(Object toSet, String value,
503 boolean isAttributeList) {
504 // separate attribute and value from string
505 String attribute = getAttribute(value);
506 //Check that an attribute was found
507 if(attribute == null)
508 return false;
509 attribute = attribute.toLowerCase();
510
511 value = getValue(value);
512 assert(value != null);
513
514 // Some properties are ignored when multiple attributes are being set on
515 // an item at the same time
516 if (isAttributeList && _Ignore.contains(attribute)) {
517 // System.out.println("Attribute ignored: " + attribute);
518 return true;
519 }
520
521 // Separate multiple values if required
522 Method toRun = _SetMethods.get( attribute);
523
524 // if this is not the name of a method, it may be the name of an agent
525 if (toRun == null) {
526 // System.out.println("Attrib not found for: " + attribute);
527 return false;
528 }
529
530 // if there are duplicate methods with the same name
531 List<Method> possibles = new LinkedList<Method>();
532 if (toRun.getDeclaringClass().isInstance(toSet))
533 possibles.add(toRun);
534 int i = 0;
535 while (_SetMethods.containsKey(attribute + i)) {
536 if (_SetMethods.get(attribute + i).getDeclaringClass()
537 .isAssignableFrom(toSet.getClass()))
538 possibles.add(_SetMethods.get(attribute + i));
539 i++;
540 }
541
542 for (Method possible : possibles) {
543 Object current = null;
544 Object[] param = {};
545 // find the corresponding get method for this set method
546 // and get the current value of the attribute
547 for (Method m : _GetMethods) {
548 if (m.getDeclaringClass().isAssignableFrom(toSet.getClass())
549 && m.getName().substring(GET_LENGTH).equals(
550 possible.getName().substring(SET_LENGTH))) {
551 try {
552 current = m.invoke(toSet, param);
553 } catch (IllegalArgumentException e) {
554 // TODO Auto-generated catch block
555 e.printStackTrace();
556 } catch (IllegalAccessException e) {
557 // TODO Auto-generated catch block
558 e.printStackTrace();
559 } catch (InvocationTargetException e) {
560 // TODO Auto-generated catch block
561 e.printStackTrace();
562 }
563 break;
564 }
565
566 }
567
568 try {
569 Object[] params = Conversion.Convert(possible, value, current);
570
571 try {
572 possible.invoke(toSet, params);
573 return true;
574 } catch (IllegalArgumentException e) {
575 // TODO Auto-generated catch block
576 e.printStackTrace();
577 } catch (IllegalAccessException e) {
578 // TODO Auto-generated catch block
579 e.printStackTrace();
580 } catch (InvocationTargetException e) {
581 MessageBay.displayMessage(toSet.getClass()
582 .getSimpleName()
583 + " type does not support that attribute.");
584 // e.printStackTrace();
585 }
586 } catch (NumberFormatException e) {
587
588 }
589 }
590
591 return false;
592 }
593
594 /**
595 * Returns the part of the given string that is after the attribute value
596 * pair separator. If that character is not there it returns empty
597 * if it is an annotation item or the entire string if it is not.
598 *
599 * @param attributeValuePair
600 * the string to get the value from.
601 * @return the value from the attribute value pair.
602 */
603 public static String getValue(String toStrip) {
604 assert (toStrip != null);
605
606 toStrip = toStrip.trim();
607 if (toStrip.length() == 0)
608 return "";
609
610 int ind = toStrip.lastIndexOf(SEPARATOR_CHAR);
611 int lineSeparator = toStrip.indexOf(Character.LINE_SEPARATOR, ind);
612 // If it is an annotation item return the empty string
613 // Annotation items can not be values only
614 if (ind < 0 && toStrip.charAt(0) == '@') {
615 return "";
616 }
617 //If its one line then our value goes to the end of the string
618 if(lineSeparator < 0)
619 lineSeparator = toStrip.length();
620
621 return toStrip.substring(ind + 1, lineSeparator).trim();
622 }
623
624 /**
625 * Returns the part of the given string that is before the attribute value
626 * pair separator, or null if the given String does not include the
627 * separator.
628 *
629 * @param attributeValuePair
630 * The String to strip
631 * @return the attribute if there is one or null if there is not
632 */
633 public static String getAttribute(String attributeValuePair) {
634 if(attributeValuePair.length() <= 1)
635 return null;
636
637 attributeValuePair = attributeValuePair.trim();
638
639 int ind = attributeValuePair.indexOf(SEPARATOR_CHAR);
640 // If its an annotation there must be no space between the @ and colon
641 // and the first character after the annotation must be a letter
642 if (attributeValuePair.charAt(0) == '@') {
643 if (!Character.isLetter(attributeValuePair.charAt(1)))
644 return null;
645 for (int i = 2; i < ind; i++) {
646 if (!Character.isLetterOrDigit(attributeValuePair.charAt(i)))
647 return null;
648 }
649 if (ind < 1)
650 return attributeValuePair.substring(0);
651 }else if (ind < 1){
652 return null;
653 }
654
655 return attributeValuePair.substring(0, ind).trim();
656 }
657
658 /**
659 * Replaces the current value for the text item with the new value.
660 *
661 * @param text
662 * the item whos value is to be changed
663 * @param newValue
664 * the new value for the item
665 */
666 public static void replaceValue(Text text, String newValue) {
667 assert (newValue != null);
668
669 String oldText = text.getFirstLine();
670 String restOfText = text.getText().substring(oldText.length());
671 String attribute = getAttribute(oldText);
672
673 if (attribute == null)
674 attribute = text.getText().trim();
675
676 text.setText(attribute + SEPARATOR_STRING + newValue + restOfText);
677 }
678
679 /**
680 * Gets the value from an attribute value pair as a double.
681 *
682 * @param attributeValuePair
683 * the text to get the value from
684 * @return the double value or null if there is none
685 */
686 public static Double getDoubleValue(String attributeValuePair) {
687 String value = getValue(attributeValuePair);
688
689 assert (value != null);
690
691 try {
692 return Double.parseDouble(value);
693 } catch (Exception e) {
694 }
695 return null;
696 }
697}
Note: See TracBrowser for help on using the repository browser.