1 /* |
1 /* |
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
48 * <li>Keep track of all Attributes. |
48 * <li>Keep track of all Attributes. |
49 * |
49 * |
50 * <li>manage mapping between namespace URIs and prefixes. |
50 * <li>manage mapping between namespace URIs and prefixes. |
51 * |
51 * |
52 * <li>TODO: provide support for interleaving. |
52 * <li>TODO: provide support for interleaving. |
|
53 * </ol> |
53 * <p><b> |
54 * <p><b> |
54 * Auto-generated, do not edit. |
55 * Auto-generated, do not edit. |
55 * </b></p> |
56 * </b></p> |
56 * @version $Id: NGCCRuntime.java,v 1.15 2002/09/29 02:55:48 okajima Exp $ |
57 * @version $Id: NGCCRuntime.java,v 1.15 2002/09/29 02:55:48 okajima Exp $ |
57 * @author Kohsuke Kawaguchi (kk@kohsuke.org) |
58 * @author Kohsuke Kawaguchi (kk@kohsuke.org) |
68 * <p> |
69 * <p> |
69 * This method can be called right after the object is created |
70 * This method can be called right after the object is created |
70 * or the reset method is called. You can't replace the root |
71 * or the reset method is called. You can't replace the root |
71 * handler while parsing is in progress. |
72 * handler while parsing is in progress. |
72 * <p> |
73 * <p> |
73 * Usually a generated class that corresponds to the <start> |
74 * Usually a generated class that corresponds to the {@code <start>} |
74 * pattern will be used as the root handler, but any NGCCHandler |
75 * pattern will be used as the root handler, but any NGCCHandler |
75 * can be a root handler. |
76 * can be a root handler. |
76 * |
77 * |
77 * @exception IllegalStateException |
78 * @exception IllegalStateException |
78 * If this method is called but it doesn't satisfy the |
79 * If this method is called but it doesn't satisfy the |
240 if(redirect!=null) { |
241 if(redirect!=null) { |
241 redirect.startElement(uri,localname,qname,atts); |
242 redirect.startElement(uri,localname,qname,atts); |
242 redirectionDepth++; |
243 redirectionDepth++; |
243 } else { |
244 } else { |
244 processPendingText(true); |
245 processPendingText(true); |
245 // System.out.println("startElement:"+localname+"->"+_attrStack.size()); |
246 // System.out.println("startElement:"+localname+"->"+_attrStack.size()); |
246 currentHandler.enterElement(uri, localname, qname, atts); |
247 currentHandler.enterElement(uri, localname, qname, atts); |
247 } |
248 } |
248 } |
249 } |
249 |
250 |
250 /** |
251 /** |
261 * <p> |
262 * <p> |
262 * This method will be called from one of handlers when it truely |
263 * This method will be called from one of handlers when it truely |
263 * consumes the enterElement event. |
264 * consumes the enterElement event. |
264 */ |
265 */ |
265 public void onEnterElementConsumed( |
266 public void onEnterElementConsumed( |
266 String uri, String localName, String qname,Attributes atts) throws SAXException { |
267 String uri, String localName, String qname,Attributes atts) throws SAXException { |
267 attStack.push(currentAtts=new AttributesImpl(atts)); |
268 attStack.push(currentAtts=new AttributesImpl(atts)); |
268 nsEffectiveStack.push( new Integer(nsEffectivePtr) ); |
269 nsEffectiveStack.push( new Integer(nsEffectivePtr) ); |
269 nsEffectivePtr = namespaces.size(); |
270 nsEffectivePtr = namespaces.size(); |
270 } |
271 } |
271 |
272 |
392 // event dispatching methods |
393 // event dispatching methods |
393 // |
394 // |
394 // |
395 // |
395 |
396 |
396 public void sendEnterAttribute( int threadId, |
397 public void sendEnterAttribute( int threadId, |
397 String uri, String local, String qname) throws SAXException { |
398 String uri, String local, String qname) throws SAXException { |
398 |
399 |
399 currentHandler.enterAttribute(uri,local,qname); |
400 currentHandler.enterAttribute(uri,local,qname); |
400 } |
401 } |
401 |
402 |
402 public void sendEnterElement( int threadId, |
403 public void sendEnterElement( int threadId, |
403 String uri, String local, String qname, Attributes atts) throws SAXException { |
404 String uri, String local, String qname, Attributes atts) throws SAXException { |
404 |
405 |
405 currentHandler.enterElement(uri,local,qname,atts); |
406 currentHandler.enterElement(uri,local,qname,atts); |
406 } |
407 } |
407 |
408 |
408 public void sendLeaveAttribute( int threadId, |
409 public void sendLeaveAttribute( int threadId, |
409 String uri, String local, String qname) throws SAXException { |
410 String uri, String local, String qname) throws SAXException { |
410 |
411 |
411 currentHandler.leaveAttribute(uri,local,qname); |
412 currentHandler.leaveAttribute(uri,local,qname); |
412 } |
413 } |
413 |
414 |
414 public void sendLeaveElement( int threadId, |
415 public void sendLeaveElement( int threadId, |
415 String uri, String local, String qname) throws SAXException { |
416 String uri, String local, String qname) throws SAXException { |
416 |
417 |
417 currentHandler.leaveElement(uri,local,qname); |
418 currentHandler.leaveElement(uri,local,qname); |
418 } |
419 } |
419 |
420 |
420 public void sendText(int threadId, String value) throws SAXException { |
421 public void sendText(int threadId, String value) throws SAXException { |
448 * @param uri,local,qname |
449 * @param uri,local,qname |
449 * Parameters passed to the enter element event. Used to |
450 * Parameters passed to the enter element event. Used to |
450 * simulate the startElement event for the new ContentHandler. |
451 * simulate the startElement event for the new ContentHandler. |
451 */ |
452 */ |
452 public void redirectSubtree( ContentHandler child, |
453 public void redirectSubtree( ContentHandler child, |
453 String uri, String local, String qname ) throws SAXException { |
454 String uri, String local, String qname ) throws SAXException { |
454 |
455 |
455 redirect = child; |
456 redirect = child; |
456 redirect.setDocumentLocator(locator); |
457 redirect.setDocumentLocator(locator); |
457 redirect.startDocument(); |
458 redirect.startDocument(); |
458 |
459 |
459 // TODO: when a prefix is re-bound to something else, |
460 // TODO: when a prefix is re-bound to something else, |
460 // the following code is potentially dangerous. It should be |
461 // the following code is potentially dangerous. It should be |
461 // modified to report active bindings only. |
462 // modified to report active bindings only. |
462 for( int i=0; i<namespaces.size(); i+=2 ) |
463 for( int i=0; i<namespaces.size(); i+=2 ) |
463 redirect.startPrefixMapping( |
464 redirect.startPrefixMapping( |
464 (String)namespaces.get(i), |
465 (String)namespaces.get(i), |
465 (String)namespaces.get(i+1) |
466 (String)namespaces.get(i+1) |
466 ); |
467 ); |
467 |
468 |
468 redirect.startElement(uri,local,qname,currentAtts); |
469 redirect.startElement(uri,local,qname,currentAtts); |
469 redirectionDepth=1; |
470 redirectionDepth=1; |
470 } |
471 } |
515 return "http://www.w3.org/XML/1998/namespace"; |
516 return "http://www.w3.org/XML/1998/namespace"; |
516 else return null; // prefix undefined |
517 else return null; // prefix undefined |
517 } |
518 } |
518 |
519 |
519 |
520 |
520 // error reporting |
521 // error reporting |
521 protected void unexpectedX(String token) throws SAXException { |
522 protected void unexpectedX(String token) throws SAXException { |
522 throw new SAXParseException(MessageFormat.format( |
523 throw new SAXParseException(MessageFormat.format( |
523 "Unexpected {0} appears at line {1} column {2}", |
524 "Unexpected {0} appears at line {1} column {2}", |
524 new Object[]{ |
525 new Object[]{ |
525 token, |
526 token, |
526 new Integer(getLocator().getLineNumber()), |
527 new Integer(getLocator().getLineNumber()), |
527 new Integer(getLocator().getColumnNumber()) }), |
528 new Integer(getLocator().getColumnNumber()) }), |
528 getLocator()); |
529 getLocator()); |
529 } |
530 } |
530 |
531 |
531 |
532 |
532 |
533 |
533 |
534 |
534 // |
535 // |
535 // |
536 // |
536 // trace functions |
537 // trace functions |
537 // |
538 // |
538 // |
539 // |
539 private int indent=0; |
540 private int indent=0; |