Project

General

Profile

« Previous | Next » 

Revision 1417

Added by Jing Tao almost 22 years ago

Add code to handle subtree.

View differences:

src/edu/ucsb/nceas/metacat/EmlSAXHandler.java
62 62
   private Hashtable additionalAccessControlMap = new Hashtable();
63 63
   private Vector describesId = new Vector(); // store the ids in
64 64
                                      //additionalmetadata/describes
65
   private Stack subTreeInfoStack = new Stack();
66
   private Vector subTreeList = new Vector();// store the final subtree
65 67
 
68
 
66 69
   // Constant
67 70
   private static final String DESCRIBES = "describes";
68 71
   private static final String ADDITIONALMETADATA = "additionalMetadata";
......
136 139
     if (hitTextNode && parentNode != null)
137 140
     {
138 141
       // write the textbuffer into db for parent node.
139
        writeTextForDBSAXNode(textBuffer, parentNode);
142
        endNodeId = writeTextForDBSAXNode(textBuffer, parentNode);
140 143
        // rest hitTextNode
141 144
        hitTextNode =false;
142 145
        // reset textbuffer
......
145 148
       
146 149
     }
147 150
     
151
  
148 152
     // Document representation that points to the root document node
149 153
     if (atFirstElement) 
150 154
     {
......
175 179
         MetaCatUtil.debugMessage("DOCTYPE-b: " + doctype, 30);
176 180
       }
177 181
       rootNode.writeNodename(docname);
178
       try {
182
       try 
183
       {
179 184
         // for validated XML Documents store a reference to XML DB Catalog
180 185
         // Because this is select statement and it needn't to roll back if
181 186
         // insert document action fialed.
......
185 190
         DBConnection dbConn = null;
186 191
         int serialNumber = -1;
187 192

  
188
         if ( systemid != null ) {
193
         if ( systemid != null ) 
194
         {
189 195
           try
190 196
           {
191 197
            // Get dbconnection
......
218 224
                               this.pub, catalogid, this.serverCode);
219 225

  
220 226

  
221
       } catch (Exception ane) {
227
       } 
228
       catch (Exception ane) 
229
       {
222 230
         throw (new SAXException("Error in DBSaxHandler.startElement " +
223 231
                                 action, ane));
224 232
       }
......
228 236
     currentNode = new DBSAXNode(connection, qName, localName, parentNode,
229 237
                                 currentDocument.getRootNodeID(),docid,
230 238
                                 currentDocument.getDoctype());
231

  
239
     // Use a local variable to store the element node id
240
     // If this element is a start point of subtree(section), it will be stored
241
     // otherwise, it will be discated
242
     long startNodeId = currentNode.getNodeID();
232 243
     // Add all of the namespaces
233 244
     String prefix;
234 245
     String nsuri;
235 246
     Enumeration prefixes = namespaces.keys();
236
     while ( prefixes.hasMoreElements() ) {
247
     while ( prefixes.hasMoreElements() ) 
248
     {
237 249
       prefix = (String)prefixes.nextElement();
238 250
       nsuri = (String)namespaces.get(prefix);
239
       currentNode.setNamespace(prefix, nsuri, docid);
251
       endNodeId = currentNode.setNamespace(prefix, nsuri, docid);
240 252
     }
241 253
     namespaces = null;
242 254
     namespaces = new Hashtable();
......
246 258
     {
247 259
       String attributeName = atts.getQName(i);
248 260
       String attributeValue = atts.getValue(i);
249
       currentNode.setAttribute(attributeName, attributeValue, docid);
261
       endNodeId = 
262
                currentNode.setAttribute(attributeName, attributeValue, docid);
250 263
       
251 264
       // To handle name space and schema location if the attribute name is
252 265
       // xsi:schemaLocation. If the name space is in not in catalog table
......
259 272
         resolver.resolveNameSpace();
260 273
         
261 274
       }
275
       else if (attributeName !=null && attributeName.equals(ID))
276
       {
277
         // handle subtree info
278
         SubTree subTress = new SubTree();
279
         // set sub tree id
280
         subTress.setSubTreeId(attributeValue);
281
         // set sub tree sstart lement name
282
         subTress.setStartElementName(currentNode.getTagName());
283
         // set start node number
284
         subTress.setStartNodeId(startNodeId);
285
         // add to stack, but it didn't get end node id yet
286
         subTreeInfoStack.push(subTress);
287
         
288
       }
262 289
     }
263 290
   
264 291
     // handle access stuff
......
324 351

  
325 352
     // Get the node from the stack
326 353
     DBSAXNode currentNode = (DBSAXNode)nodeStack.pop();
354
     String currentTag = currentNode.getTagName();
327 355
     
328 356
    
329 357
     // If before the end element, the parser hit text nodes and store them
......
332 360
     if (hitTextNode)
333 361
     {
334 362
        // get access value
335
        String currentTag = currentNode.getTagName();
336 363
        String data = null;
337 364
        // add principal
338 365
       if (currentTag.equals(PRINCIPAL) && accessRule != null) 
......
387 414
       }
388 415
       // write text to db
389 416
       MetaCatUtil.debugMessage("Write text into DB in End Element", 50);
390
       writeTextForDBSAXNode(textBuffer, currentNode);
417
       endNodeId = writeTextForDBSAXNode(textBuffer, currentNode);
391 418
     }//if
392 419
     
393 420
     //set hitText false
......
395 422
     // reset textbuff
396 423
     textBuffer = null;
397 424
     textBuffer = new StringBuffer();
425
     
426
     // hand sub stree stuff
427
     SubTree tree = (SubTree)subTreeInfoStack.peek();// get last subtree
428
     if (tree != null && tree.getStartElementName() != null && 
429
         (tree.getStartElementName()).equals(currentTag))
430
     {
431
       // find the end of sub tree and set the end node id
432
       tree.setEndNodeId(endNodeId);
433
       // add the subtree into the final store palace
434
       subTreeList.add(tree);
435
       // get rid of it from stack
436
       subTreeInfoStack.pop();
437
     }
398 438

  
399 439
     // access stuff
400
     if ((currentNode.getTagName()).equals(ALLOW) ||
401
         (currentNode.getTagName()).equals(DENY))
440
     if (currentTag.equals(ALLOW) || currentTag.equals(DENY))
402 441
     {
403 442
       // finish parser a ccess rule and  assign it to new one
404 443
       AccessRule newRule = accessRule;
......
407 446
       // reset access rule
408 447
       accessRule = null;
409 448
     }
410
     else if ((currentNode.getTagName()).equals(ACCESS))
449
     else if (currentTag.equals(ACCESS))
411 450
     {
412 451
       // finish parse a access setction and assign it to new one
413 452
       AccessSection newAccessObject = accessObject;
......
435 474
       //reset access section object
436 475
       accessObject = null;
437 476
     }
438
     else if ((currentNode.getTagName()).equals(ADDITIONALMETADATA))
477
     else if (currentTag.equals(ADDITIONALMETADATA))
439 478
     {
440 479
        //reset describesId
441 480
        describesId = new Vector();

Also available in: Unified diff