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
 *
9
 *   '$Author: tao $'
10
 *     '$Date: 2007-04-12 18:34:59 -0700 (Thu, 12 Apr 2007) $'
11
 * '$Revision: 3230 $'
12
 *
13
 * This program is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 */
27

    
28
package edu.ucsb.nceas.metacat;
29

    
30
import java.io.Reader;
31
import org.xml.sax.ContentHandler;
32
import org.xml.sax.DTDHandler;
33
import org.xml.sax.EntityResolver;
34
import org.xml.sax.ErrorHandler;
35
import org.xml.sax.InputSource;
36
import org.xml.sax.XMLReader;
37
import org.xml.sax.SAXException;
38
import org.xml.sax.SAXParseException;
39
import org.xml.sax.helpers.XMLReaderFactory;
40

    
41
//import edu.ucsb.nceas.metacat.spatial.MetacatSpatialDocument;
42

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

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

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