View Javadoc

1   /**
2    * JSpiff
3    * -----------------
4    * Copyright (c) 2005-2006 Emil A. Lefkof III
5    *
6    * I always give it my best shot to make a program useful and solid, but
7    * remeber that there is absolutely no warranty for using this program as
8    * stated in the following terms:
9    *
10   * Licensed under the Apache License, Version 2.0 (the "License");
11   * you may not use this file except in compliance with the License.
12   * You may obtain a copy of the License at
13   *
14   *     http://www.apache.org/licenses/LICENSE-2.0
15   *
16   * Unless required by applicable law or agreed to in writing, software
17   * distributed under the License is distributed on an "AS IS" BASIS,
18   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19   * See the License for the specific language governing permissions and
20   * limitations under the License.
21   */
22  package com.melloware.jspiff.jaxp;
23  
24  import java.io.ByteArrayOutputStream;
25  import java.io.File;
26  import java.io.IOException;
27  import java.io.PrintWriter;
28  import java.io.Writer;
29  import java.math.BigDecimal;
30  import java.math.BigInteger;
31  import java.net.MalformedURLException;
32  import java.net.URL;
33  import java.text.DateFormat;
34  import java.text.ParseException;
35  import java.util.ArrayList;
36  import java.util.Collection;
37  import java.util.Date;
38  import java.util.List;
39  import java.util.Locale;
40  import java.util.Stack;
41  import java.util.StringTokenizer;
42  
43  import org.w3c.dom.Attr;
44  import org.w3c.dom.Document;
45  import org.w3c.dom.Element;
46  import org.w3c.dom.EntityReference;
47  import org.w3c.dom.NamedNodeMap;
48  import org.w3c.dom.Node;
49  import org.w3c.dom.NodeList;
50  import org.w3c.dom.Text;
51  
52  /**
53   * URelaxer
54   *
55   * @since   Jan. 19, 2000
56   * @version Dec. 15, 2004
57   * @author  ASAMI, Tomoharu (asami@relaxer.org)
58   * @author Emil A. Lefkof III <info@melloware.com>
59   */
60  public final class URelaxer {
61  
62      private static char[] map__ = {
63          'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
64          'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
65          's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
66      };
67  
68      // Auto
69  
70      private static Object autoIDHandler__ = null;
71      private static String autoIDPrefix__ = null;
72      private static Boolean autoIDThreadSingle__ = null;
73      private static Boolean autoIDThreadGroupSingle__ = null;
74  
75      /*
76       *  public static class RelativeStreamHandler     extends java.net.URLStreamHandler {
77       *
78       *   protected URLConnection openConnection(URL u) throws IOException {         throw (new
79       * IOException("UnsupportedOperation"));     }
80       *
81       *   protected void parseURL(URL u, String spec, int start, int limit) {         String protocol;         String
82       * file;         String ref;         int afterProtocol = spec.indexOf(":");         protocol = spec.substring(0,
83       * afterProtocol);         int afterFile = spec.indexOf("#");         if (afterFile == -1) {             file =
84       * spec.substring(afterProtocol + 1);             ref = null;         } else {             file =
85       * spec.substring(afterProtocol + 1, afterFile);             ref = spec.substring(afterFile + 1);         }
86       * setURL(u, protocol, null, -1, file, ref);     }
87       *
88       *   protected String toExternalForm(URL u) {         return (u.getFile());     } }
89       */
90      //
91      static boolean isRigid__ = true;
92      static boolean isBadNumber__ = true;
93  
94      public static String getAttribute(Element element, String name) {
95          Attr attr = element.getAttributeNode(name);
96          if (attr == null) {
97              return (null);
98          }
99          return (attr.getValue());
100     }
101 
102     public static String getAttributeHungry(RStack stack, String name) {
103         Attr attr = stack.getContextElement().getAttributeNode(name);
104         if (attr == null) {
105             return (null);
106         }
107         if (stack.isConsumedAttribute(attr)) {
108             throw (new IllegalArgumentException());
109         }
110         stack.consumeAttribute(attr);
111         return (attr.getValue());
112     }
113 
114     public static BigDecimal getAttributePropertyAsBigDecimal(Element element, String name) {
115         try {
116             String value = getAttribute(element, name);
117             if (value == null) {
118                 return (null);
119             } else {
120                 return (new BigDecimal(value));
121             }
122         } catch (Exception e) {
123             return (_invalidBigDecimal(e));
124         }
125     }
126 
127     public static List getAttributePropertyAsBigDecimalList(Element element, String name) {
128         String value = getAttribute(element, name);
129         if (value == null) {
130             return (null);
131         }
132         List list = makeStringList(value);
133         List result = new ArrayList();
134         int size = list.size();
135         for (int i = 0; i < size; i++) {
136             String data = list.get(i).toString();
137             result.add(getBigDecimalObject(data));
138         }
139         return (result);
140     }
141 
142     public static BigInteger getAttributePropertyAsBigInteger(Element element, String name) {
143         try {
144             String value = getAttribute(element, name);
145             if (value == null) {
146                 return (null);
147             } else {
148                 return (new BigInteger(value));
149             }
150         } catch (Exception e) {
151             return (_invalidBigInteger(e));
152         }
153     }
154 
155     public static List getAttributePropertyAsBigIntegerList(Element element, String name) {
156         String value = getAttribute(element, name);
157         if (value == null) {
158             return (null);
159         }
160         List list = makeStringList(value);
161         List result = new ArrayList();
162         int size = list.size();
163         for (int i = 0; i < size; i++) {
164             String data = list.get(i).toString();
165             result.add(getBigIntegerObject(data));
166         }
167         return (result);
168     }
169 
170     public static byte[] getAttributePropertyAsBinaryBASE64(Element element, String name) {
171         String value = getAttribute(element, name);
172         return (makeBytesByBASE64(value));
173     }
174 
175     public static List getAttributePropertyAsBinaryBASE64List(Element element, String name) {
176         String value = getAttribute(element, name);
177         if (value == null) {
178             return (null);
179         }
180         List list = makeStringList(value);
181         List result = new ArrayList();
182         int size = list.size();
183         for (int i = 0; i < size; i++) {
184             String data = list.get(i).toString();
185             result.add(makeBytesByBASE64(data));
186         }
187         return (result);
188     }
189 
190     public static byte[] getAttributePropertyAsBinaryHEX(Element element, String name) {
191         String value = getAttribute(element, name);
192         return (makeBytesByHEX(value));
193     }
194 
195     public static List getAttributePropertyAsBinaryHEXList(Element element, String name) {
196         String value = getAttribute(element, name);
197         if (value == null) {
198             return (null);
199         }
200         List list = makeStringList(value);
201         List result = new ArrayList();
202         int size = list.size();
203         for (int i = 0; i < size; i++) {
204             String data = list.get(i).toString();
205             result.add(makeBytesByHEX(data));
206         }
207         return (result);
208     }
209 
210     public static boolean getAttributePropertyAsBoolean(Element element, String name) {
211         String value = getAttribute(element, name);
212         if (value == null) {
213             return (false);
214         }
215         return ("true".equals(value));
216     }
217 
218     public static List getAttributePropertyAsBooleanList(Element element, String name) {
219         String value = getAttribute(element, name);
220         if (value == null) {
221             return (null);
222         }
223         List list = makeStringList(value);
224         List result = new ArrayList();
225         int size = list.size();
226         for (int i = 0; i < size; i++) {
227             String data = list.get(i).toString();
228             if ("true".equals(data) || "1".equals(data)) {
229                 result.add(Boolean.TRUE);
230             } else {
231                 result.add(Boolean.FALSE);
232             }
233         }
234         return (result);
235     }
236 
237     public static Boolean getAttributePropertyAsBooleanObject(Element element, String name) {
238         String value = getAttribute(element, name);
239         if (value == null) {
240             return (null);
241         }
242         return (getBooleanObject(value));
243     }
244 
245     public static byte getAttributePropertyAsByte(Element element, String name) {
246         try {
247             String value = getAttribute(element, name);
248             if (value == null) {
249                 return (0);
250             } else {
251                 return (Byte.parseByte(value));
252             }
253         } catch (Exception e) {
254             return (_invalidByteValue(e));
255         }
256     }
257 
258     public static List getAttributePropertyAsByteList(Element element, String name) {
259         String value = getAttribute(element, name);
260         if (value == null) {
261             return (null);
262         }
263         List list = makeStringList(value);
264         List result = new ArrayList();
265         int size = list.size();
266         for (int i = 0; i < size; i++) {
267             String data = list.get(i).toString();
268             result.add(getByteObject(data));
269         }
270         return (result);
271     }
272 
273     public static Byte getAttributePropertyAsByteObject(Element element, String name) {
274         String value = getAttribute(element, name);
275         if (value == null) {
276             return (null);
277         } else {
278             return (getByteObject(value));
279         }
280     }
281 
282     public static Date getAttributePropertyAsDate(Element element, String name) {
283         try {
284             String value = getAttribute(element, name);
285             if (value == null) {
286                 return (null);
287             } else {
288                 DateFormat df = DateFormat.getDateInstance();
289                 return (df.parse(value));
290             }
291         } catch (Exception e) {
292             return (_invalidDate(e));
293         }
294     }
295 
296     public static List getAttributePropertyAsDateList(Element element, String name) {
297         String value = getAttribute(element, name);
298         if (value == null) {
299             return (null);
300         }
301         List list = makeStringList(value);
302         List result = new ArrayList();
303         int size = list.size();
304         for (int i = 0; i < size; i++) {
305             String data = list.get(i).toString();
306             result.add(getDateObject(data));
307         }
308         return (result);
309     }
310 
311     public static double getAttributePropertyAsDouble(Element element, String name) {
312         try {
313             String value = getAttribute(element, name);
314             if (value == null) {
315                 return (0);
316             } else {
317                 return (Double.parseDouble(value));
318             }
319         } catch (Exception e) {
320             return (_invalidDoubleValue(e));
321         }
322     }
323 
324     public static List getAttributePropertyAsDoubleList(Element element, String name) {
325         String value = getAttribute(element, name);
326         if (value == null) {
327             return (null);
328         }
329         List list = makeStringList(value);
330         List result = new ArrayList();
331         int size = list.size();
332         for (int i = 0; i < size; i++) {
333             String data = list.get(i).toString();
334             result.add(getDoubleObject(data));
335         }
336         return (result);
337     }
338 
339     public static Double getAttributePropertyAsDoubleObject(Element element, String name) {
340         String value = getAttribute(element, name);
341         if (value == null) {
342             return (null);
343         } else {
344             return (getDoubleObject(value));
345         }
346     }
347 
348     public static float getAttributePropertyAsFloat(Element element, String name) {
349         try {
350             String value = getAttribute(element, name);
351             if (value == null) {
352                 return (0);
353             } else {
354                 return (Float.parseFloat(value));
355             }
356         } catch (Exception e) {
357             return (_invalidFloatValue(e));
358         }
359     }
360 
361     public static List getAttributePropertyAsFloatList(Element element, String name) {
362         String value = getAttribute(element, name);
363         if (value == null) {
364             return (null);
365         }
366         List list = makeStringList(value);
367         List result = new ArrayList();
368         int size = list.size();
369         for (int i = 0; i < size; i++) {
370             String data = list.get(i).toString();
371             result.add(getFloatObject(data));
372         }
373         return (result);
374     }
375 
376     public static Float getAttributePropertyAsFloatObject(Element element, String name) {
377         String value = getAttribute(element, name);
378         if (value == null) {
379             return (null);
380         } else {
381             return (getFloatObject(value));
382         }
383     }
384 
385     public static int getAttributePropertyAsInt(Element element, String name) {
386         try {
387             String value = getAttribute(element, name);
388             if (value == null) {
389                 return (0);
390             } else {
391                 return (Integer.parseInt(value));
392             }
393         } catch (Exception e) {
394             return (_invalidIntValue(e));
395         }
396     }
397 
398     public static List getAttributePropertyAsIntList(Element element, String name) {
399         String value = getAttribute(element, name);
400         if (value == null) {
401             return (null);
402         }
403         List list = makeStringList(value);
404         List result = new ArrayList();
405         int size = list.size();
406         for (int i = 0; i < size; i++) {
407             String data = list.get(i).toString();
408             result.add(getIntObject(data));
409         }
410         return (result);
411     }
412 
413     public static Integer getAttributePropertyAsIntObject(Element element, String name) {
414         String value = getAttribute(element, name);
415         if (value == null) {
416             return (null);
417         } else {
418             return (getIntObject(value));
419         }
420     }
421 
422     public static Locale getAttributePropertyAsLocale(Element element, String name) {
423         String value = getAttribute(element, name);
424         if (value == null) {
425             return (null);
426         } else {
427             return (makeLocale(value));
428         }
429     }
430 
431     public static List getAttributePropertyAsLocaleList(Element element, String name) {
432         String value = getAttribute(element, name);
433         if (value == null) {
434             return (null);
435         }
436         List list = makeStringList(value);
437         List result = new ArrayList();
438         int size = list.size();
439         for (int i = 0; i < size; i++) {
440             String data = list.get(i).toString();
441             result.add(makeLocale(data));
442         }
443         return (result);
444     }
445 
446     public static long getAttributePropertyAsLong(Element element, String name) {
447         try {
448             String value = getAttribute(element, name);
449             if (value == null) {
450                 return (0);
451             } else {
452                 return (Long.parseLong(value));
453             }
454         } catch (Exception e) {
455             return (_invalidLongValue(e));
456         }
457     }
458 
459     public static List getAttributePropertyAsLongList(Element element, String name) {
460         String value = getAttribute(element, name);
461         if (value == null) {
462             return (null);
463         }
464         List list = makeStringList(value);
465         List result = new ArrayList();
466         int size = list.size();
467         for (int i = 0; i < size; i++) {
468             String data = list.get(i).toString();
469             result.add(getLongObject(data));
470         }
471         return (result);
472     }
473 
474     public static Long getAttributePropertyAsLongObject(Element element, String name) {
475         String value = getAttribute(element, name);
476         if (value == null) {
477             return (null);
478         } else {
479             return (getLongObject(value));
480         }
481     }
482 
483     public static short getAttributePropertyAsShort(Element element, String name) {
484         try {
485             String value = getAttribute(element, name);
486             if (value == null) {
487                 return (0);
488             } else {
489                 return (Short.parseShort(value));
490             }
491         } catch (Exception e) {
492             return (_invalidShortValue(e));
493         }
494     }
495 
496     public static List getAttributePropertyAsShortList(Element element, String name) {
497         String value = getAttribute(element, name);
498         if (value == null) {
499             return (null);
500         }
501         List list = makeStringList(value);
502         List result = new ArrayList();
503         int size = list.size();
504         for (int i = 0; i < size; i++) {
505             String data = list.get(i).toString();
506             result.add(getShortObject(data));
507         }
508         return (result);
509     }
510 
511     public static Short getAttributePropertyAsShortObject(Element element, String name) {
512         String value = getAttribute(element, name);
513         if (value == null) {
514             return (null);
515         } else {
516             return (getShortObject(value));
517         }
518     }
519 
520     public static java.sql.Date getAttributePropertyAsSQLDate(Element element, String name) {
521         String value = getAttribute(element, name);
522         if (value == null) {
523             return (null);
524         } else {
525             return (getSQLDate(value));
526         }
527     }
528 
529     public static List getAttributePropertyAsSQLDateList(Element element, String name) {
530         String value = getAttribute(element, name);
531         if (value == null) {
532             return (null);
533         }
534         List list = makeStringList(value);
535         List result = new ArrayList();
536         int size = list.size();
537         for (int i = 0; i < size; i++) {
538             String data = list.get(i).toString();
539             result.add(getSQLDate(data));
540         }
541         return (result);
542     }
543 
544     public static java.sql.Time getAttributePropertyAsSQLTime(Element element, String name) {
545         String value = getAttribute(element, name);
546         if (value == null) {
547             return (null);
548         } else {
549             return (getSQLTime(value));
550         }
551     }
552 
553     public static List getAttributePropertyAsSQLTimeList(Element element, String name) {
554         String value = getAttribute(element, name);
555         if (value == null) {
556             return (null);
557         }
558         List list = makeStringList(value);
559         List result = new ArrayList();
560         int size = list.size();
561         for (int i = 0; i < size; i++) {
562             String data = list.get(i).toString();
563             result.add(getSQLTime(data));
564         }
565         return (result);
566     }
567 
568     public static java.sql.Timestamp getAttributePropertyAsSQLTimestamp(Element element, String name) {
569         String value = getAttribute(element, name);
570         if (value == null) {
571             return (null);
572         } else {
573             return (getSQLTimestamp(value));
574         }
575     }
576 
577     public static List getAttributePropertyAsSQLTimestampList(Element element, String name) {
578         String value = getAttribute(element, name);
579         if (value == null) {
580             return (null);
581         }
582         List list = makeStringList(value);
583         List result = new ArrayList();
584         int size = list.size();
585         for (int i = 0; i < size; i++) {
586             String data = list.get(i).toString();
587             result.add(getSQLTimestamp(data));
588         }
589         return (result);
590     }
591 
592     public static String getAttributePropertyAsString(Element element, String name) {
593         String value = getAttribute(element, name);
594         if (value == null) {
595             return (null);
596         } else {
597             return (value);
598         }
599     }
600 
601     public static List getAttributePropertyAsStringList(Element element, String name) {
602         String value = getAttribute(element, name);
603         if (value == null) {
604             return (null);
605         }
606         return (makeStringList(value));
607     }
608 
609     public static URL getAttributePropertyAsURL(Element element, String name) {
610         String value = getAttribute(element, name);
611         if (value == null) {
612             return (null);
613         } else {
614             return (makeURL4Property(value));
615         }
616     }
617 
618     public static List getAttributePropertyAsURLList(Element element, String name) {
619         String value = getAttribute(element, name);
620         if (value == null) {
621             return (null);
622         }
623         List list = makeStringList(value);
624         List result = new ArrayList();
625         int size = list.size();
626         for (int i = 0; i < size; i++) {
627             String data = list.get(i).toString();
628             URL url = makeURL4Property(data);
629             if (url != null) {
630                 result.add(url);
631             }
632         }
633         return (result);
634     }
635 
636     public static String getAttributePropertyAsValue(Element element, String attrName, String typeName) {
637         if ("string".equals(typeName)) {
638             return (getAttributePropertyAsString(element, attrName));
639         } else {
640             return (getAttributePropertyAsValueData(element, attrName));
641         }
642     }
643 
644     public static String getAttributePropertyAsValueData(Element element, String attrName) {
645         String data = getAttributePropertyAsString(element, attrName);
646         if (data == null) {
647             return (null);
648         }
649         return (data.trim());
650     }
651 
652     public static String getAutoIDPrefix() {
653         return (autoIDPrefix__);
654     }
655 
656     public static Boolean getAutoIDThreadGroupSingle() {
657         return (autoIDThreadGroupSingle__);
658     }
659 
660     public static Boolean getAutoIDThreadSingle() {
661         return (autoIDThreadSingle__);
662     }
663 
664     public static BigDecimal getBigDecimal(String value) {
665         try {
666             return (new BigDecimal(value));
667         } catch (Exception e) {
668             return (_invalidBigDecimal(e));
669         }
670     }
671 
672     public static BigDecimal[] getBigDecimalList(String text) {
673         String[] strings = getStringList(text);
674         BigDecimal[] list = new BigDecimal[strings.length];
675         for (int i = 0; i < strings.length; i++) {
676             list[i] = getBigDecimal(strings[i]);
677         }
678         return (list);
679     }
680 
681     public static BigDecimal getBigDecimalObject(Object value) {
682         try {
683             if (value instanceof BigDecimal) {
684                 return ((BigDecimal)value);
685             } else {
686                 return (new BigDecimal(value.toString()));
687             }
688         } catch (Exception e) {
689             return (_invalidBigDecimal(e));
690         }
691     }
692 
693     public static BigInteger getBigInteger(String value) {
694         try {
695             return (new BigInteger(value));
696         } catch (Exception e) {
697             return (_invalidBigInteger(e));
698         }
699     }
700 
701     public static BigInteger[] getBigIntegerList(String text) {
702         String[] strings = getStringList(text);
703         BigInteger[] list = new BigInteger[strings.length];
704         for (int i = 0; i < strings.length; i++) {
705             list[i] = getBigInteger(strings[i]);
706         }
707         return (list);
708     }
709 
710     public static BigInteger getBigIntegerObject(Object value) {
711         try {
712             if (value instanceof BigInteger) {
713                 return ((BigInteger)value);
714             } else {
715                 return (new BigInteger(value.toString()));
716             }
717         } catch (Exception e) {
718             return (_invalidBigInteger(e));
719         }
720     }
721 
722     public static byte[] getBinary(String value) {
723         return (makeBytesByBASE64(value));
724     }
725 
726     public static byte[] getBinaryHEX(String value) {
727         return (makeBytesByHEX(value));
728     }
729 
730     public static byte[][] getBinaryHEXList(String text) {
731         String[] strings = getStringList(text);
732         byte[][] list = new byte[strings.length][];
733         for (int i = 0; i < strings.length; i++) {
734             list[i] = getBinaryHEX(strings[i]);
735         }
736         return (list);
737     }
738 
739     public static byte[] getBinaryHEXObject(Object value) {
740         if (value instanceof byte[]) {
741             return ((byte[])value);
742         } else {
743             return (makeBytesByHEX(value.toString()));
744         }
745     }
746 
747     public static byte[][] getBinaryList(String text) {
748         String[] strings = getStringList(text);
749         byte[][] list = new byte[strings.length][];
750         for (int i = 0; i < strings.length; i++) {
751             list[i] = getBinary(strings[i]);
752         }
753         return (list);
754     }
755 
756     public static byte[] getBinaryObject(Object value) {
757         if (value instanceof byte[]) {
758             return ((byte[])value);
759         } else {
760             return (getBinary(value.toString()));
761         }
762     }
763 
764     // binary type (BASE64)
765     public static String getBinaryString(byte[] value) {
766         if (value == null) {
767             return (null);
768         }
769         return (makeStringAsBASE64(value));
770     }
771 
772     public static String getBinaryString(byte[][] value) {
773         if (value == null) {
774             return (null);
775         }
776         if (value.length == 0) {
777             return ("");
778         }
779         StringBuffer buffer = new StringBuffer();
780         buffer.append(makeStringAsBASE64(value[0]));
781         for (int i = 1; i < value.length; i++) {
782             buffer.append(" ");
783             buffer.append(makeStringAsBASE64(value[i]));
784         }
785         return (new String(buffer));
786     }
787 
788     public static Boolean getBooleanObject(String text) {
789         if ("true".equals(text) || "1".equals(text)) {
790             return (Boolean.TRUE);
791         } else if ("false".equals(text) || "0".equals(text)) {
792             return (Boolean.FALSE);
793         } else {
794             return (_invalidBooleanObject(text));
795         }
796     }
797 
798     public static Boolean[] getBooleanObjectList(String text) {
799         String[] strings = getStringList(text);
800         Boolean[] list = new Boolean[strings.length];
801         for (int i = 0; i < strings.length; i++) {
802             list[i] = getBooleanObject(strings[i]);
803         }
804         return (list);
805     }
806 
807     public static boolean getBooleanValue(Object value) {
808         Boolean object;
809         if (value instanceof Boolean) {
810             object = (Boolean)value;
811             return (object.booleanValue());
812         } else {
813             String string = value.toString();
814             return ("true".equals(string) || "1".equals(string));
815         }
816     }
817 
818     public static Byte getByteObject(String text) {
819         try {
820             return (new Byte(text));
821         } catch (Exception e) {
822             return (_invalidByteObject(e));
823         }
824     }
825 
826     public static Byte[] getByteObjectList(String text) {
827         String[] strings = getStringList(text);
828         Byte[] list = new Byte[strings.length];
829         for (int i = 0; i < strings.length; i++) {
830             list[i] = getByteObject(strings[i]);
831         }
832         return (list);
833     }
834 
835     public static byte getByteValue(Object value) {
836         try {
837             Number object;
838             if (value instanceof Number) {
839                 object = (Number)value;
840             } else {
841                 object = new Byte(value.toString());
842             }
843             return (object.byteValue());
844         } catch (Exception e) {
845             return (_invalidByteValue(e));
846         }
847     }
848 
849     public static Date getDateObject(Object value) {
850         if (value instanceof Date) {
851             return ((Date)value);
852         } else {
853             return (getSQLTimestampObject(value));
854         }
855     }
856 
857     public static Double getDoubleObject(String text) {
858         try {
859             return (new Double(text));
860         } catch (Exception e) {
861             return (_invalidDoubleObject(e));
862         }
863     }
864 
865     public static Double[] getDoubleObjectList(String text) {
866         String[] strings = getStringList(text);
867         Double[] list = new Double[strings.length];
868         for (int i = 0; i < strings.length; i++) {
869             list[i] = getDoubleObject(strings[i]);
870         }
871         return (list);
872     }
873 
874     public static double getDoubleValue(Object value) {
875         try {
876             Number object;
877             if (value instanceof Number) {
878                 object = (Number)value;
879             } else {
880                 object = new Double(value.toString());
881             }
882             return (object.doubleValue());
883         } catch (Exception e) {
884             return (_invalidDoubleValue(e));
885         }
886     }
887 
888     public static BigDecimal getElementPropertyAsBigDecimal(Element element) {
889         try {
890             String text = element2Data(element);
891             return (new BigDecimal(text));
892         } catch (Exception e) {
893             return (_invalidBigDecimal(e));
894         }
895     }
896 
897     public static BigDecimal getElementPropertyAsBigDecimal(Element element, String name) {
898         try {
899             Element property = getOnlyElement(element, name);
900             String text = element2Data(property);
901             return (new BigDecimal(text));
902         } catch (Exception e) {
903             return (_invalidBigDecimal(e));
904         }
905     }
906 
907     public static BigDecimal getElementPropertyAsBigDecimalByStack(RStack stack, String name) {
908         if (stack.isEmptyElement()) {
909             return (null);
910         }
911         Element property = stack.peekElement();
912         if (!name.equals(property.getTagName())) {
913             return (null);
914         }
915         stack.popElement();
916         return (getElementPropertyAsBigDecimal(property));
917     }
918 
919     // g1u
920     public static List getElementPropertyAsBigDecimalDataList(Element element) {
921         List result = new ArrayList();
922         List strings = getElementPropertyAsStringDataList(element);
923         int size = strings.size();
924         for (int i = 0; i < size; i++) {
925             result.add(getBigDecimalObject((String)strings.get(i)));
926         }
927         return (result);
928     }
929 
930     // g2a
931     public static List getElementPropertyAsBigDecimalDataList(Element element, String name) {
932         Element property = getOnlyElement(element, name);
933         return (getElementPropertyAsBigDecimalDataList(property));
934     }
935 
936     // g4a
937     public static List getElementPropertyAsBigDecimalDataListByStack(RStack stack, String name) {
938         if (stack.isEmptyElement()) {
939             return (null);
940         }
941         Element property = stack.peekElement();
942         if (!name.equals(property.getTagName())) {
943             return (null);
944         }
945         stack.popElement();
946         return (getElementPropertyAsBigDecimalDataList(property));
947     }
948 
949     public static List getElementPropertyAsBigDecimalList(Element element, String name) {
950         Element[] nodes = getElements(element, name);
951         List list = new ArrayList();
952         for (int i = 0; i < nodes.length; i++) {
953             try {
954                 list.add(new BigDecimal(element2Data(nodes[i])));
955             } catch (Exception e) {
956                 _invalidBigDecimal(e);
957             }
958         }
959         return (list);
960     }
961 
962     public static List getElementPropertyAsBigDecimalListByStack(RStack stack, String name) {
963         List list = new ArrayList();
964         for (;;) {
965             if (stack.isEmptyElement()) {
966                 break;
967             }
968             Element property = stack.peekElement();
969             if (!name.equals(property.getTagName())) {
970                 break;
971             }
972             stack.popElement();
973             try {
974                 list.add(new BigDecimal(element2Text(property)));
975             } catch (Exception e) {
976                 _invalidBigDecimal(e);
977             }
978         }
979         return (list);
980     }
981 
982     // g3a
983     public static List getElementPropertyAsBigDecimalListDataList(Element element, String name) {
984         Element[] nodes = getElements(element, name);
985         List list = new ArrayList();
986         for (int i = 0; i < nodes.length; i++) {
987             List values = getElementPropertyAsBigDecimalDataList(nodes[i]);
988             if (values != null) {
989                 list.add(values);
990             }
991         }
992         return (list);
993     }
994 
995     // g5a
996     public static List getElementPropertyAsBigDecimalListDataListByStack(RStack stack, String name) {
997         List list = new ArrayList();
998         for (;;) {
999             if (stack.isEmptyElement()) {
1000                 break;
1001             }
1002             Element property = stack.peekElement();
1003             if (!name.equals(property.getTagName())) {
1004                 break;
1005             }
1006             stack.popElement();
1007             List value = getElementPropertyAsBigDecimalDataList(property);
1008             if (value != null) {
1009                 list.add(value);
1010             }
1011         }
1012         return (list);
1013     }
1014 
1015     public static BigInteger getElementPropertyAsBigInteger(Element element) {
1016         try {
1017             String text = element2Data(element);
1018             return (new BigInteger(text));
1019         } catch (Exception e) {
1020             return (_invalidBigInteger(e));
1021         }
1022     }
1023 
1024     public static BigInteger getElementPropertyAsBigInteger(Element element, String name) {
1025         try {
1026             Element property = getOnlyElement(element, name);
1027             String text = element2Data(property);
1028             return (new BigInteger(text));
1029         } catch (Exception e) {
1030             return (_invalidBigInteger(e));
1031         }
1032     }
1033 
1034     public static BigInteger getElementPropertyAsBigIntegerByStack(RStack stack, String name) {
1035         if (stack.isEmptyElement()) {
1036             return (null);
1037         }
1038         Element property = stack.peekElement();
1039         if (!name.equals(property.getTagName())) {
1040             return (null);
1041         }
1042         stack.popElement();
1043         return (getElementPropertyAsBigInteger(property));
1044     }
1045 
1046     // g1u
1047     public static List getElementPropertyAsBigIntegerDataList(Element element) {
1048         List result = new ArrayList();
1049         List strings = getElementPropertyAsStringDataList(element);
1050         int size = strings.size();
1051         for (int i = 0; i < size; i++) {
1052             result.add(getBigIntegerObject((String)strings.get(i)));
1053         }
1054         return (result);
1055     }
1056 
1057     // g2a
1058     public static List getElementPropertyAsBigIntegerDataList(Element element, String name) {
1059         Element property = getOnlyElement(element, name);
1060         return (getElementPropertyAsBigIntegerDataList(property));
1061     }
1062 
1063     // g4a
1064     public static List getElementPropertyAsBigIntegerDataListByStack(RStack stack, String name) {
1065         if (stack.isEmptyElement()) {
1066             return (null);
1067         }
1068         Element property = stack.peekElement();
1069         if (!name.equals(property.getTagName())) {
1070             return (null);
1071         }
1072         stack.popElement();
1073         return (getElementPropertyAsBigIntegerDataList(property));
1074     }
1075 
1076     public static List getElementPropertyAsBigIntegerList(Element element, String name) {
1077         Element[] nodes = getElements(element, name);
1078         List list = new ArrayList();
1079         for (int i = 0; i < nodes.length; i++) {
1080             try {
1081                 list.add(new BigInteger(element2Data(nodes[i])));
1082             } catch (Exception e) {
1083                 _invalidBigInteger(e);
1084             }
1085         }
1086         return (list);
1087     }
1088 
1089     public static List getElementPropertyAsBigIntegerListByStack(RStack stack, String name) {
1090         List list = new ArrayList();
1091         for (;;) {
1092             if (stack.isEmptyElement()) {
1093                 break;
1094             }
1095             Element property = stack.peekElement();
1096             if (!name.equals(property.getTagName())) {
1097                 break;
1098             }
1099             stack.popElement();
1100             try {
1101                 list.add(new BigInteger(element2Text(property)));
1102             } catch (Exception e) {
1103                 _invalidBigInteger(e);
1104             }
1105         }
1106         return (list);
1107     }
1108 
1109     // g3a
1110     public static List getElementPropertyAsBigIntegerListDataList(Element element, String name) {
1111         Element[] nodes = getElements(element, name);
1112         List list = new ArrayList();
1113         for (int i = 0; i < nodes.length; i++) {
1114             List values = getElementPropertyAsBigIntegerDataList(nodes[i]);
1115             if (values != null) {
1116                 list.add(values);
1117             }
1118         }
1119         return (list);
1120     }
1121 
1122     // g5a
1123     public static List getElementPropertyAsBigIntegerListDataListByStack(RStack stack, String name) {
1124         List list = new ArrayList();
1125         for (;;) {
1126             if (stack.isEmptyElement()) {
1127                 break;
1128             }
1129             Element property = stack.peekElement();
1130             if (!name.equals(property.getTagName())) {
1131                 break;
1132             }
1133             stack.popElement();
1134             List value = getElementPropertyAsBigIntegerDataList(property);
1135             if (value != null) {
1136                 list.add(value);
1137             }
1138         }
1139         return (list);
1140     }
1141 
1142     public static byte[] getElementPropertyAsBinaryBASE64(Element element) {
1143         String text = element2Data(element);
1144         return (makeBytesByBASE64(text));
1145     }
1146 
1147     public static byte[] getElementPropertyAsBinaryBASE64(Element element, String name) {
1148         Element property = getOnlyElement(element, name);
1149         String text = element2Data(property);
1150         return (makeBytesByBASE64(text));
1151     }
1152 
1153     public static byte[] getElementPropertyAsBinaryBASE64ByStack(RStack stack, String name) {
1154         if (stack.isEmptyElement()) {
1155             return (null);
1156         }
1157         Element property = stack.peekElement();
1158         if (!name.equals(property.getTagName())) {
1159             return (null);
1160         }
1161         stack.popElement();
1162         return (getElementPropertyAsBinaryBASE64(property));
1163     }
1164 
1165     // g1u
1166     public static List getElementPropertyAsBinaryBASE64DataList(Element element) {
1167         List result = new ArrayList();
1168         List strings = getElementPropertyAsStringDataList(element);
1169         int size = strings.size();
1170         for (int i = 0; i < size; i++) {
1171             result.add(getBinaryObject((String)strings.get(i)));
1172         }
1173         return (result);
1174     }
1175 
1176     // g2a
1177     public static List getElementPropertyAsBinaryBASE64DataList(Element element, String name) {
1178         Element property = getOnlyElement(element, name);
1179         return (getElementPropertyAsBinaryBASE64DataList(property));
1180     }
1181 
1182     // g4a
1183     public static List getElementPropertyAsBinaryBASE64DataListByStack(RStack stack, String name) {
1184         if (stack.isEmptyElement()) {
1185             return (null);
1186         }
1187         Element property = stack.peekElement();
1188         if (!name.equals(property.getTagName())) {
1189             return (null);
1190         }
1191         stack.popElement();
1192         return (getElementPropertyAsBinaryBASE64DataList(property));
1193     }
1194 
1195     // g3a
1196     public static List getElementPropertyAsBinaryBASE64ListDataList(Element element, String name) {
1197         Element[] nodes = getElements(element, name);
1198         List list = new ArrayList();
1199         for (int i = 0; i < nodes.length; i++) {
1200             List values = getElementPropertyAsBinaryBASE64DataList(nodes[i]);
1201             if (values != null) {
1202                 list.add(values);
1203             }
1204         }
1205         return (list);
1206     }
1207 
1208     // g5a
1209     public static List getElementPropertyAsBinaryBASE64ListDataListByStack(RStack stack, String name) {
1210         List list = new ArrayList();
1211         for (;;) {
1212             if (stack.isEmptyElement()) {
1213                 break;
1214             }
1215             Element property = stack.peekElement();
1216             if (!name.equals(property.getTagName())) {
1217                 break;
1218             }
1219             stack.popElement();
1220             List value = getElementPropertyAsBinaryBASE64DataList(property);
1221             if (value != null) {
1222                 list.add(value);
1223             }
1224         }
1225         return (list);
1226     }
1227 
1228     public static byte[] getElementPropertyAsBinaryHEX(Element element) {
1229         String text = element2Data(element);
1230         return (makeBytesByHEX(text));
1231     }
1232 
1233     public static byte[] getElementPropertyAsBinaryHEX(Element element, String name) {
1234         Element property = getOnlyElement(element, name);
1235         String text = element2Data(property);
1236         return (makeBytesByHEX(text));
1237     }
1238 
1239     public static byte[] getElementPropertyAsBinaryHEXByStack(RStack stack, String name) {
1240         if (stack.isEmptyElement()) {
1241             return (null);
1242         }
1243         Element property = stack.peekElement();
1244         if (!name.equals(property.getTagName())) {
1245             return (null);
1246         }
1247         stack.popElement();
1248         return (getElementPropertyAsBinaryHEX(property));
1249     }
1250 
1251     // g1u
1252     public static List getElementPropertyAsBinaryHEXDataList(Element element) {
1253         List result = new ArrayList();
1254         List strings = getElementPropertyAsStringDataList(element);
1255         int size = strings.size();
1256         for (int i = 0; i < size; i++) {
1257             result.add(getBinaryHEXObject((String)strings.get(i)));
1258         }
1259         return (result);
1260     }
1261 
1262     // g2a
1263     public static List getElementPropertyAsBinaryHEXDataList(Element element, String name) {
1264         Element property = getOnlyElement(element, name);
1265         return (getElementPropertyAsBinaryHEXDataList(property));
1266     }
1267 
1268     // g4a
1269     public static List getElementPropertyAsBinaryHEXDataListByStack(RStack stack, String name) {
1270         if (stack.isEmptyElement()) {
1271             return (null);
1272         }
1273         Element property = stack.peekElement();
1274         if (!name.equals(property.getTagName())) {
1275             return (null);
1276         }
1277         stack.popElement();
1278         return (getElementPropertyAsBinaryHEXDataList(property));
1279     }
1280 
1281     // g3a
1282     public static List getElementPropertyAsBinaryHEXListDataList(Element element, String name) {
1283         Element[] nodes = getElements(element, name);
1284         List list = new ArrayList();
1285         for (int i = 0; i < nodes.length; i++) {
1286             List values = getElementPropertyAsBinaryHEXDataList(nodes[i]);
1287             if (values != null) {
1288                 list.add(values);
1289             }
1290         }
1291         return (list);
1292     }
1293 
1294     // g5a
1295     public static List getElementPropertyAsBinaryHEXListDataListByStack(RStack stack, String name) {
1296         List list = new ArrayList();
1297         for (;;) {
1298             if (stack.isEmptyElement()) {
1299                 break;
1300             }
1301             Element property = stack.peekElement();
1302             if (!name.equals(property.getTagName())) {
1303                 break;
1304             }
1305             stack.popElement();
1306             List value = getElementPropertyAsBinaryHEXDataList(property);
1307             if (value != null) {
1308                 list.add(value);
1309             }
1310         }
1311         return (list);
1312     }
1313 
1314     public static List getElementPropertyAsBinaryListBASE64(Element element, String name) {
1315         Element[] nodes = getElements(element, name);
1316         List list = new ArrayList();
1317         for (int i = 0; i < nodes.length; i++) {
1318             byte[] binary = makeBytesByBASE64(element2Data(nodes[i]));
1319             if (binary != null) {
1320                 list.add(binary);
1321             }
1322         }
1323         return (list);
1324     }
1325 
1326     public static List getElementPropertyAsBinaryListBASE64ByStack(RStack stack, String name) {
1327         List list = new ArrayList();
1328         for (;;) {
1329             if (stack.isEmptyElement()) {
1330                 break;
1331             }
1332             Element property = stack.peekElement();
1333             if (!name.equals(property.getTagName())) {
1334                 break;
1335             }
1336             stack.popElement();
1337             byte[] binary = makeBytesByBASE64(element2Data(property));
1338             if (binary != null) {
1339                 list.add(binary);
1340             }
1341         }
1342         return (list);
1343     }
1344 
1345     public static List getElementPropertyAsBinaryListHEX(Element element, String name) {
1346         Element[] nodes = getElements(element, name);
1347         List list = new ArrayList();
1348         for (int i = 0; i < nodes.length; i++) {
1349             byte[] binary = makeBytesByHEX(element2Data(nodes[i]));
1350             if (binary != null) {
1351                 list.add(binary);
1352             }
1353         }
1354         return (list);
1355     }
1356 
1357     public static List getElementPropertyAsBinaryListHEXByStack(RStack stack, String name) {
1358         List list = new ArrayList();
1359         for (;;) {
1360             if (stack.isEmptyElement()) {
1361                 break;
1362             }
1363             Element property = stack.peekElement();
1364             if (!name.equals(property.getTagName())) {
1365                 break;
1366             }
1367             stack.popElement();
1368             byte[] binary = getElementPropertyAsBinaryHEX(property);
1369             if (binary != null) {
1370                 list.add(binary);
1371             }
1372         }
1373         return (list);
1374     }
1375 
1376     public static boolean getElementPropertyAsBoolean(Element element) {
1377         String text = element2Data(element);
1378         return ("true".equals(text) || "1".equals(text));
1379     }
1380 
1381     public static boolean getElementPropertyAsBoolean(Element element, String name) {
1382         Element property = getOnlyElement(element, name);
1383         return (getElementPropertyAsBoolean(property));
1384     }
1385 
1386     public static Boolean getElementPropertyAsBooleanByStack(RStack stack, String name) {
1387         if (stack.isEmptyElement()) {
1388             return (null);
1389         }
1390         Element property = stack.peekElement();
1391         if (!name.equals(property.getTagName())) {
1392             return (null);
1393         }
1394         stack.popElement();
1395         return (getElementPropertyAsBooleanObject(property));
1396     }
1397 
1398     // g1u
1399     public static List getElementPropertyAsBooleanDataList(Element element) {
1400         List result = new ArrayList();
1401         List strings = getElementPropertyAsStringDataList(element);
1402         int size = strings.size();
1403         for (int i = 0; i < size; i++) {
1404             result.add(getBooleanObject((String)strings.get(i)));
1405         }
1406         return (result);
1407     }
1408 
1409     // g2a
1410     public static List getElementPropertyAsBooleanDataList(Element element, String name) {
1411         Element property = getOnlyElement(element, name);
1412         return (getElementPropertyAsBooleanDataList(property));
1413     }
1414 
1415     // g4a
1416     public static List getElementPropertyAsBooleanDataListByStack(RStack stack, String name) {
1417         if (stack.isEmptyElement()) {
1418             return (null);
1419         }
1420         Element property = stack.peekElement();
1421         if (!name.equals(property.getTagName())) {
1422             return (null);
1423         }
1424         stack.popElement();
1425         return (getElementPropertyAsBooleanDataList(property));
1426     }
1427 
1428     public static List getElementPropertyAsBooleanList(Element element, String name) {
1429         Element[] nodes = getElements(element, name);
1430         List list = new ArrayList();
1431         for (int i = 0; i < nodes.length; i++) {
1432             Boolean value = getElementPropertyAsBooleanObject(nodes[i]);
1433             if (value != null) {
1434                 list.add(value);
1435             }
1436         }
1437         return (list);
1438     }
1439 
1440     public static List getElementPropertyAsBooleanListByStack(RStack stack, String name) {
1441         List list = new ArrayList();
1442         for (;;) {
1443             if (stack.isEmptyElement()) {
1444                 break;
1445             }
1446             Element property = stack.peekElement();
1447             if (!name.equals(property.getTagName())) {
1448                 break;
1449             }
1450             stack.popElement();
1451             Boolean value = getElementPropertyAsBooleanObject(property);
1452             if (value != null) {
1453                 list.add(value);
1454             }
1455         }
1456         return (list);
1457     }
1458 
1459     // g3a
1460     public static List getElementPropertyAsBooleanListDataList(Element element, String name) {
1461         Element[] nodes = getElements(element, name);
1462         List list = new ArrayList();
1463         for (int i = 0; i < nodes.length; i++) {
1464             List values = getElementPropertyAsBooleanDataList(nodes[i]);
1465             if (values != null) {
1466                 list.add(values);
1467             }
1468         }
1469         return (list);
1470     }
1471 
1472     // g5a
1473     public static List getElementPropertyAsBooleanListDataListByStack(RStack stack, String name) {
1474         List list = new ArrayList();
1475         for (;;) {
1476             if (stack.isEmptyElement()) {
1477                 break;
1478             }
1479             Element property = stack.peekElement();
1480             if (!name.equals(property.getTagName())) {
1481                 break;
1482             }
1483             stack.popElement();
1484             List value = getElementPropertyAsBooleanDataList(property);
1485             if (value != null) {
1486                 list.add(value);
1487             }
1488         }
1489         return (list);
1490     }
1491 
1492     public static Boolean getElementPropertyAsBooleanObject(Element element) {
1493         String text = element2Data(element);
1494         return (getBooleanObject(text));
1495     }
1496 
1497     public static byte getElementPropertyAsByte(Element element) {
1498         try {
1499             String text = element2Data(element);
1500             return (Byte.parseByte(text));
1501         } catch (Exception e) {
1502             return (_invalidByteValue(e));
1503         }
1504     }
1505 
1506     public static byte getElementPropertyAsByte(Element element, String name) {
1507         try {
1508             Element property = getOnlyElement(element, name);
1509             String text = element2Data(property);
1510             return (Byte.parseByte(text));
1511         } catch (Exception e) {
1512             return (_invalidByteValue(e));
1513         }
1514     }
1515 
1516     public static Byte getElementPropertyAsByteByStack(RStack stack, String name) {
1517         if (stack.isEmptyElement()) {
1518             return (null);
1519         }
1520         Element property = stack.peekElement();
1521         if (!name.equals(property.getTagName())) {
1522             return (null);
1523         }
1524         stack.popElement();
1525         return (getElementPropertyAsByteObject(property));
1526     }
1527 
1528     // g1u
1529     public static List getElementPropertyAsByteDataList(Element element) {
1530         List result = new ArrayList();
1531         List strings = getElementPropertyAsStringDataList(element);
1532         int size = strings.size();
1533         for (int i = 0; i < size; i++) {
1534             result.add(getByteObject((String)strings.get(i)));
1535         }
1536         return (result);
1537     }
1538 
1539     // g2a
1540     public static List getElementPropertyAsByteDataList(Element element, String name) {
1541         Element property = getOnlyElement(element, name);
1542         return (getElementPropertyAsByteDataList(property));
1543     }
1544 
1545     // g4a
1546     public static List getElementPropertyAsByteDataListByStack(RStack stack, String name) {
1547         if (stack.isEmptyElement()) {
1548             return (null);
1549         }
1550         Element property = stack.peekElement();
1551         if (!name.equals(property.getTagName())) {
1552             return (null);
1553         }
1554         stack.popElement();
1555         return (getElementPropertyAsByteDataList(property));
1556     }
1557 
1558     public static List getElementPropertyAsByteList(Element element, String name) {
1559         Element[] nodes = getElements(element, name);
1560         List list = new ArrayList();
1561         for (int i = 0; i < nodes.length; i++) {
1562             Byte value = getElementPropertyAsByteObject(nodes[i]);
1563             if (value != null) {
1564                 list.add(value);
1565             }
1566         }
1567         return (list);
1568     }
1569 
1570     public static List getElementPropertyAsByteListByStack(RStack stack, String name) {
1571         List list = new ArrayList();
1572