2 // PropertyKeywordFu.cs
4 // Copyright (C) 2005 Debajyoti Bera
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
.Collections
;
35 namespace Beagle
.Daemon
{
37 public class PropertyDetail
{
38 private PropertyType type
;
39 private string property_name
;
40 // a short description, so that frontends can get the description from here
41 // and they dont need to guess the meaning of a query keyword (being too nice ?!)
42 private string short_desc
;
44 public PropertyType Type
{
48 public string PropertyName
{
49 get { return property_name;}
52 public string Description
{
53 get { return short_desc; }
56 public PropertyDetail (PropertyType type
, string property_name
) {
58 this.property_name
= property_name
;
62 public PropertyDetail (PropertyType type
, string property_name
, string desc
) {
64 this.property_name
= property_name
;
65 this.short_desc
= desc
;
69 public class PropertyKeywordFu
{
71 private static Hashtable property_table
;
74 private PropertyKeywordFu () { }
76 static PropertyKeywordFu () {
77 PopulatePropertyTable ();
80 public static IDictionaryEnumerator MappingEnumerator
{
81 get { return property_table.GetEnumerator ();}
84 // FIXME handle i18n issues... user might use a i18n-ised string for "title"
85 private static void PopulatePropertyTable () {
86 property_table
= new Hashtable ();
88 // Mapping between human query keywords and beagle index property keywords
89 // These are some of the standard mapping which is available to all backends and filters.
91 property_table
.Add ("title",
92 new PropertyDetail (PropertyType
.Text
, "dc:title", "Title"));
94 property_table
.Add ("creator",
95 new PropertyDetail (PropertyType
.Text
, "dc:creator", "Creator of the content"));
97 property_table
.Add ("author",
98 new PropertyDetail (PropertyType
.Text
, "dc:creator", "Author of the content"));
101 public static void RegisterMapping (PropertyKeywordMapping mapping
)
103 if (property_table
.Contains (mapping
.Keyword
))
106 property_table
.Add (mapping
.Keyword
,
108 mapping
.IsKeyword
? PropertyType
.Keyword
: PropertyType
.Text
,
109 mapping
.PropertyName
,
110 mapping
.Description
));
113 // return false if property not found!
114 public static bool GetPropertyDetails (string keyword
, out string name
, out PropertyType type
) {
115 PropertyDetail property_detail
= property_table
[keyword
] as PropertyDetail
;
116 name
= (property_detail
== null ? null : property_detail
.PropertyName
);
117 type
= (property_detail
== null ? PropertyType
.Text
: property_detail
.Type
);
118 return (property_detail
!= null);