Ejemplo n.º 1
0
        private static bool IsEqual(XmlAttributeCollection left, XmlAttributeCollection right)
        {
            if (left == null)
            {
                return right == null;
            }

            if (right == null)
            {
                return false;
            }

            if (left.Count != right.Count)
            {
                return false;
            }

            foreach (XmlAttribute attr in left)
            {
                var rightAttrNode = right.GetNamedItem(attr.Name);

                if (rightAttrNode == null)
                {
                    return false;
                }

                if ((rightAttrNode as XmlAttribute).Value != attr.Value)
                {
                    return false;
                }
            }

            return true;
        }
Ejemplo n.º 2
0
		public static string GetAttribute(XmlAttributeCollection attributes, string name)
		{
			XmlNode attr = attributes.GetNamedItem(name);
			if (attr == null)
				return "";

			return attr.Value;
		}
Ejemplo n.º 3
0
		/// <summary>
		/// Gets float value from XML attribute
		/// </summary>
		/// <param name="name"></param>
		/// <param name="attrs"></param>
		/// <param name="value_default"></param>
		/// <returns></returns>
		public static float GetFloatAttributeValue(string name, XmlAttributeCollection attrs, float value_default)
		{
			float r = value_default;
			try{
				XmlNode attr = attrs.GetNamedItem(name);
				if (attr != null)
				{
					r = (float)Convert.ToDouble(attr.Value);
				}
			}catch(Exception ex){
				Console.WriteLine("Error 'GetFloatAttributeValue' ["+name+"]-> "+ex.Message );
			}
			return r;
		}
Ejemplo n.º 4
0
        public virtual void RemoveAttribute(string localName, string namespaceURI)
        {
            if (attributes == null)
            {
                return;
            }

            XmlAttribute attr = attributes.GetNamedItem(localName, namespaceURI) as XmlAttribute;

            if (attr != null)
            {
                Attributes.Remove(attr);
            }
        }
Ejemplo n.º 5
0
		/// <summary>
		/// Gets int value from XML attribute
		/// </summary>
		/// <param name="name"></param>
		/// <param name="attrs"></param>
		/// <param name="value_default"></param>
		/// <returns></returns>
		public static int GetIntAttributeValue(string name, XmlAttributeCollection attrs, int value_default)
		{
			int r = value_default;
			try{
				XmlNode attr = attrs.GetNamedItem(name);
				if (attr != null)
				{
					r = Convert.ToInt32(attr.Value);
				}
			}catch(Exception ex){
				Console.WriteLine("Error 'GetIntAttributeValue' ->  ["+name+"]"+ex.Message );
			}
			return r;
		}
Ejemplo n.º 6
0
		/// <summary>
		/// Gets string value from XML attribute
		/// </summary>
		/// <param name="name"></param>
		/// <param name="attrs"></param>
		/// <param name="value_default"></param>
		/// <returns></returns>
		public static string GetAttributeValue(string name, XmlAttributeCollection attrs, string value_default)
		{
			string r = value_default;
			try{
				XmlNode attr = attrs.GetNamedItem(name);
				if (attr != null)
				{
					r = attr.Value;
					//Console.WriteLine(name + ": " + r);
				}
			}catch(Exception ex){
				Console.WriteLine("Error 'GetAttributeValue'  ["+name+"]-> "+ex.Message );
			}
			return r;
		}
