/// <summary>
        /// This is used when a book is first created from a source; without it, if the shell maker left the book as trilingual when working on it,
        /// then every time someone created a new book based on it, it too would be trilingual.
        /// </summary>
        /// <remarks>
        /// This method explicitly used the CollectionSettings languages in creating a new book.
        /// </remarks>
        public static void SetInitialMultilingualSetting(BookData bookData, int oneTwoOrThreeContentLanguages)
        {
            //var multilingualClass =  new string[]{"bloom-monolingual", "bloom-bilingual","bloom-trilingual"}[oneTwoOrThreeContentLanguages-1];

            if (oneTwoOrThreeContentLanguages < 3)
            {
                bookData.RemoveAllForms("contentLanguage3");
            }
            if (oneTwoOrThreeContentLanguages < 2)
            {
                bookData.RemoveAllForms("contentLanguage2");
            }

            var language1 = bookData.CollectionSettings.Language1;

            bookData.Set("contentLanguage1", XmlString.FromUnencoded(language1.Iso639Code), false);
            bookData.Set("contentLanguage1Rtl", XmlString.FromUnencoded(language1.IsRightToLeft.ToString()), false);
            if (oneTwoOrThreeContentLanguages > 1)
            {
                var language2 = bookData.CollectionSettings.Language2;
                bookData.Set("contentLanguage2", XmlString.FromUnencoded(language2.Iso639Code), false);
                bookData.Set("contentLanguage2Rtl", XmlString.FromUnencoded(language2.IsRightToLeft.ToString()), false);
            }
            var language3 = bookData.CollectionSettings.Language3;

            if (oneTwoOrThreeContentLanguages > 2 && !String.IsNullOrEmpty(language3.Iso639Code))
            {
                bookData.Set("contentLanguage3", XmlString.FromUnencoded(language3.Iso639Code), false);
                bookData.Set("contentLanguage3Rtl", XmlString.FromUnencoded(language3.IsRightToLeft.ToString()), false);
            }
        }
예제 #2
0
        public static void UpdateMetadataAttributesOnImage(ElementProxy imgOrDivWithBackgroundImage, PalasoImage imageInfo)
        {
            //see also Book.UpdateMetadataAttributesOnImage(), which does the same thing but on the document itself, not the browser dom
            imgOrDivWithBackgroundImage.SetAttribute("data-copyright",
                                                     XmlString.FromUnencoded(imageInfo.Metadata.CopyrightNotice ?? ""));

            imgOrDivWithBackgroundImage.SetAttribute("data-creator", XmlString.FromUnencoded(imageInfo.Metadata.Creator ?? ""));

            imgOrDivWithBackgroundImage.SetAttribute("data-license", XmlString.FromUnencoded(imageInfo.Metadata.License?.ToString() ?? ""));
        }
예제 #3
0
        public void SetString_CanReturnIt()
        {
            var e = MakeElement("<div id='foo'/>");

            e.SetAttribute("id", XmlString.FromUnencoded("blah"));
            Assert.AreEqual("blah", e.GetAttribute("id"));

            MakeElement("<div/>");
            e.SetAttribute("id", XmlString.FromUnencoded("blah"));
            Assert.AreEqual("blah", e.GetAttribute("id"));
        }
예제 #4
0
        static List <Tuple <string, XmlString> > MakeList(params string[] args)
        {
            var result = new List <Tuple <string, XmlString> >();

            Assert.That(args.Length % 2, Is.EqualTo(0));
            for (var i = 0; i < args.Length / 2; i++)
            {
                result.Add(Tuple.Create(args[i * 2], XmlString.FromUnencoded(args[i * 2 + 1])));
            }
            return(result);
        }
예제 #5
0
        /// <summary>
        /// Copy the copyright & license info to the originalCopyrightAndLicense,
        /// then remove the copyright so the translator can put in their own if they
        /// want. We retain the license, but the translator is allowed to change that.
        /// If the source is already a translation (already has original copyright or license)
        /// we keep them unchanged.
        /// </summary>
        public static void SetOriginalCopyrightAndLicense(HtmlDom dom, BookData bookData, CollectionSettings collectionSettings)
        {
            // If it already has some of this information, just keep it.
            if (bookData.BookIsDerivative())
            {
                return;                 //leave the original there.
            }
            // If there's no copyright information in a source-collection book, we're presumably making
            // a new original book, and shouldn't try to record any original copyright and license information.
            // This is somewhat redundant with the check in BookStarter.SetupNewDocumentContents(), the one
            // non-unit-test current caller of this method, that doesn't call this at all if the source is
            // a template book. I was trying for a minimal reasonable change for BL-5131, and therefore
            // put in this extra check, since previously this method was simply NEVER called in a source
            // collection.
            var copyrightNotice = BookCopyrightAndLicense.GetMetadata(dom, bookData).CopyrightNotice;

            if (String.IsNullOrEmpty(copyrightNotice) && collectionSettings.IsSourceCollection)
            {
                return;
            }
            bookData.Set("originalLicenseUrl", XmlString.FromXml(BookCopyrightAndLicense.GetLicenseUrl(dom)), "*");
            bookData.Set("originalCopyright", XmlString.FromUnencoded(copyrightNotice), "*");
            bookData.Set("originalLicenseNotes", XmlString.FromXml(dom.GetBookSetting("licenseNotes").GetFirstAlternative()), "*");
        }
예제 #6
0
        public void FromUnencoded_GivenText_ThenEncodesText(string unencodedInput, string expectedXml)
        {
            var result = XmlString.FromUnencoded(unencodedInput).Xml;

            Assert.That(result, Is.EqualTo(expectedXml));
        }