2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
7 package gov
.nasa
.worldwind
.formats
.gpx
;
9 import gov
.nasa
.worldwind
.util
.Logging
;
13 * @version $Id: ElementParser.java 2471 2007-07-31 21:50:57Z tgaskins $
15 public class ElementParser
17 protected final String elementName
;
18 protected ElementParser currentElement
= null;
19 protected String currentCharacters
= null;
22 * @param elementName the element's name, may not be null
23 * @throws IllegalArgumentException if <code>elementName</code> is null
25 protected ElementParser(String elementName
)
27 if (elementName
== null)
29 String msg
= Logging
.getMessage("nullValue.ElementNameIsNull");
30 Logging
.logger().severe(msg
);
31 throw new IllegalArgumentException(msg
);
34 this.elementName
= elementName
;
37 public String
getElementName()
39 return this.elementName
;
43 * Starts an element. No parameters may be null.
49 * @throws org.xml.sax.SAXException
50 * @throws IllegalArgumentException if any argument is null
52 public void startElement(String uri
, String lname
, String qname
, org
.xml
.sax
.Attributes attributes
)
53 throws org
.xml
.sax
.SAXException
57 String msg
= Logging
.getMessage("nullValue.URIIsNull");
58 Logging
.logger().severe(msg
);
59 throw new IllegalArgumentException(msg
);
63 String msg
= Logging
.getMessage("nullValue.LNameIsNull");
64 Logging
.logger().severe(msg
);
65 throw new IllegalArgumentException(msg
);
69 String msg
= Logging
.getMessage("nullValue.QNameIsNull");
70 Logging
.logger().severe(msg
);
71 throw new IllegalArgumentException(msg
);
73 if (attributes
== null)
75 String msg
= Logging
.getMessage("nullValue.org.xml.sax.AttributesIsNull");
76 Logging
.logger().severe(msg
);
77 throw new IllegalArgumentException(msg
);
80 if (this.currentElement
!= null)
81 this.currentElement
.startElement(uri
, lname
, qname
, attributes
);
83 this.doStartElement(uri
, lname
, qname
, attributes
);
87 * Finishes an element. No parameters may be null.
92 * @throws org.xml.sax.SAXException
93 * @throws IllegalArgumentException if any argument is null
95 public void endElement(String uri
, String lname
, String qname
) throws org
.xml
.sax
.SAXException
99 String msg
= Logging
.getMessage("nullValue.URIIsNull");
100 Logging
.logger().severe(msg
);
101 throw new IllegalArgumentException(msg
);
105 String msg
= Logging
.getMessage("nullValue.LNameIsNull");
106 Logging
.logger().severe(msg
);
107 throw new IllegalArgumentException(msg
);
111 String msg
= Logging
.getMessage("nullValue.QNameIsNull");
112 Logging
.logger().severe(msg
);
113 throw new IllegalArgumentException(msg
);
115 if (this.currentElement
!= null)
117 this.currentElement
.endElement(uri
, lname
, qname
);
118 if (lname
.equalsIgnoreCase(this.currentElement
.elementName
))
119 this.currentElement
= null;
122 this.doEndElement(uri
, lname
, qname
);
124 this.currentCharacters
= null;
127 protected void doStartElement(String uri
, String lname
, String qname
, org
.xml
.sax
.Attributes attributes
)
128 throws org
.xml
.sax
.SAXException
132 protected void doEndElement(String uri
, String lname
, String qname
) throws org
.xml
.sax
.SAXException
140 * @throws IllegalArgumentException if <code>data</code> has length less than 1
142 public void characters(char[] data
, int start
, int length
)
146 String msg
= Logging
.getMessage("nullValue.ArrayIsNull");
147 Logging
.logger().severe(msg
);
148 throw new IllegalArgumentException(msg
);
152 String msg
= Logging
.getMessage("generic.ArrayInvalidLength", data
.length
);
153 Logging
.logger().severe(msg
);
154 throw new IllegalArgumentException(msg
);
158 String msg
= Logging
.getMessage("generic.indexOutOfRange", start
);
159 Logging
.logger().severe(msg
);
160 throw new IllegalArgumentException(msg
);
162 if (start
+ length
> data
.length
)
164 String msg
= Logging
.getMessage("generic.indexOutOfRange", start
+ length
);
165 Logging
.logger().severe(msg
);
166 throw new IllegalArgumentException(msg
);
169 if (this.currentElement
!= null)
170 this.currentElement
.characters(data
, start
, length
);
171 else if (this.currentCharacters
!= null)
172 this.currentCharacters
+= new String(data
, start
, length
);
174 this.currentCharacters
= new String(data
, start
, length
);