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 13:46:21 -0800 (Thu, 18 Jan 2001) $'
15
 * '$Revision: 674 $'
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("EXCEPTION HANDLING REQUIRED");
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: " + e.getMessage());
241
              }
242
              
243
              docid   = xmldoc.getDocID();
244
              docname = xmldoc.getDocname();
245
              doctype = xmldoc.getDoctype();
246
              doctitle = xmldoc.getDocTitle();
247
              createDate = xmldoc.getCreateDate();
248
              updateDate = xmldoc.getUpdateDate();
249
              //System.out.println("docname: " + docname + " doctype: " + doctype + 
250
              //                   " doctitle: " + doctitle + " createdate: " +
251
              //                   createDate + " updatedate: " + updateDate);
252
            }
253
            npstmt.close();
254
            btrs.close();
255
          }
256
          
257
          document = new StringBuffer();
258
          //System.out.println("packagdoctype: " + util.getOption("packagedoctype"));
259
          //if(!doctype.equals(util.getOption("packagedoctype")))
260
          {
261
            String completeDocid = docid + util.getOption("accNumSeparator");
262
            completeDocid += rev;
263
            document.append("<docid>").append(completeDocid).append("</docid>");
264
            if (docname != null) {
265
              document.append("<docname>" + docname + "</docname>");
266
            }
267
            if (doctype != null) {
268
              document.append("<doctype>" + doctype + "</doctype>");
269
            }
270
            if (doctitle != null) {
271
              document.append("<doctitle>" + doctitle + "</doctitle>");
272
            }
273
            if(createDate != null) {
274
              document.append("<createdate>" + createDate + "</createdate>");
275
            }
276
            if(updateDate != null) {
277
              document.append("<updatedate>" + updateDate + "</updatedate>");
278
            }
279
            // Store the document id and the root node id
280
            docListResult.put(docid,(String)document.toString());
281
          }
282

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

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

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

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

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

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

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

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

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

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