//---------------------------------------------------------------------------------------
//	MIMEContentDisposition.m created by erik on Sun 23-Mar-1997
//	This code is part of the Alexandra Newsreader Project. For copyright details see
//	GNU public license version 2 or above. No warranties implied. Use at own risk.
//	More information can be found at <http://www.object-factory.com/Alexandra>.
//	@(#)$Id: MIMEContentDisposition.m,v 1.2 1998/05/05 15:29:39 erik Exp $
//---------------------------------------------------------------------------------------

#import "Utilities.h"
#import "Message.h"


//---------------------------------------------------------------------------------------
//	constants and cached values
//---------------------------------------------------------------------------------------

NSString *MIMEInlineContentDisposition = @"inline";
NSString *MIMEAttachmentContentDisposition = @"attachment";

static NSDictionary *stringUniqueingTable = nil;


//---------------------------------------------------------------------------------------
    @implementation MIMEContentDisposition
//---------------------------------------------------------------------------------------

#ifndef LITTLE_FOUNDATION
+ (void)initialize
#else
+ initialize
#endif
{
   	if(stringUniqueingTable == nil)
		{
	    NSArray	*strings;
   
   		strings = [NSArray arrayWithObjects:MIMEInlineContentDisposition, MIMEAttachmentContentDisposition, nil];
		stringUniqueingTable = [[NSDictionary dictionaryWithObjects:strings forKeys:strings] retain];
   		}
#ifndef LITTLE_FOUNDATION
#else
    return self;
#endif
}


+ (NSString *)uniquedMIMEContentDisposition:(NSString *)string;
{
    return [stringUniqueingTable objectForKey:string];
}



//---------------------------------------------------------------------------------------
//	VALUE IMPLEMENTATION
//---------------------------------------------------------------------------------------

- (void)takeValueFromString:(NSString *)string;
{
	NSString	*value;
	NSScanner	*scanner;

	TRACE_IN
    scanner = [NSScanner scannerWithString:string];
    if([scanner scanCharactersFromSet:[NSCharacterSet MIMETokenCharacterSet] intoString:&value] == NO)
        [NSException raise:MIMEFormatException format:@"no disposition type in '%@'", string];
	[self setDisposition:value];
}


- (void)appendValueToString:(NSMutableString *)string;
{
	TRACE_IN
	[string appendString:disposition];	
}


//---------------------------------------------------------------------------------------
//	BASIC ATTRIBUTE
//---------------------------------------------------------------------------------------

- (void)setDisposition:(NSString *)string;
{
	NSString *uniquedString;

	TRACE_IN
	if(string == disposition)
		return;
    if([string rangeOfCharacterFromSet:[NSCharacterSet MIMENonTokenCharacterSet]].length != 0)
        [NSException raise:NSInvalidArgumentException format:@"invalid char in '%@'", string];
	string = [string lowercaseString];
    [disposition release];
     if((uniquedString = [MIMEContentDisposition uniquedMIMEContentDisposition:string]) != nil)
        disposition = [uniquedString retain];
    else
	    disposition = [string copyWithZone:[self zone]];
	[self invalidateStringRep];
}


- (NSString *)disposition;
{
	TRACE_IN
    return disposition;
}
    

//---------------------------------------------------------------------------------------
//	NSObject Stuff
//---------------------------------------------------------------------------------------

- (void)dealloc
{
	TRACE_IN
	[disposition release];
	[super dealloc];
}


//---------------------------------------------------------------------------------------
    @end
//---------------------------------------------------------------------------------------

