Project

General

Profile

« Previous | Next » 

Revision 1412

Added by Jing Tao almost 22 years ago

Add the code to handle text nodes were splitted to couples.

View differences:

src/edu/ucsb/nceas/metacat/EmlSAXHandler.java
128 128
     } catch (EmptyStackException e) {
129 129
       parentNode = null;
130 130
     }
131

  
131
     
132
     // If hit a text node, we need write this text for current's parent node
133
     // This will happend if the element is mixted
134
     if (hitTextNode && parentNode != null)
135
     {
136
       // write the textbuffer into db for parent node.
137
        writeTextForDBSAXNode(textBuffer, parentNode);
138
        // rest hitTextNode
139
        hitTextNode =false;
140
        // reset textbuffer
141
        textBuffer = null;
142
        textBuffer = new StringBuffer();
143
       
144
     }
145
     
132 146
     // Document representation that points to the root document node
133 147
     if (atFirstElement) 
134 148
     {
......
301 315

  
302 316
  }
303 317
  
304
    /** SAX Handler that is called for each XML text node */
305
  public void characters(char[] cbuf, int start, int len) throws SAXException 
306
  {
307
     super.characters(cbuf, start, len);
308
    
309
     // access stuff
310
     DBSAXNode currentNode = (DBSAXNode)nodeStack.peek();
311
     String currentTag = currentNode.getTagName();
312
     String data = null;
313
     // add principal
314
     if (currentTag.equals(PRINCIPAL) && accessRule != null) 
315
     {
316
        data = (new String(cbuf, start, len)).trim();
317
        accessRule.addPrincipal(data);
318

  
319
     } 
320
     else if (currentTag.equals(PERMISSION) && accessRule != null) 
321
     {
322
        data = (new String(cbuf, start, len)).trim();
323
        // we conbine different a permission into one value
324
        int permission = accessRule.getPermission();
325
        // add permision
326
        if ( data.toUpperCase().equals("READ") ) 
327
        {
328
          permission = permission | READ;
329
        } 
330
        else if ( data.toUpperCase().equals("WRITE") ) 
331
        {
332
          permission = permission | WRITE;
333
        } 
334
        else if ( data.toUpperCase().equals("CHANGEPERMISSION")) 
335
        {
336
          permission = permission | CHMOD;
337
        } 
338
        else if ( data.toUpperCase().equals("ALL") ) 
339
        {
340
          permission = permission | ALL;
341
        }
342
        accessRule.setPermission(permission);
343
     }
344
   }//character
345
  
318
   
346 319
  /** SAX Handler that is called at the end of each XML element */
347 320
   public void endElement(String uri, String localName,
348 321
                          String qName) throws SAXException 
......
352 325
     // Get the node from the stack
353 326
     DBSAXNode currentNode = (DBSAXNode)nodeStack.pop();
354 327
     
328
    
329
     // If before the end element, the parser hit text nodes and store them
330
     // into the buffer, write the buffer to data base. The reason we put
331
     // write database here is for xerces some time split text node
332
     if (hitTextNode)
333
     {
334
        // get access value
335
        String currentTag = currentNode.getTagName();
336
        String data = null;
337
        // add principal
338
       if (currentTag.equals(PRINCIPAL) && accessRule != null) 
339
       {
340
          data = (textBuffer.toString()).trim();
341
          accessRule.addPrincipal(data);
342

  
343
       } 
344
       else if (currentTag.equals(PERMISSION) && accessRule != null) 
345
       {
346
         data = (textBuffer.toString()).trim();
347
         // we conbine different a permission into one value
348
         int permission = accessRule.getPermission();
349
         // add permision
350
         if ( data.toUpperCase().equals("READ") ) 
351
         {
352
           permission = permission | READ;
353
         } 
354
         else if ( data.toUpperCase().equals("WRITE") ) 
355
         {
356
           permission = permission | WRITE;
357
         } 
358
         else if ( data.toUpperCase().equals("CHANGEPERMISSION")) 
359
         {
360
           permission = permission | CHMOD;
361
         } 
362
         else if ( data.toUpperCase().equals("ALL") ) 
363
         {
364
          permission = permission | ALL;
365
         }
366
         accessRule.setPermission(permission);
367
       }
368
       
369
       // write text to db
370
       MetaCatUtil.debugMessage("Write text into DB in End Element", 50);
371
       writeTextForDBSAXNode(textBuffer, currentNode);
372
     }//if
373
     
374
     //set hitText false
375
     hitTextNode = false;
376
     // reset textbuff
377
     textBuffer = null;
378
     textBuffer = new StringBuffer();
379

  
355 380
     // access stuff
356 381
     if ((currentNode.getTagName()).equals(ALLOW) ||
357 382
         (currentNode.getTagName()).equals(DENY))

Also available in: Unified diff