Project

General

Profile

1 1382 tao
/**
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$'
11
 *     '$Date$'
12
 * '$Revision$'
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
/**
43
 * This class a wrapper class for documentimpl for insert or update. It will
44
 * provide deferent parser base on xml document validation by dtd or schema
45
 */
46
47
public class DocumentImplWrapper
48
{
49
50
   /* Attributes */
51
   private String    ruleBase               = null;
52
   private boolean   needValidation         = false;
53
54
55
   /**
56
    *  Constructor of DocumentImpleWrapper
57
    *  @param myRuleBase  the xml is base on DTD or Schema
58
    *  @param validation  if the xml document need to be validated
59
    */
60
  public DocumentImplWrapper(String myRuleBase, boolean validation)
61
  {
62
     ruleBase       = myRuleBase;
63
     needValidation = validation;
64
65
  }//Constructor
66
67
  public String write(DBConnection conn,Reader xml,String pub,Reader dtd,
68
                      String action, String docid, String user, String[] groups)
69
                      throws Exception
70
  {
71
    return DocumentImpl.write(conn, xml, pub, dtd, action, docid, user,
72
                              groups, ruleBase, needValidation);
73
  }
74
75 1560 tao
  public String writeReplication(DBConnection conn, Reader xml,
76 1382 tao
                                        String pub, Reader dtd, String action,
77
                                        String accnum, String user,
78
                                        String[] groups,String homeServer,
79 2622 tao
                                        String notifyServer, String createDate,
80
                                        String updateDate)
81 1382 tao
                                        throws Exception
82
  {
83
    //we don't need to check validation in replciation
84 2608 tao
    // so rule base is null and need validation is false (first false)
85
    // this method is for force replication. so the table name is xml_documents
86
     // and timed replication is false (last false)
87 1382 tao
    return DocumentImpl.writeReplication(conn, xml, pub, dtd, action,
88
                                        accnum, user, groups, homeServer,
89 2608 tao
                                        notifyServer, ruleBase, false,
90 2622 tao
                                        DocumentImpl.DOCUMENTTABLE, false,
91
                                        createDate, updateDate);
92 2608 tao
                                        // last false means is not timed replication
93
94 1382 tao
  }
95 2608 tao
96
  /**
97
   * Constructor with tableName - this doc is in xml_documents or xml_revsions
98
   * If in xml_revisions, it need a special handler.
99
   * @param conn
100
   * @param xml
101
   * @param pub
102
   * @param dtd
103
   * @param action
104
   * @param accnum
105
   * @param user
106
   * @param groups
107
   * @param homeServer
108
   * @param notifyServer
109
   * @param tableName
110
   * @return
111
   * @throws Exception
112
   */
113
  public String writeReplication(DBConnection conn, Reader xml,
114
          String pub, Reader dtd, String action,
115
          String accnum, String user,
116
          String[] groups,String homeServer,
117 2622 tao
          String notifyServer, String tableName,
118
          boolean timedReplication, String createDate, String updateDate)
119 2608 tao
          throws Exception
120
  {
121
   //we don't need to check validation in replciation
122
   // so rule base is null and need validation is false
123
   return DocumentImpl.writeReplication(conn, xml, pub, dtd, action,
124
          accnum, user, groups, homeServer,
125 2622 tao
          notifyServer, ruleBase, false, tableName,
126
          timedReplication, createDate, updateDate);
127 2608 tao
  }
128 1382 tao
}//DocumentImple