E5XML/XMLEntityResolver.py

changeset 50
a36eecf45b2e
parent 15
f6ccc31d6e72
child 96
9624a110667d
diff -r f991944e859c -r a36eecf45b2e E5XML/XMLEntityResolver.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/E5XML/XMLEntityResolver.py	Tue Jan 12 17:55:24 2010 +0000
@@ -0,0 +1,48 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2004 - 2010 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing a specialized entity resolver to find our DTDs.
+"""
+
+import os.path
+from xml.sax.handler import EntityResolver
+
+import Utilities
+
+from eric5config import getConfig
+
+class XMLEntityResolver(EntityResolver):
+    """
+    Class implementing a specialized entity resolver to find our DTDs.
+    """
+    def resolveEntity(self, publicId, systemId):
+        """
+        Public method to resolve the system identifier of an entity and
+        return either the system identifier to read from as a string.
+        
+        @param publicId publicId of an entity (string)
+        @param systemId systemId of an entity to reslove (string)
+        @return resolved systemId (string)
+        """
+        if systemId.startswith('http://'):
+            sId = systemId
+            
+        elif os.path.exists(systemId):
+            sId = systemId
+            
+        else:
+            dtdDir = getConfig('ericDTDDir')
+            if not os.path.isabs(dtdDir):
+                dtdDir = os.path.abspath(dtdDir)
+            sId = os.path.join(dtdDir, systemId)
+            if not os.path.exists(sId):
+                ind = sId.rfind('-')
+                if ind != -1:
+                    sId = "%s.dtd" % sId[:ind]
+                if not os.path.exists(sId):
+                    sId = ""
+        
+        return sId
\ No newline at end of file

eric ide

mercurial