Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
7d0d58fb3dcc91639bf8d43e80d5493ccd799912
[simgrid.git] / src / java / simgrid / msg / DTDResolver.java
1 /*\r
2  * simgrid.msg.DTDResolver.java    1.00 07/05/01\r
3  *\r
4  * Copyright 2006,2007 Martin Quinson, Malek Cherier           \r
5  * All right reserved. \r
6  *\r
7  * This program is free software; you can redistribute \r
8  * it and/or modify it under the terms of the license \r
9  *(GNU LGPL) which comes with this package. \r
10  */\r
11 \r
12  \r
13 \r
14 package simgrid.msg;\r
15 \r
16 import java.io.InputStream;\r
17 import java.io.FileNotFoundException;\r
18 import org.xml.sax.EntityResolver;\r
19 import org.xml.sax.InputSource;\r
20 import org.xml.sax.SAXException;\r
21 \r
22 public class DTDResolver implements EntityResolver {\r
23     \r
24         public InputSource resolveEntity(String publicID, String systemID)\r
25         throws SAXException {\r
26         \r
27         \r
28         if(!systemID.endsWith("surfxml.dtd")){\r
29         System.out.println("\n MSG - Warning - the platform used seams invalid\n");\r
30         return null;\r
31         }\r
32                 \r
33         /* try to get the DTD from the classpath */\r
34         InputStream in = getClass().getResourceAsStream("/surfxml.dtd"); \r
35         \r
36         if(null == in)  \r
37                 /* try to get the DTD from the directory Simgrid */\r
38                 in = getClass().getResourceAsStream("/Simgrid/surfxml.dtd"); \r
39         \r
40         if(null == in)\r
41                 /* try to get the DTD from the directory Simgrid/msg */\r
42                 in = getClass().getResourceAsStream("/Simgrid/msg/surfxml.dtd"); \r
43         \r
44         if(null == in) {\r
45                         System.err.println("\nMSG - XML DTD not found (" + systemID.toString() + ").\n\nPlease put this file in one of the following destinations :\n\n"+\r
46                         "   - classpath;\n"+\r
47                         "   - the directory Simgrid;\n"+\r
48                         "   - the directory Simgrid/msg;\n"+\r
49                         "   - the directory of you simulation.\n\n"+\r
50                         "Once the DTD puted in one of the previouse destinations, retry you simulation.\n");\r
51                         \r
52                         /* \r
53                          * If not founded, returning null makes process continue normally (try to get \r
54                          * the DTD from the current directory \r
55                          */\r
56                         return null;\r
57         }\r
58         \r
59         return new InputSource(in);  \r
60         }\r
61 }\r