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: perry $'
11
 *     '$Date: 2006-08-31 16:37:13 -0700 (Thu, 31 Aug 2006) $'
12
 * '$Revision: 3034 $'
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
    return DocumentImpl.write(conn, xml, pub, dtd, action, docid, user, 
74
                              groups, ruleBase, needValidation);
75
  }
76
  
77
  public String writeReplication(DBConnection conn, Reader xml, 
78
                                        String pub, Reader dtd, String action, 
79
                                        String accnum, String user,
80
                                        String[] groups,String homeServer, 
81
                                        String notifyServer, String createDate,
82
                                        String updateDate)
83
                                        throws Exception
84
  {
85
    //we don't need to check validation in replciation
86
    // so rule base is null and need validation is false (first false)
87
    // this method is for force replication. so the table name is xml_documents
88
     // and timed replication is false (last false)
89
    return DocumentImpl.writeReplication(conn, xml, pub, dtd, action, 
90
                                        accnum, user, groups, homeServer, 
91
                                        notifyServer, ruleBase, false, 
92
                                        DocumentImpl.DOCUMENTTABLE, false, 
93
                                        createDate, updateDate);
94
                                        // last false means is not timed replication
95
                         
96
  }
97
  
98
  /**
99
   * Constructor with tableName - this doc is in xml_documents or xml_revsions
100
   * If in xml_revisions, it need a special handler.
101
   * @param conn
102
   * @param xml
103
   * @param pub
104
   * @param dtd
105
   * @param action
106
   * @param accnum
107
   * @param user
108
   * @param groups
109
   * @param homeServer
110
   * @param notifyServer
111
   * @param tableName
112
   * @return
113
   * @throws Exception
114
   */
115
  public String writeReplication(DBConnection conn, Reader xml, 
116
          String pub, Reader dtd, String action, 
117
          String accnum, String user,
118
          String[] groups,String homeServer, 
119
          String notifyServer, String tableName, 
120
          boolean timedReplication, String createDate, String updateDate)
121
          throws Exception
122
  {
123
   //we don't need to check validation in replciation
124
   // so rule base is null and need validation is false
125
   return DocumentImpl.writeReplication(conn, xml, pub, dtd, action, 
126
          accnum, user, groups, homeServer, 
127
          notifyServer, ruleBase, false, tableName, 
128
          timedReplication, createDate, updateDate);
129
  }
130
}//DocumentImple
(32-32/65)