configure.in, AssemblyInfo.cs: For those unfortunate earthlings without libchm, libwv...
[beagle.git] / BeagleClient / QueryPart.cs
blobb4e592ee4d696c79bc142f3ee968562d8eecbddb
1 //
2 // QueryPart.cs
3 //
4 // Copyright (C) 2005 Novell, Inc.
5 //
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a
9 // copy of this software and associated documentation files (the "Software"),
10 // to deal in the Software without restriction, including without limitation
11 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 // and/or sell copies of the Software, and to permit persons to whom the
13 // Software is furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 // DEALINGS IN THE SOFTWARE.
28 using System;
29 using System.IO;
30 using System.Collections;
31 using System.Text;
32 using System.Xml.Serialization;
34 using BU = Beagle.Util;
36 namespace Beagle {
38 public enum QueryPartLogic {
39 Required = 1,
40 Prohibited = 2
43 [XmlInclude (typeof (QueryPart_Text)),
44 XmlInclude (typeof (QueryPart_Property)),
45 XmlInclude (typeof (QueryPart_DateRange)),
46 XmlInclude (typeof (QueryPart_Human)),
47 XmlInclude (typeof (QueryPart_Wildcard)),
48 XmlInclude (typeof (QueryPart_Or))]
49 abstract public class QueryPart {
51 private QueryPartLogic logic = QueryPartLogic.Required;
53 public QueryPart ()
54 { }
56 public QueryPartLogic Logic {
57 get { return logic; }
58 set { logic = value; }
61 public override string ToString ()
63 return String.Format ("{0}:\n Logic: {1}\n", this.GetType (), Logic);
67 public class QueryPart_Text : QueryPart {
69 private string text;
70 private bool search_full_text = true;
71 private bool search_properties = true;
73 public QueryPart_Text ()
74 { }
76 public string Text {
77 get { return text; }
78 set { text = value; }
81 public bool SearchFullText {
82 get { return search_full_text; }
83 set { search_full_text = value; }
86 public bool SearchTextProperties {
87 get { return search_properties; }
88 set { search_properties = value; }
91 public override string ToString ()
93 return String.Format (
94 base.ToString () +
95 " Text: {0}\n" +
96 " Search full text: {1}\n" +
97 " Search text properties: {2}",
98 Text, SearchFullText, SearchTextProperties);
102 // AllProperties queries are not allowed on keywords.
103 public class QueryPart_Property : QueryPart {
105 public const string AllProperties = "_all";
107 private PropertyType type;
108 private string key;
109 private string value;
111 public QueryPart_Property ()
114 public PropertyType Type {
115 get { return type; }
116 set { type = value; }
119 public string Key {
120 get { return key; }
121 set { key = value; }
124 public string Value {
125 get { return value; }
126 set { this.value = value; } // ugh
129 public override string ToString ()
131 return String.Format (
132 base.ToString () +
133 " Type: {0}\n" +
134 " Key: {1}\n" +
135 " Value: {2}",
136 Type, Key, Value);
140 public class QueryPart_DateRange : QueryPart {
142 public const string AllPropertiesKey = "_all";
143 public const string TimestampKey = "Timestamp";
145 private string key = AllPropertiesKey;
146 private DateTime start_date;
147 private DateTime end_date;
149 public QueryPart_DateRange ()
152 public string Key {
153 get { return key; }
154 set { key = value; }
157 public DateTime StartDate {
158 get { return start_date; }
159 set { start_date = value; }
162 public DateTime EndDate {
163 get { return end_date; }
164 set { end_date = value; }
167 public override string ToString ()
169 return String.Format (
170 base.ToString () +
171 " Key: {0}\n" +
172 " Start date: {1}\n" +
173 " End date: {2}",
174 Key, StartDate, EndDate);
178 public class QueryPart_Human : QueryPart {
180 private string query_string;
182 public QueryPart_Human ()
185 public string QueryString {
186 get { return query_string; }
187 set { query_string = value; }
190 public override string ToString ()
192 return String.Format (
193 base.ToString () +
194 " QueryString: {0}",
195 QueryString);
199 public class QueryPart_Wildcard : QueryPart {
201 private string query_string;
203 public QueryPart_Wildcard ()
206 public string QueryString {
207 get { return query_string; }
208 set { query_string = value; }
211 public override string ToString ()
213 return String.Format (
214 base.ToString () +
215 " QueryString: {0}",
216 QueryString);
220 public class QueryPart_Or : QueryPart {
222 private ArrayList sub_parts = new ArrayList ();
224 public QueryPart_Or ()
227 [XmlArray ("SubParts")]
228 [XmlArrayItem (ElementName="Part", Type=typeof (QueryPart))]
229 public ArrayList SubParts_ShouldBePrivateSoPleaseDontUseThis {
230 get { return sub_parts; }
233 [XmlIgnore]
234 public ICollection SubParts {
235 get { return sub_parts; }
238 // FIXME: Really the only thing that is allowed as a subpart
239 // of an 'Or' part are required (not prohibited) text or
240 // property queries. We should be clearer about the rules,
241 // and enforce them.
242 public void Add (QueryPart part)
244 sub_parts.Add (part);
247 public override string ToString ()
249 StringBuilder sb = new StringBuilder (base.ToString ());
251 foreach (QueryPart p in sub_parts)
252 sb.Append (" " + p.ToString () + "\n");
254 return sb.ToString ();