source: trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/doctypes/DocumentSQLWriter.java@ 5944

Last change on this file since 5944 was 5944, checked in by cs025, 20 years ago

Index document type, metadata extensions

  • Property svn:keywords set to Author Date Id Revision
File size: 2.3 KB
Line 
1package org.greenstone.gsdl3.gs3build.doctypes;
2
3import java.io.PrintWriter;
4
5import java.sql.*;
6
7import org.greenstone.gsdl3.gs3build.util.XMLTools;
8import org.greenstone.gsdl3.gs3build.util.GS3SQLConnection;
9import org.greenstone.gsdl3.gs3build.database.*;
10
11public class DocumentSQLWriter
12{
13 public DocumentSQLWriter()
14 {
15 }
16
17 /**
18 * Just write the document to the database, assuming that it is not already there
19 */
20 public boolean writeDocument(DocumentInterface document, GS3SQLConnection connection)
21 {
22 // TODO: output document in METS format, with Greenstone-specific metadata
23 // placed in a wrapper inside the descriptive metadata block
24
25 // put the document into the database
26 try {
27 if (document.getID() != null)
28 { //tag = XMLTools.addAttribute(tag, "OBJID", document.getID().toString());
29 GS3SQLSelect select = new GS3SQLSelect("document");
30 select.addField("*");
31 select.setWhere(new GS3SQLWhere(new GS3SQLWhereItem("DocID", "=", document.getID().toString())));
32 connection.execute(select.toString());
33
34 ResultSet results = connection.getResultSet();
35
36 if (results == null ||
37 !results.first())
38 { GS3SQLInsert insert = new GS3SQLInsert("document");
39 insert.addValue("DocID", document.getID().toString());
40 insert.addValue("DocType", document.getDocumentType());
41
42 connection.execute(insert.toString());
43 }
44 }
45 } catch (Exception ex) {
46 System.out.println(ex);
47 }
48 // output.println(tag);
49
50 // Write the structural metadata:
51 // if in "Create METS" mode:
52 // take all the documents as being in the one group, of the "physical"
53 // document; particular document plugins may extend this behaviour,
54 // which would suggest placing it in the AbstractDocument or similar
55 // class?!
56 document.getDocumentMetadata().writeSQL(document, connection);
57
58 document.getDocumentFiles().writeSQL(document, connection);
59
60 document.getDocumentStructure().writeSQL(document, connection);
61
62 // Write the body information
63 // TODO: only output the document if there is some
64 // content/formatting change between the original and
65 // what greenstone actually does; if the original is
66 // good, then place a marker saying "get the document
67 // "from the original file"
68 return true;
69 }
70}
Note: See TracBrowser for help on using the repository browser.