Ejemplo n.º 7
0
		/// -------------------------------------------------------------------------------------
		/// <summary>
		/// Interpret the use attribute as a FunctionValues value
		/// </summary>
		/// <param name="attributes">Collection of attributes that better have a "use"
		/// attribute</param>
		/// <param name="styleName">Stylename being processed (for error reporting purposes)
		/// </param>
		/// <returns>The function of the style</returns>
		/// -------------------------------------------------------------------------------------
		private FunctionValues GetFunction(XmlAttributeCollection attributes,
			string styleName)
		{
			if (m_htReservedStyles.ContainsKey(styleName))
			{
				return m_htReservedStyles[styleName].function;
			}

			XmlNode node = attributes.GetNamedItem("use");
			string sFunction = (node != null) ? node.Value : null;
			if (sFunction == null)
				return FunctionValues.Prose;

			switch (sFunction)
			{
				case "prose":
				case "proseSentenceInitial":
				case "title":
				case "properNoun":
				case "special":
					return FunctionValues.Prose;
				case "line":
				case "lineSentenceInitial":
					return FunctionValues.Line;
				case "list":
					return FunctionValues.List;
				case "table":
					return FunctionValues.Table;
				case "chapter":
					return FunctionValues.Chapter;
				case "verse":
					return FunctionValues.Verse;
				case "footnote":
					return FunctionValues.Footnote;
				case "stanzabreak":
					return FunctionValues.StanzaBreak;
				default:
					Debug.Assert(false, "Unrecognized use attribute for style " + styleName +
						" in " + ResourceFileName + ": " + sFunction);
					throw new Exception(ResourceHelper.GetResourceString("kstidInvalidInstallation"));
			}
		}
Ejemplo n.º 8
0
		/// -------------------------------------------------------------------------------------
		/// <summary>
		/// Returns a writing system ID from the named attribute
		/// </summary>
		/// <param name="attributes">collection of XML attributes for current tag</param>
		/// <param name="attrName">name of the attribute</param>
		/// <param name="defaultVal">a default to be used if no value present in the XML</param>
		/// <returns>the writing system ID integer</returns>
		/// -------------------------------------------------------------------------------------
		protected int GetWritingSystem(XmlAttributeCollection attributes,
			string attrName, int defaultVal)
		{
			XmlNode WsAttrib = attributes.GetNamedItem(attrName);
			int wsResult;

			if (WsAttrib != null && WsAttrib.Value != string.Empty)
			{
				ILgWritingSystemFactory wsf = m_scr.Cache.LanguageWritingSystemFactoryAccessor;
				wsResult = wsf.GetWsFromStr(WsAttrib.Value);

				if (wsResult != 0)
					return wsResult;
				else
				{
					// Unlike other "getAttribute" methods, this one may encounter a WS
					// that is not installed yet.
					//REVIEW: For now we will not throw an exception,
					// but try to give a meaningful message and return the default.
					string message;
					//#if DEBUG
					message = "Error reading TePublications.xml: Unrecognized writing system attribute: "
						+ attrName + "=\"" + WsAttrib.Value + "\"" + "\n Default writing system will be used.";
					//#else
					//					message = TeResourceHelper.GetResourceString("kstidInvalidInstallation");
					//#endif
					if (m_fUnderTest)
					{
						//throw new Exception(message);
						Debug.WriteLine(message);
					}
					else
					{
						MessageBox.Show(message,
							"FieldWorks", // better caption?
							MessageBoxButtons.OK, MessageBoxIcon.Warning);
					}
					return defaultVal;
				}
			}
			else
				return defaultVal;
		}
Ejemplo n.º 9
0
		/// -------------------------------------------------------------------------------------
		/// <summary>
		/// Retrieves the measurement units for publications and returns a multiplier for
		/// converting into millipoints.
		/// </summary>
		/// <param name="attributes">collection of XML attributes for current tag</param>
		/// <param name="attrName">name of the attribute</param>
		/// <param name="defaultVal">a default conversion factor, to be used if the specified
		/// attribute is not present in the XML</param>
		/// <returns>the multiplier for converting into millipoints</returns>
		/// -------------------------------------------------------------------------------------
		protected double GetUnitConversion(XmlAttributeCollection attributes, string attrName,
			double defaultVal)
		{
			XmlNode measUnitsNode = attributes.GetNamedItem(attrName);

			if (measUnitsNode != null)
			{
				string sMeasUnits = measUnitsNode.Value;
				switch (sMeasUnits.ToLowerInvariant())
				{
					case "inch":
						return kMpPerInch;

					case "cm":
						return kMpPerCm;

					default:
						{
							string message;
#if DEBUG
							message = "Error reading TePublications.xml: Unrecognized units for "
								+ attrName + "=\"" + measUnitsNode.Value + "\"";
#else
					message = TeResourceHelper.GetResourceString("kstidInvalidInstallation");
#endif
							throw new Exception(message);
						}
				}
			}
			else
				return defaultVal;
		}
