mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Minor URL modifications
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@7912 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
e1b6bbc3e7
commit
321c8d2917
5 changed files with 73 additions and 18 deletions
|
@ -1,3 +1,8 @@
|
|||
2000-10-27 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSURLHandle.m: Make class registration thread safe.
|
||||
Tidy initialisation to use designated initialiser.
|
||||
|
||||
2000-10-27 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Added localization support
|
||||
|
|
|
@ -51,6 +51,22 @@
|
|||
<sel>usingCache:</sel>
|
||||
<arg type="BOOL">shouldUseCache</arg>
|
||||
<desc>
|
||||
Loads the resource data for the specified URL.
|
||||
<p>
|
||||
If <em>shouldUseCache</em> is <code>YES</code> then an attempt
|
||||
will be made to locate a cached NSURLHandle to provide the
|
||||
resource data, otherwise a new handle will be created and
|
||||
cached.
|
||||
</p>
|
||||
<p>
|
||||
If the handle does not have the data available, it will be
|
||||
asked to load the data in the background by calling its
|
||||
loadInBackground method.
|
||||
</p>
|
||||
<p>
|
||||
The specified client (if non-nil) will be set up to recieve
|
||||
notifications of the progress fo the background load process.
|
||||
</p>
|
||||
</desc>
|
||||
</method>
|
||||
|
||||
|
|
|
@ -71,6 +71,28 @@
|
|||
<h3><a name ="method-3">loadResourceDataNotifyingClient:usingCache:</a></h3>
|
||||
- (void) <b>loadResourceDataNotifyingClient:</b> (id)client <b>usingCache:</b> (BOOL)shouldUseCache;<br>
|
||||
|
||||
Loads the resource data for the specified URL.
|
||||
<p>
|
||||
|
||||
If <em>shouldUseCache</em> is <code>YES</code> then an attempt
|
||||
will be made to locate a cached NSURLHandle to provide the
|
||||
resource data, otherwise a new handle will be created and
|
||||
cached.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
|
||||
If the handle does not have the data available, it will be
|
||||
asked to load the data in the background by calling its
|
||||
loadInBackground method.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
|
||||
The specified client (if non-nil) will be set up to recieve
|
||||
notifications of the progress fo the background load process.
|
||||
</p>
|
||||
|
||||
|
||||
<hr>
|
||||
<h3><a name ="method-4">parameterString</a></h3>
|
||||
|
|
|
@ -591,7 +591,6 @@ NSString *NSURLPartKey_query = @"query";
|
|||
NSLog(@"*_baseURL: %@", [[url baseURL] description]);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
- (void) loadResourceDataNotifyingClient: (id)client
|
||||
usingCache: (BOOL)shouldUseCache
|
||||
{
|
||||
|
@ -635,7 +634,6 @@ NSString *NSURLPartKey_query = @"query";
|
|||
return data;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
- (NSURLHandle*) URLHandleUsingCache: (BOOL)shouldUseCache
|
||||
{
|
||||
NSURLHandle *handle = nil;
|
||||
|
@ -657,15 +655,13 @@ NSString *NSURLPartKey_query = @"query";
|
|||
return handle;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
- (BOOL) setResourceData: (NSData*)data
|
||||
{
|
||||
NSURLHandle *handle = [self URLHandleUsingCache: YES];
|
||||
|
||||
return [handle writeData: data];
|
||||
return (handle == nil) ? NO : [handle writeData: data];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
- (id) propertyForKey: (NSString*)propertyKey
|
||||
{
|
||||
NSURLHandle *handle = [self URLHandleUsingCache: YES];
|
||||
|
@ -673,7 +669,6 @@ NSString *NSURLPartKey_query = @"query";
|
|||
return [handle propertyForKey: propertyKey];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
- (BOOL) setProperty: (id)property
|
||||
forKey: (NSString*)propertyKey;
|
||||
{
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSConcreteNumber.h>
|
||||
#include <Foundation/NSLock.h>
|
||||
#include <Foundation/NSURLHandle.h>
|
||||
#include <Foundation/NSURL.h>
|
||||
#include <Foundation/NSMapTable.h>
|
||||
|
@ -39,7 +40,9 @@
|
|||
|
||||
@implementation NSURLHandle
|
||||
|
||||
static NSLock *registryLock = nil;
|
||||
static NSMutableArray *registry = nil;
|
||||
static Class NSURLHandleClass = 0;
|
||||
|
||||
+ (NSURLHandle*) cachedHandleForURL: (NSURL*)url
|
||||
{
|
||||
|
@ -47,11 +50,18 @@ static NSMutableArray *registry = nil;
|
|||
* Each subclass is supposed to do its own caching, so we must
|
||||
* find the correct subclass and ask it for its cached handle.
|
||||
*/
|
||||
if (self == [NSURLHandle class])
|
||||
if (self == NSURLHandleClass)
|
||||
{
|
||||
Class c = [self URLHandleClassForURL: url];
|
||||
|
||||
return [c cachedHandleForURL: url];
|
||||
if (c == self || c == 0)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
else
|
||||
{
|
||||
return [c cachedHandleForURL: url];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -72,7 +82,9 @@ static NSMutableArray *registry = nil;
|
|||
{
|
||||
if (self == [NSURLHandle class])
|
||||
{
|
||||
NSURLHandleClass = self;
|
||||
registry = [NSMutableArray new];
|
||||
registryLock = [NSLock new];
|
||||
[self registerURLHandleClass: [GSFileURLHandle class]];
|
||||
}
|
||||
}
|
||||
|
@ -84,13 +96,18 @@ static NSMutableArray *registry = nil;
|
|||
* Re-adding a class moves it to the end of the registry - so it will
|
||||
* be used in preference to any class added earlier.
|
||||
*/
|
||||
[registryLock lock];
|
||||
[registry removeObjectIdenticalTo: urlHandleSubclass];
|
||||
[registry addObject: urlHandleSubclass];
|
||||
[registryLock unlock];
|
||||
}
|
||||
|
||||
+ (Class) URLHandleClassForURL: (NSURL*)url
|
||||
{
|
||||
unsigned count = [registry count];
|
||||
unsigned count;
|
||||
|
||||
[registryLock lock];
|
||||
count = [registry count];
|
||||
|
||||
/*
|
||||
* Find a class to handle the URL, try most recently registered first.
|
||||
|
@ -101,9 +118,11 @@ static NSMutableArray *registry = nil;
|
|||
|
||||
if ([found canInitWithURL: url] == YES)
|
||||
{
|
||||
[registryLock unlock];
|
||||
return (Class)found;
|
||||
}
|
||||
}
|
||||
[registryLock unlock];
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -245,17 +264,16 @@ static NSMutableArray *registry = nil;
|
|||
|
||||
- (id) init
|
||||
{
|
||||
_status = NSURLHandleNotLoaded;
|
||||
_clients = [NSMutableArray new];
|
||||
_data = [NSMutableData new];
|
||||
return self;
|
||||
return [self initWithURL: nil cached: NO];
|
||||
}
|
||||
|
||||
- (id) initWithURL: (NSURL*)url
|
||||
cached: (BOOL)cached
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
return nil;
|
||||
_status = NSURLHandleNotLoaded;
|
||||
_clients = [NSMutableArray new];
|
||||
_data = [NSMutableData new];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) loadInBackground
|
||||
|
@ -394,14 +412,13 @@ static NSMutableDictionary *fileCache = nil;
|
|||
return self;
|
||||
}
|
||||
}
|
||||
self = [super init];
|
||||
if (self != nil)
|
||||
|
||||
if ((self = [super initWithURL: url cached: cached]) != nil)
|
||||
{
|
||||
_path = [path copy];
|
||||
if (cached == YES)
|
||||
{
|
||||
[fileCache setObject: self forKey: _path];
|
||||
RELEASE(self);
|
||||
}
|
||||
}
|
||||
return self;
|
||||
|
|
Loading…
Reference in a new issue