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 from eric5config import getConfig |
|
14 |
|
15 class XMLEntityResolver(EntityResolver): |
|
16 """ |
|
17 Class implementing a specialized entity resolver to find our DTDs. |
|
18 """ |
|
19 def resolveEntity(self, publicId, systemId): |
|
20 """ |
|
21 Public method to resolve the system identifier of an entity and |
|
22 return either the system identifier to read from as a string. |
|
23 |
|
24 @param publicId publicId of an entity (string) |
|
25 @param systemId systemId of an entity to reslove (string) |
|
26 @return resolved systemId (string) |
|
27 """ |
|
28 if systemId.startswith('http://'): |
|
29 sId = systemId |
|
30 |
|
31 elif os.path.exists(systemId): |
|
32 sId = systemId |
|
33 |
|
34 else: |
|
35 dtdDir = getConfig('ericDTDDir') |
|
36 if not os.path.isabs(dtdDir): |
|
37 dtdDir = os.path.abspath(dtdDir) |
|
38 sId = os.path.join(dtdDir, systemId) |
|
39 if not os.path.exists(sId): |
|
40 ind = sId.rfind('-') |
|
41 if ind != -1: |
|
42 sId = "{0}.dtd".format(sId[:ind]) |
|
43 if not os.path.exists(sId): |
|
44 sId = "" |
|
45 |
|
46 return sId |
|