Project

General

Profile

« Previous | Next » 

Revision 5099

Added by daigle over 14 years ago

Change access section in getaccesscontrol and getdocumentinfo apis to be more eml 2.1.0 compliant. Add a block access option to setaccess api.

View differences:

DocInfoHandler.java
33 33
import org.xml.sax.SAXException;
34 34
import org.xml.sax.helpers.DefaultHandler;
35 35

  
36
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlInterface;
36 37
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlList;
37 38
import edu.ucsb.nceas.metacat.accesscontrol.XMLAccessDAO;
38 39

  
39 40
/** 
40
 * A Class implementing callback bethods for the SAX parser to
41
 * A Class implementing callback methods for the SAX parser to
41 42
 * call when processing the XML messages from the replication handler
42 43
 */
43
public class DocInfoHandler extends DefaultHandler 
44
{
45
  private Hashtable<String,String> docinfo = new Hashtable<String,String>();
46
  private String currentTag = null;
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;
47 51
  
48
  private Vector<XMLAccessDAO> xmlAccessDAOList = new Vector<XMLAccessDAO>();
52
	private Vector<XMLAccessDAO> xmlAccessDAOList = new Vector<XMLAccessDAO>();
49 53
  
50
  public DocInfoHandler()
51
  {
52
  }
54
	public DocInfoHandler() {
55
	}
56

  
57
	public DocInfoHandler(String docId) {
58
		_docId = docId;
59
	}
53 60
  
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
  }
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
	}
62 76

  
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
  }
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
	}
89 94
  
90 95
  /**
91
   * put the content and the name of the tag into the hashtable.  the name of
92
   * the tag is the key.
93
   */
96
	 * put the content and the name of the tag into the hashtable. the name of
97
	 * the tag is the key.
98
	 */
94 99
  public void characters(char[] ch, int start, int length) throws SAXException
95 100
  {
96
    docinfo.put(currentTag, new String(ch, start, length));
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
	}
97 114
  }
98 115
  
99 116
  public Hashtable<String,String> getDocInfo()
100 117
  {
101
    return docinfo;
118
    return _docinfo;
102 119
  }
103 120
  
104 121
  public Vector<XMLAccessDAO> getAccessControlList() {

Also available in: Unified diff