Project

General

Profile

« Previous | Next » 

Revision 1514

Added by Jing Tao over 21 years ago

Add a new class to handle nested subtree access control.

View differences:

src/edu/ucsb/nceas/metacat/FilteredSubTree.java
1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A Class that represents an XML Text node and its contents,
4
 *             and can build itself from a database connection
5
 *  Copyright: 2000 Regents of the University of California and the
6
 *             National Center for Ecological Analysis and Synthesis
7
 *    Authors: Matt Jones
8
 *    Release: @release@
9
 *
10
 *   '$Author$'
11
 *     '$Date$'
12
 * '$Revision$'
13
 *
14
 * This program is free software; you can redistribute it and/or modify
15
 * it under the terms of the GNU General Public License as published by
16
 * the Free Software Foundation; either version 2 of the License, or
17
 * (at your option) any later version.
18
 *
19
 * This program is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 * GNU General Public License for more details.
23
 *
24
 * You should have received a copy of the GNU General Public License
25
 * along with this program; if not, write to the Free Software
26
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27
 */
28

  
29
package edu.ucsb.nceas.metacat;
30

  
31
import java.util.Stack;
32
import java.sql.PreparedStatement;
33
import java.sql.SQLException;
34
import java.sql.ResultSet;
35

  
36

  
37
/**
38
 * A Class that represents an Filtered XML Subtree, it means a subtree which 
39
 * contains another subtree has different access behavor to it.
40
 * for example, we have subtree A, it is not readable to user John. But in 
41
 * subtree A, it contains a subtree B which is readable to user John 
42
 */
