Beispiel #1
0
 /// <summary>
 /// Checks that MIME Types are valid.
 /// </summary>
 /// <param name="type">Type.</param>
 public String CheckValidMimeType(String type)
 {
     type = type.Trim().ToLowerInvariant();
     if (!MimeTypesHelper.IsValidMimeType(type))
     {
         throw new RdfException(type + " is not a valid MIME Type");
     }
     return(type);
 }
Beispiel #2
0
        /// <summary>
        /// Creates a new MIME Type Selector.
        /// </summary>
        /// <param name="type">MIME Type to match.</param>
        /// <param name="charset">Charset.</param>
        /// <param name="quality">Quality (in range 0.0-1.0).</param>
        /// <param name="order">Order of appearance (used as precendence tiebreaker where necessary).</param>
        public MimeTypeSelector(String type, String charset, double quality, int order)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type", "Type cannot be null");
            }
            _type    = type.Trim().ToLowerInvariant();
            _charset = charset != null?charset.Trim() : null;

            _quality = quality;
            _order   = order;

            // Validate parameters
            if (_quality < 0)
            {
                _quality = 0;
            }
            if (_quality > 1)
            {
                _quality = 1;
            }
            if (_order < 1)
            {
                _order = 1;
            }

            // Check what type of selector this is
            if (!MimeTypesHelper.IsValidMimeType(_type))
            {
                // Invalid
                _isInvalid = true;
            }
            else if (_type.Equals(MimeTypesHelper.Any))
            {
                // Is a */* any
                _isAny = true;
            }
            else if (_type.EndsWith("/*"))
            {
                // Is a blah/* range
                _isRange   = true;
                _rangeType = _type.Substring(0, _type.Length - 1);
            }
            else if (_type.Contains('*'))
            {
                // If it contains a * and is not */* or blah/* it is invalid
                _isInvalid = true;
            }
            else
            {
                // Must be a specific type
                _isSpecific = true;
            }
        }