Project

Profile

Help

Revision 576ab110

Added by Michael Kay over 12 years ago

Fix bug 2711894 (location info in EventPull pipeline)

View differences:

latest9.1/bj/net/sf/saxon/evpull/EventToStaxBridge.java
6 6
import net.sf.saxon.type.Type;
7 7
import net.sf.saxon.value.AtomicValue;
8 8
import net.sf.saxon.value.Whitespace;
9
import net.sf.saxon.event.PipelineConfiguration;
10
import net.sf.saxon.event.LocationProvider;
9 11

  
10 12
import javax.xml.namespace.NamespaceContext;
11 13
import javax.xml.namespace.QName;
......
438 440
    }
439 441

  
440 442
    public Location getLocation() {
441
        return new Location() {
443
        if (startElementEvent != null) {
444
            PipelineConfiguration pipe = startElementEvent.getPipelineConfiguration();
445
            final LocationProvider provider = pipe.getLocationProvider();
446
            final int locationId = startElementEvent.getLocationId();
447
            return new Location() {
448
                public int getCharacterOffset() {
449
                    return -1;
450
                }
451

  
452
                public int getColumnNumber() {
453
                    return provider.getColumnNumber(locationId);
454
                }
455

  
456
                public int getLineNumber() {
457
                    return provider.getLineNumber(locationId);
458
                }
459

  
460
                public String getPublicId() {
461
                    return null;
462
                }
463

  
464
                public String getSystemId() {
465
                    return provider.getSystemId(locationId);
466
                }
467
            };
468
        } else if (currentItem instanceof NodeInfo) {
469
            final NodeInfo node = (NodeInfo)currentItem;
470
            return new Location() {
471
                public int getCharacterOffset() {
472
                    return -1;
473
                }
474

  
475
                public int getColumnNumber() {
476
                    return node.getColumnNumber();
477
                }
478

  
479
                public int getLineNumber() {
480
                    return node.getLineNumber();
481
                }
482

  
483
                public String getPublicId() {
484
                    return null;
485
                }
486

  
487
                public String getSystemId() {
488
                    return node.getSystemId();
489
                }
490
            };
442 491

  
443
            public int getCharacterOffset() {
444
                return -1;
445
            }
446

  
447
            public int getColumnNumber() {
448
                return -1;
449
            }
450

  
451
            public int getLineNumber() {
452
                return -1;
453
            }
454

  
455
            public String getPublicId() {
456
                return null;
457
            }
458

  
459
            public String getSystemId() {
460
                return null; 
461
            }
462
        };
492
        } else {
493
            return DummyLocation.THE_INSTANCE;
494
        }
463 495
    }
464

  
465 496
    public Object getProperty(String s) throws IllegalArgumentException {
466 497
        return null;
467 498
    }
......
488 519
        return ((NamespaceResolver)provider).getURIForPrefix(prefix, true);
489 520
    }
490 521

  
491
    /**
492
     * Bridge a SAX SourceLocator to a javax.xml.stream.Location
493
     */
494

  
495
    public class SourceStreamLocation implements Location {
496

  
497
        private SourceLocator locator;
522
    public static class DummyLocation  implements Location{
523
        public static final Location THE_INSTANCE = new DummyLocation();
498 524

  
499
        /**
500
         * Create a StAX SourceStreamLocation object based on a given SAX SourceLocator
501
         * @param locator the SAX SourceLocator
502
         */
503
        public SourceStreamLocation(SourceLocator locator) {
504
            this.locator = locator;
505
        }
525
        private DummyLocation() {}
506 526

  
507 527
        public int getCharacterOffset() {
508 528
            return -1;
509 529
        }
510 530

  
511 531
        public int getColumnNumber() {
512
            return locator.getColumnNumber();
532
            return -1;
513 533
        }
514 534

  
515 535
        public int getLineNumber() {
516
            return locator.getLineNumber();
536
            return -1;
517 537
        }
518 538

  
519
        public String getPublicId() {
520
            return locator.getPublicId();
539
        public java.lang.String getPublicId() {
540
            return null;
521 541
        }
522 542

  
523
        public String getSystemId() {
524
            return locator.getSystemId();
543
        public java.lang.String getSystemId() {
544
            return null;
525 545
        }
526 546
    }
527 547

  
latest9.1/bj/net/sf/saxon/evpull/StartElementEvent.java
1 1
package net.sf.saxon.evpull;
2 2

  
3 3
import net.sf.saxon.Configuration;
4
import net.sf.saxon.trans.Err;
5 4
import net.sf.saxon.event.PipelineConfiguration;
6 5
import net.sf.saxon.expr.ExpressionLocation;
7 6
import net.sf.saxon.om.NamePool;
......
9 8
import net.sf.saxon.om.Orphan;
10 9
import net.sf.saxon.om.StandardNames;
11 10
import net.sf.saxon.sort.IntArraySet;
11
import net.sf.saxon.trans.Err;
12 12
import net.sf.saxon.trans.XPathException;
13 13
import net.sf.saxon.type.Type;
14 14

  
......
304 304
        }
305 305
    }
306 306

  
307
    /**
308
     * Get the PipelineConfiguration
309
     * @return the PipelineConfiguration
310
     */
311

  
312
    public PipelineConfiguration getPipelineConfiguration() {
313
        return pipe;
314
    }
315

  
307 316
    /**
308 317
     * Set the location associated with the event
309 318
     * @param locationId a location identifier, to be interpreted by the locationProvider
......
323 332
    public int getLocationId() {
324 333
        return locationId;
325 334
    }
335

  
336
//    public static void main(String[] args) throws Exception {
337
//        try {
338
//            Configuration config = new Configuration();
339
//            config.setLineNumbering(true);
340
//            DocumentInfo doc = config.buildDocument(new StreamSource(new File("C:/MyJava/testdata/books.xml")));
341
//            PipelineConfiguration pipe = config.makePipelineConfiguration();
342
//            EventIterator ei = new Decomposer(doc, pipe);
343
//            XMLStreamReader reader = new EventToStaxBridge(ei, config.getNamePool());
344
//            while (true) {
345
//                int event = reader.next();
346
//                if (event == XMLStreamReader.END_DOCUMENT) {
347
//                    break;
348
//                }
349
//                System.err.println("EVENT: " + event + " @ " +
350
//                        reader.getLocation().getSystemId() + "#" + reader.getLocation().getLineNumber());
351
//            }
352
//
353
//        } catch (Exception e) {
354
//            e.printStackTrace();
355
//        }
356
//    }
326 357
}
327 358

  
328 359
//

Also available in: Unified diff