Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
5c2ae715c86bb9b5f8661165140ce6498b3d678c
[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 org.xml.sax.EntityResolver;\r
18 import org.xml.sax.InputSource;\r
19 import org.xml.sax.SAXException;\r
20 \r
21 public class DTDResolver implements EntityResolver {\r
22     \r
23         public InputSource resolveEntity(String publicID, String systemID)\r
24         throws SAXException {\r
25         \r
26         \r
27         if(!systemID.endsWith("surfxml.dtd")){\r
28         System.out.println("\n MSG - Warning - the platform used seams invalid\n");\r
29         return null;\r
30         }\r
31                 \r
32         /* try to get the DTD from the classpath */\r
33         InputStream in = getClass().getResourceAsStream("/surfxml.dtd"); \r
34         \r
35         if(null == in)  \r
36              /* try to get the DTD from the surf dir in the jar */\r
37              in = getClass().getResourceAsStream("/surf/surfxml.dtd");\r
38         if(null == in)\r
39              /* try to get the DTD from the directory Simgrid */\r
40                 in = getClass().getResourceAsStream("/Simgrid/surfxml.dtd"); \r
41         \r
42         if(null == in)\r
43                 /* try to get the DTD from the directory Simgrid/msg */\r
44                 in = getClass().getResourceAsStream("/Simgrid/msg/surfxml.dtd"); \r
45         \r
46         if(null == in) {\r
47                         System.err.println("\nMSG - XML DTD not found (" + systemID.toString() + ").\n\nPlease put this file in one of the following destinations :\n\n"+\r
48                         "   - classpath;\n"+\r
49                         "   - the directory Simgrid;\n"+\r
50                         "   - the directory Simgrid/msg;\n"+\r
51                         "   - the directory of you simulation.\n\n"+\r
52                         "Once the DTD puted in one of the previouse destinations, retry you simulation.\n");\r
53                         \r
54                         /* \r
55                          * If not founded, returning null makes process continue normally (try to get \r
56                          * the DTD from the current directory \r
57                          */\r
58                         return null;\r
59         }\r
60         \r
61         return new InputSource(in);  \r
62         }\r
63 }\r