コード例 #1
0
        public void Equals_Null_False()
        {
            MultiTextBase x = new MultiTextBase();

            x["ws"] = "test";
            Assert.IsFalse(x.Equals(null));
        }
コード例 #2
0
        public void SerializeEmptyWithXmlSerializer()
        {
            MultiTextBase text        = new MultiTextBase();
            var           answerXpath = "/TestMultiTextHolder[namespace::xsd='http://www.w3.org/2001/XMLSchema' and namespace::xsi='http://www.w3.org/2001/XMLSchema-instance']/name";

            CheckSerializeWithXmlSerializer(text, answerXpath, 1);
        }
コード例 #3
0
        public void GetOrderedAndFilteredForms_EmptyMultiText_GivesEmptyList()
        {
            MultiTextBase x = new MultiTextBase();

            LanguageForm[] forms = x.GetOrderedAndFilteredForms(new string[] { "one", "three" });
            Assert.AreEqual(0, forms.Length);
        }
コード例 #4
0
        public void GetEnumerator()
        {
            MultiTextBase text        = new MultiTextBase();
            IEnumerator   ienumerator = text.GetEnumerator();

            Assert.IsNotNull(ienumerator);
        }
コード例 #5
0
        public void IterateWithForEach()
        {
            MultiTextBase text = new MultiTextBase();

            text["a"] = "alpha";
            text["b"] = "beta";
            text["g"] = "gamma";
            int i = 0;

            foreach (LanguageForm l in text)
            {
                switch (i)
                {
                case 0:
                    Assert.AreEqual("a", l.WritingSystemId);
                    Assert.AreEqual("alpha", l.Form);
                    break;

                case 1:
                    Assert.AreEqual("b", l.WritingSystemId);
                    Assert.AreEqual("beta", l.Form);
                    break;

                case 2:
                    Assert.AreEqual("g", l.WritingSystemId);
                    Assert.AreEqual("gamma", l.Form);
                    break;
                }
                i++;
            }
        }
コード例 #6
0
        public void AnnotationOfMisssingAlternative()
        {
            MultiTextBase multiTextBase = new MultiTextBase();

            Assert.IsFalse(multiTextBase.GetAnnotationOfAlternativeIsStarred("zz"));
            Assert.IsFalse(multiTextBase.ContainsAlternative("zz"), "should not cause the creation of the alt");
        }
コード例 #7
0
        /// <summary> Adds each sense of a word to be written out to lift </summary>
        private void AddSenses(LexEntry entry, Word wordEntry)
        {
            for (var i = 0; i < wordEntry.Senses.Count; i++)
            {
                // Merge in senses
                var dict = new Dictionary <string, string>();
                foreach (var gloss in wordEntry.Senses[i].Glosses)
                {
                    dict.Add(gloss.Language, gloss.Def);
                }

                var lexSense = new LexSense();
                lexSense.Gloss.MergeIn(MultiTextBase.Create(dict));
                entry.Senses.Add(lexSense);

                // Merge in semantic domains
                foreach (var semdom in wordEntry.Senses[i].SemanticDomains)
                {
                    var orc = new OptionRefCollection();
                    orc.Add(semdom.Id + " " + semdom.Name);

                    entry.Senses[i].Properties.Add(
                        new KeyValuePair <string, IPalasoDataObjectProperty>("semantic-domain-ddp4", orc));
                }
            }
        }
コード例 #8
0
 private void WriteMultiTextNoWrapper(string propertyName, MultiText text)         // review cp see WriteEmbeddedXmlCollection
 {
     if (!MultiTextBase.IsEmpty(text))
     {
         AddMultitextForms(propertyName, text);
     }
 }
コード例 #9
0
        public void GetOrderedAndFilteredForms_EmptyIdList_GivesEmptyList()
        {
            MultiTextBase x = new MultiTextBase();

            x["one"] = "test";
            Assert.AreEqual(0, x.GetOrderedAndFilteredForms(new string[] { }).Length);
        }
コード例 #10
0
        public void ClearingAnnotationOfEmptyAlternativeRemovesTheAlternative()
        {
            MultiTextBase multiTextBase = new MultiTextBase();

            multiTextBase.SetAnnotationOfAlternativeIsStarred("zz", true);
            multiTextBase.SetAnnotationOfAlternativeIsStarred("zz", false);
            Assert.IsFalse(multiTextBase.ContainsAlternative("zz"));
        }
