Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A Class that loads eml-access.xml file containing ACL 
4
 *             for a metadata document into relational DB
5
 *  Copyright: 2000 Regents of the University of California and the
6
 *             National Center for Ecological Analysis and Synthesis
7
 *    Authors: Jing Tao
8
 *    Release: @release@
9
 *
10
 *   '$Author: harris $'
11
 *     '$Date: 2006-02-20 19:41:34 -0800 (Mon, 20 Feb 2006) $'
12
 * '$Revision: 2912 $'
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.io.Reader;
32
import org.xml.sax.ContentHandler;
33
import org.xml.sax.DTDHandler;
34
import org.xml.sax.EntityResolver;
35
import org.xml.sax.ErrorHandler;
36
import org.xml.sax.InputSource;
37
import org.xml.sax.XMLReader;
38
import org.xml.sax.SAXException;
39
import org.xml.sax.SAXParseException;
40
import org.xml.sax.helpers.XMLReaderFactory;
41

    
42
import edu.ucsb.nceas.metacat.spatial.MetacatSpatialDocument;
43

    
44
/**
45
 * This class a wrapper class for documentimpl for insert or update. It will 
46
 * provide deferent parser base on xml document validation by dtd or schema
47
 */
48

    
49
public class DocumentImplWrapper
50
{
51
  
52
   /* Attributes */
53
   private String    ruleBase               = null;
54
   private boolean   needValidation         = false;
55
  
56
   
57
   /**
58
    *  Constructor of DocumentImpleWrapper
59
    *  @param myRuleBase  the xml is base on DTD or Schema
60
    *  @param validation  if the xml document need to be validated
61
    */
62
  public DocumentImplWrapper(String myRuleBase, boolean validation)
63
  {
64
     ruleBase       = myRuleBase;
65
     needValidation = validation;
66
       
67
  }//Constructor
68

    
69
  public String write(DBConnection conn,Reader xml,String pub,Reader dtd,
70
                      String action, String docid, String user, String[] groups)
71
                      throws Exception
72
  {
73
    
74
    //jhh register this transaction with the Metacat Spatial Option
75
    MetacatSpatialDocument msdoc = new MetacatSpatialDocument(docid);
76
    
77
    return DocumentImpl.write(conn, xml, pub, dtd, action, docid, user, 
78
                              groups, ruleBase, needValidation);
79
  }
80
  
81
  public String writeReplication(DBConnection conn, Reader xml, 
82
                                        String pub, Reader dtd, String action, 
83
                                        String accnum, String user,
84
                                        String[] groups,String homeServer, 
85
                                        String notifyServer, String createDate,
86
                                        String updateDate)
87
                                        throws Exception
88
  {
89
    //we don't need to check validation in replciation
90
    // so rule base is null and need validation is false (first false)
91
    // this method is for force replication. so the table name is xml_documents
92
     // and timed replication is false (last false)
93
    return DocumentImpl.writeReplication(conn, xml, pub, dtd, action, 
94
                                        accnum, user, groups, homeServer, 
95
                                        notifyServer, ruleBase, false, 
96
                                        DocumentImpl.DOCUMENTTABLE, false, 
97
                                        createDate, updateDate);
98
                                        // last false means is not timed replication
99
                         
100
  }
101
  
102
  /**
103
   * Constructor with tableName - this doc is in xml_documents or xml_revsions
104
   * If in xml_revisions, it need a special handler.
105
   * @param conn
106
   * @param xml
107
   * @param pub
108
   * @param dtd
109
   * @param action
110
   * @param accnum
111
   * @param user
112
   * @param groups
113
   * @param homeServer
114
   * @param notifyServer
115
   * @param tableName
116
   * @return
117
   * @throws Exception
118
   */
119
  public String writeReplication(DBConnection conn, Reader xml, 
120
          String pub, Reader dtd, String action, 
121
          String accnum, String user,
122
          String[] groups,String homeServer, 
123
          String notifyServer, String tableName, 
124
          boolean timedReplication, String createDate, String updateDate)
125
          throws Exception
126
  {
127
   //we don't need to check validation in replciation
128
   // so rule base is null and need validation is false
129
   return DocumentImpl.writeReplication(conn, xml, pub, dtd, action, 
130
          accnum, user, groups, homeServer, 
131
          notifyServer, ruleBase, false, tableName, 
132
          timedReplication, createDate, updateDate);
133
  }
134
}//DocumentImple
(32-32/65)