Project

General

Profile

« Previous | Next » 

Revision 1343

Added by Jing Tao over 21 years ago

Revise code to make validateion work.

View differences:

src/edu/ucsb/nceas/metacat/DBValidate.java
64 64
  XMLReader parser;
65 65
  ErrorStorer ef;
66 66
  String xml_doc; // document to be parsed
67
  public boolean alreadyHandle = false;
67 68
    
68 69
  /** Construct a new validation object */
69 70
  public DBValidate(String parserName) {
70

  
71
    alreadyHandle = false;
71 72
    try {
72 73
      // Get an instance of the parser
73 74
      parser = XMLReaderFactory.createXMLReader(parserName);
......
126 127
        
127 128
    } catch (Exception e) {} 
128 129

  
129
      // {System.out.println("Exception parsing:Could not parse :"+xml_doc);} 
130 130
    
131
    
131 132
    if (ef != null && ef.getErrorNodes()!=null && 
132 133
      ef.getErrorNodes().size() > 0 ) {
133 134
      return false; 
......
148 149
    parser.setErrorHandler(ef);
149 150
      
150 151
    InputSource is = new InputSource(new StringReader(xmldoc));
151
    try {
152
    try 
153
    {
154
      
152 155
      parser.parse(is);
156
     
153 157
    }
154
    catch (Exception e) {
155
      System.out.println("Error in parsing in DBValidate.validateString");
158
    catch (SAXParseException e) 
159
    {
160
      System.out.println("SAXParseException Error in DBValidate.validateString"
161
                         +e.getMessage());
162
      ef.error(e);
156 163
    }
164
    catch (SAXException saxe)
165
    {
166
      System.out.println("SAXException error in validateString: "
167
                          +saxe.getMessage());
168
      ef.otherError(saxe, null);
169
      
170
    }
171
    catch (IOException ioe)
172
    {
173
      System.out.println("IOExcption error in validateString "
174
                          +ioe.getMessage());
175
      ef.otherError(ioe, null);
176
    }
157 177

  
158 178
    if (ef != null && ef.getErrorNodes()!=null && 
159 179
      ef.getErrorNodes().size() > 0 ) {
......
276 296
    
277 297
    /***/
278 298
    public void warning(SAXParseException ex) {
299
        
279 300
        handleError(ex, WARNING);
301
        
280 302
    }
281 303

  
282 304
    public void error(SAXParseException ex) {
305
      
283 306
        handleError(ex, ERROR);
307
       
284 308
    }
285 309

  
286
    public void fatalError(SAXParseException ex) throws SAXException {
310
    public void fatalError(SAXParseException ex){
311
      
287 312
        handleError(ex, FATAL_ERROR);
313
        
288 314
    }
315
    
316
    public void otherError(Exception ex, String fileName)
317
    {
318
      if (!alreadyHandle)
319
      {
320
        if (errorNodes == null) 
321
        {
322
          errorNodes = new Vector();
323
        }
324
      
325
        ParseError error = new ParseError(fileName, ex.getMessage());
326
        errorNodes.addElement(error);
327
       
328
      }
329
    }
289 330
        
290 331
    private void handleError(SAXParseException ex, int type) {
291
      // System.out.println("!!! handleError: "+ex.getMessage());
292

  
332
     
293 333
      if (errorNodes == null) {
294 334
        errorNodes = new Vector();
295 335
      }
296

  
336
      
297 337
      ParseError eip = null;
338
      
298 339
      eip = new ParseError(ex.getSystemId(), ex.getLineNumber(),
299 340
                           ex.getColumnNumber(), ex.getMessage());
300
        
341
      
301 342
      // put it in the Hashtable.
302 343
      errorNodes.addElement(eip);
344
      alreadyHandle = true;
345
      
303 346
    }
304 347
        
305 348
  }
......
330 373
      this.charOffset=charOffset;
331 374
      this.msg=msg;
332 375
    }
333

  
376
    public ParseError(String fileName, String msg) {
377
      this.fileName=fileName;
378
      this.msg=msg;
379
    }
334 380
    //
335 381
    // Getters...
336 382
    //

Also available in: Unified diff