Project

General

Profile

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-11-03 10:31:34 -0800 (Tue, 03 Nov 2009) $'
10
 * '$Revision: 5099 $'
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.AccessControlInterface;
37
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlList;
38
import edu.ucsb.nceas.metacat.accesscontrol.XMLAccessDAO;
39

    
40
/** 
41
 * A Class implementing callback methods for the SAX parser to
42
 * call when processing the XML messages from the replication handler
43
 */
44
public class DocInfoHandler extends DefaultHandler {
45
	
46
	private Hashtable<String, String> _docinfo = new Hashtable<String, String>();
47
	private String _currentTag = null;
48
	private XMLAccessDAO _currentAccessDAO = null;
49
	private String _accessPermOrder;
50
	private String _docId;
51
  
52
	private Vector<XMLAccessDAO> xmlAccessDAOList = new Vector<XMLAccessDAO>();
53
  
54
	public DocInfoHandler() {
55
	}
56

    
57
	public DocInfoHandler(String docId) {
58
		_docId = docId;
59
	}
60
  
61
   /**
62
	 * capture the name of the tag.
63
	 */
64
	public void startElement(String uri, String localName, String qName,
65
			Attributes attributes) throws SAXException {
66
		_currentTag = localName;
67
		if (_currentTag.equals("access")) {
68
			if (_accessPermOrder == null) {
69
				_accessPermOrder = attributes.getValue("order");			
70
			}
71
			_currentAccessDAO = new XMLAccessDAO();
72
			_currentAccessDAO.setDocId(_docId);
73
			_currentAccessDAO.setPermOrder(_accessPermOrder);
74
		}
75
	}
76

    
77
	public void endElement(String uri, String localName, String qName)
78
			throws SAXException {
79
		if (localName.equals("access")) {			
80
			if (_currentAccessDAO != null) {
81
				xmlAccessDAOList.add(_currentAccessDAO);
82
			}			
83
			_currentAccessDAO = null;
84
		} else if (qName.equals(AccessControlInterface.ALLOW)) {
85
			if (_currentAccessDAO != null) {
86
				_currentAccessDAO.setPermType(AccessControlInterface.ALLOW);
87
			}
88
		} else if (qName.equals(AccessControlInterface.DENY)) {
89
			if (_currentAccessDAO != null) {
90
				_currentAccessDAO.setPermType(AccessControlInterface.DENY);
91
			}
92
		}
93
	}
94
  
95
  /**
96
	 * put the content and the name of the tag into the hashtable. the name of
97
	 * the tag is the key.
98
	 */
99
  public void characters(char[] ch, int start, int length) throws SAXException
100
  {
101
    _docinfo.put(_currentTag, new String(ch, start, length));
102
    	
103
    if (_currentTag.equals(AccessControlInterface.PRINCIPAL)) {
104
		if (_currentAccessDAO != null) {
105
			_currentAccessDAO.setPrincipalName(new String(ch, start, length));
106
		}
107
	} else if (_currentTag.equals(AccessControlInterface.PERMISSION)) {
108
		if (_currentAccessDAO != null) {
109
			String permString = new String(ch, start, length);
110
			Long permLong = Long.valueOf(AccessControlList.intValue(permString));
111
			_currentAccessDAO.addPermission(permLong);
112
		}
113
	}
114
  }
115
  
116
  public Hashtable<String,String> getDocInfo()
117
  {
118
    return _docinfo;
119
  }
120
  
121
  public Vector<XMLAccessDAO> getAccessControlList() {
122
	  return xmlAccessDAOList;
123
  }
124
}
(24-24/58)