1
/* Copyright (c) 2006 Google Inc.
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
* you may not use this file except in compliance with the License.
5
* You may obtain a copy of the License at
7
* http://www.apache.org/licenses/LICENSE-2.0
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
* See the License for the specific language governing permissions and
13
* limitations under the License.
18
using System.Globalization;
19
using Google.GData.Client;
21
namespace Google.GData.Blogger
24
//////////////////////////////////////////////////////////////////////
26
/// A subclass of FeedQuery, to create a Blogger query URI.
28
//////////////////////////////////////////////////////////////////////
29
public class BloggerQuery : FeedQuery
32
/// constant string for the order by updated query
34
public const string OrderByUpdated = "updated";
36
/// constant string for the order by published query
38
public const string OrderByPublished = "published";
40
private string orderBy;
42
/// default constructor, does nothing
44
public BloggerQuery() : base()
49
/// base constructor, with initial queryUri
51
/// <param name="queryUri">the query to use</param>
52
public BloggerQuery(string queryUri)
57
//////////////////////////////////////////////////////////////////////
58
/// <summary>You can add orderby=published or orderby=updated to a GData query
59
/// to get the posts sorted in that order.
61
/// - updated is the default
62
/// - This has no effect on comments feeds, whose updated and published
63
/// dates are the same
64
/// - Pagination in the by-updated feed is limited to the most recently
65
/// published 500 posts. </summary>
66
/// <returns> </returns>
67
//////////////////////////////////////////////////////////////////////
70
get {return this.orderBy;}
71
set {this.orderBy = value;}
74
#if WindowsCE || PocketPC
76
//////////////////////////////////////////////////////////////////////
77
/// <summary>protected void ParseUri</summary>
78
/// <param name="targetUri">takes an incoming Uri string and parses all the properties out of it</param>
79
/// <returns>throws a query exception when it finds something wrong with the input, otherwise returns a baseuri</returns>
80
//////////////////////////////////////////////////////////////////////
81
protected override Uri ParseUri(Uri targetUri)
83
base.ParseUri(targetUri);
84
if (targetUri != null)
86
char[] deli = { '?', '&' };
88
TokenCollection tokens = new TokenCollection(targetUri.Query, deli);
89
foreach (String token in tokens)
93
char[] otherDeli = { '=' };
94
String[] parameters = token.Split(otherDeli, 2);
95
switch (parameters[0])
98
this.OrderBy = parameters[1];
109
//////////////////////////////////////////////////////////////////////
110
/// <summary>Creates the partial URI query string based on all
111
/// set properties.</summary>
112
/// <returns> string => the query part of the URI </returns>
113
//////////////////////////////////////////////////////////////////////
114
protected override string CalculateQuery(string basePath)
116
string path = base.CalculateQuery(basePath);
117
StringBuilder newPath = new StringBuilder(path, 2048);
118
char paramInsertion = InsertionParameter(path);
120
if (this.OrderBy != null && this.OrderBy.Length > 0)
122
newPath.Append(paramInsertion);
123
newPath.AppendFormat(CultureInfo.InvariantCulture, "orderby={0}", Utilities.UriEncodeReserved(this.OrderBy));
124
paramInsertion = '&';
126
return newPath.ToString();