def __createHighlightBySetting(self, setting): if setting is None: return for language in setting.getChildren(): if language is None or language.getName() is None or "" == language.getName(): continue languageName = language.getName().lower().strip() if not languages.LANGUAGE_MAP.has_key(languageName): continue lexer = languages.LANGUAGE_MAP[languageName] """ gets path of style file """ if language.getAttrs().has_key("style"): styleFilePath = language.getAttrs()["style"].strip() if "" == styleFilePath: continue styleFilePath = "%s%s..%s..%s..%s%s" % ( os.path.dirname(__file__), os.path.sep, os.path.sep, os.path.sep, os.path.sep, styleFilePath, ) if not os.path.exists(styleFilePath): continue styleSettings = XmlLoader().load(styleFilePath) if styleSettings is None: continue highlightStyle = Highlight() for setting in styleSettings.getChildren(): if setting is None or "" == setting.getName(): continue if "keywords" == setting.getName(): keywords = setting.getCharData().strip() if "" != keywords: highlightStyle.setKeywords(keywords) elif "styles" == setting.getName(): for mode in setting.getChildren(): if mode is None or mode.getName() is None or "" == mode.getName(): continue font = self.__createFontBySetting(mode) highlightStyle.getHighlightStyles()[mode.getName().lower().strip()] = font self.getEditorStyle().getHighlightStyles()[lexer] = highlightStyle
def load(self): configFile = "%s%sconfig%sconfig.xml" % (self.getWorkPath(), os.path.sep, os.path.sep) xmlLoader = XmlLoader() xmlroot = xmlLoader.load(configFile) if xmlroot is None: raise Exception("Failed to load config file.\n%s" % configFile) for config in xmlroot.getChildren(): for setting in config.getChildren(): if "editors" == setting.getName().lower(): self.__parseEditorsSettings(setting) elif "encodings" == setting.getName().lower(): self.__parseEncodingSettings(setting) elif "actions" == setting.getName().lower(): self.__parseActionsSettings(setting) elif "appearance" == setting.getName().lower(): self.__parseAppearanceSettings(setting)
self._file.write(charData + '\n') self._file.write(elementEnd) def __writeSingleElement(self, name, attrs, indent): attrStr = self.__getAttrsString(attrs) if attrStr is None or '' == attrStr: element = '%s<%s/>\n' % ('\t' * indent, name) else: element = '%s<%s %s/>\n' % ('\t' * indent, name, attrStr) self._file.write(element) def __getAttrsString(self, attrs): if attrs is None or 0 == len(attrs.keys()): return None attrStr = '' for key in attrs.keys(): value = attrs.get(key) attrStr += '%s=\'%s\' ' % (key, value) return attrStr.strip() if __name__ == '__main__': import os from org.graver.utils.xmlLoader import XmlLoader configFile = '%s%s..%s..%s..%sconfig%sconfig.xml' % (os.path.dirname(__file__), os.path.sep, os.path.sep, os.path.sep, os.path.sep, os.path.sep) outputFile = '%s%s..%s..%s..%sconfig%stest.xml' % (os.path.dirname(__file__), os.path.sep, os.path.sep, os.path.sep, os.path.sep, os.path.sep) xmlLoader = XmlLoader() xmlroot = xmlLoader.load(configFile) writer = XmlWriter(outputFile) writer.write(xmlroot)