VocalEasel/Sources/VLXMLDocument.mm

99 lines
2.9 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
//
2008-05-29 18:54:30 +00:00
// Copyright © 2006-2008 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)
- (NSFileWrapper *)XMLFileWrapperWithError:(NSError **)outError flat:(BOOL)flat;
{
2008-01-26 20:56:36 +00:00
static NSArray * sPropertyKeys = nil;
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];
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:
2011-09-04 01:21:14 +00:00
@"staffSize", @"chordSize", @"lyricSize",
@"topPadding", @"titlePadding", @"staffPadding", @"chordPadding", @"lyricPadding", nil];
2008-01-26 20:56:36 +00:00
NSData * prop = [NSPropertyListSerialization dataFromPropertyList:
[self dictionaryWithValuesForKeys:sPropertyKeys]
format:NSPropertyListXMLFormat_v1_0
errorDescription:nil];
[wrap addRegularFileWithContents:prop preferredFilename:@"Properties"];
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-26 20:56:36 +00:00
// Read properties dictionary
//
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
2008-01-27 10:43:16 +00:00
//
2008-01-26 20:56:36 +00:00
NSFileWrapper * print = [wrappers objectForKey:@"PrintInfo"];
if (print) {
NSUndoManager * undoMgr = [self undoManager];
[undoMgr disableUndoRegistration];
NSPrintInfo * pi = [NSUnarchiver unarchiveObjectWithData:
[print regularFileContents]];
[self setPrintInfo:pi];
[undoMgr enableUndoRegistration];
}
return [self readFromFileWrapper:[wrappers objectForKey:@"Song"] withFilter:VLMusicXMLType
2007-09-03 13:58:37 +00:00
error:outError];
2007-09-03 14:28:27 +00:00
} else {
if ([self readFromFileWrapper:wrapper withFilter:VLMusicXMLType error:outError]) {
2007-09-03 14:28:27 +00:00
[self setFileURL:nil];
return YES;
} else
return NO;
}
}
2006-10-13 08:10:40 +00:00
@end