00001 00002 @import <Foundation/CPObject.j> 00003 00004 CPURLNameKey = @"CPURLNameKey"; 00005 CPURLLocalizedNameKey = @"CPURLLocalizedNameKey"; 00006 CPURLIsRegularFileKey = @"CPURLIsRegularFileKey"; 00007 CPURLIsDirectoryKey = @"CPURLIsDirectoryKey"; 00008 CPURLIsSymbolicLinkKey = @"CPURLIsSymbolicLinkKey"; 00009 CPURLIsVolumeKey = @"CPURLIsVolumeKey"; 00010 CPURLIsPackageKey = @"CPURLIsPackageKey"; 00011 CPURLIsSystemImmutableKey = @"CPURLIsSystemImmutableKey"; 00012 CPURLIsUserImmutableKey = @"CPURLIsUserImmutableKey"; 00013 CPURLIsHiddenKey = @"CPURLIsHiddenKey"; 00014 CPURLHasHiddenExtensionKey = @"CPURLHasHiddenExtensionKey"; 00015 CPURLCreationDateKey = @"CPURLCreationDateKey"; 00016 CPURLContentAccessDateKey = @"CPURLContentAccessDateKey"; 00017 CPURLContentModificationDateKey = @"CPURLContentModificationDateKey"; 00018 CPURLAttributeModificationDateKey = @"CPURLAttributeModificationDateKey"; 00019 CPURLLinkCountKey = @"CPURLLinkCountKey"; 00020 CPURLParentDirectoryURLKey = @"CPURLParentDirectoryURLKey"; 00021 CPURLVolumeURLKey = @"CPURLTypeIdentifierKey"; 00022 CPURLTypeIdentifierKey = @"CPURLTypeIdentifierKey"; 00023 CPURLLocalizedTypeDescriptionKey = @"CPURLLocalizedTypeDescriptionKey"; 00024 CPURLLabelNumberKey = @"CPURLLabelNumberKey"; 00025 CPURLLabelColorKey = @"CPURLLabelColorKey"; 00026 CPURLLocalizedLabelKey = @"CPURLLocalizedLabelKey"; 00027 CPURLEffectiveIconKey = @"CPURLEffectiveIconKey"; 00028 CPURLCustomIconKey = @"CPURLCustomIconKey"; 00029 00030 @implementation CPURL : CPObject 00031 { 00032 } 00033 00034 + (id)alloc 00035 { 00036 return new CFURL(); 00037 } 00038 00039 - (id)init 00040 { 00041 return nil; 00042 } 00043 00044 - (id)initWithScheme:(CPString)aScheme host:(CPString)aHost path:(CPString)aPath 00045 { 00046 var URLString = (aScheme ? aScheme + ":" : "") + (aHost ? aHost + "//" : "") + (aPath || ""); 00047 00048 return [self initWithString:URLString]; 00049 } 00050 00051 - (id)initWithString:(CPString)URLString 00052 { 00053 return [self initWithString:URLString relativeToURL:nil]; 00054 } 00055 00056 + (id)URLWithString:(CPString)URLString 00057 { 00058 return [[self alloc] initWithString:URLString]; 00059 } 00060 00061 - (id)initWithString:(CPString)URLString relativeToURL:(CPURL)aBaseURL 00062 { 00063 return new CFURL(URLString, aBaseURL); 00064 } 00065 00066 + (id)URLWithString:(CPString)URLString relativeToURL:(CPURL)aBaseURL 00067 { 00068 return [[self alloc] initWithString:URLString relativeToURL:aBaseURL]; 00069 } 00070 00071 - (CPURL)absoluteURL 00072 { 00073 return self.absoluteURL(); 00074 } 00075 00076 - (CPURL)baseURL 00077 { 00078 return self.baseURL(); 00079 } 00080 00081 - (CPString)absoluteString 00082 { 00083 return self.absoluteString(); 00084 } 00085 00086 // if absolute, returns same as absoluteString 00087 - (CPString)relativeString 00088 { 00089 return self.string(); 00090 } 00091 00092 - (CPString)path 00093 { 00094 return [self absoluteURL].path(); 00095 } 00096 00097 // if absolute, returns the same as path 00098 - (CPString)relativePath 00099 { 00100 return self.path(); 00101 } 00102 00103 - (CPString)scheme 00104 { 00105 return self.scheme(); 00106 } 00107 00108 - (CPString)user 00109 { 00110 return [self absoluteURL].user(); 00111 } 00112 00113 - (CPString)password 00114 { 00115 return [self absoluteURL].password(); 00116 } 00117 00118 - (CPString)host 00119 { 00120 return [self absoluteURL].domain(); 00121 } 00122 00123 - (Number)port 00124 { 00125 var portNumber = [self absoluteURL].portNumber(); 00126 00127 if (portNumber === -1) 00128 return nil; 00129 00130 return portNumber; 00131 } 00132 00133 - (CPString)parameterString 00134 { 00135 return self.queryString(); 00136 } 00137 00138 - (CPString)fragment 00139 { 00140 return self.fragment(); 00141 } 00142 00143 - (BOOL)isEqual:(id)anObject 00144 { 00145 // Is checking if baseURL isEqual correct? Does "identical" mean same object or equivalent values? 00146 return [self relativeString] === [anObject relativeString] && 00147 ([self baseURL] === [anObject baseURL] || [[self baseURL] isEqual:[anObject baseURL]]); 00148 } 00149 00150 - (CPString)lastPathComponent 00151 { 00152 return [self absoluteURL].lastPathComponent(); 00153 } 00154 00155 - (CPString)pathExtension 00156 { 00157 return self.pathExtension(); 00158 } 00159 00160 - (CPURL)standardizedURL 00161 { 00162 return self.standardizedURL(); 00163 } 00164 00165 - (BOOL)isFileURL 00166 { 00167 return [self scheme] === "file"; 00168 } 00169 00170 - (CPString)description 00171 { 00172 return [self absoluteString]; 00173 } 00174 00175 - (id)resourceValueForKey:(CPString)aKey 00176 { 00177 return self.resourcePropertyForKey(aKey); 00178 } 00179 00180 - (id)setResourceValue:(id)anObject forKey:(CPString)aKey 00181 { 00182 return self.setResourcePropertyForKey(aKey, anObject); 00183 } 00184 00185 - (CPString)staticResourceData 00186 { 00187 return self.staticResourceData(); 00188 } 00189 00190 @end 00191 00192 var CPURLURLStringKey = @"CPURLURLStringKey", 00193 CPURLBaseURLKey = @"CPURLBaseURLKey"; 00194 00195 @implementation CPURL (CPCoding) 00196 00197 - (id)initWithCoder:(CPCoder)aCoder 00198 { 00199 return [self initWithString:[aCoder decodeObjectForKey:CPURLURLStringKey] 00200 relativeToURL:[aCoder decodeObjectForKey:CPURLBaseURLKey]]; 00201 } 00202 00203 - (void)encodeWithCoder:(CPCoder)aCoder 00204 { 00205 [aCoder encodeObject:_baseURL forKey:CPURLBaseURLKey]; 00206 [aCoder encodeObject:_string forKey:CPURLURLStringKey]; 00207 } 00208 00209 @end 00210 00211 CFURL.prototype.isa = [CPURL class];