Ejemplo n.º 1
0
		public void NullConditions()
		{
			MultiTextBase text = new MultiTextBase();
			Assert.AreSame(string.Empty, text["foo"], "never before heard of alternative should give back an empty string");
			Assert.AreSame(string.Empty, text["foo"], "second time");
			Assert.AreSame(string.Empty, text.GetBestAlternative("fox"));
			text.SetAlternative("zox", "");
			Assert.AreSame(string.Empty, text["zox"]);
			text.SetAlternative("zox", null);
			Assert.AreSame(string.Empty, text["zox"], "should still be empty string after setting to null");
			text.SetAlternative("zox", "something");
			text.SetAlternative("zox", null);
			Assert.AreSame(string.Empty, text["zox"], "should still be empty string after setting something and then back to null");
		}
Ejemplo n.º 2
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));
 }
Ejemplo n.º 3
0
 protected static void CopyForms(Dictionary <string, string> forms, MultiTextBase m)
 {
     if (forms != null && forms.Keys != null)
     {
         foreach (string key in forms.Keys)
         {
             LanguageForm f = m.Find(key);
             if (f != null)
             {
                 f.Form = forms[key];
             }
             else
             {
                 m.SetAlternative(key, forms[key]);
             }
         }
     }
 }
Ejemplo n.º 4
0
		protected static void CopyForms(Dictionary<string, string> forms, MultiTextBase m)
		{
			if (forms != null && forms.Keys != null)
			{
				foreach (string key in forms.Keys)
				{
					LanguageForm f = m.Find(key);
					if (f != null)
					{
						f.Form = forms[key];
					}
					else
					{
						m.SetAlternative(key, forms[key]);
					}
				}
			}
		}
Ejemplo n.º 5
0
        /// <summary>
        /// walk throught the sourceDom, collecting up values from elements that have data-book or data-collection attributes.
        /// </summary>
        private void GatherDataItemsFromXElement(DataSet data, XmlNode sourceElement
			/* can be the whole sourceDom or just a page */)
        {
            string elementName = "*";
            try
            {
                string query = String.Format(".//{0}[(@data-book or @data-library or @data-collection)]", elementName);

                XmlNodeList nodesOfInterest = sourceElement.SafeSelectNodes(query);

                foreach (XmlElement node in nodesOfInterest)
                {
                    bool isCollectionValue = false;

                    string key = node.GetAttribute("data-book").Trim();
                    if (key == String.Empty)
                    {
                        key = node.GetAttribute("data-collection").Trim();
                        if (key == String.Empty)
                        {
                            key = node.GetAttribute("data-library").Trim(); //the old (pre-version 1) name of collections was 'library'
                        }
                        isCollectionValue = true;
                    }

                    string value = node.InnerXml.Trim(); //may contain formatting
                    if (node.Name.ToLower() == "img")
                    {
                        value = node.GetAttribute("src");
                        //Make the name of the image safe for showing up in raw html (not just in the relatively safe confines of the src attribut),
                        //becuase it's going to show up between <div> tags.  E.g. "Land & Water.png" as the cover page used to kill us.
                        value = WebUtility.HtmlEncode(WebUtility.HtmlDecode(value));
                    }
                    if (!String.IsNullOrEmpty(value) && !value.StartsWith("{"))
                        //ignore placeholder stuff like "{Book Title}"; that's not a value we want to collect
                    {
                        string lang = node.GetOptionalStringAttribute("lang", "*");
                        if (lang == "") //the above doesn't stop a "" from getting through
                            lang = "*";
                        if ((elementName.ToLower() == "textarea" || elementName.ToLower() == "input" ||
                             node.GetOptionalStringAttribute("contenteditable", "false") == "true") &&
                            (lang == "V" || lang == "N1" || lang == "N2"))
                        {
                            throw new ApplicationException(
                                "Editable element (e.g. TextArea) should not have placeholder @lang attributes (V,N1,N2)\r\n\r\n" +
                                node.OuterXml);
                        }

                        //if we don't have a value for this variable and this language, add it
                        if (!data.TextVariables.ContainsKey(key))
                        {
                            var t = new MultiTextBase();
                            t.SetAlternative(lang, value);
                            data.TextVariables.Add(key, new NamedMutliLingualValue(t, isCollectionValue));
                        }
                        else if (!data.TextVariables[key].TextAlternatives.ContainsAlternative(lang))
                        {
                            MultiTextBase t = data.TextVariables[key].TextAlternatives;
                            t.SetAlternative(lang, value);
                        }
                    }
                }
            }
            catch (Exception error)
            {
                throw new ApplicationException(
                    "Error in GatherDataItemsFromDom(," + elementName + "). RawDom was:\r\n" + sourceElement.OuterXml,
                    error);
            }
        }
Ejemplo n.º 6
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));
		}
Ejemplo n.º 7
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));
		}
Ejemplo n.º 8
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));
		}
Ejemplo n.º 9
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));
		}
Ejemplo n.º 10
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));
		}
Ejemplo n.º 11
0
		public void SetAlternative_ThreeDifferentLanguages_LanguageFormsAreSortedbyWritingSystem()
		{

			MultiTextBase multiTextBaseToPopulate = new MultiTextBase();
			multiTextBaseToPopulate.SetAlternative("fr", "fr Word3");
			multiTextBaseToPopulate.SetAlternative("de", "de Word1");
			multiTextBaseToPopulate.SetAlternative("en", "en Word2");
			Assert.AreEqual(3, multiTextBaseToPopulate.Forms.Length);
			Assert.AreEqual("de", multiTextBaseToPopulate.Forms[0].WritingSystemId);
			Assert.AreEqual("en", multiTextBaseToPopulate.Forms[1].WritingSystemId);
			Assert.AreEqual("fr", multiTextBaseToPopulate.Forms[2].WritingSystemId);
		}