@@ -361,142 +361,166 @@ public void startElement(
361
361
}
362
362
363
363
// start a new modification section
364
- if (APPEND .equals (localName )) {
365
- final String child = atts .getValue ("child" );
366
- modification = new Append (broker , documentSet , select , child , namespaces , variables );
367
- } else if (UPDATE .equals (localName ))
368
- {modification = new Update (broker , documentSet , select , namespaces , variables );}
369
- else if (INSERT_BEFORE .equals (localName ))
370
- {modification =
371
- new Insert (broker , documentSet , select , Insert .INSERT_BEFORE , namespaces , variables );}
372
- else if (INSERT_AFTER .equals (localName ))
373
- {modification =
374
- new Insert (broker , documentSet , select , Insert .INSERT_AFTER , namespaces , variables );}
375
- else if (REMOVE .equals (localName ))
376
- {modification = new Remove (broker , documentSet , select , namespaces , variables );}
377
- else if (RENAME .equals (localName ))
378
- {modification = new Rename (broker , documentSet , select , namespaces , variables );}
379
- else if (REPLACE .equals (localName ))
380
- {modification = new Replace (broker , documentSet , select , namespaces , variables );}
381
-
382
- // process commands for node creation
383
- else if (ELEMENT .equals (localName )) {
384
- String name = atts .getValue ("name" );
385
- if (name == null )
386
- {throw new SAXException ("element requires a name attribute" );}
387
- final int p = name .indexOf (':' );
388
- String namespace = null ;
389
- String prefix = "" ;
390
- if (p != Constants .STRING_NOT_FOUND ) {
391
- prefix = name .substring (0 , p );
392
- if (name .length () == p + 1 )
393
- {throw new SAXException (
394
- "illegal prefix in qname: " + name );}
395
- name = name .substring (p + 1 );
396
- namespace = atts .getValue ("namespace" );
397
- if (namespace == null )
398
- {namespace = (String ) namespaces .get (prefix );}
399
- if (namespace == null ) {
400
- throw new SAXException (
401
- "no namespace defined for prefix " + prefix );
364
+ switch (localName ) {
365
+ case APPEND :
366
+ final String child = atts .getValue ("child" );
367
+ modification = new Append (broker , documentSet , select , child , namespaces , variables );
368
+ break ;
369
+ case UPDATE :
370
+ modification = new Update (broker , documentSet , select , namespaces , variables );
371
+ break ;
372
+ case INSERT_BEFORE :
373
+ modification =
374
+ new Insert (broker , documentSet , select , Insert .INSERT_BEFORE , namespaces , variables );
375
+ break ;
376
+ case INSERT_AFTER :
377
+ modification =
378
+ new Insert (broker , documentSet , select , Insert .INSERT_AFTER , namespaces , variables );
379
+ break ;
380
+ case REMOVE :
381
+ modification = new Remove (broker , documentSet , select , namespaces , variables );
382
+ break ;
383
+ case RENAME :
384
+ modification = new Rename (broker , documentSet , select , namespaces , variables );
385
+ break ;
386
+ case REPLACE :
387
+ modification = new Replace (broker , documentSet , select , namespaces , variables );
388
+ break ;
389
+
390
+ // process commands for node creation
391
+ case ELEMENT : {
392
+ String name = atts .getValue ("name" );
393
+ if (name == null ) {
394
+ throw new SAXException ("element requires a name attribute" );
395
+ }
396
+ final int p = name .indexOf (':' );
397
+ String namespace = null ;
398
+ String prefix = "" ;
399
+ if (p != Constants .STRING_NOT_FOUND ) {
400
+ prefix = name .substring (0 , p );
401
+ if (name .length () == p + 1 ) {
402
+ throw new SAXException (
403
+ "illegal prefix in qname: " + name );
404
+ }
405
+ name = name .substring (p + 1 );
406
+ namespace = atts .getValue ("namespace" );
407
+ if (namespace == null ) {
408
+ namespace = (String ) namespaces .get (prefix );
409
+ }
410
+ if (namespace == null ) {
411
+ throw new SAXException (
412
+ "no namespace defined for prefix " + prefix );
413
+ }
414
+ }
415
+ Element elem ;
416
+ if (namespace != null && namespace .length () > 0 ) {
417
+ elem = doc .createElementNS (namespace , name );
418
+ elem .setPrefix (prefix );
419
+ } else {
420
+ elem = doc .createElement (name );
402
421
}
403
- }
404
- Element elem ;
405
- if (namespace != null && namespace .length () > 0 )
406
- {
407
- elem = doc .createElementNS (namespace , name );
408
- elem .setPrefix (prefix );
409
- }
410
- else
411
- {elem = doc .createElement (name );}
412
422
413
- final Element last = stack .peek ();
414
- if (last == null ) {
415
- contents .add (elem );
416
- } else {
417
- last .appendChild (elem );
418
- }
423
+ final Element last = stack .peek ();
424
+ if (last == null ) {
425
+ contents .add (elem );
426
+ } else {
427
+ last .appendChild (elem );
428
+ }
419
429
420
- stack .push (elem );
421
- this .setWhitespaceHandling (elem );
422
- } else if (ATTRIBUTE .equals (localName )) {
423
- final String name = atts .getValue ("name" );
424
- if (name == null )
425
- {throw new SAXException ("attribute requires a name attribute" );}
426
- final int p = name .indexOf (':' );
427
- String namespace = null ;
428
- if (p != Constants .STRING_NOT_FOUND ) {
429
- final String prefix = name .substring (0 , p );
430
- if (name .length () == p + 1 )
431
- {throw new SAXException (
432
- "illegal prefix in qname: " + name );}
433
- namespace = atts .getValue ("namespace" );
434
- if (namespace == null )
435
- {namespace = (String ) namespaces .get (prefix );}
436
- if (namespace == null )
437
- {throw new SAXException (
438
- "no namespace defined for prefix " + prefix );}
430
+ stack .push (elem );
431
+ this .setWhitespaceHandling (elem );
432
+ break ;
439
433
}
440
- Attr attrib = namespace != null && namespace .length () > 0 ?
441
- doc .createAttributeNS (namespace , name ) :
442
- doc .createAttribute (name );
443
- if (stack .isEmpty ()) {
444
- for (int i = 0 ; i < contents .getLength (); i ++) {
445
- final Node n = contents .item (i );
446
- String ns = n .getNamespaceURI ();
447
- final String nname = ns == null ? n .getNodeName () : n .getLocalName ();
448
- if (ns == null ) {
449
- ns = XMLConstants .NULL_NS_URI ;
434
+ case ATTRIBUTE : {
435
+ final String name = atts .getValue ("name" );
436
+ if (name == null ) {
437
+ throw new SAXException ("attribute requires a name attribute" );
438
+ }
439
+ final int p = name .indexOf (':' );
440
+ String namespace = null ;
441
+ if (p != Constants .STRING_NOT_FOUND ) {
442
+ final String prefix = name .substring (0 , p );
443
+ if (name .length () == p + 1 ) {
444
+ throw new SAXException (
445
+ "illegal prefix in qname: " + name );
446
+ }
447
+ namespace = atts .getValue ("namespace" );
448
+ if (namespace == null ) {
449
+ namespace = (String ) namespaces .get (prefix );
450
+ }
451
+ if (namespace == null ) {
452
+ throw new SAXException (
453
+ "no namespace defined for prefix " + prefix );
450
454
}
451
- // check for duplicate attributes
452
- if (n .getNodeType () == Node .ATTRIBUTE_NODE &&
453
- nname .equals (name ) &&
454
- ns .equals (namespace ))
455
- {throw new SAXException ("The attribute " + attrib .getNodeName () + " cannot be specified twice" );}
456
455
}
457
- contents .add (attrib );
458
- } else {
459
- final Element last = stack .peek ();
460
- if (namespace != null && last .hasAttributeNS (namespace , name ) ||
461
- namespace == null && last .hasAttribute (name ))
462
- {throw new SAXException ("The attribute " + attrib .getNodeName () + " cannot be specified " +
463
- "twice on the same element" );}
464
- if (namespace != null )
465
- {last .setAttributeNodeNS (attrib );}
466
- else
467
- {last .setAttributeNode (attrib );}
468
- }
469
- inAttribute = true ;
470
- currentNode = attrib ;
471
-
472
- // process value-of
473
- } else if (VALUE_OF .equals (localName )) {
474
- select = atts .getValue ("select" );
475
- if (select == null )
476
- {throw new SAXException ("value-of requires a select attribute" );}
477
- final Sequence seq = processQuery (select );
478
- if (LOG .isDebugEnabled ())
479
- {LOG .debug ("Found " + seq .getItemCount () + " items for value-of" );}
480
- Item item ;
481
- try {
482
- for (final SequenceIterator i = seq .iterate (); i .hasNext ();) {
483
- item = i .nextItem ();
484
- if (Type .subTypeOf (item .getType (), Type .NODE )) {
485
- final Node node = NodeSetHelper .copyNode (doc , ((NodeValue )item ).getNode ());
486
- final Element last = stack .peek ();
487
- if (last == null ) {
488
- contents .add (node );
489
- } else {
490
- last .appendChild (node );
456
+ Attr attrib = namespace != null && namespace .length () > 0 ?
457
+ doc .createAttributeNS (namespace , name ) :
458
+ doc .createAttribute (name );
459
+ if (stack .isEmpty ()) {
460
+ for (int i = 0 ; i < contents .getLength (); i ++) {
461
+ final Node n = contents .item (i );
462
+ String ns = n .getNamespaceURI ();
463
+ final String nname = ns == null ? n .getNodeName () : n .getLocalName ();
464
+ if (ns == null ) {
465
+ ns = XMLConstants .NULL_NS_URI ;
491
466
}
467
+ // check for duplicate attributes
468
+ if (n .getNodeType () == Node .ATTRIBUTE_NODE &&
469
+ nname .equals (name ) &&
470
+ ns .equals (namespace )) {
471
+ throw new SAXException ("The attribute " + attrib .getNodeName () + " cannot be specified twice" );
472
+ }
473
+ }
474
+ contents .add (attrib );
475
+ } else {
476
+ final Element last = stack .peek ();
477
+ if (namespace != null && last .hasAttributeNS (namespace , name ) ||
478
+ namespace == null && last .hasAttribute (name )) {
479
+ throw new SAXException ("The attribute " + attrib .getNodeName () + " cannot be specified " +
480
+ "twice on the same element" );
481
+ }
482
+ if (namespace != null ) {
483
+ last .setAttributeNodeNS (attrib );
492
484
} else {
493
- final String value = item .getStringValue ();
494
- characters (value .toCharArray (), 0 , value .length ());
485
+ last .setAttributeNode (attrib );
495
486
}
496
487
}
497
- } catch (final XPathException e ) {
498
- throw new SAXException (e .getMessage (), e );
488
+ inAttribute = true ;
489
+ currentNode = attrib ;
490
+
491
+ // process value-of
492
+ break ;
499
493
}
494
+ case VALUE_OF :
495
+ select = atts .getValue ("select" );
496
+ if (select == null ) {
497
+ throw new SAXException ("value-of requires a select attribute" );
498
+ }
499
+ final Sequence seq = processQuery (select );
500
+ if (LOG .isDebugEnabled ()) {
501
+ LOG .debug ("Found " + seq .getItemCount () + " items for value-of" );
502
+ }
503
+ Item item ;
504
+ try {
505
+ for (final SequenceIterator i = seq .iterate (); i .hasNext (); ) {
506
+ item = i .nextItem ();
507
+ if (Type .subTypeOf (item .getType (), Type .NODE )) {
508
+ final Node node = NodeSetHelper .copyNode (doc , ((NodeValue ) item ).getNode ());
509
+ final Element last = stack .peek ();
510
+ if (last == null ) {
511
+ contents .add (node );
512
+ } else {
513
+ last .appendChild (node );
514
+ }
515
+ } else {
516
+ final String value = item .getStringValue ();
517
+ characters (value .toCharArray (), 0 , value .length ());
518
+ }
519
+ }
520
+ } catch (final XPathException e ) {
521
+ throw new SAXException (e .getMessage (), e );
522
+ }
523
+ break ;
500
524
}
501
525
} else if (inModification ) {
502
526
final Element elem = namespaceURI != null && namespaceURI .length () > 0 ?
0 commit comments