Revision 9976
Added by Jing Tao about 8 years ago
src/edu/ucsb/nceas/metacat/accesscontrol/AccessControlList.java | ||
---|---|---|
38 | 38 |
import org.apache.log4j.Logger; |
39 | 39 |
import org.xml.sax.Attributes; |
40 | 40 |
import org.xml.sax.ContentHandler; |
41 |
import org.xml.sax.DTDHandler; |
|
41 | 42 |
import org.xml.sax.EntityResolver; |
42 | 43 |
import org.xml.sax.ErrorHandler; |
43 | 44 |
import org.xml.sax.InputSource; |
44 | 45 |
import org.xml.sax.SAXException; |
45 | 46 |
import org.xml.sax.XMLReader; |
47 |
import org.xml.sax.ext.LexicalHandler; |
|
46 | 48 |
import org.xml.sax.helpers.DefaultHandler; |
47 | 49 |
import org.xml.sax.helpers.XMLReaderFactory; |
48 | 50 |
|
49 | 51 |
import edu.ucsb.nceas.metacat.BasicNode; |
50 | 52 |
import edu.ucsb.nceas.metacat.DBEntityResolver; |
53 |
import edu.ucsb.nceas.metacat.DBSAXNode; |
|
51 | 54 |
import edu.ucsb.nceas.metacat.DocumentImpl; |
52 | 55 |
import edu.ucsb.nceas.metacat.McdbException; |
53 | 56 |
import edu.ucsb.nceas.metacat.database.DBConnection; |
... | ... | |
63 | 66 |
* SAX parsing events when processing the XML stream. |
64 | 67 |
*/ |
65 | 68 |
public class AccessControlList extends DefaultHandler |
66 |
implements AccessControlInterface
|
|
69 |
implements AccessControlInterface, LexicalHandler
|
|
67 | 70 |
{ |
68 | 71 |
|
69 | 72 |
|
... | ... | |
198 | 201 |
|
199 | 202 |
// Turn off validation |
200 | 203 |
parser.setFeature("http://xml.org/sax/features/validation", true); |
204 |
parser.setProperty("http://xml.org/sax/properties/lexical-handler", this); |
|
201 | 205 |
|
202 | 206 |
// Set Handlers in the parser |
203 | 207 |
// Set the ContentHandler to this instance |
... | ... | |
207 | 211 |
// Set the EntityReslover to DBEntityResolver instance |
208 | 212 |
EntityResolver eresolver = new DBEntityResolver(connection,this,null); |
209 | 213 |
parser.setEntityResolver((EntityResolver)eresolver); |
214 |
parser.setDTDHandler((DTDHandler)this); |
|
210 | 215 |
|
211 | 216 |
// Set the ErrorHandler to this instance |
212 | 217 |
parser.setErrorHandler((ErrorHandler)this); |
... | ... | |
238 | 243 |
* element is detected. Used in this context to parse and store |
239 | 244 |
* the acl information in class variables. |
240 | 245 |
*/ |
246 |
@Override |
|
241 | 247 |
public void startElement (String uri, String localName, |
242 | 248 |
String qName, Attributes atts) |
243 | 249 |
throws SAXException |
... | ... | |
383 | 389 |
* @param publicId Public Identifier of the DTD |
384 | 390 |
* @param systemId System Identifier of the DTD |
385 | 391 |
*/ |
392 |
@Override |
|
386 | 393 |
public void startDTD(String name, String publicId, String systemId) |
387 | 394 |
throws SAXException { |
395 |
processingDTD = true; |
|
396 |
logMetacat.debug("AccessControlList.startDTD - Setting processingDTD to true"); |
|
397 |
logMetacat.debug("AccessControlList.startDTD - start DTD"); |
|
388 | 398 |
docname = name; |
389 | 399 |
doctype = publicId; |
390 | 400 |
systemid = systemId; |
391 | 401 |
} |
402 |
|
|
403 |
/** |
|
404 |
* SAX Handler that receives notification of end of DTD |
|
405 |
*/ |
|
406 |
@Override |
|
407 |
public void endDTD() throws SAXException |
|
408 |
{ |
|
392 | 409 |
|
410 |
processingDTD = false; |
|
411 |
logMetacat.debug("AccessControlList.endDTD - Setting processingDTD to false"); |
|
412 |
logMetacat.debug("AccessControlList.endDTD - end DTD"); |
|
413 |
} |
|
414 |
|
|
393 | 415 |
/** |
394 | 416 |
* SAX Handler that receives notification of the start of entities. |
395 | 417 |
* @param name name of the entity |
396 | 418 |
*/ |
397 | 419 |
public void startEntity(String name) throws SAXException { |
420 |
logMetacat.debug("AccessControlList.startEntity "); |
|
398 | 421 |
if (name.equals("[dtd]")) { |
422 |
logMetacat.debug("AccessControlList.startEntity set processingDTD to true."); |
|
399 | 423 |
processingDTD = true; |
400 | 424 |
} |
401 | 425 |
} |
... | ... | |
405 | 429 |
* @param name name of the entity |
406 | 430 |
*/ |
407 | 431 |
public void endEntity(String name) throws SAXException { |
432 |
logMetacat.debug("AccessControlList.endEntity "); |
|
408 | 433 |
if (name.equals("[dtd]")) { |
434 |
logMetacat.debug("AccessControlList.endEntity set processingDTD to false."); |
|
409 | 435 |
processingDTD = false; |
410 | 436 |
} |
411 | 437 |
} |
... | ... | |
771 | 797 |
}//finally |
772 | 798 |
} |
773 | 799 |
|
800 |
/** |
|
801 |
* SAX Handler that receives notification of comments in the DTD |
|
802 |
*/ |
|
803 |
public void comment(char[] ch, int start, int length) throws SAXException |
|
804 |
{ |
|
805 |
logMetacat.trace("AccessControlList.comment - starting comment"); |
|
806 |
|
|
807 |
} |
|
808 |
|
|
809 |
/** |
|
810 |
* SAX Handler that receives notification of the start of CDATA sections |
|
811 |
*/ |
|
812 |
public void startCDATA() throws SAXException |
|
813 |
{ |
|
814 |
logMetacat.trace("AccessControlList.startCDATA - starting CDATA"); |
|
815 |
} |
|
816 |
|
|
817 |
/** |
|
818 |
* SAX Handler that receives notification of the end of CDATA sections |
|
819 |
*/ |
|
820 |
public void endCDATA() throws SAXException |
|
821 |
{ |
|
822 |
logMetacat.trace("AccessControlList.endCDATA - end CDATA"); |
|
823 |
} |
|
824 |
|
|
774 | 825 |
public static void main(String[] args) { |
775 | 826 |
System.out.println("text value for CHMOD (" + CHMOD + "): " + txtValue(CHMOD)); |
776 | 827 |
System.out.println("text value for READ: (" + READ + "): " + txtValue(READ)); |
Also available in: Unified diff
Made the class implements the interface LexicalHandler.