-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle canonical LF tag names in LfMerge
Now LfMerge can create a CmPossibilityList in FLEx data if it doesn't already exist, which will allow us to create the custom field that will store LF tags in FLEx data.
- Loading branch information
Showing
5 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
src/LfMerge.Core/DataConverters/CanonicalSources/CanonicalLfTagItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) 2016-2018 SIL International | ||
// This software is licensed under the MIT license (http://opensource.org/licenses/MIT) | ||
using System.Xml; | ||
using SIL.LCModel; | ||
|
||
namespace LfMerge.Core.DataConverters.CanonicalSources | ||
{ | ||
public class CanonicalLfTagItem : CanonicalItem | ||
{ | ||
public override void PopulateFromXml(XmlReader reader) | ||
{ | ||
if (reader.LocalName != "item" || string.IsNullOrEmpty(reader.GetAttribute("guid"))) | ||
return; // If we weren't on the right kind of node, do nothing | ||
GuidStr = reader.GetAttribute("guid"); | ||
while (reader.Read()) | ||
{ | ||
switch (reader.NodeType) | ||
{ | ||
case XmlNodeType.Element: | ||
{ | ||
switch (reader.LocalName) | ||
{ | ||
case "item": | ||
if (!string.IsNullOrEmpty(reader.GetAttribute("id"))) | ||
{ | ||
Key = reader.GetAttribute("id"); | ||
} | ||
break; | ||
case "abbrev": | ||
AddAbbrev(reader.GetAttribute("ws"), reader.ReadInnerXml()); | ||
break; | ||
case "term": | ||
AddName(reader.GetAttribute("ws"), reader.ReadInnerXml()); | ||
break; | ||
case "def": | ||
AddDescription(reader.GetAttribute("ws"), reader.ReadInnerXml()); | ||
break; | ||
} | ||
break; | ||
} | ||
case XmlNodeType.EndElement: | ||
{ | ||
if (reader.LocalName == "item") | ||
{ | ||
if (string.IsNullOrEmpty(Key)) { | ||
Key = AbbrevByWs(KeyWs); | ||
} | ||
reader.Read(); // Skip past the closing element before returning | ||
return; | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
protected override void PopulatePossibilityFromExtraData(ICmPossibility poss) | ||
{ | ||
// CanonicalLfTagItem instances don't need anything from ExtraData | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/LfMerge.Core/DataConverters/CanonicalSources/CanonicalLfTagSource.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) 2016 SIL International | ||
// This software is licensed under the MIT license (http://opensource.org/licenses/MIT) | ||
|
||
namespace LfMerge.Core.DataConverters.CanonicalSources | ||
{ | ||
public class CanonicalLfTagSource : CanonicalOptionListSource | ||
{ | ||
public CanonicalLfTagSource() | ||
: base("canonical-lf-tags.xml", "item") | ||
{ | ||
} | ||
|
||
public override void LoadCanonicalData() | ||
{ | ||
LoadCanonicalData<CanonicalLfTagItem>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters