| 1 |
/****************************************************************************** |
| 2 |
* The MIT License |
| 3 |
* Copyright (c) 2003 Novell Inc. www.novell.com |
| 4 |
* |
| 5 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 |
* of this software and associated documentation files (the Software), to deal |
| 7 |
* in the Software without restriction, including without limitation the rights |
| 8 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 |
* copies of the Software, and to permit persons to whom the Software is |
| 10 |
* furnished to do so, subject to the following conditions: |
| 11 |
* |
| 12 |
* The above copyright notice and this permission notice shall be included in |
| 13 |
* all copies or substantial portions of the Software. |
| 14 |
* |
| 15 |
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 |
* SOFTWARE. |
| 22 |
*******************************************************************************/ |
| 23 |
// |
| 24 |
// Novell.Directory.Ldap.Controls.LdapSortKey.cs |
| 25 |
// |
| 26 |
// Author: |
| 27 |
// Sunil Kumar ([email protected]) |
| 28 |
// |
| 29 |
// (C) 2003 Novell, Inc (http://www.novell.com) |
| 30 |
// |
| 31 |
|
| 32 |
using System; |
| 33 |
namespace Novell.Directory.Ldap.Controls |
| 34 |
{ |
| 35 |
|
| 36 |
/// <summary> Encapsulates parameters for sorting search results. |
| 37 |
/// </summary> |
| 38 |
public class LdapSortKey |
| 39 |
{ |
| 40 |
/// <summary> Returns the attribute to used for sorting. |
| 41 |
/// |
| 42 |
/// </summary> |
| 43 |
/// <returns> The name of the attribute used for sorting. |
| 44 |
/// </returns> |
| 45 |
virtual public System.String Key |
| 46 |
{ |
| 47 |
get |
| 48 |
{ |
| 49 |
return key; |
| 50 |
} |
| 51 |
|
| 52 |
} |
| 53 |
/// <summary> Returns the sorting order, ascending or descending. |
| 54 |
/// |
| 55 |
/// </summary> |
| 56 |
/// <returns> True if the sorting is done is descending order; false, if the |
| 57 |
/// sorting is done is ascending order. |
| 58 |
/// </returns> |
| 59 |
virtual public bool Reverse |
| 60 |
{ |
| 61 |
get |
| 62 |
{ |
| 63 |
return reverse; |
| 64 |
} |
| 65 |
|
| 66 |
} |
| 67 |
/// <summary> Returns the OID to be used as a matching rule. |
| 68 |
/// |
| 69 |
/// </summary> |
| 70 |
/// <returns> The OID to be used as matching rule, or null if none is to be |
| 71 |
/// used. |
| 72 |
/// </returns> |
| 73 |
virtual public System.String MatchRule |
| 74 |
{ |
| 75 |
get |
| 76 |
{ |
| 77 |
return matchRule; |
| 78 |
} |
| 79 |
|
| 80 |
} |
| 81 |
|
| 82 |
private System.String key; |
| 83 |
private bool reverse; |
| 84 |
private System.String matchRule; |
| 85 |
|
| 86 |
// Constructors |
| 87 |
|
| 88 |
/// <summary> Constructs a new LdapSortKey object using an attribute as the sort key. |
| 89 |
/// |
| 90 |
/// </summary> |
| 91 |
/// <param name="keyDescription">The single attribute to use for sorting. If the |
| 92 |
/// name is preceded by a minus sign (-), the sorting |
| 93 |
/// is done in reverse (descending) order. |
| 94 |
/// An OID for a matching rule may be appended |
| 95 |
/// following a ":". |
| 96 |
/// |
| 97 |
/// Examples: |
| 98 |
/// <ul> |
| 99 |
/// <li> "cn" (sorts in ascending order by the cn attribute)</li> |
| 100 |
/// <li> "-cn" (sorts in descending order by the cn attribute) </li> |
| 101 |
/// <li> "cn:1.2.3.4.5" (sorts in ascending order by the cn attribute |
| 102 |
/// using the matching rule 1.2.3.4.5) </li> |
| 103 |
/// </ul> |
| 104 |
/// </param> |
| 105 |
public LdapSortKey(System.String keyDescription) |
| 106 |
{ |
| 107 |
matchRule = null; |
| 108 |
reverse = false; |
| 109 |
System.String myKey = keyDescription; |
| 110 |
if (myKey[0] == '-') |
| 111 |
{ |
| 112 |
myKey = myKey.Substring(1); |
| 113 |
this.reverse = true; |
| 114 |
} |
| 115 |
int pos = myKey.IndexOf(":"); |
| 116 |
if (pos != - 1) |
| 117 |
{ |
| 118 |
this.key = myKey.Substring(0, (pos) - (0)); |
| 119 |
this.matchRule = myKey.Substring(pos + 1); |
| 120 |
} |
| 121 |
else |
| 122 |
{ |
| 123 |
this.key = myKey; |
| 124 |
} |
| 125 |
return ; |
| 126 |
} |
| 127 |
|
| 128 |
/// <summary> Constructs a new LdapSortKey object with the specified attribute name |
| 129 |
/// and sort order. |
| 130 |
/// |
| 131 |
/// </summary> |
| 132 |
/// <param name="key"> The single attribute to use for sorting. |
| 133 |
/// |
| 134 |
/// </param> |
| 135 |
/// <param name="reverse">If true, sorting is done in descending order. If false, |
| 136 |
/// sorting is done in ascending order. |
| 137 |
/// </param> |
| 138 |
public LdapSortKey(System.String key, bool reverse):this(key, reverse, null) |
| 139 |
{ |
| 140 |
return ; |
| 141 |
} |
| 142 |
|
| 143 |
/// <summary> Constructs a new LdapSortKey object with the specified attribute name, |
| 144 |
/// sort order, and a matching rule. |
| 145 |
/// |
| 146 |
/// </summary> |
| 147 |
/// <param name="key"> The attribute name (for example, "cn") to use for sorting. |
| 148 |
/// |
| 149 |
/// </param> |
| 150 |
/// <param name="reverse"> If true, sorting is done in descending order. If false, |
| 151 |
/// sorting is done in ascending order. |
| 152 |
/// |
| 153 |
/// </param> |
| 154 |
/// <param name="matchRule"> The object ID (OID) of a matching rule used for |
| 155 |
/// collation. If the object will be used to request |
| 156 |
/// server-side sorting of search results, it should |
| 157 |
/// be the OID of a matching rule known to be |
| 158 |
/// supported by that server. |
| 159 |
/// </param> |
| 160 |
public LdapSortKey(System.String key, bool reverse, System.String matchRule) |
| 161 |
{ |
| 162 |
this.key = key; |
| 163 |
this.reverse = reverse; |
| 164 |
this.matchRule = matchRule; |
| 165 |
return ; |
| 166 |
} |
| 167 |
} |
| 168 |
} |