Project

General

Profile

« Previous | Next » 

Revision 1896

Added by Jing Tao about 21 years ago

Set system id for transforming.

View differences:

src/edu/ucsb/nceas/metacat/DBTransform.java
155 155
            transformer.setParameter(key, value);
156 156
          }
157 157
        }
158

  
159
        transformer.transform(new StreamSource(new StringReader(doc)),
160
                              new StreamResult(pw));
158
        
159
       
160
        StreamSource xml = new StreamSource(new StringReader(doc));
161
        //modify the system id for dtd
162
        modifiedXmlStreamSource(xml, sourceType);
163
        transformer.transform(xml, new StreamResult(pw));
161 164
      } catch (Exception e) {
162 165
        pw.println(xslSystemId + "Error transforming document in " +
163 166
                   "DBTransform.transformXMLDocument: " +
......
198 201
          transformer.setParameter("sessid", sessionid);
199 202
        }
200 203
        transformer.setParameter("qFormat", qFormat);
201
        transformer.transform(new StreamSource(new StringReader(doc)),
202
                              new StreamResult(pw));
204
        StreamSource xml = new StreamSource(new StringReader(doc));
205
        //modify the system id for dtd
206
        modifiedXmlStreamSource(xml, sourceType);
207
        transformer.transform(xml, new StreamResult(pw));
203 208
      } catch (Exception e) {
204 209
        util.debugMessage(xslSystemId + "Error transforming document in " +
205 210
                   "DBTransform.transformXMLDocument: " +
......
362 367
    return systemId;
363 368
  }
364 369

  
365
  /**
366
   * Lookup a stylesheet reference from the db catalog
367
   *
368
   * @param objecttype the type of the object we want to retrieve
369
   * @param sourcetype the document type of the source
370
   * @param targettype the document type of the target
371
   */
372
  public String getSystemId(String objecttype, String sourcetype,
373
                String targettype) {
374

  
375
    // Look up the System ID of a particular object
376
    PreparedStatement pstmt = null;
377
    String the_system_id = null;
378
    DBConnection dbConn = null;
379
    int serialNumber = -1;
380
    try {
381
      dbConn=DBConnectionPool.
382
                  getDBConnection("DBTransform.getSystemId");
383
      serialNumber=dbConn.getCheckOutSerialNumber();
384
      pstmt =
385
        dbConn.prepareStatement("SELECT system_id " +
386
                "FROM xml_catalog " +
387
                "WHERE entry_type = ? " +
388
                "AND source_doctype = ? " +
389
                "AND target_doctype = ? ");
390
      // Bind the values to the query
391
      pstmt.setString(1, objecttype);
392
      pstmt.setString(2, sourcetype);
393
      pstmt.setString(3, targettype);
394
      pstmt.execute();
395
      try {
396
        ResultSet rs = pstmt.getResultSet();
397
        try {
398
          boolean tableHasRows = rs.next();
399
          if (tableHasRows) {
400
            try {
401
              the_system_id = rs.getString(1);
402
            } catch (SQLException e) {
403
              System.out.println("Error with getString in " +
404
                                 "DBTransform.getSystemId: " + e.getMessage());
405
            }
406
          } else {
407
            the_system_id = null;
408
          }
409
        } catch (SQLException e) {
410
          System.err.println("Error with next in DBTransform.getSystemId: " +
411
                              e.getMessage());
412
          return ("Error with next: " + e.getMessage());
413
        }
414
      } catch (SQLException e) {
415
        System.err.println("Error with getrset in DBTransform.getSystemId: " +
416
                            e.getMessage());
417
        return ("Error with getrset: " + e.getMessage());
418
      }
419
      pstmt.close();
420
    } catch (SQLException e) {
421
      System.err.println("Error getting id in DBTransform.getSystemId: " +
422
                          e.getMessage());
423
      return ("Error getting id in DBTransform.getSystemId:: " +
424
               e.getMessage());
370
 /* Method to modified the system id of xml input -- make sure it
371
    points to system id in xml_catalog table
372
  */
373
  private void modifiedXmlStreamSource(StreamSource xml, String publicId)   
374
                                       throws Exception
375
  {
376
    // make sure the xml is not null
377
    if (xml == null || publicId == null)
378
    {
379
      return;
425 380
    }
426
    finally
427
    {
428
      try
429
      {
430
        pstmt.close();
431
      }//try
432
      catch (SQLException sqlE)
433
      {
434
        MetaCatUtil.debugMessage("Error in DBTransform.getSystemId: "
435
                                   +sqlE.getMessage(), 30);
436
      }//catch
437
      finally
438
      {
439
        DBConnectionPool.returnDBConnection(dbConn, serialNumber);
440
      }//finally
441
    }//finally
442
    return the_system_id;
381
    MetaCatUtil.debugMessage("public id of input stream is " +publicId, 25);
382
    // Get system id from xml_catalog table
383
    String systemId = DBEntityResolver.getDTDSystemID(publicId);
384
    MetaCatUtil.debugMessage("system id of input stream from xml_catalog"
385
                               +"table is " +systemId, 25);
386
    //set system id to input stream
387
    xml.setSystemId(systemId);
443 388
  }
444 389

  
445 390
  /**

Also available in: Unified diff