///<summary> /// Returns an instance of an ldml in folder writing system reposistory. ///</summary> ///<param name="basePath">base location of the global writing system repository</param> ///<param name="migrationHandler">Callback if during the initialization any writing system id's are changed</param> ///<param name="loadProblemHandler">Callback if during the initialization any writing systems cannot be loaded</param> ///<param name="compatibilityMode"></param> public static LdmlInFolderWritingSystemRepository Initialize( string basePath, LdmlVersion0MigrationStrategy.MigrationHandler migrationHandler, WritingSystemLoadProblemHandler loadProblemHandler, WritingSystemCompatibility compatibilityMode ) { var migrator = new LdmlInFolderWritingSystemRepositoryMigrator(basePath, migrationHandler, compatibilityMode); migrator.Migrate(); var instance = new LdmlInFolderWritingSystemRepository(basePath, compatibilityMode); instance.LoadAllDefinitions(); // Call the loadProblemHandler with both migration problems and load problems var loadProblems = new List <WritingSystemRepositoryProblem>(); loadProblems.AddRange(migrator.MigrationProblems); loadProblems.AddRange(instance.LoadProblems); if (loadProblems.Count > 0 && loadProblemHandler != null) { loadProblemHandler(loadProblems); } return(instance); }
/// <summary> /// Constructor, set the CompatibilityMode /// </summary> protected WritingSystemRepositoryBase(WritingSystemCompatibility compatibilityMode) { CompatibilityMode = compatibilityMode; _writingSystems = new Dictionary <string, IWritingSystemDefinition>(StringComparer.OrdinalIgnoreCase); _writingSystemsToIgnore = new Dictionary <string, DateTime>(StringComparer.OrdinalIgnoreCase); _idChangeMap = new Dictionary <string, string>(); //_sharedStore = LdmlSharedWritingSystemRepository.Singleton; }
/// <summary> /// Constructor, set the CompatibilityMode /// </summary> protected WritingSystemRepositoryBase(WritingSystemCompatibility compatibilityMode) { CompatibilityMode = compatibilityMode; _writingSystems = new Dictionary<string, IWritingSystemDefinition>(StringComparer.OrdinalIgnoreCase); _writingSystemsToIgnore = new Dictionary<string, DateTime>(StringComparer.OrdinalIgnoreCase); _idChangeMap = new Dictionary<string, string>(); //_sharedStore = LdmlSharedWritingSystemRepository.Singleton; }
public LdmlVersion0MigrationStrategy( MigrationHandler migrationHandler, IAuditTrail auditLog, int fromVersion, WritingSystemCompatibility roundtripBogusFlex70PrivateUse) : this(migrationHandler, auditLog, fromVersion) { _roundTripBogusFlex70PrivateUse = roundtripBogusFlex70PrivateUse; }
public WritingSystemLdmlVersionGetter(WritingSystemCompatibility compatibilityMode) { var versionNodeVersion = new XPathVersion(1, "/ldml/special/palaso:version/@value"); versionNodeVersion.NamespaceManager.AddNamespace("palaso", "urn://palaso.org/ldmlExtensions/v1"); if(compatibilityMode == WritingSystemCompatibility.Flex7V0Compatible){ var flexPrivateUseVersionGetter = new XPathVersion(1, "/ldml/identity/language/@type"); flexPrivateUseVersionGetter.VersionParser = str => { return (str.StartsWith("x-", StringComparison.OrdinalIgnoreCase) || str.Equals("x")) ? 2 : -1; }; _versionGetters.Add(flexPrivateUseVersionGetter); } _versionGetters.Add(versionNodeVersion); }
public WritingSystemLdmlVersionGetter(WritingSystemCompatibility compatibilityMode) { var versionNodeVersion = new XPathVersion(1, "/ldml/special/palaso:version/@value"); versionNodeVersion.NamespaceManager.AddNamespace("palaso", "urn://palaso.org/ldmlExtensions/v1"); if (compatibilityMode == WritingSystemCompatibility.Flex7V0Compatible) { var flexPrivateUseVersionGetter = new XPathVersion(1, "/ldml/identity/language/@type"); flexPrivateUseVersionGetter.VersionParser = str => { return((str.StartsWith("x-", StringComparison.OrdinalIgnoreCase) || str.Equals("x")) ? 2 : -1); }; _versionGetters.Add(flexPrivateUseVersionGetter); } _versionGetters.Add(versionNodeVersion); }
public LdmlInFolderWritingSystemRepositoryMigrator( string ldmlPath, LdmlVersion0MigrationStrategy.MigrationHandler migrationHandler, WritingSystemCompatibility compatibilityMode ) : base(WritingSystemDefinition.LatestWritingSystemDefinitionVersion, ldmlPath) { SearchPattern = "*.ldml"; //The first versiongetter checks for the palaso:version node. //The DefaultVersion is a catchall that identifies any file as version 0 that the first version getter can't identify AddVersionStrategy(new WritingSystemLdmlVersionGetter(compatibilityMode)); AddVersionStrategy(new DefaultVersion(0, 0)); var auditLog = new WritingSystemChangeLog( new WritingSystemChangeLogDataMapper(Path.Combine(ldmlPath, "idchangelog.xml")) ); AddMigrationStrategy(new LdmlVersion0MigrationStrategy(migrationHandler, auditLog, 0, compatibilityMode)); // Version 0 strategy has been enhanced to also migrate version 1. AddMigrationStrategy(new LdmlVersion0MigrationStrategy(migrationHandler, auditLog, 1, compatibilityMode)); }
///<summary> /// Returns an instance of an ldml in folder writing system reposistory. ///</summary> ///<param name="basePath">base location of the global writing system repository</param> ///<param name="migrationHandler">Callback if during the initialization any writing system id's are changed</param> ///<param name="loadProblemHandler">Callback if during the initialization any writing systems cannot be loaded</param> ///<param name="compatibilityMode"></param> public static LdmlInFolderWritingSystemRepository Initialize( string basePath, LdmlVersion0MigrationStrategy.MigrationHandler migrationHandler, WritingSystemLoadProblemHandler loadProblemHandler, WritingSystemCompatibility compatibilityMode ) { var migrator = new LdmlInFolderWritingSystemRepositoryMigrator(basePath, migrationHandler, compatibilityMode); migrator.Migrate(); var instance = new LdmlInFolderWritingSystemRepository(basePath, compatibilityMode); instance.LoadAllDefinitions(); // Call the loadProblemHandler with both migration problems and load problems var loadProblems = new List<WritingSystemRepositoryProblem>(); loadProblems.AddRange(migrator.MigrationProblems); loadProblems.AddRange(instance.LoadProblems); if (loadProblems.Count > 0 && loadProblemHandler != null) { loadProblemHandler(loadProblems); } return instance; }
/// <summary> /// use a special path for the repository /// </summary> /// <param name="basePath"></param> /// <param name="compatibilityMode"></param> protected internal LdmlInFolderWritingSystemRepository(string basePath, WritingSystemCompatibility compatibilityMode) : base(compatibilityMode) { PathToWritingSystems = basePath; _changeLog = new WritingSystemChangeLog(new WritingSystemChangeLogDataMapper(Path.Combine(PathToWritingSystems, "idchangelog.xml"))); }
/// <summary> /// The "oldFileReader" parameter allows the LdmldataMapper to allow data that it doesn't understand to be roundtripped. /// </summary> /// <param name="filePath"></param> /// <param name="ws"></param> /// <param name="oldFile"></param> public void Write(XmlWriter xmlWriter, WritingSystemDefinition ws, XmlReader oldFileReader, WritingSystemCompatibility compatibilityMode) { _compatibilityMode = compatibilityMode; if (xmlWriter == null) { throw new ArgumentNullException("xmlWriter"); } if (ws == null) { throw new ArgumentNullException("ws"); } // We don't want to run any risk of persisting an invalid writing system in an LDML. ws.RequiresValidTag = true; XmlReader reader = null; try { if (oldFileReader != null) { XmlReaderSettings settings = new XmlReaderSettings(); settings.NameTable = _nameSpaceManager.NameTable; settings.IgnoreWhitespace = true; settings.ConformanceLevel = ConformanceLevel.Auto; settings.ValidationType = ValidationType.None; settings.XmlResolver = null; settings.ProhibitDtd = false; reader = XmlReader.Create(oldFileReader, settings); } WriteLdml(xmlWriter, reader, ws); } finally { if (reader != null) { reader.Close(); } } }
/// <summary> /// The "oldFile" parameter allows the LdmldataMapper to allow data that it doesn't understand to be roundtripped. /// </summary> /// <param name="filePath"></param> /// <param name="ws"></param> /// <param name="oldFile"></param> /// <param name="compatibilityMode"></param> public void Write(string filePath, WritingSystemDefinition ws, Stream oldFile, WritingSystemCompatibility compatibilityMode) { _compatibilityMode = compatibilityMode; if (filePath == null) { throw new ArgumentNullException("filePath"); } if (ws == null) { throw new ArgumentNullException("ws"); } XmlReader reader = null; try { if (oldFile != null) { var readerSettings = new XmlReaderSettings(); readerSettings.NameTable = _nameSpaceManager.NameTable; readerSettings.IgnoreWhitespace = true; readerSettings.ConformanceLevel = ConformanceLevel.Auto; readerSettings.ValidationType = ValidationType.None; readerSettings.XmlResolver = null; readerSettings.ProhibitDtd = false; reader = XmlReader.Create(oldFile, readerSettings); } string backupFilePath = null; if (File.Exists(filePath)) { try { backupFilePath = Path.ChangeExtension(Path.GetTempFileName(), Path.GetExtension(filePath)); File.Copy(filePath, backupFilePath); } catch (Exception) { backupFilePath = null; } } try { using (var writer = XmlWriter.Create(filePath, CanonicalXmlSettings.CreateXmlWriterSettings())) { writer.WriteStartDocument(); WriteLdml(writer, reader, ws); } } catch (Exception) { if (backupFilePath != null) File.Copy(backupFilePath, filePath, true); throw; } if (backupFilePath != null) File.Delete(backupFilePath); } finally { if (reader != null) { reader.Close(); } } }
/// <summary> /// The "oldFile" parameter allows the LdmldataMapper to allow data that it doesn't understand to be roundtripped. /// </summary> /// <param name="filePath"></param> /// <param name="ws"></param> /// <param name="oldFile"></param> /// <param name="compatibilityMode"></param> public void Write(string filePath, WritingSystemDefinition ws, Stream oldFile, WritingSystemCompatibility compatibilityMode) { _compatibilityMode = compatibilityMode; if (filePath == null) { throw new ArgumentNullException("filePath"); } if (ws == null) { throw new ArgumentNullException("ws"); } XmlReader reader = null; try { if (oldFile != null) { var readerSettings = new XmlReaderSettings(); readerSettings.NameTable = _nameSpaceManager.NameTable; readerSettings.IgnoreWhitespace = true; readerSettings.ConformanceLevel = ConformanceLevel.Auto; readerSettings.ValidationType = ValidationType.None; readerSettings.XmlResolver = null; readerSettings.ProhibitDtd = false; reader = XmlReader.Create(oldFile, readerSettings); } using (var writer = XmlWriter.Create(filePath, CanonicalXmlSettings.CreateXmlWriterSettings())) { writer.WriteStartDocument(); WriteLdml(writer, reader, ws); writer.Close(); } } finally { if (reader != null) { reader.Close(); } } }