|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2004 - 2010 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a specialized entity resolver to find our DTDs. |
|
8 """ |
|
9 |
|
10 import os.path |
|
11 from xml.sax.handler import EntityResolver |
|
12 |
|
13 import Utilities |
|
14 |
|
15 from eric5config import getConfig |
|
16 |
|
17 class XMLEntityResolver(EntityResolver): |
|
18 """ |
|
19 Class implementing a specialized entity resolver to find our DTDs. |
|
20 """ |
|
21 def resolveEntity(self, publicId, systemId): |
|
22 """ |
|
23 Public method to resolve the system identifier of an entity and |
|
24 return either the system identifier to read from as a string. |
|
25 |
|
26 @param publicId publicId of an entity (string) |
|
27 @param systemId systemId of an entity to reslove (string) |
|
28 @return resolved systemId (string) |
|
29 """ |
|
30 if systemId.startswith('http://'): |
|
31 sId = systemId |
|
32 |
|
33 elif os.path.exists(systemId): |
|
34 sId = systemId |
|
35 |
|
36 else: |
|
37 dtdDir = getConfig('ericDTDDir') |
|
38 if not os.path.isabs(dtdDir): |
|
39 dtdDir = os.path.abspath(dtdDir) |
|
40 sId = os.path.join(dtdDir, systemId) |
|
41 if not os.path.exists(sId): |
|
42 ind = sId.rfind('-') |
|
43 if ind != -1: |
|
44 sId = "%s.dtd" % sId[:ind] |
|
45 if not os.path.exists(sId): |
|
46 sId = "" |
|
47 |
|
48 return sId |