Ejemplo n.º 10
0
        private string getValueAtributo(XmlAttributeCollection coleccion, string valor)
        {
            XmlNode atributoDecisor = coleccion.GetNamedItem(_prefijo + ":" + valor);

            if (atributoDecisor != null)
            {
                return atributoDecisor.Value;
            }
            else
                return "";
        }
Ejemplo n.º 11
0
 private static string ExtractAttributeValueFromNode(string attributeName, XmlAttributeCollection attributes)
 {
     return attributes.GetNamedItem(attributeName) != null ? attributes.GetNamedItem(attributeName).Value : null;
 }
Ejemplo n.º 12
0
		/// -------------------------------------------------------------------------------------
		/// <summary>
		/// Interpret the type attribute as a StyleType value
		/// </summary>
		/// <param name="attributes">Collection of attributes that better have a "type"
		/// attribute</param>
		/// <param name="styleName">Stylename being processed (for error reporting purposes)
		/// </param>
		/// <param name="context"></param>
		/// <returns>The type of the style</returns>
		/// -------------------------------------------------------------------------------------
		public StyleType GetType(XmlAttributeCollection attributes, string styleName,
			ContextValues context)
		{
			if (m_htReservedStyles.ContainsKey(styleName))
				return m_htReservedStyles[styleName].styleType;
			string sType = attributes.GetNamedItem("type").Value;
			ValidateContext(context, styleName);
			switch(sType)
			{
				case "paragraph":
					ValidateParagraphContext(context, styleName);
					return StyleType.kstParagraph;
				case "character":
					return StyleType.kstCharacter;
				default:
					Debug.Assert(false, "Unrecognized type attribute for style " + styleName +
						" in " + ResourceFileName + ": " + sType);
					throw new Exception(ResourceHelper.GetResourceString("kstidInvalidInstallation"));
			}
		}
Ejemplo n.º 13
0
 /// <summary>
 /// Separates XML namespace related attributes from "normal"
 /// attributes.
 /// </summary>
 private static Attributes SplitAttributes(XmlAttributeCollection map)
 {
     XmlAttribute sLoc = map.GetNamedItem("schemaLocation",
                                          XmlSchema.InstanceNamespace)
         as XmlAttribute;
     XmlAttribute nNsLoc = map.GetNamedItem("noNamespaceSchemaLocation",
                                            XmlSchema.InstanceNamespace)
         as XmlAttribute;
     List<XmlAttribute> rest = new List<XmlAttribute>();
     foreach (XmlAttribute a in map) {
         if (XmlSchema.InstanceNamespace != a.NamespaceURI
             &&
             "http://www.w3.org/2000/xmlns/" != a.NamespaceURI) {
             rest.Add(a);
         }
     }
     return new Attributes(sLoc, nNsLoc, rest);
 }
Ejemplo n.º 14
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Returns the integer value from the named attribute.
		/// If named item is not present, the default value is returned.
		/// </summary>
		/// <param name="attributes">collection of XML attributes for current tag</param>
		/// <param name="attrName">name of the attribute</param>
		/// <param name="defaultVal">The default value.</param>
		/// <returns>the integer value, or null</returns>
		/// ------------------------------------------------------------------------------------
		protected static int GetInt(XmlAttributeCollection attributes, string attrName,
			int defaultVal)
		{
			XmlNode attrib = attributes.GetNamedItem(attrName);
			if (attrib != null && attrib.Value != string.Empty)
			{
				try
				{
					return System.Int32.Parse(attrib.Value);
				}
				catch
				{
					string message;
#if DEBUG
					message = "Error reading TePublications.xml: Unrecognized integer attribute: "
						+ attrName + "=\"" + attrib.Value + "\"";
#else
					message = TeResourceHelper.GetResourceString("kstidInvalidInstallation");
#endif
					throw new Exception(message);
				}
			}
			else
				return defaultVal;
		}