コード例 #11
0
        public void HasFormWithSameContent_BothEmpty_True()
        {
            MultiTextBase x = new MultiTextBase();
            MultiTextBase y = new MultiTextBase();

            Assert.IsTrue(x.HasFormWithSameContent(y));
            Assert.IsTrue(y.HasFormWithSameContent(x));
        }
コード例 #12
0
        public void CompareTo_MultiTextWithMoreForms_ReturnsLess()
        {
            MultiTextBase multiTextBase          = new MultiTextBase();
            MultiTextBase multiTextBaseToCompare = new MultiTextBase();

            multiTextBaseToCompare.SetAlternative("de", "Word 1");
            Assert.AreEqual(-1, multiTextBase.CompareTo(multiTextBaseToCompare));
        }
コード例 #13
0
        public void ClearingAnnotationOfNonEmptyAlternative()
        {
            MultiTextBase multiTextBase = new MultiTextBase();

            multiTextBase.SetAnnotationOfAlternativeIsStarred("zz", true);
            multiTextBase["zz"] = "hello";
            multiTextBase.SetAnnotationOfAlternativeIsStarred("zz", false);
            Assert.IsTrue(multiTextBase.ContainsAlternative("zz"));
        }
コード例 #14
0
 public void AddLanguageString(string key, string value, string writingSystemId, bool isCollectionValue)
 {
     if (!TextVariables.ContainsKey(key))
     {
         var text = new MultiTextBase();
         TextVariables.Add(key, new NamedMutliLingualValue(text, isCollectionValue));
     }
     TextVariables[key].TextAlternatives.SetAlternative(writingSystemId, value);
 }
コード例 #15
0
        public void CompareTo_MultiTextWithFewerForms_ReturnsGreater()
        {
            MultiTextBase multiTextBase = new MultiTextBase();

            multiTextBase.SetAlternative("de", "Word 1");
            MultiTextBase multiTextBaseToCompare = new MultiTextBase();

            Assert.AreEqual(1, multiTextBase.CompareTo(multiTextBaseToCompare));
        }
コード例 #16
0
        public void HasFormWithSameContent_Identity_True()
        {
            MultiTextBase x = new MultiTextBase();

            x["ws1"] = "testing";
            x["ws"]  = "test";
            x["ws2"] = "testing";
            Assert.IsTrue(x.HasFormWithSameContent(x));
        }
コード例 #17
0
        public void SetAnnotation()
        {
            MultiTextBase multiTextBase = new MultiTextBase();

            multiTextBase.SetAnnotationOfAlternativeIsStarred("zz", true);
            Assert.AreEqual(String.Empty, multiTextBase.GetExactAlternative("zz"));
            Assert.IsTrue(multiTextBase.GetAnnotationOfAlternativeIsStarred("zz"));
            multiTextBase.SetAnnotationOfAlternativeIsStarred("zz", false);
            Assert.IsFalse(multiTextBase.GetAnnotationOfAlternativeIsStarred("zz"));
        }
コード例 #18
0
        public void EmptyingTextOfFlaggedAlternativeDoesNotDeleteIfFlagged()
        {
            // REVIEW: not clear really what behavior we want here, since user deletes via clearing text
            MultiTextBase multiTextBase = new MultiTextBase();

            multiTextBase["zz"] = "hello";
            multiTextBase.SetAnnotationOfAlternativeIsStarred("zz", true);
            multiTextBase["zz"] = "";
            Assert.IsTrue(multiTextBase.ContainsAlternative("zz"));
        }
コード例 #19
0
        public void Count()
        {
            MultiTextBase text = new MultiTextBase();

            Assert.AreEqual(0, text.Count);
            text["a"] = "alpha";
            text["b"] = "beta";
            text["g"] = "gamma";
            Assert.AreEqual(3, text.Count);
        }
