Changeset 20811

Show
Ignore:
Timestamp:
12.10.2009 21:20:59 (10 years ago)
Author:
ak19
Message:

showXMLParseFailureLine() now splits lines into an array which is used to display the erroneous line, rather than looping through lines based on the newline char which can break on the last line if this lacks a newline character.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • gli/trunk/src/org/greenstone/gatherer/util/XMLTools.java

    r18377 r20811  
    520520        String line = ""; 
    521521        int linenumber = e.getLineNumber(); 
    522         DebugStream.println("\n****SAXParseException on LINE NUMBER: " + linenumber); 
     522        DebugStream.print("\n****SAXParseException on LINE NUMBER: " + linenumber); 
    523523        if(DebugStream.isDebuggingEnabled()) { 
    524524            if(linenumber != -1) {  
    525                 // find the line in xmlContents string (xmlContents is only set if GLI is run with debugging turned on) 
    526                 int start = 0; 
    527                 int end = xmlContents.length(); 
    528                 for(int i = 1; i <= linenumber; i++) { 
    529                     end = xmlContents.indexOf("\n"); 
    530                     if(end > 0) { 
    531                         line = xmlContents.substring(start, end); 
    532                     } 
    533                     start = end+1; 
    534                 } 
     525        String[] lines = xmlContents.split("\n"); 
     526        if (lines.length > 0) { 
     527            DebugStream.println(" (number of lines: " + lines.length + ")"); 
     528            if(lines.length >= linenumber) { 
     529            line = lines[linenumber-1]; 
     530            } else { // error is past the last line 
     531            line = "Error is past the last line (" + lines.length + "): " + lines[lines.length-1];           
     532            } 
     533        } else { 
     534            DebugStream.print("\n"); 
     535        } 
     536        lines = null; 
     537 
    535538                DebugStream.println("The parsing error occurred on this line:\n***********START\n" + line + "\n***********END"); 
    536539                DebugStream.println("SAXParseException message: " + e.getMessage() + "\n");