I’m writing a applet that uses a DTD file to check the content of the XML it receives.
I had the problem of the DTD not placed in the right folder with the applet viewer, but now that I’m testing this on the server I get the same error again.
java.security.AccessControlException:
access denied (java.io.FilePermission/leveldtd.dtd read)
How can I fix this when the applet is on the server?
public static void parseThis(InputSource is) throws Exception{
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLHandlerLevel myExampleHandler = new XMLHandlerLevel();
XMLReader xr = sp.getXMLReader();
xr.setContentHandler(myExampleHandler);
/* Begin parsing */
xr.parse(is);
}
XML parser creation.
For an applet to get a resource from a server, it must use an URL. File objects will not work because:
Fileobject will point to a place on the computer of the user.Fileobjects. Hence theAccessControlExceptionin your output.URLs to resources can easily be formed using the
URL(baseURL, pathString)constructor where the base URL is obtained fromApplet.getDocumentBase()orApplet.getCodeBase().Here is a code snippet taken from JaNeLA that uses an XSD located inside one of the Jars. The URL is stored in
schemaSource.