コード例 #20
0
        public void CompareTo_IdenticalMultiText_ReturnsEqual()
        {
            MultiTextBase multiTextBase = new MultiTextBase();

            multiTextBase.SetAlternative("de", "Word 1");
            MultiTextBase multiTextBaseToCompare = new MultiTextBase();

            multiTextBaseToCompare.SetAlternative("de", "Word 1");
            Assert.AreEqual(0, multiTextBase.CompareTo(multiTextBaseToCompare));
        }
コード例 #21
0
        public void CompareTo_MultiTextWithNonIdenticalFormsAndFirstNonidenticalformIsAlphabeticallyLater_ReturnsLess()
        {
            MultiTextBase multiTextBase = new MultiTextBase();

            multiTextBase.SetAlternative("de", "Word 1");
            MultiTextBase multiTextBaseToCompare = new MultiTextBase();

            multiTextBaseToCompare.SetAlternative("de", "Word 2");
            Assert.AreEqual(-1, multiTextBase.CompareTo(multiTextBaseToCompare));
        }
コード例 #22
0
        public void CompareTo_MultiTextWithNonIdenticalWritingSystemsAndFirstNonidenticalWritingSystemIsAlphabeticallyEarlier_ReturnsGreater()
        {
            MultiTextBase multiTextBase = new MultiTextBase();

            multiTextBase.SetAlternative("en", "Word 1");
            MultiTextBase multiTextBaseToCompare = new MultiTextBase();

            multiTextBaseToCompare.SetAlternative("de", "Word 1");
            Assert.AreEqual(1, multiTextBase.CompareTo(multiTextBaseToCompare));
        }
コード例 #23
0
        public void SerializeWithXmlSerializer()
        {
            MultiTextBase text = new MultiTextBase();

            text["foo"] = "alpha";
            text["boo"] = "beta";
            var answerXPath = "/TestMultiTextHolder[namespace::xsd='http://www.w3.org/2001/XMLSchema' and namespace::xsi='http://www.w3.org/2001/XMLSchema-instance']/name/form";

            CheckSerializeWithXmlSerializer(text, answerXPath, 2);
        }
コード例 #24
0
        public void HasFormWithSameContent_OneEmpty_False()
        {
            MultiTextBase x = new MultiTextBase();
            MultiTextBase y = new MultiTextBase();

            y["ws"] = "test";
            y.SetAnnotationOfAlternativeIsStarred("ws", true);
            Assert.IsFalse(x.HasFormWithSameContent(y));
            Assert.IsFalse(y.HasFormWithSameContent(x));
        }
コード例 #25
0
        private static void CopyItemToFieldsInPages(HtmlDom dom, string key, string valueAttribute = null, string[] languagePreferences = null)
        {
            if (languagePreferences == null)
            {
                languagePreferences = new[] { "*", "en" }
            }
            ;

            MultiTextBase source = dom.GetBookSetting(key);

            if (key == "copyright")
            {
                // For CC0, we store the "copyright", but don't display it in the text of the book.
                var licenseUrl = dom.GetBookSetting("licenseUrl").GetExactAlternative("*");
                if (licenseUrl == CreativeCommonsLicense.CC0Url)
                {
                    source = new MultiTextBase();
                }
            }

            foreach (XmlElement target in dom.SafeSelectNodes("//*[@data-derived='" + key + "']"))
            {
                //just put value into the text of the element
                if (string.IsNullOrEmpty(valueAttribute))
                {
                    //clear out what's there now
                    target.RemoveAttribute("lang");
                    target.InnerText = "";

                    var form = source.GetBestAlternative(languagePreferences);
                    if (form != null && !string.IsNullOrWhiteSpace(form.Form))
                    {
                        // HtmlDom.GetBookSetting(key) returns the result of XmlNode.InnerXml which will be Html encoded (&amp; &lt; etc).
                        // HtmlDom.SetElementFromUserStringPreservingLineBreaks() calls XmlNode.InnerText, which Html encodes if necessary.
                        // So we need to decode here to prevent double encoding.  See http://issues.bloomlibrary.org/youtrack/issue/BL-4585.
                        // Note that HtmlDom.SetElementFromUserStringPreservingLineBreaks() handles embedded <br/> elements, but makes no
                        // effort to handle p or div elements.
                        var decoded = System.Web.HttpUtility.HtmlDecode(form.Form);
                        HtmlDom.SetElementFromUserStringSafely(target, decoded);
                        target.SetAttribute("lang", form.WritingSystemId);                         //this allows us to set the font to suit the language
                    }
                }
                else                 //Put the value into an attribute. The license image goes through this path.
                {
                    target.SetAttribute(valueAttribute, source.GetBestAlternativeString(languagePreferences));
                    if (source.Empty)
                    {
                        //if the license image is empty, make sure we don't have some alternative text
                        //about the image being missing or slow to load
                        target.SetAttribute("alt", "");
                        //over in javascript land, @alt will get set appropriately when the image url is not empty.
                    }
                }
            }
        }
