1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
//------------------------------------------------------------------------------
// <copyright file="ConfigurationSectionHelper.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.Mobile
{
using System.Xml;
using System.Configuration;
using System.Diagnostics;
using System.Globalization;
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
internal class ConfigurationSectionHelper
{
private XmlNode _currentNode = null;
internal ConfigurationSectionHelper() {
}
internal /*public*/ XmlNode Node
{
get
{
return _currentNode;
}
set
{
_currentNode = value;
}
}
private XmlNode GetAndRemoveAttribute(String attributeName, bool required)
{
XmlNode attibuteNode = _currentNode.Attributes.RemoveNamedItem(attributeName);
if (required && attibuteNode == null)
{
String msg = SR.GetString(SR.ConfigSect_MissingAttr,
attributeName);
throw new ConfigurationErrorsException(msg, _currentNode);
}
return attibuteNode;
}
internal /*public*/ String RemoveStringAttribute(String attributeName,
bool required)
{
Debug.Assert(null != _currentNode);
XmlNode attributeNode = GetAndRemoveAttribute(attributeName, required);
if(attributeNode != null)
{
if(required && (attributeNode.Value != null && attributeNode.Value.Length == 0))
{
String msg = SR.GetString(SR.ConfigSect_MissingValue,
attributeName);
throw new ConfigurationErrorsException(msg, _currentNode);
}
return attributeNode.Value;
}
else
{
return null;
}
}
#if UNUSED_CODE
internal /*public*/ bool RemoveBoolAttribute(String attributeName,
bool required,
bool defaultValue)
{
Debug.Assert(null != _currentNode);
XmlNode attributeNode = GetAndRemoveAttribute(attributeName, required);
if(attributeNode != null)
{
try
{
return bool.Parse(attributeNode.Value);
}
catch
{
String msg =
SR.GetString(SR.ConfigSect_InvalidBooleanAttr,
attributeName);
throw new ConfigurationErrorsException(msg, _currentNode);
}
}
else
{
return defaultValue;
}
}
internal /*public*/ int RemoveIntAttribute(String attributeName,
bool required,
int defaultValue)
{
Debug.Assert(null != _currentNode);
XmlNode attributeNode = GetAndRemoveAttribute(attributeName, required);
if(attributeNode != null)
{
try
{
return int.Parse(attributeNode.Value, CultureInfo.InvariantCulture);
}
catch
{
String msg =
SR.GetString(SR.ConfigSect_InvalidIntegerAttr,
attributeName);
throw new ConfigurationErrorsException(msg, _currentNode);
}
}
else
{
return defaultValue;
}
}
#endif
internal /*public*/ void CheckForUnrecognizedAttributes()
{
Debug.Assert(null != _currentNode);
if(_currentNode.Attributes.Count != 0)
{
String msg = SR.GetString(SR.ConfigSect_UnknownAttr,
_currentNode.Attributes[0].Name);
throw new ConfigurationErrorsException(msg, _currentNode);
}
}
internal /*public*/ bool IsWhitespaceOrComment()
{
Debug.Assert(null != _currentNode);
return _currentNode.NodeType == XmlNodeType.Comment ||
_currentNode.NodeType == XmlNodeType.Whitespace;
}
internal /*public*/ void RejectNonElement()
{
Debug.Assert(null != _currentNode);
if(_currentNode.NodeType != XmlNodeType.Element)
{
throw new ConfigurationErrorsException(SR.GetString(SR.ConfigSect_UnrecognizedXML),
_currentNode);
}
}
}
}
|