API 0.9.5
Foundation/CPURL.j
Go to the documentation of this file.
00001 /*
00002  * CPURL.j
00003  * Foundation
00004  *
00005  * Created by Francisco Tolmasky.
00006  * Copyright 2008, 280 North, Inc.
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00023 
00024 CPURLNameKey                        = @"CPURLNameKey";
00025 CPURLLocalizedNameKey               = @"CPURLLocalizedNameKey";
00026 CPURLIsRegularFileKey               = @"CPURLIsRegularFileKey";
00027 CPURLIsDirectoryKey                 = @"CPURLIsDirectoryKey";
00028 CPURLIsSymbolicLinkKey              = @"CPURLIsSymbolicLinkKey";
00029 CPURLIsVolumeKey                    = @"CPURLIsVolumeKey";
00030 CPURLIsPackageKey                   = @"CPURLIsPackageKey";
00031 CPURLIsSystemImmutableKey           = @"CPURLIsSystemImmutableKey";
00032 CPURLIsUserImmutableKey             = @"CPURLIsUserImmutableKey";
00033 CPURLIsHiddenKey                    = @"CPURLIsHiddenKey";
00034 CPURLHasHiddenExtensionKey          = @"CPURLHasHiddenExtensionKey";
00035 CPURLCreationDateKey                = @"CPURLCreationDateKey";
00036 CPURLContentAccessDateKey           = @"CPURLContentAccessDateKey";
00037 CPURLContentModificationDateKey     = @"CPURLContentModificationDateKey";
00038 CPURLAttributeModificationDateKey   = @"CPURLAttributeModificationDateKey";
00039 CPURLLinkCountKey                   = @"CPURLLinkCountKey";
00040 CPURLParentDirectoryURLKey          = @"CPURLParentDirectoryURLKey";
00041 CPURLVolumeURLKey                   = @"CPURLTypeIdentifierKey";
00042 CPURLTypeIdentifierKey              = @"CPURLTypeIdentifierKey";
00043 CPURLLocalizedTypeDescriptionKey    = @"CPURLLocalizedTypeDescriptionKey";
00044 CPURLLabelNumberKey                 = @"CPURLLabelNumberKey";
00045 CPURLLabelColorKey                  = @"CPURLLabelColorKey";
00046 CPURLLocalizedLabelKey              = @"CPURLLocalizedLabelKey";
00047 CPURLEffectiveIconKey               = @"CPURLEffectiveIconKey";
00048 CPURLCustomIconKey                  = @"CPURLCustomIconKey";
00049 @implementation CPURL : CPObject
00050 {
00051     id __doxygen__;
00052 }
00053 
00054 + (id)alloc
00055 {
00056     var result = new CFURL();
00057     result.isa = [self class];
00058     return result;
00059 }
00060 
00061 - (id)init
00062 {
00063     return nil;
00064 }
00065 
00066 - (id)initWithScheme:(CPString)aScheme host:(CPString)aHost path:(CPString)aPath
00067 {
00068     var URLString = (aScheme ? aScheme + ":" : "") + (aHost ? aHost + "//" : "") + (aPath || "");
00069 
00070     return [self initWithString:URLString];
00071 }
00072 
00073 - (id)initWithString:(CPString)URLString
00074 {
00075     return [self initWithString:URLString relativeToURL:nil];
00076 }
00077 
00078 + (id)URLWithString:(CPString)URLString
00079 {
00080     return [[self alloc] initWithString:URLString];
00081 }
00082 
00083 - (id)initWithString:(CPString)URLString relativeToURL:(CPURL)aBaseURL
00084 {
00085     var result = new CFURL(URLString, aBaseURL);
00086     result.isa = [self class];
00087     return result;
00088 }
00089 
00090 + (id)URLWithString:(CPString)URLString relativeToURL:(CPURL)aBaseURL
00091 {
00092     return [[self alloc] initWithString:URLString relativeToURL:aBaseURL];
00093 }
00094 
00095 - (CPURL)absoluteURL
00096 {
00097     return self.absoluteURL();
00098 }
00099 
00100 - (CPURL)baseURL
00101 {
00102     return self.baseURL();
00103 }
00104 
00105 - (CPString)absoluteString
00106 {
00107     return self.absoluteString();
00108 }
00109 
00110 // if absolute, returns same as absoluteString
00111 - (CPString)relativeString
00112 {
00113     return self.string();
00114 }
00115 
00116 - (CPString)path
00117 {
00118     return [self absoluteURL].path();
00119 }
00120 
00121 - (CPArray)pathComponents
00122 {
00123     var path = self.pathComponents();
00124     return [path copy];
00125 }
00126 
00127 // if absolute, returns the same as path
00128 - (CPString)relativePath
00129 {
00130     return self.path();
00131 }
00132 
00133 - (CPString)scheme
00134 {
00135     return self.scheme();
00136 }
00137 
00138 - (CPString)user
00139 {
00140     return [self absoluteURL].user();
00141 }
00142 
00143 - (CPString)password
00144 {
00145     return [self absoluteURL].password();
00146 }
00147 
00148 - (CPString)host
00149 {
00150     return [self absoluteURL].domain();
00151 }
00152 
00153 - (Number)port
00154 {
00155     var portNumber = [self absoluteURL].portNumber();
00156 
00157     if (portNumber === -1)
00158         return nil;
00159 
00160     return portNumber;
00161 }
00162 
00163 - (CPString)parameterString
00164 {
00165     return self.queryString();
00166 }
00167 
00168 - (CPString)fragment
00169 {
00170     return self.fragment();
00171 }
00172 
00173 - (BOOL)isEqual:(id)anObject
00174 {
00175     if (self === anObject)
00176         return YES;
00177 
00178     if (!anObject || ![anObject isKindOfClass:[CPURL class]])
00179         return NO;
00180 
00181     return [self isEqualToURL:anObject];
00182 }
00183 
00184 - (BOOL)isEqualToURL:(id)aURL
00185 {
00186     if (self === aURL)
00187         return YES;
00188 
00189     // Is checking if baseURL isEqual correct? Does "identical" mean same object or equivalent values?
00190     return [[self absoluteString] isEqual:[aURL absoluteString]];
00191 }
00192 
00193 - (CPString)lastPathComponent
00194 {
00195     return [self absoluteURL].lastPathComponent();
00196 }
00197 
00198 - (CPString)pathExtension
00199 {
00200     return self.pathExtension();
00201 }
00202 
00203 - (CPURL)standardizedURL
00204 {
00205     return self.standardizedURL();
00206 }
00207 
00208 - (BOOL)isFileURL
00209 {
00210     return [self scheme] === "file";
00211 }
00212 
00213 - (CPString)description
00214 {
00215     return [self absoluteString];
00216 }
00217 
00218 - (id)resourceValueForKey:(CPString)aKey
00219 {
00220     return self.resourcePropertyForKey(aKey);
00221 }
00222 
00223 - (id)setResourceValue:(id)anObject forKey:(CPString)aKey
00224 {
00225     return self.setResourcePropertyForKey(aKey, anObject);
00226 }
00227 
00228 - (CPData)staticResourceData
00229 {
00230     return self.staticResourceData();
00231 }
00232 
00233 @end
00234 
00235 var CPURLURLStringKey   = @"CPURLURLStringKey",
00236     CPURLBaseURLKey     = @"CPURLBaseURLKey";
00237 
00238 @implementation CPURL (CPCoding)
00239 
00240 - (id)initWithCoder:(CPCoder)aCoder
00241 {
00242     return [self initWithString:[aCoder decodeObjectForKey:CPURLURLStringKey]
00243                   relativeToURL:[aCoder decodeObjectForKey:CPURLBaseURLKey]];
00244 }
00245 
00246 - (void)encodeWithCoder:(CPCoder)aCoder
00247 {
00248     [aCoder encodeObject:_baseURL forKey:CPURLBaseURLKey];
00249     [aCoder encodeObject:_string forKey:CPURLURLStringKey];
00250 }
00251 
00252 @end
00253 
00254 CFURL.prototype.isa = [CPURL class];
 All Classes Files Functions Variables Defines