This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTagURI.cs
105 lines (94 loc) · 3.24 KB
/
TagURI.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* JUG Java Uuid Generator
*
* Copyright (c) 2002,2010 Tatu Saloranta, tatu.saloranta@iki.fi, Tommi S.E. Laukkanen, tommi.s.e.laukkanen@gmail.com
*
* Licensed under the License specified in the file LICENSE which is
* included with the source code.
* You may not use this file except in compliance with the License.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System.Text;
using System;
namespace Jug
{
/**
* A class that allows creation of tagURI instances.
*
* TagURIs are specified in IETF draft <draft-kindberg-tag-uri-01.txt>;
* available for example at:
*
* http://sunsite.cnlab-switch.ch/ftp/mirror/internet-drafts/draft-kindberg-tag-uri-01.txt
*/
public class TagURI
{
private String mDesc;
/**
* Constructor for creating tagURI instances.
*
* Typical string representations of tagURIs may look like:
* <ul>
* <li>tag:hp1.hp.com,2001:tst.1234567890
* <li>tag:fred@flintstone.biz,2001-07-02:rock.123
* </ul>
* (see tagURI draft for more examples and full explanation of the
* basic concepts)
*
* @param authority Authority that created tag URI; usually either a
* fully-qualified domain name ("www.w3c.org") or an email address
* ("tatu.saloranta@iki.fi").
* @param identifier A locally unique identifier; often file path or
* URL path component (like, "tst.1234567890", "/home/tatu/index.html")
* @param date Date to add as part of the tag URI, if any; null is used
* used to indicate that no datestamp should be added.
*
*/
public TagURI(String authority, String identifier, Nullable<DateTime> date)
{
StringBuilder b = new StringBuilder();
b.Append("tag:");
b.Append(authority);
if (date != null)
{
b.Append(',');
b.Append(date.Value.Year);
// Month is optional if it's "january" and day is "1st":
int month = date.Value.Month;
int day = date.Value.Day;
if (month != 1 || day != 1)
{
b.Append('-');
b.Append(month);
}
if (day != 1)
{
b.Append('-');
b.Append(day);
}
}
b.Append(':');
b.Append(identifier);
mDesc = b.ToString();
}
public override String ToString()
{
return mDesc;
}
public override bool Equals(Object o)
{
if (o != null && o.GetType() == typeof(TagURI))
{
return mDesc.Equals(((TagURI)o).ToString());
}
return false;
}
public override int GetHashCode()
{
return mDesc.GetHashCode();
}
}
}