API  0.9.10
CPURL.j
Go to the documentation of this file.
1 /*
2  * CPURL.j
3  * Foundation
4  *
5  * Created by Francisco Tolmasky.
6  * Copyright 2008, 280 North, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 
24 CPURLNameKey = @"CPURLNameKey";
25 CPURLLocalizedNameKey = @"CPURLLocalizedNameKey";
26 CPURLIsRegularFileKey = @"CPURLIsRegularFileKey";
27 CPURLIsDirectoryKey = @"CPURLIsDirectoryKey";
28 CPURLIsSymbolicLinkKey = @"CPURLIsSymbolicLinkKey";
29 CPURLIsVolumeKey = @"CPURLIsVolumeKey";
30 CPURLIsPackageKey = @"CPURLIsPackageKey";
31 CPURLIsSystemImmutableKey = @"CPURLIsSystemImmutableKey";
32 CPURLIsUserImmutableKey = @"CPURLIsUserImmutableKey";
33 CPURLIsHiddenKey = @"CPURLIsHiddenKey";
34 CPURLHasHiddenExtensionKey = @"CPURLHasHiddenExtensionKey";
35 CPURLCreationDateKey = @"CPURLCreationDateKey";
36 CPURLContentAccessDateKey = @"CPURLContentAccessDateKey";
37 CPURLContentModificationDateKey = @"CPURLContentModificationDateKey";
38 CPURLAttributeModificationDateKey = @"CPURLAttributeModificationDateKey";
39 CPURLLinkCountKey = @"CPURLLinkCountKey";
40 CPURLParentDirectoryURLKey = @"CPURLParentDirectoryURLKey";
41 CPURLVolumeURLKey = @"CPURLTypeIdentifierKey";
42 CPURLTypeIdentifierKey = @"CPURLTypeIdentifierKey";
43 CPURLLocalizedTypeDescriptionKey = @"CPURLLocalizedTypeDescriptionKey";
44 CPURLLabelNumberKey = @"CPURLLabelNumberKey";
45 CPURLLabelColorKey = @"CPURLLabelColorKey";
46 CPURLLocalizedLabelKey = @"CPURLLocalizedLabelKey";
47 CPURLEffectiveIconKey = @"CPURLEffectiveIconKey";
48 CPURLCustomIconKey = @"CPURLCustomIconKey";
49 @implementation CPURL : CPObject
50 {
51  id __doxygen__;
52 }
53 
54 + (id)alloc
55 {
56  var result = new CFURL();
57  result.isa = [self class];
58  return result;
59 }
60 
61 - (id)init
62 {
63  return nil;
64 }
65 
66 - (id)initWithScheme:(CPString)aScheme host:(CPString)aHost path:(CPString)aPath
67 {
68  var URLString = (aScheme ? aScheme + ":" : "") + (aHost ? aHost + "//" : "") + (aPath || "");
69 
70  return [self initWithString:URLString];
71 }
72 
73 - (id)initWithString:(CPString)URLString
74 {
75  return [self initWithString:URLString relativeToURL:nil];
76 }
77 
78 + (id)URLWithString:(CPString)URLString
79 {
80  return [[self alloc] initWithString:URLString];
81 }
82 
83 - (id)initWithString:(CPString)URLString relativeToURL:(CPURL)aBaseURL
84 {
85  var result = new CFURL(URLString, aBaseURL);
86  result.isa = [self class];
87  return result;
88 }
89 
90 + (id)URLWithString:(CPString)URLString relativeToURL:(CPURL)aBaseURL
91 {
92  return [[self alloc] initWithString:URLString relativeToURL:aBaseURL];
93 }
94 
96 {
97  return self.absoluteURL();
98 }
99 
101 {
102  return self.baseURL();
103 }
104 
106 {
107  return self.absoluteString();
108 }
109 
110 // if absolute, returns same as absoluteString
112 {
113  return self.string();
114 }
115 
117 {
118  return [self absoluteURL].path();
119 }
120 
121 - (CPArray)pathComponents
122 {
123  var components = self.pathComponents();
124  return [components copy];
125 }
126 
127 // if absolute, returns the same as path
129 {
130  return self.path();
131 }
132 
134 {
135  return self.scheme();
136 }
137 
139 {
140  return [self absoluteURL].user();
141 }
142 
144 {
145  return [self absoluteURL].password();
146 }
147 
149 {
150  return [self absoluteURL].domain();
151 }
152 
153 - (Number)port
154 {
155  var portNumber = [self absoluteURL].portNumber();
156 
157  if (portNumber === -1)
158  return nil;
159 
160  return portNumber;
161 }
162 
164 {
165  return self.queryString();
166 }
167 
169 {
170  return self.fragment();
171 }
172 
173 - (BOOL)isEqual:(id)anObject
174 {
175  if (self === anObject)
176  return YES;
177 
178  if (!anObject || ![anObject isKindOfClass:[CPURL class]])
179  return NO;
180 
181  return [self isEqualToURL:anObject];
182 }
183 
184 - (BOOL)isEqualToURL:(id)aURL
185 {
186  if (self === aURL)
187  return YES;
188 
189  // Is checking if baseURL isEqual correct? Does "identical" mean same object or equivalent values?
190  return [[self absoluteString] isEqual:[aURL absoluteString]];
191 }
192 
194 {
195  return [self absoluteURL].lastPathComponent();
196 }
197 
199 {
200  return self.pathExtension();
201 }
202 
204 {
205  var result = self.createCopyDeletingLastPathComponent();
206  result.isa = [self class];
207  return result;
208 }
209 
211 {
212  return self.standardizedURL();
213 }
214 
215 - (BOOL)isFileURL
216 {
217  return [self scheme] === "file";
218 }
219 
221 {
222  return [self absoluteString];
223 }
224 
225 - (id)resourceValueForKey:(CPString)aKey
226 {
227  return self.resourcePropertyForKey(aKey);
228 }
229 
230 - (id)setResourceValue:(id)anObject forKey:(CPString)aKey
231 {
232  return self.setResourcePropertyForKey(aKey, anObject);
233 }
234 
236 {
237  return self.staticResourceData();
238 }
239 
240 @end
241 
242 var CPURLURLStringKey = @"CPURLURLStringKey",
243  CPURLBaseURLKey = @"CPURLBaseURLKey";
244 
245 @implementation CPURL (CPCoding)
246 
247 - (id)initWithCoder:(CPCoder)aCoder
248 {
249  return [self initWithString:[aCoder decodeObjectForKey:CPURLURLStringKey]
250  relativeToURL:[aCoder decodeObjectForKey:CPURLBaseURLKey]];
251 }
252 
253 - (void)encodeWithCoder:(CPCoder)aCoder
254 {
255  [aCoder encodeObject:self._baseURL forKey:CPURLBaseURLKey];
256  [aCoder encodeObject:self._string forKey:CPURLURLStringKey];
257 }
258 
259 @end
260 
261 CFURL.prototype.isa = [CPURL class];
CPURL standardizedURL()
Definition: CPURL.j:210
CPURLIsPackageKey
Definition: CPURL.j:30
CPString relativeString()
Definition: CPURL.j:111
CPString pathExtension()
Definition: CPURL.j:198
var CPURLBaseURLKey
Definition: CPURL.j:243
BOOL isFileURL()
Definition: CPURL.j:215
var isEqual
CPURLEffectiveIconKey
Definition: CPURL.j:47
CPArray pathComponents()
Definition: CPURL.j:121
CPData staticResourceData()
Definition: CPURL.j:235
CPURLCustomIconKey
Definition: CPURL.j:48
CPString host()
Definition: CPURL.j:148
CPURLHasHiddenExtensionKey
Definition: CPURL.j:34
CPURL absoluteURL()
Definition: CPURL.j:95
CPURLAttributeModificationDateKey
Definition: CPURL.j:38
CPURLIsUserImmutableKey
Definition: CPURL.j:32
id init()
Definition: CPURL.j:61
id alloc()
Definition: CPURL.j:54
A Cappuccino wrapper for any data type.
Definition: CPData.h:2
id initWithString:(CPString URLString)
Definition: CPURL.j:73
CPString description()
Definition: CPURL.j:220
CPURLLocalizedLabelKey
Definition: CPURL.j:46
BOOL isEqualToURL:(id aURL)
Definition: CPURL.j:184
CPURLIsVolumeKey
Definition: CPURL.j:29
Number port()
Definition: CPURL.j:153
CPString scheme()
Definition: CPURL.j:133
CPURLLocalizedTypeDescriptionKey
Definition: CPURL.j:43
An immutable string (collection of characters).
Definition: CPString.h:2
CPString absoluteString()
Definition: CPURL.j:105
CPString path()
Definition: CPURL.j:116
CPURLLabelColorKey
Definition: CPURL.j:45
CPURLContentModificationDateKey
Definition: CPURL.j:37
CPString fragment()
Definition: CPURL.j:168
CPURLLocalizedNameKey
Definition: CPURL.j:25
CPURL baseURL()
Definition: CPURL.j:100
CPURLIsRegularFileKey
Definition: CPURL.j:26
CPURLContentAccessDateKey
Definition: CPURL.j:36
CPURLTypeIdentifierKey
Definition: CPURL.j:42
var CPURLURLStringKey
Definition: CPURL.j:242
CPString lastPathComponent()
Definition: CPString.j:824
CPString lastPathComponent()
Definition: CPURL.j:193
Defines methods for use when archiving & restoring (enc/decoding).
Definition: CPCoder.h:2
CPURLLabelNumberKey
Definition: CPURL.j:44
CPString password()
Definition: CPURL.j:143
CPString pathExtension()
Definition: CPString.j:811
CPString user()
Definition: CPURL.j:138
CPURLCreationDateKey
Definition: CPURL.j:35
CPURLParentDirectoryURLKey
Definition: CPURL.j:40
Class class()
Definition: CPObject.j:179
CPURLIsSymbolicLinkKey
Definition: CPURL.j:28
CPURLIsSystemImmutableKey
Definition: CPURL.j:31
CPURLIsHiddenKey
Definition: CPURL.j:33
CPString relativePath()
Definition: CPURL.j:128
BOOL isEqual:(id anObject)
Definition: CPString.j:569
Definition: CPURL.h:2
id string()
Definition: CPString.j:98
CPString parameterString()
Definition: CPURL.j:163
CPURLNameKey
Definition: CPURL.j:24
CPURLLinkCountKey
Definition: CPURL.j:39
CPURLVolumeURLKey
Definition: CPURL.j:41
CPURLIsDirectoryKey
Definition: CPURL.j:27
CPURL URLByDeletingLastPathComponent()
Definition: CPURL.j:203
id initWithString:relativeToURL:(CPString URLString, [relativeToURL] CPURL aBaseURL)
Definition: CPURL.j:83