1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Purpose: a class to handle document info request xml strings
|
4
|
* Copyright: 2000 Regents of the University of California and the
|
5
|
* National Center for Ecological Analysis and Synthesis
|
6
|
* Authors: Chad Berkley
|
7
|
*
|
8
|
* '$Author: daigle $'
|
9
|
* '$Date: 2009-10-30 15:39:35 -0700 (Fri, 30 Oct 2009) $'
|
10
|
* '$Revision: 5098 $'
|
11
|
*
|
12
|
* This program is free software; you can redistribute it and/or modify
|
13
|
* it under the terms of the GNU General Public License as published by
|
14
|
* the Free Software Foundation; either version 2 of the License, or
|
15
|
* (at your option) any later version.
|
16
|
*
|
17
|
* This program is distributed in the hope that it will be useful,
|
18
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20
|
* GNU General Public License for more details.
|
21
|
*
|
22
|
* You should have received a copy of the GNU General Public License
|
23
|
* along with this program; if not, write to the Free Software
|
24
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
25
|
*/
|
26
|
|
27
|
package edu.ucsb.nceas.metacat;
|
28
|
|
29
|
import java.util.Vector;
|
30
|
import java.util.Hashtable;
|
31
|
|
32
|
import org.xml.sax.Attributes;
|
33
|
import org.xml.sax.SAXException;
|
34
|
import org.xml.sax.helpers.DefaultHandler;
|
35
|
|
36
|
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlList;
|
37
|
import edu.ucsb.nceas.metacat.accesscontrol.XMLAccessDAO;
|
38
|
|
39
|
/**
|
40
|
* A Class implementing callback bethods for the SAX parser to
|
41
|
* call when processing the XML messages from the replication handler
|
42
|
*/
|
43
|
public class DocInfoHandler extends DefaultHandler
|
44
|
{
|
45
|
private Hashtable<String,String> docinfo = new Hashtable<String,String>();
|
46
|
private String currentTag = null;
|
47
|
|
48
|
private Vector<XMLAccessDAO> xmlAccessDAOList = new Vector<XMLAccessDAO>();
|
49
|
|
50
|
public DocInfoHandler()
|
51
|
{
|
52
|
}
|
53
|
|
54
|
/**
|
55
|
* capture the name of the tag.
|
56
|
*/
|
57
|
public void startElement(String uri, String localName, String qName,
|
58
|
Attributes attributes) throws SAXException
|
59
|
{
|
60
|
currentTag = localName;
|
61
|
}
|
62
|
|
63
|
public void endElement (String uri, String localName, String qName)
|
64
|
throws SAXException
|
65
|
{
|
66
|
if (localName.equals("access")) {
|
67
|
//harvest the latest values from the Map
|
68
|
String docid = (String) docinfo.get("docid");
|
69
|
String principal = (String) docinfo.get("principal");
|
70
|
String permission = (String) docinfo.get("permission");
|
71
|
String permType = (String) docinfo.get("permType");
|
72
|
String permOrder = (String) docinfo.get("permOrder");
|
73
|
XMLAccessDAO xmlAccessDAO = null;
|
74
|
try {
|
75
|
xmlAccessDAO = new XMLAccessDAO();
|
76
|
xmlAccessDAO.setDocId(docid);
|
77
|
xmlAccessDAO.setPrincipalName(principal);
|
78
|
xmlAccessDAO.setPermission(new Long(AccessControlList.intValue(permission)));
|
79
|
xmlAccessDAO.setPermType(permType);
|
80
|
xmlAccessDAO.setPermOrder(permOrder);
|
81
|
|
82
|
} catch (Exception e) {
|
83
|
// TODO Auto-generated catch block
|
84
|
e.printStackTrace();
|
85
|
}
|
86
|
xmlAccessDAOList.add(xmlAccessDAO);
|
87
|
}
|
88
|
}
|
89
|
|
90
|
/**
|
91
|
* put the content and the name of the tag into the hashtable. the name of
|
92
|
* the tag is the key.
|
93
|
*/
|
94
|
public void characters(char[] ch, int start, int length) throws SAXException
|
95
|
{
|
96
|
docinfo.put(currentTag, new String(ch, start, length));
|
97
|
}
|
98
|
|
99
|
public Hashtable<String,String> getDocInfo()
|
100
|
{
|
101
|
return docinfo;
|
102
|
}
|
103
|
|
104
|
public Vector<XMLAccessDAO> getAccessControlList() {
|
105
|
return xmlAccessDAOList;
|
106
|
}
|
107
|
}
|