Project

General

Profile

« Previous | Next » 

Revision 1384

Added by Jing Tao almost 22 years ago

Add schema validation parameter here.

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
121 121
  private static final String SUCCESSCLOSE = "</success>";
122 122
  private static final String ERROR = "<error>";
123 123
  private static final String ERRORCLOSE = "</error>";
124
  private static final String SCHEMALOCATIONKEYWORD = "xsi:schemaLocation";
124 125

  
125 126
  /**
126 127
   * Initialize the servlet by creating appropriate database connections
......
1329 1330
 }//readFromRemoteMetaCat
1330 1331

  
1331 1332
  // END OF READ SECTION
1332

  
1333
  
1334
 
1335
  
1333 1336
  // INSERT/UPDATE SECTION
1334 1337
  /**
1335 1338
   * Handle the database putdocument request and write an XML document
......
1362 1365

  
1363 1366
      StringReader xml = null;
1364 1367
      boolean validate = false;
1368
      DocumentImplWrapper documentWrapper = null;
1365 1369
      try {
1366 1370
        // look inside XML Document for <!DOCTYPE ... PUBLIC/SYSTEM ... >
1367 1371
        // in order to decide whether to use validation parser
1368
        validate = validateXML(doctext[0]);
1372
        validate = needDTDValidation(doctext[0]);
1373
        if (validate)
1374
        {
1375
          // set a dtd base validation parser
1376
          String rule = DocumentImpl.DTD;
1377
          documentWrapper = new DocumentImplWrapper(rule, validate);
1378
        }
1379
        else if (needSchemaValidation(doctext[0]))
1380
        {
1381
          // set schema base validation parser
1382
          String rule = DocumentImpl.SCHEMA;
1383
          documentWrapper = new DocumentImplWrapper(rule, true);
1384
        }
1385
        else
1386
        {
1387
          documentWrapper = new DocumentImplWrapper("", false);
1388
        }
1389
        
1369 1390
        xml = new StringReader(doctext[0]);
1370 1391

  
1371 1392
        String[] action = (String[])params.get("action");
......
1396 1417
            {
1397 1418
              accNumber = null;
1398 1419
            }//if
1399
            newdocid = DocumentImpl.write(dbConn, xml, pub, dtd, doAction,
1400
                                          accNumber, user, groups, validate);
1420
            newdocid = documentWrapper.write(dbConn, xml, pub, dtd, doAction,
1421
                                          accNumber, user, groups);
1401 1422

  
1402 1423
          }//try
1403 1424
          catch (NullPointerException npe)
1404 1425
          {
1405
            newdocid = DocumentImpl.write(dbConn, xml, pub, dtd, doAction,
1406
                                          null, user, groups, validate);
1426
            newdocid = documentWrapper.write(dbConn, xml, pub, dtd, doAction,
1427
                                          null, user, groups);
1407 1428
          }//catch
1408 1429
        }//try
1409 1430
        finally
......
1453 1474
   * Parse XML Document to look for <!DOCTYPE ... PUBLIC/SYSTEM ... >
1454 1475
   * in order to decide whether to use validation parser
1455 1476
   */
1456
  private static boolean validateXML(String xmltext) throws IOException {
1477
  private static boolean needDTDValidation(String xmltext) throws IOException {
1457 1478

  
1458 1479
    StringReader xmlreader = new StringReader(xmltext);
1459 1480
    StringBuffer cbuff = new StringBuffer();
......
1504 1525
      }
1505 1526
    }
1506 1527

  
1507
System.out.println("Validation is " + validate);
1528
    MetaCatUtil.debugMessage("Validation for dtd is " + validate, 10);
1508 1529
    return validate;
1509 1530
  }
1510 1531
  // END OF INSERT/UPDATE SECTION
1511

  
1532
  
1533
  /* check if the xml string contains key words to specify schema loocation*/
1534
  private boolean needSchemaValidation(String xml)
1535
  {
1536
    boolean needSchemaValidate =false;
1537
    if (xml == null)
1538
    {
1539
      MetaCatUtil.debugMessage("Validation for schema is " +
1540
                               needSchemaValidate, 10);
1541
      return needSchemaValidate;
1542
    }
1543
    else if (xml.indexOf(SCHEMALOCATIONKEYWORD) != -1)
1544
    {
1545
      // if contains schema location key word, should be validate
1546
      needSchemaValidate = true;
1547
    }
1548
    
1549
    MetaCatUtil.debugMessage("Validation for schema is " + 
1550
                             needSchemaValidate, 10);
1551
    return needSchemaValidate;
1552
   
1553
  }
1554
  
1512 1555
  // DELETE SECTION
1513 1556
  /**
1514 1557
   * Handle the database delete request and delete an XML document

Also available in: Unified diff