1 |
562
|
berkley
|
/**
|
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$'
|
9 |
|
|
* '$Date$'
|
10 |
|
|
* '$Revision$'
|
11 |
669
|
jones
|
*
|
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 |
562
|
berkley
|
*/
|
26 |
|
|
|
27 |
|
|
package edu.ucsb.nceas.metacat;
|
28 |
|
|
|
29 |
5104
|
leinfelder
|
import java.util.Stack;
|
30 |
562
|
berkley
|
import java.util.Vector;
|
31 |
|
|
import java.util.Hashtable;
|
32 |
|
|
|
33 |
|
|
import org.xml.sax.Attributes;
|
34 |
|
|
import org.xml.sax.SAXException;
|
35 |
|
|
import org.xml.sax.helpers.DefaultHandler;
|
36 |
|
|
|
37 |
5099
|
daigle
|
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlInterface;
|
38 |
5098
|
daigle
|
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlList;
|
39 |
|
|
import edu.ucsb.nceas.metacat.accesscontrol.XMLAccessDAO;
|
40 |
5090
|
daigle
|
|
41 |
562
|
berkley
|
/**
|
42 |
5099
|
daigle
|
* A Class implementing callback methods for the SAX parser to
|
43 |
562
|
berkley
|
* call when processing the XML messages from the replication handler
|
44 |
|
|
*/
|
45 |
5099
|
daigle
|
public class DocInfoHandler extends DefaultHandler {
|
46 |
|
|
|
47 |
|
|
private Hashtable<String, String> _docinfo = new Hashtable<String, String>();
|
48 |
|
|
private String _currentTag = null;
|
49 |
|
|
private XMLAccessDAO _currentAccessDAO = null;
|
50 |
|
|
private String _accessPermOrder;
|
51 |
|
|
private String _docId;
|
52 |
5103
|
daigle
|
private boolean _inPrincipal = false;
|
53 |
|
|
private boolean _inPermission = false;
|
54 |
5104
|
leinfelder
|
private boolean _inAllow = false;
|
55 |
|
|
private boolean _inDeny = false;
|
56 |
562
|
berkley
|
|
57 |
5099
|
daigle
|
private Vector<XMLAccessDAO> xmlAccessDAOList = new Vector<XMLAccessDAO>();
|
58 |
5104
|
leinfelder
|
private Stack<XMLAccessDAO> xmlAccessDAOStack = new Stack<XMLAccessDAO>();
|
59 |
4419
|
leinfelder
|
|
60 |
5099
|
daigle
|
public DocInfoHandler() {
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
public DocInfoHandler(String docId) {
|
64 |
|
|
_docId = docId;
|
65 |
|
|
}
|
66 |
562
|
berkley
|
|
67 |
5099
|
daigle
|
/**
|
68 |
|
|
* capture the name of the tag.
|
69 |
|
|
*/
|
70 |
|
|
public void startElement(String uri, String localName, String qName,
|
71 |
|
|
Attributes attributes) throws SAXException {
|
72 |
|
|
_currentTag = localName;
|
73 |
|
|
if (_currentTag.equals("access")) {
|
74 |
|
|
if (_accessPermOrder == null) {
|
75 |
|
|
_accessPermOrder = attributes.getValue("order");
|
76 |
|
|
}
|
77 |
5104
|
leinfelder
|
} else if (_currentTag.equals(AccessControlInterface.ALLOW)) {
|
78 |
|
|
_inAllow = true;
|
79 |
|
|
} else if (_currentTag.equals(AccessControlInterface.DENY)) {
|
80 |
|
|
_inDeny = true;
|
81 |
|
|
} else if (_currentTag.equals(AccessControlInterface.PERMISSION)) {
|
82 |
|
|
_inPermission = true;
|
83 |
|
|
} else if (_currentTag.equals(AccessControlInterface.PRINCIPAL)) {
|
84 |
|
|
// new principal means new DAO for storing it
|
85 |
|
|
_inPrincipal = true;
|
86 |
5099
|
daigle
|
_currentAccessDAO = new XMLAccessDAO();
|
87 |
|
|
_currentAccessDAO.setDocId(_docId);
|
88 |
|
|
_currentAccessDAO.setPermOrder(_accessPermOrder);
|
89 |
5104
|
leinfelder
|
if (_inAllow) {
|
90 |
|
|
_currentAccessDAO.setPermType(AccessControlInterface.ALLOW);
|
91 |
|
|
}
|
92 |
|
|
if (_inDeny) {
|
93 |
|
|
_currentAccessDAO.setPermType(AccessControlInterface.DENY);
|
94 |
|
|
}
|
95 |
5099
|
daigle
|
}
|
96 |
|
|
}
|
97 |
4486
|
daigle
|
|
98 |
5099
|
daigle
|
public void endElement(String uri, String localName, String qName)
|
99 |
|
|
throws SAXException {
|
100 |
5104
|
leinfelder
|
|
101 |
|
|
if (localName.equals(AccessControlInterface.ALLOW)) {
|
102 |
|
|
_inAllow = false;
|
103 |
|
|
} else if (localName.equals(AccessControlInterface.DENY)) {
|
104 |
|
|
_inDeny = false;
|
105 |
5103
|
daigle
|
} else if (_currentTag.equals(AccessControlInterface.PRINCIPAL)) {
|
106 |
|
|
_inPrincipal = false;
|
107 |
5104
|
leinfelder
|
xmlAccessDAOStack.push(_currentAccessDAO);
|
108 |
5103
|
daigle
|
} else if (_currentTag.equals(AccessControlInterface.PERMISSION)) {
|
109 |
|
|
_inPermission = false;
|
110 |
5099
|
daigle
|
}
|
111 |
5104
|
leinfelder
|
//end of a section for allow/deny
|
112 |
|
|
if (
|
113 |
|
|
localName.equals(AccessControlInterface.ALLOW)
|
114 |
|
|
||
|
115 |
|
|
localName.equals(AccessControlInterface.DENY)
|
116 |
|
|
) {
|
117 |
|
|
//get all the DAOs for this section and add them to the overall list
|
118 |
|
|
xmlAccessDAOList.addAll(xmlAccessDAOStack);
|
119 |
|
|
xmlAccessDAOStack.clear();
|
120 |
|
|
}
|
121 |
5099
|
daigle
|
}
|
122 |
4419
|
leinfelder
|
|
123 |
562
|
berkley
|
/**
|
124 |
5099
|
daigle
|
* put the content and the name of the tag into the hashtable. the name of
|
125 |
|
|
* the tag is the key.
|
126 |
|
|
*/
|
127 |
562
|
berkley
|
public void characters(char[] ch, int start, int length) throws SAXException
|
128 |
|
|
{
|
129 |
5099
|
daigle
|
_docinfo.put(_currentTag, new String(ch, start, length));
|
130 |
|
|
|
131 |
5103
|
daigle
|
if (_currentTag.equals(AccessControlInterface.PRINCIPAL) && _inPrincipal) {
|
132 |
5099
|
daigle
|
if (_currentAccessDAO != null) {
|
133 |
|
|
_currentAccessDAO.setPrincipalName(new String(ch, start, length));
|
134 |
|
|
}
|
135 |
5103
|
daigle
|
} else if (_currentTag.equals(AccessControlInterface.PERMISSION) && _inPermission) {
|
136 |
5099
|
daigle
|
if (_currentAccessDAO != null) {
|
137 |
|
|
String permString = new String(ch, start, length);
|
138 |
|
|
Long permLong = Long.valueOf(AccessControlList.intValue(permString));
|
139 |
5104
|
leinfelder
|
//add this permission for each DAO in the stack
|
140 |
|
|
for (int i = 0; i < xmlAccessDAOStack.size(); i++) {
|
141 |
|
|
xmlAccessDAOStack.get(i).addPermission(permLong);
|
142 |
|
|
}
|
143 |
5099
|
daigle
|
}
|
144 |
|
|
}
|
145 |
562
|
berkley
|
}
|
146 |
|
|
|
147 |
4486
|
daigle
|
public Hashtable<String,String> getDocInfo()
|
148 |
562
|
berkley
|
{
|
149 |
5099
|
daigle
|
return _docinfo;
|
150 |
562
|
berkley
|
}
|
151 |
4486
|
daigle
|
|
152 |
5098
|
daigle
|
public Vector<XMLAccessDAO> getAccessControlList() {
|
153 |
|
|
return xmlAccessDAOList;
|
154 |
4486
|
daigle
|
}
|
155 |
562
|
berkley
|
}
|