Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A Class that searches a relational DB for elements and 
4
 *             attributes that have free text matches a query string,
5
 *             or structured query matches to a path specified node in the 
6
 *             XML hierarchy.  It returns a result set consisting of the 
7
 *             document ID for each document that satisfies the query
8
 *  Copyright: 2000 Regents of the University of California and the
9
 *             National Center for Ecological Analysis and Synthesis
10
 *    Authors: Matt Jones
11
 *    Release: @release@
12
 *
13
 *   '$Author: berkley $'
14
 *     '$Date: 2001-01-18 15:15:21 -0800 (Thu, 18 Jan 2001) $'
15
 * '$Revision: 675 $'
16
 *
17
 * This program is free software; you can redistribute it and/or modify
18
 * it under the terms of the GNU General Public License as published by
19
 * the Free Software Foundation; either version 2 of the License, or
20
 * (at your option) any later version.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 * GNU General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU General Public License
28
 * along with this program; if not, write to the Free Software
29
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
30
 */
31

    
32
package edu.ucsb.nceas.metacat;
33

    
34
import java.io.*;
35
import java.util.Vector;
36
import java.net.URL;
37
import java.net.MalformedURLException;
38
import java.sql.*;
39
import java.util.Stack;
40
import java.util.Hashtable;
41
import java.util.Enumeration;
42

    
43
/** 
44
 * A Class that searches a relational DB for elements and 
45
 * attributes that have free text matches a query string,
46
 * or structured query matches to a path specified node in the 
47
 * XML hierarchy.  It returns a result set consisting of the 
48
 * document ID for each document that satisfies the query
49
 */
