Source Code Cross Referenced for XMLStreamReader.java in  » 6.0-JDK-Modules » jsr173-Stax » javax » xml » stream » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » jsr173 Stax » javax.xml.stream 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package javax.xml.stream;
002:
003:        import java.io.Reader;
004:        import javax.xml.namespace.NamespaceContext;
005:        import javax.xml.namespace.QName;
006:
007:        /**
008:         *  The XMLStreamReader interface allows forward, read-only access to XML.
009:         *  It is designed to be the lowest level and most efficient way to
010:         *  read XML data.
011:         *
012:         * <p> The XMLStreamReader is designed to iterate over XML using
013:         * next() and hasNext().  The data can be accessed using methods such as getEventType(),
014:         * getNamespaceURI(), getLocalName() and getText();
015:         *
016:         * <p> The <a href="#next()">next()</a> method causes the reader to read the next parse event.
017:         * The next() method returns an integer which identifies the type of event just read.
018:         * <p> The event type can be determined using <a href="#getEventType()">getEventType()</a>.
019:         * <p> Parsing events are defined as the XML Declaration, a DTD,
020:         * start tag, character data, white space, end tag, comment,
021:         * or processing instruction.  An attribute or namespace event may be encountered
022:         * at the root level of a document as the result of a query operation.
023:         *
024:         * <p>For XML 1.0 compliance an XML processor must pass the
025:         * identifiers of declared unparsed entities, notation declarations and their
026:         * associated identifiers to the application.  This information is
027:         * provided through the property API on this interface.
028:         * The following two properties allow access to this information:
029:         * javax.xml.stream.notations and javax.xml.stream.entities.
030:         * When the current event is a DTD the following call will return a
031:         * list of Notations
032:         *  <code>List l = (List) getProperty("javax.xml.stream.notations");</code>
033:         * The following call will return a list of entity declarations:
034:         * <code>List l = (List) getProperty("javax.xml.stream.entities");</code>
035:         * These properties can only be accessed during a DTD event and
036:         * are defined to return null if the information is not available.
037:         *
038:         * <p>The following table describes which methods are valid in what state.
039:         * If a method is called in an invalid state the method will throw a
040:         * java.lang.IllegalStateException.
041:         *
042:         * <table border="2" rules="all" cellpadding="4">
043:         *   <thead>
044:         *     <tr>
045:         *       <th align="center" colspan="2">
046:         *         Valid methods for each state
047:         *       </th>
048:         *     </tr>
049:         *   </thead>
050:         *   <tbody>
051:         *     <tr>
052:         *       <th>Event Type</th>
053:         *       <th>Valid Methods</th>
054:         *     </tr>
055:         *     <tr>
056:         *       <td> All States  </td>
057:         *       <td> getProperty(), hasNext(), require(), close(),
058:         *            getNamespaceURI(), isStartElement(),
059:         *            isEndElement(), isCharacters(), isWhiteSpace(),
060:         *            getNamespaceContext(), getEventType(),getLocation(),
061:         *            hasText(), hasName()
062:         *       </td>
063:         *     </tr>
064:         *     <tr>
065:         *       <td> START_ELEMENT  </td>
066:         *       <td> next(), getName(), getLocalName(), hasName(), getPrefix(),
067:         *            getAttributeXXX(), isAttributeSpecified(),
068:         *            getNamespaceXXX(),
069:         *            getElementText(), nextTag()
070:         *       </td>
071:         *     </tr>
072:         *       <td> ATTRIBUTE  </td>
073:         *       <td> next(), nextTag()
074:         *            getAttributeXXX(), isAttributeSpecified(),
075:         *       </td>
076:         *     </tr>
077:         *     </tr>
078:         *       <td> NAMESPACE  </td>
079:         *       <td> next(), nextTag()
080:         *            getNamespaceXXX()
081:         *       </td>
082:         *     </tr>
083:         *     <tr>
084:         *       <td> END_ELEMENT  </td>
085:         *       <td> next(), getName(), getLocalName(), hasName(), getPrefix(),
086:         *            getNamespaceXXX(), nextTag()
087:         *      </td>
088:         *     </tr>
089:         *     <tr>
090:         *       <td> CHARACTERS  </td>
091:         *       <td> next(), getTextXXX(), nextTag() </td>
092:         *     </tr>
093:         *     <tr>
094:         *       <td> CDATA  </td>
095:         *       <td> next(), getTextXXX(), nextTag() </td>
096:         *     </tr>
097:         *     <tr>
098:         *       <td> COMMENT  </td>
099:         *       <td> next(), getTextXXX(), nextTag() </td>
100:         *     </tr>
101:         *     <tr>
102:         *       <td> SPACE  </td>
103:         *       <td> next(), getTextXXX(), nextTag() </td>
104:         *     </tr>
105:         *     <tr>
106:         *       <td> START_DOCUMENT  </td>
107:         *       <td> next(), getEncoding(), getVersion(), isStandalone(), standaloneSet(),
108:         *            getCharacterEncodingScheme(), nextTag()</td>
109:         *     </tr>
110:         *     <tr>
111:         *       <td> END_DOCUMENT  </td>
112:         *       <td> close()</td>
113:         *     </tr>
114:         *     <tr>
115:         *       <td> PROCESSING_INSTRUCTION  </td>
116:         *       <td> next(), getPITarget(), getPIData(), nextTag() </td>
117:         *     </tr>
118:         *     <tr>
119:         *       <td> ENTITY_REFERENCE  </td>
120:         *       <td> next(), getLocalName(), getText(), nextTag() </td>
121:         *     </tr>
122:         *     <tr>
123:         *       <td> DTD  </td>
124:         *       <td> next(), getText(), nextTag() </td>
125:         *     </tr>
126:         *   </tbody>
127:         *  </table>
128:         *
129:         * @version 1.0
130:         * @author Copyright (c) 2003 by BEA Systems. All Rights Reserved.
131:         * @see javax.xml.stream.events.XMLEvent
132:         * @see XMLInputFactory
133:         * @see XMLStreamWriter
134:         */
135:        public interface XMLStreamReader extends XMLStreamConstants {
136:            /**
137:             * Get the value of a feature/property from the underlying implementation
138:             * @param name The name of the property, may not be null
139:             * @return The value of the property
140:             * @throws IllegalArgumentException if name is null
141:             */
142:            public Object getProperty(java.lang.String name)
143:                    throws java.lang.IllegalArgumentException;
144:
145:            /**
146:             * Get next parsing event - a processor may return all contiguous
147:             * character data in a single chunk, or it may split it into several chunks.
148:             * If the property javax.xml.stream.isCoalescing is set to true
149:             * element content must be coalesced and only one CHARACTERS event
150:             * must be returned for contiguous element content or
151:             * CDATA Sections.  
152:             *
153:             * By default entity references must be 
154:             * expanded and reported transparently to the application.
155:             * An exception will be thrown if an entity reference cannot be expanded.
156:             * If element content is empty (i.e. content is "") then no CHARACTERS event will be reported.
157:             *
158:             * <p>Given the following XML:<br>
159:             * &lt;foo>&lt;!--description-->content text&lt;![CDATA[&lt;greeting>Hello&lt;/greeting>]]>other content&lt;/foo><br>
160:             * The behavior of calling next() when being on foo will be:<br>
161:             * 1- the comment (COMMENT)<br>
162:             * 2- then the characters section (CHARACTERS)<br>
163:             * 3- then the CDATA section (another CHARACTERS)<br>
164:             * 4- then the next characters section (another CHARACTERS)<br>
165:             * 5- then the END_ELEMENT<br>
166:             *
167:             * <p><b>NOTE:</b> empty element (such as &lt;tag/>) will be reported
168:             *  with  two separate events: START_ELEMENT, END_ELEMENT - This preserves
169:             *   parsing equivalency of empty element to &lt;tag>&lt;/tag>.
170:             *
171:             * This method will throw an IllegalStateException if it is called after hasNext() returns false.
172:             * @see javax.xml.stream.events.XMLEvent
173:             * @return the integer code corresponding to the current parse event
174:             * @throws NoSuchElementException if this is called when hasNext() returns false
175:             * @throws XMLStreamException  if there is an error processing the underlying XML source
176:             */
177:            public int next() throws XMLStreamException;
178:
179:            /**
180:             * Test if the current event is of the given type and if the namespace and name match the current
181:             * namespace and name of the current event.  If the namespaceURI is null it is not checked for equality,
182:             * if the localName is null it is not checked for equality.
183:             * @param type the event type
184:             * @param namespaceURI the uri of the event, may be null
185:             * @param localName the localName of the event, may be null
186:             * @throws XMLStreamException if the required values are not matched.
187:             */
188:            public void require(int type, String namespaceURI, String localName)
189:                    throws XMLStreamException;
190:
191:            /**
192:             * Reads the content of a text-only element, an exception is thrown if this is
193:             * not a text-only element.
194:             * Regardless of value of javax.xml.stream.isCoalescing this method always returns coalesced content.
195:             * <br /> Precondition: the current event is START_ELEMENT.
196:             * <br /> Postcondition: the current event is the corresponding END_ELEMENT.
197:             *
198:             * <br />The method does the following (implementations are free to optimized 
199:             * but must do equivalent processing):
200:             * <pre>
201:             * if(getEventType() != XMLStreamConstants.START_ELEMENT) {
202:             * throw new XMLStreamException(
203:             * "parser must be on START_ELEMENT to read next text", getLocation());
204:             * }
205:             * int eventType = next();
206:             * StringBuffer content = new StringBuffer();
207:             * while(eventType != XMLStreamConstants.END_ELEMENT ) {
208:             * if(eventType == XMLStreamConstants.CHARACTERS
209:             * || eventType == XMLStreamConstants.CDATA
210:             * || eventType == XMLStreamConstants.SPACE
211:             * || eventType == XMLStreamConstants.ENTITY_REFERENCE) {
212:             * buf.append(getText());
213:             * } else if(eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
214:             * || eventType == XMLStreamConstants.COMMENT) {
215:             * // skipping
216:             * } else if(eventType == XMLStreamConstants.END_DOCUMENT) {
217:             * throw new XMLStreamException(
218:             * "unexpected end of document when reading element text content", this);
219:             * } else if(eventType == XMLStreamConstants.START_ELEMENT) {
220:             * throw new XMLStreamException(
221:             * "element text content may not contain START_ELEMENT", getLocation());
222:             * } else {
223:             * throw new XMLStreamException(
224:             * "Unexpected event type "+eventType, getLocation());
225:             * }
226:             * eventType = next();
227:             * }
228:             * return buf.toString();
229:             * </pre>
230:             *
231:             * @throws XMLStreamException if the current event is not a START_ELEMENT 
232:             * or if a non text element is encountered
233:             */
234:            public String getElementText() throws XMLStreamException;
235:
236:            /**
237:             * Skips any white space (isWhiteSpace() returns true), COMMENT,
238:             * or PROCESSING_INSTRUCTION,
239:             * until a START_ELEMENT or END_ELEMENT is reached.
240:             * If other than white space characters, COMMENT, PROCESSING_INSTRUCTION, START_ELEMENT, END_ELEMENT
241:             * are encountered, an exception is thrown. This method should
242:             * be used when processing element-only content seperated by white space. 
243:             *
244:             * <br /> Precondition: none
245:             * <br /> Postcondition: the current event is START_ELEMENT or END_ELEMENT
246:             * and cursor may have moved over any whitespace event.
247:             *
248:             * <br />Essentially it does the following (implementations are free to optimized 
249:             * but must do equivalent processing):
250:             * <pre>
251:             * int eventType = next();
252:             * while((eventType == XMLStreamConstants.CHARACTERS &amp;&amp; isWhiteSpace()) // skip whitespace
253:             * || (eventType == XMLStreamConstants.CDATA &amp;&amp; isWhiteSpace()) 
254:             * // skip whitespace
255:             * || eventType == XMLStreamConstants.SPACE
256:             * || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
257:             * || eventType == XMLStreamConstants.COMMENT
258:             * ) {
259:             * eventType = next();
260:             * }
261:             * if (eventType != XMLStreamConstants.START_ELEMENT &amp;&amp; eventType != XMLStreamConstants.END_ELEMENT) {
262:             * throw new String XMLStreamException("expected start or end tag", getLocation());
263:             * }
264:             * return eventType;
265:             * </pre>
266:             *
267:             * @return the event type of the element read (START_ELEMENT or END_ELEMENT)
268:             * @throws XMLStreamException if the current event is not white space, PROCESSING_INSTRUCTION,
269:             * START_ELEMENT or END_ELEMENT
270:             * @throws NoSuchElementException if this is called when hasNext() returns false
271:             */
272:            public int nextTag() throws XMLStreamException;
273:
274:            /**
275:             * Returns true if there are more parsing events and false
276:             * if there are no more events.  This method will return
277:             * false if the current state of the XMLStreamReader is
278:             * END_DOCUMENT
279:             * @return true if there are more events, false otherwise
280:             * @throws XMLStreamException if there is a fatal error detecting the next state
281:             */
282:            public boolean hasNext() throws XMLStreamException;
283:
284:            /**
285:             * Frees any resources associated with this Reader.  This method does not close the
286:             * underlying input source.
287:             * @throws XMLStreamException if there are errors freeing associated resources
288:             */
289:            public void close() throws XMLStreamException;
290:
291:            /**
292:             * Return the uri for the given prefix.
293:             * The uri returned depends on the current state of the processor.
294:             *
295:             * <p><strong>NOTE:</strong>The 'xml' prefix is bound as defined in
296:             * <a href="http://www.w3.org/TR/REC-xml-names/#ns-using">Namespaces in XML</a>
297:             * specification to "http://www.w3.org/XML/1998/namespace".
298:             *
299:             * <p><strong>NOTE:</strong> The 'xmlns' prefix must be resolved to following namespace
300:             * <a href="http://www.w3.org/2000/xmlns/">http://www.w3.org/2000/xmlns/</a>
301:             * @param prefix The prefix to lookup, may not be null
302:             * @return the uri bound to the given prefix or null if it is not bound
303:             * @throws IllegalArgumentException if the prefix is null
304:             */
305:            public String getNamespaceURI(String prefix);
306:
307:            /**
308:             * Returns true if the cursor points to a start tag (otherwise false)
309:             * @return true if the cursor points to a start tag, false otherwise
310:             */
311:            public boolean isStartElement();
312:
313:            /**
314:             * Returns true if the cursor points to an end tag (otherwise false)
315:             * @return true if the cursor points to an end tag, false otherwise
316:             */
317:            public boolean isEndElement();
318:
319:            /**
320:             * Returns true if the cursor points to a character data event
321:             * @return true if the cursor points to character data, false otherwise
322:             */
323:            public boolean isCharacters();
324:
325:            /**
326:             * Returns true if the cursor points to a character data event
327:             * that consists of all whitespace
328:             * @return true if the cursor points to all whitespace, false otherwise
329:             */
330:            public boolean isWhiteSpace();
331:
332:            /**
333:             * Returns the normalized attribute value of the
334:             * attribute with the namespace and localName
335:             * If the namespaceURI is null the namespace
336:             * is not checked for equality
337:             * @param namespaceURI the namespace of the attribute
338:             * @param localName the local name of the attribute, cannot be null
339:             * @return returns the value of the attribute , returns null if not found
340:             * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
341:             */
342:            public String getAttributeValue(String namespaceURI,
343:                    String localName);
344:
345:            /**
346:             * Returns the count of attributes on this START_ELEMENT,
347:             * this method is only valid on a START_ELEMENT or ATTRIBUTE.  This
348:             * count excludes namespace definitions.  Attribute indices are
349:             * zero-based.
350:             * @return returns the number of attributes
351:             * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
352:             */
353:            public int getAttributeCount();
354:
355:            /** Returns the qname of the attribute at the provided index
356:             *
357:             * @param index the position of the attribute
358:             * @return the QName of the attribute
359:             * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
360:             */
361:            public QName getAttributeName(int index);
362:
363:            /**
364:             * Returns the namespace of the attribute at the provided
365:             * index
366:             * @param index the position of the attribute
367:             * @return the namespace URI (can be null)
368:             * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
369:             */
370:            public String getAttributeNamespace(int index);
371:
372:            /**
373:             * Returns the localName of the attribute at the provided
374:             * index
375:             * @param index the position of the attribute
376:             * @return the localName of the attribute
377:             * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
378:             */
379:            public String getAttributeLocalName(int index);
380:
381:            /**
382:             * Returns the prefix of this attribute at the
383:             * provided index
384:             * @param index the position of the attribute
385:             * @return the prefix of the attribute
386:             * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
387:             */
388:            public String getAttributePrefix(int index);
389:
390:            /**
391:             * Returns the XML type of the attribute at the provided
392:             * index
393:             * @param index the position of the attribute
394:             * @return the XML type of the attribute
395:             * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
396:             */
397:            public String getAttributeType(int index);
398:
399:            /**
400:             * Returns the value of the attribute at the
401:             * index
402:             * @param index the position of the attribute
403:             * @return the attribute value
404:             * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
405:             */
406:            public String getAttributeValue(int index);
407:
408:            /**
409:             * Returns a boolean which indicates if this
410:             * attribute was created by default
411:             * @param index the position of the attribute
412:             * @return true if this is a default attribute
413:             * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
414:             */
415:            public boolean isAttributeSpecified(int index);
416:
417:            /**
418:             * Returns the count of namespaces declared on this START_ELEMENT or END_ELEMENT,
419:             * this method is only valid on a START_ELEMENT, END_ELEMENT or NAMESPACE. On
420:             * an END_ELEMENT the count is of the namespaces that are about to go
421:             * out of scope.  This is the equivalent of the information reported
422:             * by SAX callback for an end element event.
423:             * @return returns the number of namespace declarations on this specific element
424:             * @throws IllegalStateException if this is not a START_ELEMENT, END_ELEMENT or NAMESPACE
425:             */
426:            public int getNamespaceCount();
427:
428:            /**
429:             * Returns the prefix for the namespace declared at the
430:             * index.  Returns null if this is the default namespace
431:             * declaration
432:             *
433:             * @param index the position of the namespace declaration
434:             * @return returns the namespace prefix
435:             * @throws IllegalStateException if this is not a START_ELEMENT, END_ELEMENT or NAMESPACE
436:             */
437:            public String getNamespacePrefix(int index);
438:
439:            /**
440:             * Returns the uri for the namespace declared at the
441:             * index.
442:             *
443:             * @param index the position of the namespace declaration
444:             * @return returns the namespace uri
445:             * @throws IllegalStateException if this is not a START_ELEMENT, END_ELEMENT or NAMESPACE
446:             */
447:            public String getNamespaceURI(int index);
448:
449:            /**
450:             * Returns a read only namespace context for the current
451:             * position.  The context is transient and only valid until
452:             * a call to next() changes the state of the reader.
453:             * @return return a namespace context
454:             */
455:            public NamespaceContext getNamespaceContext();
456:
457:            /**
458:             * Returns a reader that points to the current start element
459:             * and all of its contents.  Throws an XMLStreamException if the
460:             * cursor does not point to a START_ELEMENT.<p>
461:             * The sub stream is read from it MUST be read before the parent stream is
462:             * moved on, if not any call on the sub stream will cause an XMLStreamException to be
463:             * thrown.   The parent stream will always return the same result from next()
464:             * whatever is done to the sub stream.
465:             * @return an XMLStreamReader which points to the next element
466:             */
467:            //  public XMLStreamReader subReader() throws XMLStreamException;
468:            /**
469:             * Allows the implementation to reset and reuse any underlying tables
470:             */
471:            //  public void recycle() throws XMLStreamException;
472:            /**
473:             * Returns an integer code that indicates the type
474:             * of the event the cursor is pointing to.
475:             */
476:            public int getEventType();
477:
478:            /**
479:             * Returns the current value of the parse event as a string,
480:             * this returns the string value of a CHARACTERS event,
481:             * returns the value of a COMMENT, the replacement value
482:             * for an ENTITY_REFERENCE, the string value of a CDATA section,
483:             * the string value for a SPACE event,
484:             * or the String value of the internal subset of the DTD.
485:             * If an ENTITY_REFERENCE has been resolved, any character data
486:             * will be reported as CHARACTERS events.
487:             * @return the current text or null
488:             * @throws java.lang.IllegalStateException if this state is not
489:             * a valid text state.
490:             */
491:            public String getText();
492:
493:            /**
494:             * Returns an array which contains the characters from this event.
495:             * This array should be treated as read-only and transient. I.e. the array will
496:             * contain the text characters until the XMLStreamReader moves on to the next event.
497:             * Attempts to hold onto the character array beyond that time or modify the
498:             * contents of the array are breaches of the contract for this interface.
499:             * @return the current text or an empty array
500:             * @throws java.lang.IllegalStateException if this state is not
501:             * a valid text state.
502:             */
503:            public char[] getTextCharacters();
504:
505:            /**
506:             * Gets the the text associated with a CHARACTERS, SPACE or CDATA event.  
507:             * Text starting a "sourceStart" is copied into "target" starting at "targetStart".  
508:             * Up to "length" characters are copied.  The number of characters actually copied is returned.
509:             *
510:             * The "sourceStart" argument must be greater or equal to 0 and less than or equal to 
511:             * the number of characters associated with the event.  Usually, one requests text starting at a "sourceStart" of 0.  
512:             * If the number of characters actually copied is less than the "length", then there is no more text.  
513:             * Otherwise, subsequent calls need to be made until all text has been retrieved. For example:
514:             * 
515:             *<code>
516:             * int length = 1024;
517:             * char[] myBuffer = new char[ length ];
518:             * 
519:             * for ( int sourceStart = 0 ; ; sourceStart += length )
520:             * {
521:             *    int nCopied = stream.getTextCharacters( sourceStart, myBuffer, 0, length );
522:             *
523:             *   if (nCopied < length)
524:             *       break;
525:             * }
526:             * </code>
527:             * XMLStreamException may be thrown if there are any XML errors in the underlying source. 
528:             * The "targetStart" argument must be greater than or equal to 0 and less than the length of "target",  
529:             * Length must be greater than 0 and "targetStart + length" must be less than or equal to length of "target".  
530:             *
531:             * @param sourceStart the index of the first character in the source array to copy
532:             * @param target the destination array
533:             * @param targetStart the start offset in the target array
534:             * @param length the number of characters to copy
535:             * @return the number of characters actually copied
536:             * @throws XMLStreamException if the underlying XML source is not well-formed
537:             * @throws IndexOutOfBoundsException if targetStart < 0 or > than the length of target
538:             * @throws IndexOutOfBoundsException if length < 0 or targetStart + length > length of target
539:             * @throws UnsupportedOperationException if this method is not supported 
540:             * @throws NullPointerException is if target is null
541:             */
542:            public int getTextCharacters(int sourceStart, char[] target,
543:                    int targetStart, int length) throws XMLStreamException;
544:
545:            /**
546:             * Gets the text associated with a CHARACTERS, SPACE or CDATA event.  Allows the underlying
547:             * implementation to return the text as a stream of characters.  The reference to the 
548:             * Reader returned by this method is only valid until next() is called.
549:             *
550:             * All characters must have been checked for well-formedness.
551:             *
552:             * <p> This method is optional and will throw UnsupportedOperationException if it is not supported.  
553:             * @throws UnsupportedOperationException if this method is not supported
554:             * @throws IllegalStateException if this is not a valid text state
555:             */
556:            //public Reader getTextStream();
557:            /**
558:             * Returns the offset into the text character array where the first
559:             * character (of this text event) is stored.
560:             * @throws java.lang.IllegalStateException if this state is not
561:             * a valid text state.
562:             */
563:            public int getTextStart();
564:
565:            /**
566:             * Returns the length of the sequence of characters for this
567:             * Text event within the text character array.
568:             * @throws java.lang.IllegalStateException if this state is not
569:             * a valid text state.
570:             */
571:            public int getTextLength();
572:
573:            /**
574:             * Return input encoding if known or null if unknown.
575:             * @return the encoding of this instance or null
576:             */
577:            public String getEncoding();
578:
579:            /**
580:             * Return true if the current event has text, false otherwise
581:             * The following events have text:
582:             * CHARACTERS,DTD ,ENTITY_REFERENCE, COMMENT, SPACE
583:             */
584:            public boolean hasText();
585:
586:            /**
587:             * Return the current location of the processor.
588:             * If the Location is unknown the processor should return
589:             * an implementation of Location that returns -1 for the
590:             * location and null for the publicId and systemId.
591:             * The location information is only valid until next() is
592:             * called.
593:             */
594:            public Location getLocation();
595:
596:            /**
597:             * Returns a QName for the current START_ELEMENT or END_ELEMENT event
598:             * @return the QName for the current START_ELEMENT or END_ELEMENT event
599:             * @throws IllegalStateException if this is not a START_ELEMENT or
600:             * END_ELEMENT
601:             */
602:            public QName getName();
603:
604:            /**
605:             * Returns the (local) name of the current event.
606:             * For START_ELEMENT or END_ELEMENT returns the (local) name of the current element.
607:             * For ENTITY_REFERENCE it returns entity name.
608:             * The current event must be START_ELEMENT or END_ELEMENT, 
609:             * or ENTITY_REFERENCE
610:             * @return the localName
611:             * @throws IllegalStateException if this not a START_ELEMENT,
612:             * END_ELEMENT or ENTITY_REFERENCE
613:             */
614:            public String getLocalName();
615:
616:            /**
617:             * returns true if the current event has a name (is a START_ELEMENT or END_ELEMENT)
618:             * returns false otherwise
619:             */
620:            public boolean hasName();
621:
622:            /**
623:             * If the current event is a START_ELEMENT or END_ELEMENT  this method
624:             * returns the URI of the prefix or the default namespace.
625:             * Returns null if the event does not have a prefix.
626:             * @return the URI bound to this elements prefix, the default namespace, or null
627:             */
628:            public String getNamespaceURI();
629:
630:            /**
631:             * Returns the prefix of the current event or null if the event does not have a prefix
632:             * @return the prefix or null
633:             */
634:            public String getPrefix();
635:
636:            /**
637:             * Get the xml version declared on the xml declaration
638:             * Returns null if none was declared
639:             * @return the XML version or null
640:             */
641:            public String getVersion();
642:
643:            /**
644:             * Get the standalone declaration from the xml declaration
645:             * @return true if this is standalone, or false otherwise
646:             */
647:            public boolean isStandalone();
648:
649:            /**
650:             * Checks if standalone was set in the document
651:             * @return true if standalone was set in the document, or false otherwise
652:             */
653:            public boolean standaloneSet();
654:
655:            /**
656:             * Returns the character encoding declared on the xml declaration
657:             * Returns null if none was declared
658:             * @return the encoding declared in the document or null
659:             */
660:            public String getCharacterEncodingScheme();
661:
662:            /**
663:             * Get the target of a processing instruction
664:             * @return the target or null
665:             */
666:            public String getPITarget();
667:
668:            /**
669:             * Get the data section of a processing instruction
670:             * @return the data or null
671:             */
672:            public String getPIData();
673:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.