Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
        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)