43
public class FilteredSubTree
44
{
45
  private String docId = null;
46
  private String subTreeId = null;
47
  private String startElementName = null;
48
  private long   startNodeId = -1;
49
  private long   endNodeId =   -1;
50
 
51
    
52
    /**
53
     * Constructor of subtree
54
     */
55
    public FilteredSubTree(String myDocId, String mySubTreeId, 
56
                  long myStartNodeId, long myEndNodeId)
57
                  throws McdbException
58
    {
59
      this.docId = myDocId;
60
      MetaCatUtil.debugMessage("Docid of FilteredSubtree: " + docId, 30);
61
      this.subTreeId = mySubTreeId;
62
      MetaCatUtil.debugMessage("id of FilteredSubtree: " + subTreeId, 30);
63
      this.startNodeId = myStartNodeId;
64
      MetaCatUtil.debugMessage("start node id of FilteredSubtree: " + 
65
                                startNodeId, 30);
66
      this.endNodeId = myEndNodeId;
67
      MetaCatUtil.debugMessage("end node id of FilteredSubtree: " + endNodeId, 30);
68
     }
69
    
70
  
71
 
72
    /** Set the a docId */
73
    public void setDocId(String myId)
74
    {
75
      MetaCatUtil.debugMessage("set doc id: "+myId, 35);
76
      this.docId = myId;
77
    }
78

  
79
    /** Get the docId */
80
    public String getDocId() 
81
    {
82
      return this.docId;
83
    }
84

  
85
 
86
    /** Set the a subtreeId */
87
    public void setSubTreeId(String myId)
88
    {
89
      MetaCatUtil.debugMessage("set sub tree id: "+myId, 35);
90
      this.subTreeId = myId;
91
    }
92

  
93
    /** Get the subTreeId */
94
    public String getSubTreeId() 
95
    {
96
      return this.subTreeId;
97
    }
98

  
99
    /** 
100
     * Set a startElementName
101
     */
102
    public void setStartElementName(String elementName) 
103
    {
104
      MetaCatUtil.debugMessage("set start elementname: "+elementName, 35);
105
      this.startElementName = elementName;
106
    }
107
    
108
    /**
109
     * Get startElementName
110
     */
111
    public String getStartElementName()
112
    {
113
      return this.startElementName;
114
    }
115
    
116
    /** Set a start node id */
117
    public void setStartNodeId(long nodeId)
118
    {
119
      MetaCatUtil.debugMessage("set start node id: "+nodeId, 35);
120
      this.startNodeId = nodeId;
121
    }
122
    
123
    /** Get start node id */
124
    public long getStartNodeId()
125
    {
126
      return this.startNodeId;
127
    }
128
    
129
    /** Set a end node id */
130
    public void setEndNodeId(long nodeId)
131
    {
132
      MetaCatUtil.debugMessage("set end node id: "+nodeId, 35);
133
      this.endNodeId = nodeId;
134
    }
135
    
136
    /** Get end node id */
137
    public long getEndNodeId()
138
    {
139
      return this.endNodeId;
140
    }
141
    
142
    /* Put a subtree node into a stack, on top is the start point of subtree*/
143
    private Stack getSubTreeNodeList() throws McdbException
144
    {
145
       PreparedStatement pstmt = null;
146
       DBConnection dbconn = null;
147
       int serialNumber = -1;
148
       Stack nodeRecordList = new Stack();
149
       long nodeid = 0;
150
       long parentnodeid = 0;
151
       long nodeindex = 0;
152
       String nodetype = null;
153
       String nodename = null;
154
       String nodeprefix = null;
155
       String nodedata = null;
156
       String sql = "SELECT nodeid, parentnodeid, nodeindex, " +
157
                    "nodetype, nodename, nodeprefix, nodedata " +               
158
                    "FROM xml_nodes WHERE docid = ? AND nodeid >= ? AND " +
159
                    "nodeid <= ? ORDER BY nodeid DESC";
160
       try 
161
       {
162
         dbconn=DBConnectionPool.
163
                    getDBConnection("SubTree.getSubTreeNodeList");
164
         serialNumber=dbconn.getCheckOutSerialNumber();
165
         pstmt = dbconn.prepareStatement(sql);
166

  
167
         // Bind the values to the query
168
         pstmt.setString(1, docId);
169
         pstmt.setLong(2, startNodeId);
170
         pstmt.setLong(3, endNodeId);
171

  
172
         pstmt.execute();
173
         ResultSet rs = pstmt.getResultSet();
174
         boolean tableHasRows = rs.next();
175
        
176
         while (tableHasRows) 
177
         {
178
           nodeid = rs.getLong(1);
179
           parentnodeid = rs.getLong(2);
180
           nodeindex = rs.getLong(3);
181
           nodetype = rs.getString(4);
182
           nodename = rs.getString(5);
183
           nodeprefix = rs.getString(6);
184
           nodedata = rs.getString(7);
185
           nodedata = MetaCatUtil.normalize(nodedata);
186
           // add the data to the node record list hashtable
187
           NodeRecord currentRecord = new NodeRecord(nodeid,parentnodeid,nodeindex,
188
                                      nodetype, nodename, nodeprefix, nodedata);
189
           nodeRecordList.push(currentRecord);
190

  
191
           // Advance to the next node
192
           tableHasRows = rs.next();
193
         }//while
194
         pstmt.close();
195

  
196
      } //try
197
      catch (SQLException e) 
198
      {
199
        throw new McdbException("Error in SubTree.getSubTreeNodeList 1 " +
200
                              e.getMessage());
201
      }//catch
202
      finally
203
      {
204
        try
205
        {
206
          pstmt.close();
207
        }
208
        catch (SQLException ee)
209
        {
210
          MetaCatUtil.debugMessage("error in SubTree.getSubTreeNodeList 2: "
211
                                    +ee.getMessage(), 30);
212
        }
213
        finally
214
        {
215
          DBConnectionPool.returnDBConnection(dbconn, serialNumber);
216
        }
217
      }//finally
218
  
219
      return nodeRecordList;
220
   
221
    }//getSubtreeNodeList
222
    
223
    public static void main (String agus)
224
    {
225
      
226
    }
227
}
0 228

  

Also available in: Unified diff