Ejemplo n.º 15
0
		/// -------------------------------------------------------------------------------------
		/// <summary>
		/// Returns the string value from the named attribute.
		/// If named item is not present, null is returned.
		/// </summary>
		/// <param name="attributes">collection of XML attributes for current tag</param>
		/// <param name="attrName">name of the attribute</param>
		/// <returns>the string value, or null</returns>
		/// -------------------------------------------------------------------------------------
		protected static string GetString(XmlAttributeCollection attributes, string attrName)
		{
			XmlNode attrib = attributes.GetNamedItem(attrName);
			if (attrib != null)
				return attrib.Value;
			else
				return null;
		}
Ejemplo n.º 16
0
		/// -------------------------------------------------------------------------------------
		/// <summary>
		/// Retrieves the specified measurement attribute and computes the value in millipoints
		/// </summary>
		/// <param name="attributes">collection of XML attributes for current tag</param>
		/// <param name="attrName">name of the attribute</param>
		/// <param name="defaultVal">a default measurement in millipoints, to be used if
		/// no value is present in the XML</param>
		/// <param name="conversion">multiplier (based on the publication units) to convert
		/// retrieved value into millipoints</param>
		/// <returns>the integer measurement in millipoints from the named item</returns>
		/// -------------------------------------------------------------------------------------
		private int GetMeasurement(XmlAttributeCollection attributes, string attrName,
			int defaultVal, double conversion)
		{
			double measurementInSourceUnits;
			XmlNode measurementAttrib = attributes.GetNamedItem(attrName);

			if (measurementAttrib != null && measurementAttrib.Value != string.Empty)
			{
				try
				{
					// Always read measurements with "en" culture because they have been formatted
					// in that way.
					measurementInSourceUnits = Double.Parse(measurementAttrib.Value,
						CultureInfo.CreateSpecificCulture("en"));
				}
				catch
				{
					string message;
#if DEBUG
					message = "Error reading TePublications.xml: Unrecognized measurement for "
						+ attrName + "=\"" + measurementAttrib.Value + "\"";
#else
					message = TeResourceHelper.GetResourceString("kstidInvalidInstallation");
#endif
					throw new Exception(message);
				}
			}
			else
				return defaultVal;
			return (int)(measurementInSourceUnits * conversion);
		}
Ejemplo n.º 17
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets the height and width of the page.
		/// </summary>
		/// <param name="attributes">collection of XML attributes for current tag</param>
		/// <param name="pub">The publication object in which the height and width are to be
		/// stored.</param>
		/// <param name="supportedPubPageSizes">The supported publication page sizes.</param>
		/// ------------------------------------------------------------------------------------
		private void GetPageHeightAndWidth(XmlAttributeCollection attributes, IPublication pub,
			XmlNode supportedPubPageSizes)
		{
			XmlNode pageSize = attributes.GetNamedItem("PageSize");

			if (pageSize != null)
			{
				string sPageSize = pageSize.Value;

				try
				{
					XmlNode pubPageSize =
						supportedPubPageSizes.SelectSingleNode("PublicationPageSize[@id='" + sPageSize + "']");
					pub.PageHeight = GetMeasurement(pubPageSize.Attributes, "Height", 0, m_conversion);
					pub.PageWidth = GetMeasurement(pubPageSize.Attributes, "Width", 0, m_conversion);
				}
				catch
				{
#if DEBUG
					throw new Exception("Error reading TePublications.xml: Problem reading PageSize. value was \"" +
						sPageSize + "\"");
#else
					pub.PageHeight = 0;
					pub.PageWidth = 0;
#endif
				}
			}
			else
			{
				pub.PageHeight = 0;
				pub.PageWidth = 0;
			}
		}
