Project

General

Profile

« Previous | Next » 

Revision 1590

Added by Jing Tao over 21 years ago

Add code to parse triple.

View differences:

src/edu/ucsb/nceas/metacat/DBSAXHandler.java
28 28

  
29 29
package edu.ucsb.nceas.metacat;
30 30

  
31
import edu.ucsb.nceas.morpho.datapackage.Triple;
32
import edu.ucsb.nceas.morpho.datapackage.TripleCollection;
33

  
31 34
import java.sql.*;
32 35
import java.io.StringReader;
33 36
import java.util.Stack;
......
84 87
   protected long  endNodeId = -1;    // The end node id for a substree
85 88
// DOCTITLE attr cleared from the db
86 89
//   private static final int MAXTITLELEN = 1000;
90
   //HandlerTriple stuff
91
   TripleCollection tripleList = new TripleCollection();
92
   Triple currentTriple        = new Triple();
93
   boolean startParseTriple    = false;
94
   boolean hasTriple           = false;
87 95

  
88 96
   /** Construct an instance of the handler class
89 97
    *
......
172 180
     MetaCatUtil.debugMessage("end Document", 50);
173 181
     // Starting new thread for writing XML Index.
174 182
     // It calls the run method of the thread.
183
     
184
     //if it is data package insert triple into relationtion table;
185
     if ( doctype != null && 
186
         MetaCatUtil.getOptionList(MetaCatUtil.getOption("packagedoctype")).
187
         contains(doctype) && hasTriple)
188
      {
189
        try
190
        {
191
          //initial handler and write into relationdb
192
          RelationHandler handler = 
193
                        new RelationHandler(docid,doctype, connection, tripleList);
194
        }
195
        catch (Exception e)
196
        {
197
          MetaCatUtil.debugMessage
198
                            ("Failed to write triples into relation table", 30);
199
          throw new SAXException("Failed to write triples into relation table");
200
        }
201
      }
202
     
203
     
175 204
     try {
176 205
       xmlIndex.start();
177 206
     } catch (NullPointerException e) {
......
348 377
     nodeStack.push(currentNode);
349 378
     // Add the node to the vector used by thread for writing XML Index
350 379
     nodeIndex.addElement(currentNode);
351

  
380
     // start parsing triple
381
     if ( doctype != null && 
382
         MetaCatUtil.getOptionList(MetaCatUtil.getOption("packagedoctype")).contains(doctype)
383
         && localName.equals("triple"))
384
      {
385
        startParseTriple = true;
386
        hasTriple = true;
387
        currentTriple = new Triple();
388
      }
352 389
  }
353 390

  
354 391
  /* The run method of xmlIndex thread. It writes XML Index for the document. */
......
515 552
     {
516 553
       MetaCatUtil.debugMessage("Write text into DB in End Element", 50);
517 554
       endNodeId = writeTextForDBSAXNode(textBuffer, currentNode);
555
       
556
       //if it is triple parsing process
557
       if (startParseTriple)
558
       {
559
         
560
          String content = textBuffer.toString().trim();
561
          if(localName.equals("subject"))
562
          { //get the subject content
563
            currentTriple.setSubject(content);
564
          }
565
          else if(localName.equals("relationship"))
566
          { //get the relationship content
567
            currentTriple.setRelationship(content);
568
          }
569
          else if(localName.equals("object"))
570
          { //get the object content
571
            currentTriple.setObject(content);
572
          }
573
       }
574
       
518 575
     }//if
519 576
     
520 577
     //set hitText false
......
525 582

  
526 583
     // Get the node from the stack
527 584
     currentNode = (DBSAXNode)nodeStack.pop();
585
     //finishing parsing single triple
586
     if (startParseTriple && localName.equals("triple"))
587
      {
588
        // add trip to triple collection
589
        tripleList.addTriple(currentTriple);
590
        //rest variable
591
        currentTriple = null;
592
        startParseTriple = false;   
593
      }
528 594
   }
529 595

  
530 596
   //

Also available in: Unified diff