Project

General

Profile

« Previous | Next » 

Revision 660

Added by bojilova almost 24 years ago

- turned on the validation in order only valid xml docs comformed to the specified dtd (if any) to be submitted in metacat
- with validation "on" white spaces are reported from ignorableWhitespace() callback, not from characters() (as with validation "off")
Thus included insert of whitespaces from ignorableWhitespace()
- excluded insertion of the comments coming from the dtd file.
There are feature "external-parameter_entities" that when turned to "off"
supposed to exclude the insertion of all external paramer entities (the external DTD also)
but it doesn't work probably b' the name of the feature is not correct

View differences:

src/edu/ucsb/nceas/metacat/DBSAXHandler.java
291 291
   }
292 292

  
293 293
   /** 
294
    * SAX Handler that is called for each XML text node that is Ignorable
295
    * white space
294
    * SAX Handler that is called for each XML text node that is
295
    * Ignorable white space
296 296
    */
297
   public void ignorableWhitespace(char[] cbuf, int start, int len) {
297
   public void ignorableWhitespace(char[] cbuf, int start, int len)
298
               throws SAXException {
299
     // When validation is turned "on", white spaces are reported here
300
     // When validation is turned "off" white spaces are not reported here,
301
     // but through characters() callback
298 302
     MetaCatUtil.debugMessage("IGNORABLEWHITESPACE");
303
     //System.out.println("Whitespace:" + len + "x" + new String(cbuf, start, len) + "x");
304

  
305
     DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
306
     String data = null;
307
     int leftover = len;
308
     int offset = start;
309
     boolean moredata = true;
310
     
311
     // This loop deals with the case where there are more characters 
312
     // than can fit in a single database text field (limit is 
313
     // MAXDATACHARS).  If the text to be inserted exceeds MAXDATACHARS,
314
     // write a series of nodes that are MAXDATACHARS long, and then the
315
     // final node contains the remainder
316
     while (moredata) {
317
       if (leftover > MAXDATACHARS) {
318
         data = new String(cbuf, offset, MAXDATACHARS);
319
         leftover -= MAXDATACHARS;
320
         offset += MAXDATACHARS;
321
       } else {
322
         data = new String(cbuf, offset, leftover);
323
         moredata = false;
324
       }
325

  
326
       // Write the content of the node to the database
327
       currentNode.writeChildNodeToDB("TEXT", null, data, docid);
328
     }
299 329
   }
300 330

  
301 331
   /** 
......
347 377
    */
348 378
   public void comment(char[] ch, int start, int length) throws SAXException {
349 379
     MetaCatUtil.debugMessage("COMMENT");
350
     DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
351
     currentNode.writeChildNodeToDB("COMMENT", null, new String(ch), docid);
380
     if ( !processingDTD ) {
381
       DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
382
       currentNode.writeChildNodeToDB("COMMENT", null, new String(ch), docid);
383
     }
352 384
   }
353 385

  
354 386
   /** 
......
439 471
    */
440 472
   public void error(SAXParseException exception) throws SAXException {
441 473
     MetaCatUtil.debugMessage("ERROR");
474
     throw (new SAXException("Processing error.", exception));
442 475
   }
443 476

  
444 477
   /** 
......
446 479
    */
447 480
   public void warning(SAXParseException exception) throws SAXException {
448 481
     MetaCatUtil.debugMessage("WARNING");
482
     throw (new SAXException("Warning.", exception));
449 483
   }
450 484

  
451 485
   // 
src/edu/ucsb/nceas/metacat/DocumentImpl.java
1024 1024
      String parserName = util.getOption("saxparser");
1025 1025
      parser = XMLReaderFactory.createXMLReader(parserName);
1026 1026

  
1027
      // Turn off validation
1028
      parser.setFeature("http://xml.org/sax/features/validation", false);
1027
      // Turn on validation
1028
      parser.setFeature("http://xml.org/sax/features/validation", true);
1029
      // Turn off Including all external parameter entities
1030
      // (the external DTD subset also)
1031
      // Doesn't work well, probably the feature name is not correct
1032
      // parser.setFeature(
1033
      //  "http://xml.org/sax/features/external-parameter-entities", false);
1029 1034
      
1030 1035
      // Set Handlers in the parser
1031 1036
      parser.setProperty("http://xml.org/sax/properties/declaration-handler",
src/edu/ucsb/nceas/metacat/AccessControlList.java
59 59

  
60 60
  private String resourceURL;
61 61
  private String resourceId;
62
  private Vector principalName;
62
  private Vector principal;
63 63
  private int    permission;
64 64
  private String permType;
65 65
  private String permOrder;
......
103 103
    this.user = user;
104 104
    this.group = group;
105 105
    this.aclid = aclid;
106
    this.principalName = new Vector();
106
    this.principal = new Vector();
107 107
    this.permission = 0;
108 108
    this.ticketCount = 0;
109 109
    
......
129 129
         user, group);
130 130
  }
131 131
  
132
  /**
133
   * Set up the SAX parser for reading the XML serialized ACL
134
   */
132
  /* Set up the SAX parser for reading the XML serialized ACL */
135 133
  private XMLReader initializeParser() throws SAXException 
136 134
  {
137 135
    XMLReader parser = null;
......
231 229
      }
232 230
      // end of check for "all" perm on resourceId
233 231

  
234
    } else if (currentTag.equals("principalName")) {
232
    } else if (currentTag.equals("principal")) {
235 233

  
236
      principalName.addElement(new String(inputString));
234
      principal.addElement(new String(inputString));
237 235

  
238 236
    } else if (currentTag.equals("permission")) {
239 237

  
......
292 290
      }
293 291

  
294 292
      // reset the allowed permission
295
      principalName = new Vector();
293
      principal = new Vector();
296 294
      permission = 0;
297 295
      beginTime = null;
298 296
      endTime = null;
......
311 309
      }
312 310

  
313 311
      // reset the denied permission
314
      principalName = new Vector();
312
      principal = new Vector();
315 313
      permission = 0;
316 314
      beginTime = null;
317 315
      endTime = null;
......
433 431
      } else {
434 432
        pstmt.setString(8, "");
435 433
      }
436
      for ( int i = 0; i < principalName.size(); i++ ) {
437
        pstmt.setString(2, (String)principalName.elementAt(i));
434
      for ( int i = 0; i < principal.size(); i++ ) {
435
        pstmt.setString(2, (String)principal.elementAt(i));
438 436
        pstmt.execute();
439 437
      }
440 438

  

Also available in: Unified diff