Ejemplo n.º 18
0
        /// <summary>
        /// This function gets called by the ogmo level loader
        /// </summary>
        public static void MyCreateEntity(Scene scene, XmlAttributeCollection ogmoParameters)
        {
            //ok ogmo gives us the position in x and y, and the list of decorators in DecoratorList
            int x = ogmoParameters.Int("x", -1);
            int y = ogmoParameters.Int("y", -1);

            //this is how you read a string from ogmo
            string decoList = ogmoParameters.GetNamedItem("DecoratorList").Value;

            //create an instance
            Tank t = new Tank(x, y);

            //try and load an id; if there is none, the id will be -1
            t.NetworkId = ogmoParameters.Int("NetworkId", -1);

            //add to the scene because the decorators need that
            scene.Add(t);

            //split the decorators; they are seperated by a ":" in the DecoratorList string
            string[] decoArray = decoList.Split(':');

            //add each decorator
            foreach (string decoratorName in decoArray)
            {
                //parse the name of the decorator to the decorator-enum, and then add to the tank
                t.AddDecorator((Decorators) Enum.Parse(typeof(Decorators), decoratorName));
            }
        }
Ejemplo n.º 19
0
        private bool GetValue(XmlAttributeCollection amlAttributes, string nodeName, out string value)
        {
            XmlNode xmlNode = amlAttributes.GetNamedItem(nodeName);
              if (xmlNode == null)
              {
            value = "";
            return false;
              }

              string xmlValue = xmlNode.Value;

              value = xmlValue.Trim();
              return value == "" ? false : true;
        }
Ejemplo n.º 20
0
		/// -------------------------------------------------------------------------------------
		/// <summary>
		/// Get the ws value (hvo) from the wsId contained in the given attributes
		/// </summary>
		/// <param name="attribs">Collection of attributes that better have an "wsId"
		/// attribute</param>
		/// <returns></returns>
		/// -------------------------------------------------------------------------------------
		private int GetWs(XmlAttributeCollection attribs)
		{
			string wsId = attribs.GetNamedItem("wsId").Value;
			if (string.IsNullOrEmpty(wsId))
				return 0;
			return Cache.ServiceLocator.WritingSystemManager.GetWsFromStr(wsId);
		}
Ejemplo n.º 21
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Interprets a given attribute as a boolean value
		/// </summary>
		/// <param name="attributes">Collection of attributes to look in</param>
		/// <param name="sAttrib">Named attribute</param>
		/// <param name="styleName">The name of the style to which this attribute pertains (used
		/// only for debug error reporting)</param>
		/// <param name="fileName">Name of XML file (for error reporting)</param>
		/// <returns>true if attribute value is "yes" or "true"</returns>
		/// ------------------------------------------------------------------------------------
		static public bool GetBoolAttribute(XmlAttributeCollection attributes, string sAttrib,
			string styleName, string fileName)
		{
			string sVal = attributes.GetNamedItem(sAttrib).Value;
			if (sVal == "yes" || sVal == "true")
				return true;
			else if (sVal == "no" || sVal == "false" || sVal == String.Empty)
				return false;

			ReportInvalidInstallation(String.Format(
				FrameworkStrings.ksUnknownStyleAttribute, sAttrib, styleName, fileName));
			return false; // Can't actually get here, but don't tell the compiler that!
		}
Ejemplo n.º 22
0
		/// -------------------------------------------------------------------------------------
		/// <summary>
		/// Get the ws value (hvo) from the iculocale contained in the given attributes
		/// </summary>
		/// <param name="attribs">Collection of attributes that better have an "iculocale"
		/// attribute</param>
		/// <returns></returns>
		/// -------------------------------------------------------------------------------------
		private int GetWs(XmlAttributeCollection attribs)
		{
			string iculocale = attribs.GetNamedItem("iculocale").Value;
			if (iculocale == null || iculocale == string.Empty)
				return 0;

			int ws = 0;
			if (!m_htIcuToWs.TryGetValue(iculocale, out ws))
			{
				ws = m_scr.Cache.LanguageEncodings.GetWsFromIcuLocale(iculocale);
				m_htIcuToWs[iculocale] = ws;
			}
			return ws;
		}
