VocalEasel/Sources/VLXMLDocument.mm

89 lines
2.3 KiB
Plaintext
Raw Normal View History

2006-10-13 08:10:40 +00:00
//
2007-04-27 06:41:34 +00:00
// File: VLXMLDocument.mm - Read and write native (MusicXML) document format
2006-10-13 08:10:40 +00:00
//
2007-04-27 06:41:34 +00:00
// Author(s):
//
// (MN) Matthias Neeracher
//
// Copyright © 2006-2007 Matthias Neeracher
2006-10-13 08:10:40 +00:00
//
#import "VLXMLDocument.h"
2007-08-31 22:37:55 +00:00
#import "VLPListDocument.h"
2006-10-13 08:10:40 +00:00
@implementation VLDocument (XML)
2007-05-06 05:55:16 +00:00
- (NSArray *)propertyKeys
{
static NSArray * sPropertyKeys = nil;
if (!sPropertyKeys)
sPropertyKeys = [[NSArray alloc] initWithObjects:
@"songGroove", @"songTempo", nil];
return sPropertyKeys;
}
- (NSFileWrapper *)XMLFileWrapperWithError:(NSError **)outError flat:(BOOL)flat;
{
2007-08-31 22:37:55 +00:00
NSFileWrapper * contents = [self fileWrapperWithFilter:@"VLMusicXMLType" error:outError];
if (!contents) {
return nil;
} else if (flat) {
2007-08-31 22:37:55 +00:00
return contents;
} else {
NSFileWrapper * wrap = [[[NSFileWrapper alloc]
initDirectoryWithFileWrappers:
[NSDictionary dictionary]]
autorelease];
2007-08-31 22:37:55 +00:00
[contents setPreferredFilename:@"Song"];
[wrap addFileWrapper:contents];
2007-05-06 05:55:16 +00:00
NSDictionary * prop =
[self dictionaryWithValuesForKeys:[self propertyKeys]];
[wrap addRegularFileWithContents:
[NSPropertyListSerialization dataFromPropertyList:prop
format:NSPropertyListXMLFormat_v1_0
errorDescription:nil]
preferredFilename:@"Properties"];
if (vcsWrapper)
[wrap addFileWrapper:vcsWrapper];
return wrap;
}
}
- (BOOL)readFromXMLFileWrapper:(NSFileWrapper *)wrapper error:(NSError **)outError
{
2007-09-03 13:58:37 +00:00
if ([wrapper isDirectory]) {
NSDictionary * wrappers = [wrapper fileWrappers];
if ((vcsWrapper = [wrappers objectForKey:@"CVS"])
|| (vcsWrapper = [wrappers objectForKey:@".svn"])
)
[vcsWrapper retain];
NSFileWrapper * prop = [wrappers objectForKey:@"Properties"];
if (prop) {
NSUndoManager * undoMgr = [self undoManager];
[undoMgr disableUndoRegistration];
[self setValuesForKeysWithDictionary:
[NSPropertyListSerialization
propertyListFromData:[prop regularFileContents]
mutabilityOption:NSPropertyListImmutable
format:nil errorDescription:nil]];
[undoMgr enableUndoRegistration];
}
return [self readFromFileWrapper:[wrappers objectForKey:@"Song"] withFilter:@"VLMusicXMLType"
error:outError];
2007-09-03 14:28:27 +00:00
} else {
if ([self readFromFileWrapper:wrapper withFilter:@"VLMusicXMLType" error:outError]) {
[self setFileURL:nil];
return YES;
} else
return NO;
}
}
2006-10-13 08:10:40 +00:00
@end