コード例 #26
0
        public void UpdateGenericLanguageString(string key, string value, bool isCollectionValue)
        {
            var text = new MultiTextBase();

            text.SetAlternative("*", value);
            if (TextVariables.ContainsKey(key))
            {
                TextVariables.Remove(key);
            }
            TextVariables.Add(key, new NamedMutliLingualValue(text, isCollectionValue));
        }
コード例 #27
0
        public void HasFormWithSameContent_DifferentValue_False()
        {
            MultiTextBase x = new MultiTextBase();

            x["ws"] = "test";
            MultiTextBase y = new MultiTextBase();

            y["ws"] = "tests";
            Assert.IsFalse(x.HasFormWithSameContent(y));
            Assert.IsFalse(y.HasFormWithSameContent(x));
        }
コード例 #28
0
        private void WriteCustomMultiTextField(string type, MultiText text)          // review cp see WriteEmbeddedXmlCollection
        {
            if (!MultiTextBase.IsEmpty(text))
            {
                Writer.WriteStartElement("field");

                Writer.WriteAttributeString("type", type);
                WriteMultiTextNoWrapper(type, text);
                Writer.WriteEndElement();
            }
        }
コード例 #29
0
        public static Metadata CreateMetadata(MultiTextBase copyright, string licenseUrl, MultiTextBase licenseNotes, BookData bookData)
        {
            var metadata = new Metadata();

            if (!copyright.Empty)
            {
                metadata.CopyrightNotice = GetBestMultiTextBaseValue(copyright, bookData);
            }

            if (string.IsNullOrWhiteSpace(licenseUrl))
            {
                //NB: we are mapping "RightsStatement" (which comes from XMP-dc:Rights) to "LicenseNotes" in the html.
                //custom licenses live in this field, so if we have notes (and no URL) it is a custom one.
                if (!licenseNotes.Empty)
                {
                    metadata.License = new CustomLicense {
                        RightsStatement = GetBestMultiTextBaseValue(licenseNotes, bookData)
                    };
                }
                else
                {
                    // The only remaining current option is a NullLicense
                    metadata.License = new NullLicense();                     //"contact the copyright owner
                }
            }
            else             // there is a licenseUrl, which means it is a CC license
            {
                try
                {
                    metadata.License = CreativeCommonsLicense.FromLicenseUrl(licenseUrl);
                }
                catch (IndexOutOfRangeException)
                {
                    // Need to handle urls which do not end with the version number.
                    // Simply set it to the default version.
                    if (!licenseUrl.EndsWith("/"))
                    {
                        licenseUrl += "/";
                    }
                    licenseUrl      += CreativeCommonsLicense.kDefaultVersion;
                    metadata.License = CreativeCommonsLicense.FromLicenseUrl(licenseUrl);
                }
                catch (Exception e)
                {
                    throw new ApplicationException("Bloom had trouble parsing this license url: '" + licenseUrl + "'. (ref BL-4108)", e);
                }
                //are there notes that go along with that?
                if (!licenseNotes.Empty)
                {
                    metadata.License.RightsStatement = GetBestMultiTextBaseValue(licenseNotes, bookData);
                }
            }
            return(metadata);
        }
コード例 #30
0
        public void ContainsEqualForm_DifferentValue_False()
        {
            MultiTextBase x = new MultiTextBase();

            x["ws"] = "test";
            LanguageForm form = new LanguageForm();

            form.WritingSystemId = "ws";
            form.Form            = "tests";
            Assert.IsFalse(x.ContainsEqualForm(form));
        }