Ejemplo n.º 23
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Retrieves a valid TE style name from the specified attributes.
		/// </summary>
		/// <param name="attributes">The attributes containing the style id to use</param>
		/// <returns>a valid TE style name</returns>
		/// ------------------------------------------------------------------------------------
		private static string GetStyleName(XmlAttributeCollection attributes)
		{
			return attributes.GetNamedItem("id").Value.Replace("_", " ");
		}
Ejemplo n.º 24
0
 private static void CompareAttributes(XmlAttributeCollection attribs1, XmlAttributeCollection attribs2,
     string attribute)
 {
     var attr1 = attribs1.GetNamedItem(attribute);
     var attr2 = attribs2.GetNamedItem(attribute);
     Assert.IsFalse(attr1 == null && attr2 != null);
     Assert.IsFalse(attr1 != null && attr2 == null);
     if (attr1 != null)
         Assert.AreEqual(attr1.Value, attr2.Value);
 }
Ejemplo n.º 25
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Interpret the based on attribute
		/// </summary>
		/// <param name="attributes">Collection of attributes that better have a "context"
		/// attribute</param>
		/// <param name="styleName">Stylename being processed (for error reporting purposes)
		/// </param>
		/// <returns>The name of the based-on style</returns>
		/// ------------------------------------------------------------------------------------
		private string GetBasedOn(XmlAttributeCollection attributes, string styleName)
		{
			if (m_htReservedStyles.ContainsKey(styleName))
			{
				return m_htReservedStyles[styleName].basedOn;
			}
			XmlNode basedOn = attributes.GetNamedItem("basedOn");
			return (basedOn == null) ? null : basedOn.Value.Replace("_", " ");
		}
Ejemplo n.º 26
0
 private string getAttribute(XmlAttributeCollection theAttributes, string strName)
 {
     XmlNode anAttribute = theAttributes.GetNamedItem(strName);
     if (anAttribute != null)
         return anAttribute.Value;
     else
         return "";
 }
Ejemplo n.º 27
0
		/// -------------------------------------------------------------------------------------
		/// <summary>
		/// Interpret the context attribute as a ContextValues value
		/// </summary>
		/// <param name="attributes">Collection of attributes that better have a "context"
		/// attribute</param>
		/// <param name="styleName">Stylename being processed (for error reporting purposes)
		/// </param>
		/// <returns>The context of the style</returns>
		/// -------------------------------------------------------------------------------------
		private ContextValues GetContext(XmlAttributeCollection attributes,
			string styleName)
		{
			if (m_htReservedStyles.ContainsKey(styleName))
			{
				return m_htReservedStyles[styleName].context;
			}

			string sContext = attributes.GetNamedItem("context").Value;
			// EndMarker was left out of the original conversion and would have raised an exception.
			if (sContext == "back") sContext = "BackMatter";
			try
			{   // convert the string to a valid enum case insensitive
				return (ContextValues)Enum.Parse(typeof(ContextValues), sContext, true);
			}
			catch (Exception ex)
			{
				Debug.Assert(false, "Unrecognized context attribute for style " + styleName +
					" in " + ResourceFileName + ": " + sContext);
				throw new Exception(ResourceHelper.GetResourceString("kstidInvalidInstallation"));
			}
		}
