5 // Copyright 2011 GRNET S.A. All rights reserved.
7 // Redistribution and use in source and binary forms, with or
8 // without modification, are permitted provided that the following
11 // 1. Redistributions of source code must retain the above
12 // copyright notice, this list of conditions and the following
15 // 2. Redistributions in binary form must reproduce the above
16 // copyright notice, this list of conditions and the following
17 // disclaimer in the documentation and/or other materials
18 // provided with the distribution.
20 // THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
21 // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
24 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 // AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 // POSSIBILITY OF SUCH DAMAGE.
33 // The views and conclusions contained in the software and
34 // documentation are those of the authors and should not be
35 // interpreted as representing official policies, either expressed
36 // or implied, of GRNET S.A.
38 #import "PithosObjectNode.h"
39 #import "ASIPithosRequest.h"
40 #import "ASIPithosObjectRequest.h"
41 #import "ASIPithosContainer.h"
42 #import "ASIPithosObject.h"
43 #import "ASIDownloadCache.h"
44 #import "PithosNodeInfoController.h"
46 @implementation PithosObjectNode
47 @synthesize pithosContainer, pithosObject;
51 #pragma mark Object Lifecycle
53 - (id)initWithPithosContainer:(ASIPithosContainer *)aPithosContainer pithosObject:(ASIPithosObject *)aPithosObject {
54 if ((self = [super init])) {
55 self.pithosContainer = aPithosContainer;
56 self.pithosObject = aPithosObject;
63 [refreshMetadataObjectRequest clearDelegatesAndCancel];
64 [refreshMetadataObjectRequest release];
65 [applyMetadataObjectRequest clearDelegatesAndCancel];
66 [applyMetadataObjectRequest release];
67 [pithosObject release];
68 [pithosContainer release];
73 #pragma mark Properties
77 url = [[NSString alloc] initWithFormat:@"object %@/%@/%@", [ASIPithosRequest storageURL], pithosContainer.name, pithosObject.name];
81 - (NSArray *)children {
85 - (NSString *)displayName {
86 if (displayName == nil) {
87 // XXX check if there are problems with . or other special characters
88 displayName = [pithosObject.name lastPathComponent];
89 if([pithosObject.name hasSuffix:@"/"])
90 displayName = [displayName stringByAppendingString:@"/"];
93 return [[displayName copy] autorelease];
98 icon = [[[NSWorkspace sharedWorkspace] iconForFileType:[pithosObject.name pathExtension]] retain];
102 - (void)setPithosObject:(ASIPithosObject *)aPithosObject {
103 if (![pithosObject isEqualTo:aPithosObject]) {
104 [pithosObject release];
105 pithosObject = [aPithosObject retain];
107 self.isPublic = (pithosObject.publicURI != nil);
114 @synchronized(self) {
115 if (applyMetadataObjectRequest == nil) {
116 applyMetadataObjectRequest = [[ASIPithosObjectRequest updateObjectMetadataRequestWithContainerName:pithosContainer.name
117 objectName:pithosObject.name
119 contentDisposition:nil
121 sharing:pithosObject.sharing
122 isPublic:(isPublic ? ASIPithosObjectRequestPublicTrue : ASIPithosObjectRequestPublicFalse)
123 metadata:pithosObject.metadata
125 applyMetadataObjectRequest.delegate = self;
126 [applyMetadataObjectRequest startAsynchronous];
131 - (void)refreshInfo {
132 @synchronized(self) {
133 if (refreshMetadataObjectRequest == nil) {
134 refreshMetadataObjectRequest = [[ASIPithosObjectRequest objectMetadataRequestWithContainerName:pithosContainer.name
135 objectName:pithosObject.name] retain];
136 refreshMetadataObjectRequest.delegate = self;
137 refreshMetadataObjectRequest.downloadCache = [ASIDownloadCache sharedCache];
138 [refreshMetadataObjectRequest startAsynchronous];
144 #pragma mark ASIHTTPRequestDelegate
146 - (void)requestFinished:(ASIHTTPRequest *)request {
147 NSLog(@"URL: %@", [request url]);
148 NSLog(@"cached: %d", [request didUseCachedResponse]);
150 if ([request isEqualTo:applyMetadataObjectRequest]) {
151 @synchronized(self) {
152 [applyMetadataObjectRequest release];
153 applyMetadataObjectRequest = nil;
156 } else if ([request isEqualTo:refreshMetadataObjectRequest]) {
157 self.pithosObject = [refreshMetadataObjectRequest object];
158 @synchronized(self) {
159 [refreshMetadataObjectRequest release];
160 refreshMetadataObjectRequest = nil;
165 - (void)requestFailed:(ASIHTTPRequest *)request {
166 if ([request isEqualTo:applyMetadataObjectRequest]) {
167 // XXX do something on error, cleanup
168 NSLog(@"error:%@", [applyMetadataObjectRequest error]);
169 @synchronized(self) {
170 [applyMetadataObjectRequest release];
171 applyMetadataObjectRequest = nil;
173 } else if ([request isEqualTo:refreshMetadataObjectRequest]) {
174 // XXX do something on error, cleanup
175 NSLog(@"error:%@", [refreshMetadataObjectRequest error]);
176 @synchronized(self) {
177 [refreshMetadataObjectRequest release];
178 refreshMetadataObjectRequest = nil;