From 42848b23d2f5f49ff753baa9816da32b5ddd9e6e Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 19 Jun 2009 14:35:03 +0000 Subject: =?UTF-8?q?=E2=80=A2=20added=20to=20TableContent.m:=20-=20(NSArray?= =?UTF-8?q?=20*=20)currentDataResult=20--=20like=20currentResult=20but=20r?= =?UTF-8?q?eturns=20"BLOB"=20for=20blob=20data=20and=20a=20base64=20encode?= =?UTF-8?q?d=20string=20for=20images=20=C3=A0=20la=20=20=20-=20(NSString=20*=20)=20base64EncodingO?= =?UTF-8?q?fData:(NSData=20*=20)data=20withLineLength:(unsigned=20int)line?= =?UTF-8?q?Length=20--=20it=20returns=20a=20base64=20encoded=20string=20of?= =?UTF-8?q?=20data=20=E2=80=A2=20changed:=20currentDataResult=20is=20now?= =?UTF-8?q?=20called=20for=20printing=20from=20the=20Table=20Content=20Bro?= =?UTF-8?q?wser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/TableContent.m | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) (limited to 'Source/TableContent.m') diff --git a/Source/TableContent.m b/Source/TableContent.m index 46fde6b3..319b46ae 100644 --- a/Source/TableContent.m +++ b/Source/TableContent.m @@ -40,6 +40,15 @@ #import "SPTextViewAdditions.h" #import "QLPreviewPanel.h" + +static char encodingTable[64] = { +'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P', +'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f', +'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v', +'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/' }; + + + @implementation TableContent /** @@ -1250,6 +1259,114 @@ return retVal; } +//getter methods +- (NSArray *)currentDataResult +/* + returns the current result (as shown in table content view) as array, the first object containing the field names as array, the following objects containing the rows as array + */ +{ + NSArray *tableColumns; + NSEnumerator *enumerator; + id tableColumn; + NSMutableArray *currentResult = [NSMutableArray array]; + NSMutableArray *tempRow = [NSMutableArray array]; + int i; + + //load table if not already done + if ( ![tablesListInstance contentLoaded] ) { + [self loadTable:[tablesListInstance tableName]]; + } + + tableColumns = [tableContentView tableColumns]; + enumerator = [tableColumns objectEnumerator]; + + //set field names as first line + while ( (tableColumn = [enumerator nextObject]) ) { + [tempRow addObject:[[tableColumn headerCell] stringValue]]; + } + [currentResult addObject:[NSArray arrayWithArray:tempRow]]; + + //add rows + for ( i = 0 ; i < [self numberOfRowsInTableView:nil] ; i++) { + [tempRow removeAllObjects]; + enumerator = [tableColumns objectEnumerator]; + while ( (tableColumn = [enumerator nextObject]) ) { + id o = [[fullResult objectAtIndex:i] objectForKey:[[tableColumn headerCell] stringValue]]; + if([o isKindOfClass:[NSNull class]]) + [tempRow addObject:@"NULL"]; + else if([o isKindOfClass:[NSString class]]) + [tempRow addObject:[o description]]; + else { + NSImage *image = [[NSImage alloc] initWithData:o]; + if(image) { + [tempRow addObject:[NSString stringWithFormat:@"", [self base64EncodingOfData: o withLineLength:0]]]; + } else { + [tempRow addObject:@"<BLOB>"]; + } + if(image) [image release]; + } + } + [currentResult addObject:[NSArray arrayWithArray:tempRow]]; + } + return currentResult; +} + +- (NSString *) base64EncodingOfData:(NSData*)data withLineLength:(unsigned int)lineLength { + const unsigned char *bytes = [data bytes]; + NSMutableString *result = [NSMutableString stringWithCapacity:[data length]]; + unsigned long ixtext = 0; + unsigned long lentext = [data length]; + long ctremaining = 0; + unsigned char inbuf[3], outbuf[4]; + short i = 0; + short charsonline = 0, ctcopy = 0; + unsigned long ix = 0; + + while( YES ) { + ctremaining = lentext - ixtext; + if( ctremaining <= 0 ) break; + + for( i = 0; i < 3; i++ ) { + ix = ixtext + i; + if( ix < lentext ) inbuf[i] = bytes[ix]; + else inbuf [i] = 0; + } + + outbuf [0] = (inbuf [0] & 0xFC) >> 2; + outbuf [1] = ((inbuf [0] & 0x03) << 4) | ((inbuf [1] & 0xF0) >> 4); + outbuf [2] = ((inbuf [1] & 0x0F) << 2) | ((inbuf [2] & 0xC0) >> 6); + outbuf [3] = inbuf [2] & 0x3F; + ctcopy = 4; + + switch( ctremaining ) { + case 1: + ctcopy = 2; + break; + case 2: + ctcopy = 3; + break; + } + + for( i = 0; i < ctcopy; i++ ) + [result appendFormat:@"%c", encodingTable[outbuf[i]]]; + + for( i = ctcopy; i < 4; i++ ) + [result appendFormat:@"%c",'=']; + + ixtext += 3; + charsonline += 4; + + if( lineLength > 0 ) { + if (charsonline >= lineLength) { + charsonline = 0; + [result appendString:@"\n"]; + } + } + } + + return result; +} + //getter methods - (NSArray *)currentResult /* -- cgit v1.2.3