Ejemplo n.º 28
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Compares the XML attributes.
		/// </summary>
		/// <param name="owningNodeName">The name of the owning node.</param>
		/// <param name="expected">The expected attributes.</param>
		/// <param name="actual">The actual attributes.</param>
		/// <param name="strDifference">out: A string describing the difference in attributes.</param>
		/// <returns>
		/// 	<c>true</c> if the attributes are the same; <c>false</c> otherwise
		/// </returns>
		/// ------------------------------------------------------------------------------------
		public static bool CompareXmlAttributes(string owningNodeName, XmlAttributeCollection expected,
			XmlAttributeCollection actual, out string strDifference)
		{
			strDifference = string.Empty;

			int expectedCount = (expected == null ? 0 : expected.Count);
			int actualCount = (actual == null ? 0 : actual.Count);
			if (expectedCount != actualCount)
			{
				strDifference = string.Format("Count of attributes different in node {0}. Expected {1} but was {2}",
					owningNodeName, expectedCount, actualCount);
				return false;
			}

			if (expectedCount == 0)
				return true;

			foreach (XmlAttribute expectedAttrib in expected)
			{
				XmlNode actualAttrib =
					(actual != null ? actual.GetNamedItem(expectedAttrib.Name) : null);

				if (actualAttrib == null)
				{
					strDifference = string.Format("Attribute {0} is missing.", expectedAttrib.Name);
					return false;
				}

				if (expectedAttrib.InnerText != actualAttrib.InnerText)
				{
					strDifference = "Attributes are different for attribute " +
						expectedAttrib.Name + ": " + Environment.NewLine +
						" Expected: " + expectedAttrib.InnerText + Environment.NewLine +
						" Actual:   " + actualAttrib.InnerText;
					return false;
				}
			}

			strDifference = string.Empty;
			return true;
		}
Ejemplo n.º 29
0
		/// -------------------------------------------------------------------------------------
		/// <summary>
		/// Interpret the use attribute as a StructureValues value
		/// </summary>
		/// <param name="attributes">Collection of attributes that better have a "structure"
		/// attribute</param>
		/// <param name="styleName">Stylename being processed (for error reporting purposes)
		/// </param>
		/// <returns>The structure of the style</returns>
		/// -------------------------------------------------------------------------------------
		private StructureValues GetStructure(XmlAttributeCollection attributes,
			string styleName)
		{
			if (m_htReservedStyles.ContainsKey(styleName))
			{
				return m_htReservedStyles[styleName].structure;
			}

			XmlNode node = attributes.GetNamedItem("structure");
			string sStructure = (node != null) ? node.Value : null;

			if (sStructure == null)
				return StructureValues.Undefined;

			switch(sStructure)
			{
				case "heading":
					return StructureValues.Heading;
				case "body":
					return StructureValues.Body;
				default:
					Debug.Assert(false, "Unrecognized structure attribute for style " + styleName +
						" in " + ResourceFileName + ": " + sStructure);
					throw new Exception(ResourceHelper.GetResourceString("kstidInvalidInstallation"));
			}
		}
Ejemplo n.º 30
0
 public static string GetAttributeValue(XmlAttributeCollection attrs, string attrName)
 {
   XmlNode attrNode = attrs.GetNamedItem(attrName);
   if (attrNode != null) {
     return attrNode.Value;
   }
   return null;
 }
Ejemplo n.º 31
0
		/// -------------------------------------------------------------------------------------
		/// <summary>
		/// Returns a DivisionStartOption from the named attribute.
		/// </summary>
		/// <param name="attributes">collection of XML attributes for current tag</param>
		/// <param name="attrName">name of the attribute</param>
		/// <param name="defaultVal">a default to be used if no value present in the XML</param>
		/// <returns>the DivisionStartOption enum</returns>
		/// -------------------------------------------------------------------------------------
		protected DivisionStartOption GetDivisionStart(XmlAttributeCollection attributes,
			string attrName, DivisionStartOption defaultVal)
		{
			XmlNode divStartAttrib = attributes.GetNamedItem(attrName);

			if (divStartAttrib != null && divStartAttrib.Value != string.Empty)
			{
				try
				{
					return (DivisionStartOption)Enum.Parse(typeof(DivisionStartOption),
						divStartAttrib.Value, true);
				}
				catch
				{
					string message;
#if DEBUG
					message = "Error reading TePublications.xml: Unrecognized DivisionStartOption attribute: "
						+ attrName + "=\"" + divStartAttrib.Value + "\"";
#else
					message = TeResourceHelper.GetResourceString("kstidInvalidInstallation");
#endif
					throw new Exception(message);
				}
			}
			else
				return defaultVal;
		}