Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions Src/xWorks/ConfiguredLcmGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ internal static IFragment GenerateContentForFieldByReflection(object field, List
fileProperty = propertyValue as ICmFile;
fileOwner = field as ICmObject;
return fileProperty != null && fileOwner != null
? GenerateContentForPicture(fileProperty, nodeList, fileOwner, settings)
? GenerateContentForPicture(fileProperty, nodeList, fileOwner, settings, field)
: GenerateContentForPictureCaption(propertyValue, nodeList, settings);

case PropertyType.CmPossibility:
Expand Down Expand Up @@ -981,7 +981,7 @@ private static IFragment GenerateContentForPictureCaption(object propertyValue,
}

private static IFragment GenerateContentForPicture(ICmFile pictureFile, List<ConfigurableDictionaryNode> nodeList,
ICmObject owner, GeneratorSettings settings)
ICmObject owner, GeneratorSettings settings, object field)
{
var srcAttribute = GenerateSrcAttributeFromFilePath(pictureFile, settings.UseRelativePaths ? "pictures" : null, settings);
if (!string.IsNullOrEmpty(srcAttribute))
Expand All @@ -990,7 +990,9 @@ private static IFragment GenerateContentForPicture(ICmFile pictureFile, List<Con
// An XHTML id attribute must be unique but the ICmfile is used for all references to the same file within the project.
// The ICmPicture that owns the file does have unique guid so we use that.
var ownerGuid = owner.Guid.ToString();
return settings.ContentGenerator.AddImage(nodeList.Last(), settings, className, srcAttribute, ownerGuid);

string license = GeneratePictureLicenseContent(field, nodeList);
return settings.ContentGenerator.AddImage(nodeList.Last(), settings, className, srcAttribute, ownerGuid, license);
}
return settings.ContentGenerator.CreateFragment();
}
Expand Down Expand Up @@ -2119,6 +2121,35 @@ private static IFragment GeneratePictureContent(List<ConfigurableDictionaryNode>
}
}

