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: 2017-05-17 20:39:55 -0700 (Wed, 17 May 2017) $'
11
 * '$Revision: 10290 $'
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 java.util.Date;
32

    
33
import org.dataone.service.types.v1.Checksum;
34

    
35
import edu.ucsb.nceas.metacat.database.DBConnection;
36

    
37
//import edu.ucsb.nceas.metacat.spatial.MetacatSpatialDocument;
38

    
39
/**
40
 * This class a wrapper class for documentimpl for insert or update. It will 
41
 * provide deferent parser base on xml document validation by dtd or schema
42
 */
43

    
44
public class DocumentImplWrapper {
45

    
46
	/* Attributes */
47
	private String ruleBase = null;
48
	private boolean needValidation = false;
49
	private boolean writeAccessRules = true;
50

    
51
	/**
52
	 *  Constructor of DocumentImpleWrapper
53
	 *  @param myRuleBase  the xml is base on DTD or Schema
54
	 *  @param validation  if the xml document need to be validated
55
	 */
56
	public DocumentImplWrapper(String myRuleBase, boolean validation, boolean writeAccessRules) {
57
		ruleBase = myRuleBase;
58
		needValidation = validation;
59
		this.writeAccessRules = writeAccessRules;
60

    
61
	}//Constructor
62

    
63
	public String write(DBConnection conn, String xml, String pub, Reader dtd,
64
			String action, String docid, String user, String[] groups, byte[]xmlBytes, String schemaLocalLocation, Checksum checksum) throws Exception {
65
		return DocumentImpl.write(conn, xml, pub, dtd, action, docid, user, groups,
66
				ruleBase, needValidation, writeAccessRules, xmlBytes, schemaLocalLocation, checksum);
67
	}
68

    
69
	public String writeReplication(DBConnection conn, String xml, byte[]xmlBytes, String pub, Reader dtd,
70
			String action, String accnum, String user, String[] groups,
71
			String homeServer, String notifyServer, Date createDate, Date updateDate)
72
			throws Exception {
73
		//we don't need to check validation in replication
74
		// so rule base is null and need validation is false (first false)
75
		// this method is for force replication. so the table name is xml_documents
76
		// and timed replication is false (last false)
77
	    String schemaLocation = null;
78
	    boolean needValidate = false;
79
		return DocumentImpl.writeReplication(conn, xml, xmlBytes, pub, dtd, action, accnum, user,
80
				groups, homeServer, notifyServer, ruleBase, needValidate,
81
				DocumentImpl.DOCUMENTTABLE, false, createDate, updateDate, schemaLocation);
82
		// last false means is not timed replication
83

    
84
	}
85

    
86
	/**
87
	 * Constructor with tableName - this doc is in xml_documents or xml_revsions
88
	 * If in xml_revisions, it need a special handler.
89
	 * @param conn
90
	 * @param xml
91
	 * @param pub
92
	 * @param dtd
93
	 * @param action
94
	 * @param accnum
95
	 * @param user
96
	 * @param groups
97
	 * @param homeServer
98
	 * @param notifyServer
99
	 * @param tableName
100
	 * @return
101
	 * @throws Exception
102
	 */
103
	public String writeReplication(DBConnection conn, String xml, byte[]xmlBytes, String pub, Reader dtd,
104
			String action, String accnum, String user, String[] groups,
105
			String homeServer, String notifyServer, String tableName,
106
			boolean timedReplication, Date createDate, Date updateDate)
107
			throws Exception {
108
		//we don't need to check validation in replication
109
		// so rule base is null and need validation is false
110
	    String schemaLocation = null;
111
	    boolean needValidate = false;
112
		return DocumentImpl.writeReplication(conn, xml, xmlBytes, pub, dtd, action, accnum, user,
113
				groups, homeServer, notifyServer, ruleBase, needValidate, tableName,
114
				timedReplication, createDate, updateDate, schemaLocation);
115
	}
116

    
117
}
(28-28/64)