50
public class DBQuery {
51

    
52
  static final int ALL = 1;
53
  static final int WRITE = 2;
54
  static final int READ = 4;
55

    
56
  private Connection  conn = null;
57
  private String  parserName = null;
58
  private MetaCatUtil util = new MetaCatUtil();
59
  /**
60
   * the main routine used to test the DBQuery utility.
61
   * <p>
62
   * Usage: java DBQuery <xmlfile>
63
   *
64
   * @param xmlfile the filename of the xml file containing the query
65
   */
66
  static public void main(String[] args) {
67
     
68
     if (args.length < 1)
69
     {
70
        System.err.println("Wrong number of arguments!!!");
71
        System.err.println("USAGE: java DBQuery <xmlfile>");
72
        return;
73
     } else {
74
        try {
75
                    
76
          String xmlfile  = args[0];
77

    
78
          // Open a connection to the database
79
          MetaCatUtil   util = new MetaCatUtil();
80
          Connection dbconn = util.openDBConnection();
81

    
82
          // Execute the query
83
          DBQuery queryobj = new DBQuery(dbconn, util.getOption("saxparser"));
84
          FileReader xml = new FileReader(new File(xmlfile));
85
          Hashtable nodelist = null;
86
          nodelist = queryobj.findDocuments(xml, null, null);
87

    
88
          // Print the reulting document listing
89
          StringBuffer result = new StringBuffer();
90
          String document = null;
91
          String docid = null;
92
          result.append("<?xml version=\"1.0\"?>\n");
93
          result.append("<resultset>\n"); 
94
  // following line removed by Dan Higgins to avoid insertion of query XML inside returned XML doc
95
  //        result.append("  <query>" + xmlfile + "</query>\n");
96
          Enumeration doclist = nodelist.keys(); 
97
          while (doclist.hasMoreElements()) {
98
            docid = (String)doclist.nextElement();
99
            document = (String)nodelist.get(docid);
100
            result.append("  <document>\n    " + document + 
101
                          "\n  </document>\n");
102
          }
103
          result.append("</resultset>\n");
104

    
105
          System.out.println(result);
106

    
107
        } catch (Exception e) {
108
          System.err.println("Error in DBQuery.main");
109
          System.err.println(e.getMessage());
110
          e.printStackTrace(System.err);
111
        }
112
     }
113
  }
114
  
115
  /**
116
   * construct an instance of the DBQuery class 
117
   *
118
   * <p>Generally, one would call the findDocuments() routine after creating 
119
   * an instance to specify the search query</p>
120
   *
121
   * @param conn the JDBC connection that we use for the query
122
   * @param parserName the fully qualified name of a Java class implementing
123
   *                   the org.xml.sax.XMLReader interface
124
   */
125
  public DBQuery( Connection conn, String parserName ) 
126
                  throws IOException, 
127
                         SQLException, 
128
                         ClassNotFoundException {
129
    this.conn = conn;
130
    this.parserName = parserName;
131
  }
132
  
133
  public Hashtable findDocuments(Reader xmlquery, String user, String group)
134
  {
135
    return findDocuments(xmlquery, user, group, null);
136
  }
137
  
138
  /** 
139
   * routine to search the elements and attributes looking to match query
140
   *
141
   * @param xmlquery the xml serialization of the query (@see pathquery.dtd)
142
   * @param user the username of the user
143
   * @param group the group of the user
144
   * @param returndoc an array of document types to backtrack against.
145
   */
146
  public Hashtable findDocuments(Reader xmlquery, String user, String group,
147
                                 String[] returndoc)
148
  {
149
    //System.out.println("in finddocuments");
150
      Hashtable   docListResult = new Hashtable();
151
      PreparedStatement pstmt = null;
152
      String docid = null;
153
      String docname = null;
154
      String doctype = null;
155
      String doctitle = null;
156
      String createDate = null;
157
      String updateDate = null;
158
      String fieldname = null;
159
      String fielddata = null;
160
      String relation = null;
161
      Connection dbconn = null;
162
      int rev = 0;
163
      StringBuffer document = null; 
164
      Vector returndocVec = new Vector();
165
      
166
      if(returndoc != null)
167
      {//add the returndoc elements to a vector for easier manipulation
168
        for(int i=0; i<returndoc.length; i++)
169
        {
170
          returndocVec.add(new String((String)returndoc[i]));
171
        }
172
      }
173
      
174
      try {
175
        dbconn = util.openDBConnection();
176
        // Get the XML query and covert it into a SQL statment
177
        QuerySpecification qspec = new QuerySpecification(xmlquery, 
178
                                   parserName, 
179
                                   util.getOption("accNumSeparator"));
180
       // System.out.println(qspec.printSQL());
181
        pstmt = dbconn.prepareStatement( qspec.printSQL() );
182

    
183
        // Execute the SQL query using the JDBC connection
184
        pstmt.execute();
185
        ResultSet rs = pstmt.getResultSet();
186
        boolean tableHasRows = rs.next();
187
        while (tableHasRows) 
188
        {
189
          docid = rs.getString(1);
190
          if ( !hasPermission(dbconn, user, group, docid) ) {
191
            // Advance to the next record in the cursor
192
            tableHasRows = rs.next();
193
            continue;
194
          }
195
          docname = rs.getString(2);
196
          doctype = rs.getString(3);
197
          doctitle = rs.getString(4);
198
          createDate = rs.getString(5);
199
          updateDate = rs.getString(6);
200
          rev = rs.getInt(7);
201
          
202
          //System.out.println("vec.size = " + returndocVec.size());
203
          if(returndocVec.size() != 0 && !returndocVec.contains(doctype))
204
          { //there are returndocs to match (backtracking can now be performed). 
205
            //System.out.println("olddoctype: " + doctype);
206
            StringBuffer btBuf = new StringBuffer();
207
            btBuf.append("select object from xml_relation where ");
208
            btBuf.append("objdoctype in (");
209
            //build the doctype list for the backtracking sql statement
210
            for(int i=0; i<returndocVec.size(); i++)
211
            {
212
              btBuf.append("'").append((String)returndocVec.get(i)).append("'");
213
              if(i != (returndocVec.size() - 1))
214
              {
215
                btBuf.append(", ");
216
              } 
217
            }
218
            btBuf.append(") ");
219
            btBuf.append("and subject like '");
220
            //btBuf.append("metacat://").append(util.getOption("server"));
221
            //btBuf.append("?docid=").append(docid).append("'");
222
            btBuf.append("%docid=").append(docid).append("'");
223
            //System.out.println("sql: " + btBuf.toString());
224
            
225
            PreparedStatement npstmt = dbconn.prepareStatement(btBuf.toString());
226
            npstmt.execute();
227
            ResultSet btrs = npstmt.getResultSet();
228
            boolean hasBtRows = btrs.next();
229
            if(hasBtRows)
230
            { //there was a backtrackable document found
231
              DocumentImpl xmldoc = null;
232
              //System.out.println("document found is: " + btrs.getString(1));
233
              MetacatURL objURL = new MetacatURL(btrs.getString(1));
234
              try
235
              {
236
                xmldoc = new DocumentImpl(dbconn, objURL.getParam(0)[1]);
237
              }
238
              catch(Exception e)
239
              {
240
                System.out.println("Error getting document in " + 
241
                                   "DBQuery.findDocuments: " + e.getMessage());
242
              }
243
              
244
              docid   = xmldoc.getDocID();
245
              docname = xmldoc.getDocname();
246
              doctype = xmldoc.getDoctype();
247
              doctitle = xmldoc.getDocTitle();
248
              createDate = xmldoc.getCreateDate();
249
              updateDate = xmldoc.getUpdateDate();
250
              //System.out.println("docname: " + docname + " doctype: " + doctype + 
251
              //                   " doctitle: " + doctitle + " createdate: " +
252
              //                   createDate + " updatedate: " + updateDate);
253
            }
254
            npstmt.close();
255
            btrs.close();
256
          }
257
          
258
          document = new StringBuffer();
259
          //System.out.println("packagdoctype: " + util.getOption("packagedoctype"));
260
          //if(!doctype.equals(util.getOption("packagedoctype")))
261
          {
262
            String completeDocid = docid + util.getOption("accNumSeparator");
263
            completeDocid += rev;
264
            document.append("<docid>").append(completeDocid).append("</docid>");
265
            if (docname != null) {
266
              document.append("<docname>" + docname + "</docname>");
267
            }
268
            if (doctype != null) {
269
              document.append("<doctype>" + doctype + "</doctype>");
270
            }
271
            if (doctitle != null) {
272
              document.append("<doctitle>" + doctitle + "</doctitle>");
273
            }
274
            if(createDate != null) {
275
              document.append("<createdate>" + createDate + "</createdate>");
276
            }
277
            if(updateDate != null) {
278
              document.append("<updatedate>" + updateDate + "</updatedate>");
279
            }
280
            // Store the document id and the root node id
281
            docListResult.put(docid,(String)document.toString());
282
          }
283

    
284
          // Advance to the next record in the cursor
285
          tableHasRows = rs.next();
286
        }
287
        rs.close();
288
        //pstmt.close();
289
        
290
        if(qspec.containsExtendedSQL())
291
        {
292
          Vector extendedFields = new Vector(qspec.getReturnFieldList());
293
          Vector results = new Vector();
294
          Enumeration keylist = docListResult.keys();
295
          StringBuffer doclist = new StringBuffer();
296
          while(keylist.hasMoreElements())
297
          {
298
            doclist.append("'");
299
            doclist.append((String)keylist.nextElement());
300
            doclist.append("',");
301
          }
302
          doclist.deleteCharAt(doclist.length()-1); //remove the last comma
303
          pstmt.close();
304
          pstmt = dbconn.prepareStatement(qspec.printExtendedSQL(
305
                                        doclist.toString()));
306
          pstmt.execute();
307
          rs = pstmt.getResultSet();
308
          tableHasRows = rs.next();
309
          while(tableHasRows) 
310
          {
311
            docid = rs.getString(1);
312
            if ( !hasPermission(dbconn, user, group, docid) ) {
313
              // Advance to the next record in the cursor
314
              tableHasRows = rs.next();
315
              continue;
316
            }
317
            fieldname = rs.getString(2);
318
            fielddata = rs.getString(3);
319
            
320
            document = new StringBuffer();
321

    
322
            document.append("<param name=\"");
323
            document.append(fieldname);
324
            document.append("\">");
325
            document.append(fielddata);
326
            document.append("</param>");
327

    
328
            tableHasRows = rs.next();
329
            if(docListResult.containsKey(docid))
330
            {
331
              String removedelement = (String)docListResult.remove(docid);
332
              docListResult.put(docid, removedelement + document.toString());
333
            }
334
            else
335
            {
336
              docListResult.put(docid, document.toString()); 
337
            }
338
          }
339
          rs.close();
340
        }
341

    
342
        //this loop adds the relation data to the resultdoc
343
        //this code might be able to be added to the backtracking code above
344
        Enumeration docidkeys = docListResult.keys();
345
        while(docidkeys.hasMoreElements())
346
        {
347
          //String connstring = "metacat://"+util.getOption("server")+"?docid=";
348
          String connstring = "%docid=";
349
          String docidkey = (String)docidkeys.nextElement();
350
          //System.out.println("relationsql: " + qspec.printRelationSQL(
351
          //                                           connstring + docidkey));
352
          pstmt.close();
353
          pstmt = dbconn.prepareStatement(
354
                  qspec.printRelationSQL(connstring + docidkey));
355
          pstmt.execute();
356
          rs = pstmt.getResultSet();
357
          tableHasRows = rs.next();
358
          while(tableHasRows)
359
          {
360
            String sub = rs.getString(1);
361
            String rel = rs.getString(2);
362
            String obj = rs.getString(3);
363
            String subDT = rs.getString(4);
364
            String objDT = rs.getString(5);
365
            
366
            MetacatURL murl = new MetacatURL(sub);
367
            if(murl.getProtocol().equals("metacat"))
368
            {//we only want to process metacat urls here.
369
              String[] tempparam = murl.getParam(0);
370
              if(tempparam[0].equals("docid") && tempparam[1].equals(docidkey))
371
              {
372
                document = new StringBuffer();
373
                document.append("<relation>");
374
                document.append("<relationtype>").append(rel);
375
                document.append("</relationtype>");
376
                document.append("<relationdoc>").append(obj);
377
                document.append("</relationdoc>");
378
                document.append("<relationdoctype>").append(objDT);
379
                document.append("</relationdoctype>");
380
                document.append("</relation>");
381
                
382
                String removedelement = (String)docListResult.remove(docidkey);
383
                docListResult.put(docidkey, removedelement + document.toString());
384
                
385
              }
386
            }
387
            tableHasRows = rs.next();
388
          }
389
          rs.close();
390
          pstmt.close();
391
        }
392
        
393
      } catch (SQLException e) {
394
        System.err.println("SQL Error in DBQuery.findDocuments: " + 
395
                           e.getMessage());
396
      } catch (IOException ioe) {
397
        System.err.println("IO error in DBQuery.findDocuments:");
398
        System.err.println(ioe.getMessage());
399
      } catch (Exception ee) {
400
        System.out.println("Exception in DBQuery.findDocuments: " + 
401
                           ee.getMessage());
402
      }
403
      finally {
404
        try
405
        {
406
          dbconn.close();
407
        }
408
        catch(SQLException sqle)
409
        {
410
          System.out.println("error closing conn in DBQuery.findDocuments");
411
        }
412
      }
413
    //System.out.println("docListResult: ");
414
    //System.out.println(docListResult.toString());
415
    return docListResult;
416
  }
417
  
418
  /**
419
   * returns a string array of the contents of a particular node. 
420
   * If the node appears more than once, the contents are returned 
421
   * in the order in which they appearred in the document.
422
   * @param nodename the name or path of the particular node.
423
   * @param docid the docid of the document you want the node from.
424
   * @param conn a database connection-this allows this method to be static
425
   */
426
  public static Object[] getNodeContent(String nodename, String docid, 
427
                                        Connection conn)
428
  {
429
    StringBuffer query = new StringBuffer();
430
    Vector result = new Vector();
431
    PreparedStatement pstmt = null;
432
    query.append("select nodedata from xml_nodes where parentnodeid in ");
433
    query.append("(select nodeid from xml_index where path like '");
434
    query.append(nodename);
435
    query.append("' and docid like '").append(docid).append("')");
436
    try
437
    {
438
      pstmt = conn.prepareStatement(query.toString());
439

    
440
      // Execute the SQL query using the JDBC connection
441
      pstmt.execute();
442
      ResultSet rs = pstmt.getResultSet();
443
      boolean tableHasRows = rs.next();
444
      while (tableHasRows) 
445
      {
446
        result.add(rs.getString(1));
447
        System.out.println(rs.getString(1));
448
        tableHasRows = rs.next();
449
      }
450
    } 
451
    catch (SQLException e) 
452
    {
453
      System.err.println("Error in DBQuery.getNodeContent: " + e.getMessage());
454
    } finally {
455
      try
456
      {
457
        pstmt.close();
458
      }
459
      catch(SQLException sqle) {}
460
    }
461
    return result.toArray();
462
  }
463
  
464
  /**
465
   * format a structured query as an XML document that conforms
466
   * to the pathquery.dtd and is appropriate for submission to the DBQuery
467
   * structured query engine
468
   *
469
   * @param params The list of parameters that  should be included in the query
470
   */
471
  public static String createSQuery(Hashtable params)
472
  { 
473
    StringBuffer query = new StringBuffer();
474
    Enumeration elements;
475
    Enumeration keys;
476
    String doctype = null;
477
    String casesensitive = null;
478
    String searchmode = null;
479
    Object nextkey;
480
    Object nextelement;
481
    //add the xml headers
482
    query.append("<?xml version=\"1.0\"?>\n");
483
    query.append("<pathquery version=\"1.0\"><meta_file_id>");
484
    
485
    if(params.containsKey("meta_file_id"))
486
    {
487
      query.append( ((String[])params.get("meta_file_id"))[0]);
488
      query.append("</meta_file_id>");
489
    }
490
    else
491
    {
492
      query.append("unspecified</meta_file_id>");
493
    }
494
    
495
    query.append("<querytitle>");
496
    if(params.containsKey("querytitle"))
497
    {
498
      query.append(((String[])params.get("querytitle"))[0]);
499
      query.append("</querytitle>");
500
    }
501
    else
502
    {
503
      query.append("unspecified</querytitle>");
504
    }
505
    
506
    if(params.containsKey("doctype"))
507
    {
508
      doctype = ((String[])params.get("doctype"))[0]; 
509
    }
510
    else
511
    {
512
      doctype = "ANY";  
513
    }
514
    
515
    if(params.containsKey("returnfield"))
516
    {
517
      String[] returnfield = ((String[])params.get("returnfield"));
518
      for(int i=0; i<returnfield.length; i++)
519
      {
520
        query.append("<returnfield>").append(returnfield[i]);
521
        query.append("</returnfield>");
522
      }
523
    }
524
    
525
    if(params.containsKey("owner"))
526
    {
527
      String[] owner = ((String[])params.get("owner"));
528
      for(int i=0; i<owner.length; i++)
529
      {
530
        query.append("<owner>").append(owner[i]);
531
        query.append("</owner>");
532
      }
533
    }
534
    
535
    if(params.containsKey("site"))
536
    {
537
      String[] site = ((String[])params.get("site"));
538
      for(int i=0; i<site.length; i++)
539
      {
540
        query.append("<site>").append(site[i]);
541
        query.append("</site>");
542
      }
543
    }
544
    
545
    //if you don't limit the query by doctype, then it just creates
546
    //an empty returndoctype tag.
547
    if (!doctype.equals("any") && 
548
        !doctype.equals("ANY") &&
549
        !doctype.equals("") ) 
550
    {
551
       query.append("<returndoctype>");
552
       query.append(doctype).append("</returndoctype>");
553
    }
554
    else
555
    { 
556
      query.append("<returndoctype></returndoctype>");
557
    }
558
    
559
    //allows the dynamic switching of boolean operators
560
    if(params.containsKey("operator"))
561
    {
562
      query.append("<querygroup operator=\"" + 
563
                ((String[])params.get("operator"))[0] + "\">");
564
    }
565
    else
566
    { //the default operator is UNION
567
      query.append("<querygroup operator=\"UNION\">"); 
568
    }
569
        
570
    if(params.containsKey("casesensitive"))
571
    {
572
      casesensitive = ((String[])params.get("casesensitive"))[0]; 
573
    }
574
    else
575
    {
576
      casesensitive = "false"; 
577
    }
578
    
579
    if(params.containsKey("searchmode"))
580
    {
581
      searchmode = ((String[])params.get("searchmode"))[0]; 
582
    }
583
    else
584
    {
585
      searchmode = "contains"; 
586
    }
587
        
588
    //anyfield is a special case because it does a 
589
    //free text search.  It does not have a <pathexpr>
590
    //tag.  This allows for a free text search within the structured
591
    //query.  This is useful if the INTERSECT operator is used.
592
    if(params.containsKey("anyfield"))
593
    {
594
       String[] anyfield = ((String[])params.get("anyfield"));
595
       //allow for more than one value for anyfield
596
       for(int i=0; i<anyfield.length; i++)
597
       {
598
         if(!anyfield[i].equals(""))
599
         {
600
           query.append("<queryterm casesensitive=\"" + casesensitive + 
601
                        "\" " + "searchmode=\"" + searchmode + "\"><value>" +
602
                        anyfield[i] +
603
                        "</value></queryterm>"); 
604
         }
605
       }
606
    }
607
        
608
    //this while loop finds the rest of the parameters
609
    //and attempts to query for the field specified
610
    //by the parameter.
611
    elements = params.elements();
612
    keys = params.keys();
613
    while(keys.hasMoreElements() && elements.hasMoreElements())
614
    {
615
      nextkey = keys.nextElement();
616
      nextelement = elements.nextElement();
617

    
618
      //make sure we aren't querying for any of these
619
      //parameters since the are already in the query
620
      //in one form or another.
621
      if(!nextkey.toString().equals("doctype") && 
622
         !nextkey.toString().equals("action")  &&
623
         !nextkey.toString().equals("qformat") && 
624
         !nextkey.toString().equals("anyfield") &&
625
         !nextkey.toString().equals("returnfield") &&
626
         !nextkey.toString().equals("owner") &&
627
         !nextkey.toString().equals("site") &&
628
         !nextkey.toString().equals("operator") )
629
      {
630
        //allow for more than value per field name
631
        for(int i=0; i<((String[])nextelement).length; i++)
632
        {
633
          if(!((String[])nextelement)[i].equals(""))
634
          {
635
            query.append("<queryterm casesensitive=\"" + casesensitive +"\" " + 
636
                         "searchmode=\"" + searchmode + "\">" +
637
                         "<value>" +
638
                         //add the query value
639
                         ((String[])nextelement)[i] +
640
                         "</value><pathexpr>" +
641
                         //add the path to query by 
642
                         nextkey.toString() + 
643
                         "</pathexpr></queryterm>");
644
          }
645
        }
646
      }
647
    }
648
    query.append("</querygroup></pathquery>");
649
    //append on the end of the xml and return the result as a string
650
    return query.toString();
651
  }
652
  
653
  /**
654
   * format a simple free-text value query as an XML document that conforms
655
   * to the pathquery.dtd and is appropriate for submission to the DBQuery
656
   * structured query engine
657
   *
658
   * @param value the text string to search for in the xml catalog
659
   * @param doctype the type of documents to include in the result set -- use
660
   *        "any" or "ANY" for unfiltered result sets
661
   */
662
   public static String createQuery(String value, String doctype) {
663
     StringBuffer xmlquery = new StringBuffer();
664
     xmlquery.append("<?xml version=\"1.0\"?>\n");
665
     xmlquery.append("<pathquery version=\"1.0\">");
666
     xmlquery.append("<meta_file_id>Unspecified</meta_file_id>");
667
     xmlquery.append("<querytitle>Unspecified</querytitle>");
668

    
669
     if (!doctype.equals("any") && !doctype.equals("ANY")) {
670
       xmlquery.append("<returndoctype>");
671
       xmlquery.append(doctype).append("</returndoctype>");
672
     }
673

    
674
     xmlquery.append("<querygroup operator=\"UNION\">");
675
     //chad added - 8/14
676
     //the if statement allows a query to gracefully handle a null 
677
     //query.  Without this if a nullpointerException is thrown.
678
     if(!value.equals(""))
679
     {
680
       xmlquery.append("<queryterm casesensitive=\"false\" ");
681
       xmlquery.append("searchmode=\"contains\">");
682
       xmlquery.append("<value>").append(value).append("</value>");
683
       xmlquery.append("</queryterm>");
684
     }
685
     xmlquery.append("</querygroup>");
686
     xmlquery.append("</pathquery>");
687

    
688
     
689
     return (xmlquery.toString());
690
   }
691

    
692
  /**
693
   * format a simple free-text value query as an XML document that conforms
694
   * to the pathquery.dtd and is appropriate for submission to the DBQuery
695
   * structured query engine
696
   *
697
   * @param value the text string to search for in the xml catalog
698
   */
699
   public static String createQuery(String value) {
700
     return createQuery(value, "any");
701
   }
702
   
703
  /** 
704
    * Check for "READ" permission on @docid for @user and/or @group 
705
    * from DB connection 
706
    */
707
  private boolean hasPermission ( Connection conn, String user,
708
                                  String group, String docid ) 
709
                  throws SQLException
710
  {
711
    // b' of the command line invocation
712
    if ( (user == null) && (group == null) ) {
713
      return true;
714
    }
715
    
716
    // Check for READ permission on @docid for @user and/or @group
717
    AccessControlList aclobj = new AccessControlList(conn);
718
    boolean hasPermission = aclobj.hasPermission("READ",user,docid);
719
    if ( !hasPermission && group != null ) {
720
      hasPermission = aclobj.hasPermission("READ",group,docid);
721
    }
722
    
723
    return hasPermission;
724
  }
725
   
726
}
(14-14/43)