private static string GeneratePictureLicenseContent(object item, List<ConfigurableDictionaryNode> nodeList)
{
foreach (ConfigurableDictionaryNode node in nodeList)
{
// The Copyright & License node is a child of the Pictures node.
// It uses an extension method, so in order to get the copyright info,
// we need to get the extension method in question, and then get its value.
if (node.Label == "Pictures")
{
foreach (var child in node.ReferencedOrDirectChildren)
{
if (child.Label == "Copyright & License")
{
MemberInfo property;
var extensionType = GetExtensionMethodType(child.FieldDescription);
property = extensionType.GetMethod(
GetExtensionMethodName(child.FieldDescription),
BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
// GetValueFromMember returns an "object" type, but for Copyright & License,
// the object is a string, so we can safely cast it here.
return (string)GetValueFromMember(property, item);
}
}
}
}

return String.Empty;
}

private static IFragment GenerateCollectionItemContent(List<ConfigurableDictionaryNode> nodeList,
DictionaryPublicationDecorator publicationDecorator, object item, object collectionOwner, GeneratorSettings settings,
bool first, ConfigurableDictionaryNode factoredTypeField = null)
Expand Down
2 changes: 1 addition & 1 deletion Src/xWorks/ILcmContentGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ IFragment GenerateGroupingNode(List<ConfigurableDictionaryNode> nodeList, object
void BeginObjectProperty(IFragmentWriter writer, ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, bool isBlockProperty, string getCollectionItemClassAttribute);
void EndObject(IFragmentWriter writer);
void WriteProcessedContents(IFragmentWriter writer, ConfigurableDictionaryNode config, IFragment contents);
IFragment AddImage(ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, string classAttribute, string srcAttribute, string pictureGuid);
IFragment AddImage(ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, string classAttribute, string srcAttribute, string pictureGuid, string license);
IFragment AddImageCaption(ConfigurableDictionaryNode config, IFragment captionContent);
IFragment GenerateSenseNumber(List<ConfigurableDictionaryNode> nodeList, ConfiguredLcmGenerator.GeneratorSettings settings, string formattedSenseNumber, string senseNumberWs);
IFragment AddLexReferences(List<ConfigurableDictionaryNode> nodeList, bool generateLexType, IFragment lexTypeContent, string className, IFragment referencesContent, bool typeBefore);
Expand Down
4 changes: 3 additions & 1 deletion Src/xWorks/LcmJsonGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public void WriteProcessedContents(IFragmentWriter writer, ConfigurableDictionar
}
}

public IFragment AddImage(ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, string classAttribute, string srcAttribute, string pictureGuid)
public IFragment AddImage(ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, string classAttribute, string srcAttribute, string pictureGuid, string license)
{
var bldr = new StringBuilder();
var fragment = new StringFragment();
Expand All @@ -357,6 +357,8 @@ public IFragment AddImage(ConfigurableDictionaryNode config, ConfiguredLcmGenera
xw.WriteValue("g" + pictureGuid);
xw.WritePropertyName("src");
xw.WriteValue(srcAttribute.Replace("\\", "/")); // expecting relative paths only
xw.WritePropertyName("copyrightLicense");
xw.WriteValue(license);
xw.Flush();
return fragment;
}
Expand Down
2 changes: 1 addition & 1 deletion Src/xWorks/LcmWordGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1770,7 +1770,7 @@ public void WriteProcessedContents(IFragmentWriter writer, ConfigurableDictionar
((WordFragmentWriter)writer).Insert(contents);
}
}
public IFragment AddImage(ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, string classAttribute, string srcAttribute, string pictureGuid)
public IFragment AddImage(ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, string classAttribute, string srcAttribute, string pictureGuid, string license)
{
DocFragment imageFrag = new DocFragment();
string partId = AddImagePartToPackage(srcAttribute);
Expand Down
3 changes: 2 additions & 1 deletion Src/xWorks/LcmXhtmlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ public void WriteProcessedContents(IFragmentWriter writer, ConfigurableDictionar

/// <summary/>
/// <param name="pictureGuid">This is used as an id in the xhtml and must be unique.</param>
public IFragment AddImage(ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, string classAttribute, string srcAttribute, string pictureGuid)
public IFragment AddImage(ConfigurableDictionaryNode config, ConfiguredLcmGenerator.GeneratorSettings settings, string classAttribute, string srcAttribute, string pictureGuid, string license)
{
var bldr = new StringBuilder();
var fragment = new StringFragment(bldr);
Expand All @@ -952,6 +952,7 @@ public IFragment AddImage(ConfigurableDictionaryNode config, ConfiguredLcmGenera
xw.WriteAttributeString("class", classAttribute);
xw.WriteAttributeString("src", srcAttribute);
xw.WriteAttributeString("id", "g" + pictureGuid);
xw.WriteAttributeString("title", license);
WriteNodeId(xw, config, settings);
xw.WriteEndElement();
xw.Flush();
Expand Down
6 changes: 3 additions & 3 deletions Src/xWorks/xWorksTests/LcmJsonGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public void GenerateJsonForEntry_OneSenseWithSinglePicture()
//SUT
var result = ConfiguredLcmGenerator.GenerateContentForEntry(entry, mainEntryNode, null, settings, 0).ToString();
var expectedResults = @"{""xhtmlTemplate"": ""lexentry"",""guid"":""g" + entry.Guid + @""",""letterHead"": ""c"",""sortIndex"": 0,
""pictures"": [{""guid"":""g" + sensePic.Guid + @""",""src"":""pictures/test_auth_copy_license.jpg"",
""pictures"": [{""guid"":""g" + sensePic.Guid + @""",""src"":""pictures/test_auth_copy_license.jpg"", ""copyrightLicense"":"""",
""sensenumber"": [{""lang"":""en"",""value"":""1""}],""caption"": [{""lang"":""en"",""value"":""caption""}]}]}";
var expected = (JObject)JsonConvert.DeserializeObject(expectedResults, new JsonSerializerSettings { Formatting = Formatting.None });
VerifyJson(result, expected);
Expand Down Expand Up @@ -982,8 +982,8 @@ public void GenerateJsonForEntry_TwoDifferentPicturesGetUniqueWebFriendlyPaths()

// Bug: The second filename should be different after the export with relative path settings (fix later)
var expectedResults = @"{""xhtmlTemplate"": ""lexentry"",""guid"":""g" + testEntry.Guid + @""",""letterHead"": ""c"",""sortIndex"": 0,
""pictures"": [{""guid"":""g" + sensePic.Guid + @""",""src"":""pictures/" + fileName + @"""},
{""guid"":""g" + sensePic2.Guid + @""",""src"":""pictures/" + fileName + @"""}],}";
""pictures"": [{""guid"":""g" + sensePic.Guid + @""",""src"":""pictures/" + fileName + @""", ""copyrightLicense"":"""",},
{""guid"":""g" + sensePic2.Guid + @""",""src"":""pictures/" + fileName + @""", ""copyrightLicense"":""""}],}";
var expected = (JObject)JsonConvert.DeserializeObject(expectedResults, new JsonSerializerSettings { Formatting = Formatting.None });
VerifyJson(result, expected);
}
Expand Down
Loading