-
Notifications
You must be signed in to change notification settings - Fork 3
/
uri.e
executable file
·202 lines (162 loc) · 5.74 KB
/
uri.e
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
note
component: "Eiffel Object Modelling Framework"
description: "[
Model of a URI, or Universal Resource Identifier, as defined by W3C
RFC 3896. See %"Universal Resource Identifiers in WWW%" by
Tim Berners-Lee at http://www.ietf.org/rfc/rfc3986.txt.
This is a World-Wide Web RFC for global
identification of resources. In current use on the web,
eg by Mosaic, Netscape and similar tools.
See http://www.w3.org/Addressing for a starting point on URIs.
FIXME: This class does not implement this RFC at the moment. It will use the
Gobo class to do so in the future, since URIs are made persisitent,
this class will have to iinherit from DT_CONVERTIBLE and list only value as
being persistent.
]"
keywords: "www, uri, uniform, resource, identifier"
author: "Thomas Beale <[email protected]>"
support: "http://www.openehr.org/issues/browse/AWB"
copyright: "Copyright (c) 2005- Ocean Informatics Pty Ltd <http://www.oceaninfomatics.com>"
license: "Apache 2.0 License <http://www.apache.org/licenses/LICENSE-2.0.html>"
class URI
inherit
ANY
redefine
out, is_equal
end
create
make, make_from_string, default_create
feature -- Initialisation
make (a_scheme, a_path, a_query, a_fragment: STRING)
require
Scheme_exists: not a_scheme.is_empty
Path_exists: not a_path.is_empty
Valid_query: a_query /= Void implies not a_query.is_empty
Valid_fragment: a_fragment /= Void implies not a_fragment.is_empty
do
value := format(a_scheme, a_path, a_query, a_fragment)
end
make_from_string (a_uri_string: STRING)
require
valid_string: valid_uri (a_uri_string)
do
value := a_uri_string
end
feature -- Definitions
Scheme_delimiter: STRING = ":"
-- indicates the end of the scheme name
Authority_delimiter: STRING = "//"
-- indicates start of authority id under which next level of ids are sensible
Fragment_delimiter: STRING = "#"
-- Indicates the start of a fragment identifier
Query_delimiter: STRING = "?"
-- Indicates the start of a query string
Hierarchy_delimiter: STRING = "/"
-- Delimiter character for objects whose relationship is
-- hierarchical.
Escape_char: STRING = "%%"
-- Used for escaping characters in a local scheme which
-- have specific significance in a URI. Note that a double
-- %% must be used here since % is also the Eiffel Escape
-- character.
Reserved_chars: STRING = "/#?*.!+%%"
-- Characters reserved for use in URIs. Where these
-- characters occur in local names, they will be escaped
-- with the escape character.
feature -- Access
value: STRING
-- the complete URI value
attribute
create Result.make_empty
end
scheme: STRING
-- A distributed information "space" in which information
-- objects exist. The scheme simultaneously specifies an
-- information space and a mechanism for accessing objects
-- in that space. For example if scheme = "ftp", it
-- identifies the information space in which all ftpable
-- objects exist, and also the application - ftp - which
-- can be used to access them.
--
-- Values may include: "ftp", "telnet", "mailto", "gopher"
-- and many others. Refer to WWW URI RFC for a full list.
-- New information spaces can be accommodated within the
-- URI specification.
do
create Result.make_empty
end
path: STRING
-- A string whose format is a function of the scheme.
-- Identifies the location in <scheme>-space of an
-- information entity. Typical values include hierarchical
-- directory paths for any machine. For example, with
-- scheme = "ftp", path might be /pub/images/image_01. The
-- strings "." and ".." are reserved for use in the path.
-- Paths may include internet/intranet location identifiers
-- of the form: sub_domain...domain, e.g. "info.cern.ch"
do
create Result.make_empty
end
fragment_id: STRING
-- A part of, a fragment or a sub-function within an
-- object. Allows references to sub-parts of objects, such
-- as a certain line and character position in a text
-- object. The syntax and semantics are defined by the
-- application responsible for the object.
do
create Result.make_empty
end
query: STRING
-- Query string to send to application implied by scheme
-- and path Enables queries to applications, including
-- databases to be included in the URI Any query
-- meaningful to the server, including SQL.
do
create Result.make_empty
end
feature -- Status Report
is_empty: BOOLEAN
do
Result := value.is_empty
end
feature -- Comparison
is_equal (other: like Current): BOOLEAN
do
Result := value.is_equal (other.value)
end
feature -- Validation
valid_uri (a_str: STRING): BOOLEAN
-- True if a_str in valid URI syntax
do
-- FIXME: for the moment, anything is valid. We need to use the Gobo UT_URI class to
-- do proper validation
Result := not a_str.is_empty -- a_str.substring_index(Scheme_delimiter + Authority_delimiter, 1) > 1
end
feature -- Modification
wipe_out
do
value.wipe_out
end
feature -- Conversion
as_string: STRING
do
Result := value
end
feature -- output
out: STRING
do
Result := as_string
end
feature {NONE} -- Implementation
format(a_scheme, a_path, a_query, a_fragment:STRING): STRING
do
Result := a_scheme.twin
Result.append(Scheme_delimiter + Authority_delimiter + a_path)
if a_query /= Void then
Result.append(Query_delimiter + a_query)
end
if a_fragment /= Void then
Result.append(Fragment_delimiter + a_fragment)
end
end
end