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)
|
|
|
|
|
2006-10-29 07:49:33 +00:00
|
|
|
- (NSFileWrapper *)XMLFileWrapperWithError:(NSError **)outError flat:(BOOL)flat;
|
|
|
|
{
|
2008-01-26 20:56:36 +00:00
|
|
|
static NSArray * sPropertyKeys = nil;
|
|
|
|
|
2007-08-31 22:37:55 +00:00
|
|
|
NSFileWrapper * contents = [self fileWrapperWithFilter:@"VLMusicXMLType" error:outError];
|
2006-10-29 07:49:33 +00:00
|
|
|
|
|
|
|
if (!contents) {
|
|
|
|
return nil;
|
|
|
|
} else if (flat) {
|
2007-08-31 22:37:55 +00:00
|
|
|
return contents;
|
2006-10-29 07:49:33 +00:00
|
|
|
} else {
|
|
|
|
NSFileWrapper * wrap = [[[NSFileWrapper alloc]
|
|
|
|
initDirectoryWithFileWrappers:
|
|
|
|
[NSDictionary dictionary]]
|
|
|
|
autorelease];
|
2007-08-31 22:37:55 +00:00
|
|
|
[contents setPreferredFilename:@"Song"];
|
|
|
|
[wrap addFileWrapper:contents];
|
2006-11-17 08:57:29 +00:00
|
|
|
if (vcsWrapper)
|
|
|
|
[wrap addFileWrapper:vcsWrapper];
|
2008-01-26 20:56:36 +00:00
|
|
|
NSData * pd = [NSArchiver archivedDataWithRootObject:
|
|
|
|
[self printInfo]];
|
|
|
|
[wrap addRegularFileWithContents:pd preferredFilename:@"PrintInfo"];
|
|
|
|
if (!sPropertyKeys)
|
|
|
|
sPropertyKeys = [[NSArray alloc] initWithObjects:
|
|
|
|
@"staffSize", @"chordSize", @"lyricSize", nil];
|
|
|
|
NSData * prop = [NSPropertyListSerialization dataFromPropertyList:
|
|
|
|
[self dictionaryWithValuesForKeys:sPropertyKeys]
|
|
|
|
format:NSPropertyListXMLFormat_v1_0
|
|
|
|
errorDescription:nil];
|
|
|
|
[wrap addRegularFileWithContents:prop preferredFilename:@"Properties"];
|
2006-10-29 07:49:33 +00:00
|
|
|
|
|
|
|
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];
|
2008-01-19 21:31:40 +00:00
|
|
|
//
|
2008-01-26 20:56:36 +00:00
|
|
|
// Read properties dictionary
|
2008-01-19 21:31:40 +00:00
|
|
|
//
|
2007-09-03 13:58:37 +00:00
|
|
|
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];
|
|
|
|
}
|
2008-01-26 20:56:36 +00:00
|
|
|
//
|
|
|
|
// Read print info
|
|
|
|
NSFileWrapper * print = [wrappers objectForKey:@"PrintInfo"];
|
|
|
|
if (print) {
|
|
|
|
NSUndoManager * undoMgr = [self undoManager];
|
|
|
|
[undoMgr disableUndoRegistration];
|
|
|
|
NSPrintInfo * pi = [NSUnarchiver unarchiveObjectWithData:
|
|
|
|
[print regularFileContents]];
|
|
|
|
[self setPrintInfo:pi];
|
|
|
|
[undoMgr enableUndoRegistration];
|
|
|
|
}
|
2007-09-03 13:58:37 +00:00
|
|
|
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-29 07:49:33 +00:00
|
|
|
}
|
|
|
|
|
2006-10-13 08:10:40 +00:00
|
|
|
@end
|