diff --git a/AppKit/CPThemeBlend.j b/AppKit/CPThemeBlend.j index 5e0ab95a9..cf523037a 100644 --- a/AppKit/CPThemeBlend.j +++ b/AppKit/CPThemeBlend.j @@ -43,7 +43,7 @@ if (self) { - _bundle = [[CPBundle alloc] initWithPath:aURL + "/Info.plist"]; + _bundle = [[CPBundle alloc] initWithPath:aURL]; } return self; @@ -65,7 +65,7 @@ { var path = [aBundle pathForResource:themes[count]], unarchiver = [[_CPThemeKeyedUnarchiver alloc] - initForReadingWithData:[CPData dataWithString:objj_files[path].contents] + initForReadingWithData:[[CPURL URLWithString:path] staticResourceData] bundle:_bundle]; [unarchiver decodeObjectForKey:@"root"]; diff --git a/AppKit/Cib/CPCib.j b/AppKit/Cib/CPCib.j index 5942ffbb0..eb2ea4266 100644 --- a/AppKit/Cib/CPCib.j +++ b/AppKit/Cib/CPCib.j @@ -171,7 +171,7 @@ var CPCibObjectDataKey = @"CPCibObjectDataKey"; - (void)connection:(CPURLConnection)aConnection didReceiveData:(CPString)data { - _data = [CPData dataWithString:data]; + _data = [CPData dataWithEncodedString:data]; } - (void)connection:(CPURLConnection)aConnection didFailWithError:(CPError)anError diff --git a/Foundation/CPURL.j b/Foundation/CPURL.j index 14c1d0c5c..bfc2ab507 100644 --- a/Foundation/CPURL.j +++ b/Foundation/CPURL.j @@ -200,6 +200,12 @@ CPURLCustomIconKey = @"CPURLCustomIconKey"; [_resourceValues setObject:anObject forKey:aKey]; } +- (CPString)staticResourceData +{ + // FIXME: This probably shouldn't go through CFBundle for no reason. + return CFBundle.dataContentsAtPath([self path]); +} + @end @implementation CPURL (CPCoding) diff --git a/Foundation/CPURLConnection.j b/Foundation/CPURLConnection.j index 7a567998f..584620477 100644 --- a/Foundation/CPURLConnection.j +++ b/Foundation/CPURLConnection.j @@ -26,12 +26,6 @@ @import "CPURLResponse.j" -var XMLHTTPRequestUninitialized = 0, - XMLHTTPRequestLoading = 1, - XMLHTTPRequestLoaded = 2, - XMLHTTPRequestInteractive = 3, - XMLHTTPRequestComplete = 4; - var CPURLConnectionDelegate = nil; /*! @@ -84,8 +78,8 @@ var CPURLConnectionDelegate = nil; id _delegate; BOOL _isCanceled; BOOL _isLocalFileConnection; - - XMLHTTPRequest _XMLHTTPRequest; + + HTTPRequest _HTTPRequest; } + (void)setClassDelegate:(id)delegate @@ -100,12 +94,12 @@ var CPURLConnectionDelegate = nil; @param anError not used @return the data at the URL or \c nil if there was an error */ -+ (CPData)sendSynchronousRequest:(CPURLRequest)aRequest returningResponse:({CPURLResponse})aURLResponse error:({CPError})anError ++ (CPData)sendSynchronousRequest:(CPURLRequest)aRequest returningResponse:({CPURLResponse})aURLResponse { try { - var request = objj_request_xmlhttp(); - + var request = new HTTPRequest(); + request.open([aRequest HTTPMethod], [[aRequest URL] absoluteString], NO); var fields = [aRequest allHTTPHeaderFields], @@ -117,7 +111,7 @@ var CPURLConnectionDelegate = nil; request.send([aRequest HTTPBody]); - return [CPData dataWithString:request.responseText]; + return [CPData dataWithEncodedString:request.responseText()]; } catch (anException) { @@ -163,7 +157,7 @@ var CPURLConnectionDelegate = nil; window.location && (window.location.protocol === "file:" || window.location.protocol === "app:")); - _XMLHTTPRequest = objj_request_xmlhttp(); + _HTTPRequest = new HTTPRequest(); if (shouldStartImmediately) [self start]; @@ -194,18 +188,18 @@ var CPURLConnectionDelegate = nil; try { - _XMLHTTPRequest.open([_request HTTPMethod], [[_request URL] absoluteString], YES); - - _XMLHTTPRequest.onreadystatechange = function() { [self _readyStateDidChange]; } + _HTTPRequest.open([_request HTTPMethod], [[_request URL] absoluteString], YES); + + _HTTPRequest.onreadystatechange = function() { [self _readyStateDidChange]; } var fields = [_request allHTTPHeaderFields], key = nil, keys = [fields keyEnumerator]; - + while (key = [keys nextObject]) - _XMLHTTPRequest.setRequestHeader(key, [fields objectForKey:key]); - - _XMLHTTPRequest.send([_request HTTPBody]); + _HTTPRequest.setRequestHeader(key, [fields objectForKey:key]); + + _HTTPRequest.send([_request HTTPBody]); } catch (anException) { @@ -223,7 +217,7 @@ var CPURLConnectionDelegate = nil; try { - _XMLHTTPRequest.abort(); + _HTTPRequest.abort(); } // We expect an exception in some browsers like FireFox. catch (anException) @@ -239,9 +233,9 @@ var CPURLConnectionDelegate = nil; /* @ignore */ - (void)_readyStateDidChange { - if (_XMLHTTPRequest.readyState == XMLHTTPRequestComplete) + if (_HTTPRequest.readyState() === HTTPRequest.CompleteState) { - var statusCode = _XMLHTTPRequest.status, + var statusCode = _HTTPRequest.status(), URL = [_request URL]; if ([_delegate respondsToSelector:@selector(connection:didReceiveResponse:)]) @@ -259,12 +253,12 @@ var CPURLConnectionDelegate = nil; } if (!_isCanceled) { - if (statusCode == 401 && [CPURLConnectionDelegate respondsToSelector:@selector(connectionDidReceiveAuthenticationChallenge:)]) + if (statusCode === 401 && [CPURLConnectionDelegate respondsToSelector:@selector(connectionDidReceiveAuthenticationChallenge:)]) [CPURLConnectionDelegate connectionDidReceiveAuthenticationChallenge:self]; else { if ([_delegate respondsToSelector:@selector(connection:didReceiveData:)]) - [_delegate connection:self didReceiveData:_XMLHTTPRequest.responseText]; + [_delegate connection:self didReceiveData:_HTTPRequest.responseText()]; if ([_delegate respondsToSelector:@selector(connectionDidFinishLoading:)]) [_delegate connectionDidFinishLoading:self]; } @@ -275,9 +269,27 @@ var CPURLConnectionDelegate = nil; } /* @ignore */ -- (void)_XMLHTTPRequest +- (HTTPRequest)_HTTPRequest { - return _XMLHTTPRequest; + return _HTTPRequest; } @end + +@implementation CPURLConnection (Deprecated) + ++ (CPData)sendSynchronousRequest:(CPURLRequest)aRequest returningResponse:({CPURLResponse})aURLResponse error:({CPError})anError +{ + CPLog.warn("[CPURLConnecton sendSynchronousRequest:returningResponse:error:] is deprecated, using [CPURLConnecton sendSynchronousRequest:returningResponse:] instead."); + + return [self sendSynchronousRequest:aRequest returningResponse:aURLResponse error:NULL]; +} + +- (HTTPRequest)_XMLHTTPRequest +{ + CPLog.warn("[CPURLConnecton _XMLHTTPRequest] is deprecated, using _HTTPRequest instead."); + + return [self _HTTPRequest]; +} + +@end \ No newline at end of file diff --git a/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js b/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js index 34ddf9070..582416357 100644 --- a/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js +++ b/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js @@ -341,7 +341,7 @@ BundleTask.prototype.infoPlist = function() var infoPlistPath = this.infoPlistPath(); if (infoPlistPath && FILE.exists(infoPlistPath)) - var infoPlist = PropertyList.createFromString(FILE.read(infoPlistPath, { charset:"UTF-8" })); + var infoPlist = PropertyList.propertyListFromString(FILE.read(infoPlistPath, { charset:"UTF-8" })); else var infoPlist = new require("objective-j/core").Dictionary(); @@ -372,7 +372,7 @@ BundleTask.prototype.defineInfoPlistTask = function() filedir (infoPlistProductPath, function() { - FILE.write(infoPlistProductPath, PropertyList.createStringWithFormat(bundleTask.infoPlist(), PropertyList.Format280North_v1_0), { charset:"UTF-8" }); + FILE.write(infoPlistProductPath, PropertyList.stringFromPropertyList(bundleTask.infoPlist(), PropertyList.Format280North_v1_0), { charset:"UTF-8" }); }); var infoPlistPath = this.infoPlistPath(); diff --git a/Objective-J/Data.js b/Objective-J/Data.js index 0f18adf86..421ce9d5d 100644 --- a/Objective-J/Data.js +++ b/Objective-J/Data.js @@ -48,6 +48,7 @@ Data.prototype.base64 = function() function MutableData() { + Data.call(this); } MutableData.prototype = new Data(); @@ -82,7 +83,7 @@ MutableData.prototype.setBytes = function(/*Array*/ bytes) this._bytes = bytes; } -MutableData.prototype.setEncodedString = function(/*String*/ aBase64String) +MutableData.prototype.setBase64String = function(/*String*/ aBase64String) { clearMutableData(this); diff --git a/Objective-J/HTTPRequest.js b/Objective-J/HTTPRequest.js index b5a3eae39..a24b3054a 100644 --- a/Objective-J/HTTPRequest.js +++ b/Objective-J/HTTPRequest.js @@ -46,6 +46,12 @@ function HTTPRequest() } } +HTTPRequest.UninitializedState = 0; +HTTPRequest.LoadingState = 1; +HTTPRequest.LoadedState = 2; +HTTPRequest.InteractiveState = 3; +HTTPRequest.CompleteState = 4; + HTTPRequest.prototype.status = function() { try @@ -109,9 +115,9 @@ HTTPRequest.prototype.responsePropertyList = function() var responseText = this.responseText(); if (PropertyList.sniffedFormatOfString(responseText) === PropertyList.FormatXML_v1_0) - return PropertyList.createFromXML(this.responseXML()); + return PropertyList.propertyListFromXML(this.responseXML()); - return PropertyList.createFromString(responseText); + return PropertyList.propertyListFromString(responseText); } HTTPRequest.prototype.responseText = function() @@ -201,6 +207,8 @@ FileRequest.prototype.responseXML = function() FileRequest.prototype.responsePropertyList = function() { - return PropertyList.createFromString(this.responseText()); + return PropertyList.propertyListFromString(this.responseText()); } #endif + +exports.HTTPRequest = HTTPRequest; diff --git a/Objective-J/PropertyList.js b/Objective-J/PropertyList.js index c2ed37d9f..7aff982c2 100644 --- a/Objective-J/PropertyList.js +++ b/Objective-J/PropertyList.js @@ -44,7 +44,7 @@ PropertyList.sniffedFormatOfString = function(/*String*/ aString) PropertyList.dataFromPropertyList = function(/*PropertyList*/ aPropertyList, /*Format*/ aFormat) { - return new Data(PropertyList.stringWithPropertyList(aPropertyList, aFormat)); + return new Data(PropertyList.stringFromPropertyList(aPropertyList, aFormat)); } PropertyList.stringFromPropertyList = function(/*PropertyList*/ aPropertyList, /*Format*/ aFormat) @@ -59,20 +59,6 @@ PropertyList.stringFromPropertyList = function(/*PropertyList*/ aPropertyList, / serializers["finish"](); } -PropertyList.createDataWithFormat = function(/*Format*/ aFormat) -{ - return new Data(PropertyList.createStringWithFormat(aFormat)); -} - -PropertyList.createStringWithFormat = function(/*PropertyList*/ aPropertyList, /*Format*/ aFormat) -{ - var serializers = PropertyListSerializers[aFormat]; - - return serializers["start"]() + - serializePropertyList(aPropertyList, serializers) + - serializers["finish"](); -} - function serializePropertyList(/*PropertyList*/ aPropertyList, /*Object*/ serializers) { var type = typeof aPropertyList, @@ -345,24 +331,18 @@ var _plist_traverseNextNode = function(anXMLNode, stayWithin, stack) return null; } -console.log("problem..."); -PropertyList.createFromData = function(/*Data*/ aData) +PropertyList.propertyListFromData = function(/*Data*/ aData) { - return PropertyList.createFromStringWithFormat(aData.createStringWithFormat(aFormat), aFormat); + return PropertyList.propertyListFromString(aData.encodedString(), aFormat); } -PropertyList.createFromString = function(/*String*/ aString) -{ - return PropertyList.createFromStringWithFormat(aString); -} - -PropertyList.createFromStringWithFormat = function(/*String*/ aString, /*Format*/ aFormat) +PropertyList.propertyListFromString = function(/*String*/ aString, /*Format*/ aFormat) { if (!aFormat) aFormat = PropertyList.sniffedFormatOfString(aString); if (aFormat === PropertyList.FormatXML_v1_0) - return PropertyList.createFromXML(aString); + return PropertyList.propertyListFromXML(aString); if (aFormat === PropertyList.Format280North_v1_0) return propertyListFrom280NorthString(aString); @@ -463,7 +443,7 @@ function decodeHTMLComponent(/*String*/ aString) return aString.replace(/"/g, '"').replace(/'/g, '\'').replace(/</g,'<').replace(/>/g,'>').replace(/&/g,'&'); } -PropertyList.createFromXML = function(/*String | XMLNode*/ aStringOrXMLNode) +PropertyList.propertyListFromXML = function(/*String | XMLNode*/ aStringOrXMLNode) { var XMLNode = aStringOrXMLNode;