summaryrefslogtreecommitdiffstats
path: root/extensions/source/macosx
diff options
context:
space:
mode:
authorKurt Zenker <kz@openoffice.org>2007-10-09 14:05:20 +0000
committerKurt Zenker <kz@openoffice.org>2007-10-09 14:05:20 +0000
commitae10bde58034c3d5e53e9a5018ab7c2381150232 (patch)
tree960caae894ccc457d26a040ddbef3f5ab7965ece /extensions/source/macosx
parentINTEGRATION: CWS spotlightplugin01 (1.24.84); FILE MERGED (diff)
downloadcore-ae10bde58034c3d5e53e9a5018ab7c2381150232.tar.gz
core-ae10bde58034c3d5e53e9a5018ab7c2381150232.zip
INTEGRATION: CWS spotlightplugin01 (1.1.2); FILE ADDED
2007/09/18 00:45:03 fheckl 1.1.2.2: Some method refactorings 2007/09/14 21:06:33 fheckl 1.1.2.1: #72355 adding new files for macosx spotlight plugin
Diffstat (limited to 'extensions/source/macosx')
-rw-r--r--extensions/source/macosx/spotlight/OOoContentDataParser.h66
-rw-r--r--extensions/source/macosx/spotlight/OOoContentDataParser.m141
-rw-r--r--extensions/source/macosx/spotlight/OOoMetaDataParser.h60
-rw-r--r--extensions/source/macosx/spotlight/OOoMetaDataParser.m208
-rw-r--r--extensions/source/macosx/spotlight/OOoSpotlightImporter.h50
-rw-r--r--extensions/source/macosx/spotlight/OOoSpotlightImporter.m239
6 files changed, 764 insertions, 0 deletions
diff --git a/extensions/source/macosx/spotlight/OOoContentDataParser.h b/extensions/source/macosx/spotlight/OOoContentDataParser.h
new file mode 100644
index 000000000000..c3d48305dc9d
--- /dev/null
+++ b/extensions/source/macosx/spotlight/OOoContentDataParser.h
@@ -0,0 +1,66 @@
+/*************************************************************************
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* $RCSfile: OOoContentDataParser.h,v $
+*
+* $Revision: 1.2 $
+*
+* last change: $Author: kz $ $Date: 2007-10-09 15:04:29 $
+*
+* The Contents of this file are made available subject to
+* the terms of GNU Lesser General Public License Version 2.1.
+*
+*
+* GNU Lesser General Public License Version 2.1
+* =============================================
+* Copyright 2005 by Sun Microsystems, Inc.
+* 901 San Antonio Road, Palo Alto, CA 94303, USA
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License version 2.1, as published by the Free Software Foundation.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+* MA 02111-1307 USA
+*
+*************************************************************************/
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface OOoContentDataParser : NSObject {
+ // indicates if we are interested in an element's content
+ BOOL shouldReadCharacters;
+
+ // the MD importer's values
+ NSMutableDictionary *mdiValues;
+
+ // all of the text inside a document
+ NSMutableString *textContent;
+
+ // the current element's content
+ NSMutableString *runningTextContent;
+}
+
+- (void)parseXML:(NSData*)data intoDictionary:(NSMutableDictionary*)dict;
+
+// delegates
+- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict;
+
+- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName;
+
+- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string;
+
+- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError;
+
+- (void)parserDidEndDocument:(NSXMLParser *)parser;
+
+@end
diff --git a/extensions/source/macosx/spotlight/OOoContentDataParser.m b/extensions/source/macosx/spotlight/OOoContentDataParser.m
new file mode 100644
index 000000000000..75f90fc8384f
--- /dev/null
+++ b/extensions/source/macosx/spotlight/OOoContentDataParser.m
@@ -0,0 +1,141 @@
+/*************************************************************************
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* $RCSfile: OOoContentDataParser.m,v $
+*
+* $Revision: 1.2 $
+*
+* last change: $Author: kz $ $Date: 2007-10-09 15:04:39 $
+*
+* The Contents of this file are made available subject to
+* the terms of GNU Lesser General Public License Version 2.1.
+*
+*
+* GNU Lesser General Public License Version 2.1
+* =============================================
+* Copyright 2005 by Sun Microsystems, Inc.
+* 901 San Antonio Road, Palo Alto, CA 94303, USA
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License version 2.1, as published by the Free Software Foundation.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+* MA 02111-1307 USA
+*
+*************************************************************************/
+
+#import "OOoContentDataParser.h"
+
+@implementation OOoContentDataParser
+
+- (id)init
+{
+ if ((self = [super init]) != nil) {
+ shouldReadCharacters = NO;
+ textContent = nil;
+ runningTextContent = nil;
+
+ return self;
+ }
+
+ return nil;
+}
+
+- (void)parseXML:(NSData*)data intoDictionary:(NSMutableDictionary*)dict
+{
+ mdiValues = dict;
+
+ //NSLog(@"data: %@ %d", data, [data length]);
+
+ //init parser settings
+ shouldReadCharacters = NO;
+
+ NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
+
+ [parser setDelegate:self];
+ [parser setShouldResolveExternalEntities:NO];
+ [parser parse];
+
+ [parser release];
+
+ //NSLog(@"finished");
+}
+
+- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
+{
+ // all text content is stored inside <text:p> elements
+ if ([elementName isEqualToString:@"text:p"] == YES) {
+ runningTextContent = [NSMutableString new];
+ shouldReadCharacters = YES;
+ //NSLog(@"start");
+ } else {
+ return;
+ }
+
+ //NSLog(@"start element %@", elementName);
+}
+
+- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
+{
+ if (shouldReadCharacters == TRUE) {
+ if (textContent == nil) {
+ textContent = [NSMutableString new];
+ } else if ([runningTextContent isEqualToString:@""] == NO) {
+ // separate by whitespace
+ [textContent appendString:@" "];
+ }
+ //NSLog(@"end");
+
+ [textContent appendString:[NSString stringWithString:runningTextContent]];
+ [runningTextContent release];
+ }
+ shouldReadCharacters = NO;
+}
+
+- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
+{
+ if (shouldReadCharacters == NO) {
+ return;
+ }
+ //NSLog(string);
+
+ [runningTextContent appendString:string];
+
+ //NSLog(@"currentElement: %@", currentElement);
+ //NSLog(@"read: %@", string);
+
+}
+
+- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError
+{
+ //NSLog(@"parsing finished with error");
+ NSLog([NSString stringWithFormat:@"An error occured parsing the document. (Error %i, Description: %@, Line: %i, Column: %i)", [parseError code],
+ [[parser parserError] localizedDescription], [parser lineNumber],
+ [parser columnNumber]]);
+
+ if (runningTextContent != nil) {
+ [runningTextContent release];
+ }
+ if (textContent != nil) {
+ [textContent release];
+ }
+}
+
+- (void)parserDidEndDocument:(NSXMLParser *)parser
+{
+ if (textContent != nil && [textContent length] > 0) {
+ [mdiValues setObject:[NSString stringWithString:textContent] forKey:(NSString*)kMDItemTextContent];
+ [textContent release];
+ }
+}
+
+@end
diff --git a/extensions/source/macosx/spotlight/OOoMetaDataParser.h b/extensions/source/macosx/spotlight/OOoMetaDataParser.h
new file mode 100644
index 000000000000..eecd5e1b9d55
--- /dev/null
+++ b/extensions/source/macosx/spotlight/OOoMetaDataParser.h
@@ -0,0 +1,60 @@
+/*************************************************************************
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* $RCSfile: OOoMetaDataParser.h,v $
+*
+* $Revision: 1.2 $
+*
+* last change: $Author: kz $ $Date: 2007-10-09 15:04:49 $
+*
+* The Contents of this file are made available subject to
+* the terms of GNU Lesser General Public License Version 2.1.
+*
+*
+* GNU Lesser General Public License Version 2.1
+* =============================================
+* Copyright 2005 by Sun Microsystems, Inc.
+* 901 San Antonio Road, Palo Alto, CA 94303, USA
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License version 2.1, as published by the Free Software Foundation.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+* MA 02111-1307 USA
+*
+*************************************************************************/
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface OOoMetaDataParser : NSObject {
+ //indicates if content should be read
+ BOOL shouldReadCharacters;
+ //indicates if the current element is a custom metadata tag
+ BOOL isCustom;
+
+ NSMutableDictionary *metaValues;
+ NSMutableString *textCurrentElement;
+ NSString *customAttribute;
+}
+
+- (void)parseXML:(NSData*)data intoDictionary:(NSMutableDictionary*)dict;
+
+//delegates
+- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict;
+
+- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName;
+
+- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string;
+
+- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError;
+@end
diff --git a/extensions/source/macosx/spotlight/OOoMetaDataParser.m b/extensions/source/macosx/spotlight/OOoMetaDataParser.m
new file mode 100644
index 000000000000..9bd341ae7d45
--- /dev/null
+++ b/extensions/source/macosx/spotlight/OOoMetaDataParser.m
@@ -0,0 +1,208 @@
+/*************************************************************************
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* $RCSfile: OOoMetaDataParser.m,v $
+*
+* $Revision: 1.2 $
+*
+* last change: $Author: kz $ $Date: 2007-10-09 15:05:00 $
+*
+* The Contents of this file are made available subject to
+* the terms of GNU Lesser General Public License Version 2.1.
+*
+*
+* GNU Lesser General Public License Version 2.1
+* =============================================
+* Copyright 2005 by Sun Microsystems, Inc.
+* 901 San Antonio Road, Palo Alto, CA 94303, USA
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License version 2.1, as published by the Free Software Foundation.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+* MA 02111-1307 USA
+*
+*************************************************************************/
+
+#import "OOoMetaDataParser.h"
+
+static NSSet *singleValueXMLElements;
+static NSSet *multiValueXMLElements;
+static NSDictionary *metaXML2MDIKeys;
+
+@implementation OOoMetaDataParser
+
++ (void)initialize
+{
+ static BOOL isInitialized = NO;
+
+ if (isInitialized == NO) {
+ //set up the meta elements with only one value
+ NSMutableSet *temp = [NSMutableSet new];
+ [temp addObject:@"dc:title"];
+ [temp addObject:@"dc:description"];
+ [temp addObject:@"meta:user-defined"];
+ singleValueXMLElements = [[NSSet setWithSet:temp] retain];
+
+ //set up the meta elements that can have more than one value
+ [temp removeAllObjects];
+ [temp addObject:@"dc:subject"];
+ [temp addObject:@"meta:keyword"];
+ [temp addObject:@"meta:initial-creator"];
+ [temp addObject:@"dc:creator"];
+ multiValueXMLElements = [[NSSet setWithSet:temp] retain];
+ [temp release];
+
+ //set up the map to store the values with the correct MDI keys
+ NSMutableDictionary *tempDict = [NSMutableDictionary new];
+ [tempDict setObject:(NSString*)kMDItemTitle forKey:@"dc:title"];
+ [tempDict setObject:(NSString*)kMDItemDescription forKey:@"dc:description"];
+ [tempDict setObject:(NSString*)kMDItemKeywords forKey:@"dc:subject"];
+ [tempDict setObject:(NSString*)kMDItemAuthors forKey:@"meta:initial-creator"];
+ [tempDict setObject:(NSString*)kMDItemAuthors forKey:@"dc:creator"];
+ [tempDict setObject:(NSString*)kMDItemKeywords forKey:@"meta:keyword"];
+ [tempDict setObject:@"org_openoffice_opendocument_custominfo1" forKey:@"Info 1"];
+ [tempDict setObject:@"org_openoffice_opendocument_custominfo2" forKey:@"Info 2"];
+ [tempDict setObject:@"org_openoffice_opendocument_custominfo3" forKey:@"Info 3"];
+ [tempDict setObject:@"org_openoffice_opendocument_custominfo4" forKey:@"Info 4"];
+ metaXML2MDIKeys = [[NSDictionary dictionaryWithDictionary:tempDict] retain];
+ [tempDict release];
+
+ isInitialized = YES;
+ }
+}
+
+- (id)init
+{
+ if ((self = [super init]) != nil) {
+ shouldReadCharacters = NO;
+// currentElement = nil;
+ textCurrentElement = nil;
+
+ return self;
+ }
+
+ return nil;
+}
+
+- (void)parseXML:(NSData*)data intoDictionary:(NSMutableDictionary*)dict
+{
+ metaValues = dict;
+
+ //NSLog(@"data: %@ %d", data, [data length]);
+
+ //init parser settings
+ shouldReadCharacters = NO;
+
+ NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
+
+ [parser setDelegate:self];
+ [parser setShouldResolveExternalEntities:NO];
+ [parser parse];
+
+ [parser release];
+
+ //NSLog(@"finished parsing meta");
+}
+
+- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
+{
+// NSLog(@"<%@>", elementName);
+ if ([singleValueXMLElements containsObject:elementName] == YES) {
+ shouldReadCharacters = YES;
+ } else if ([multiValueXMLElements containsObject:elementName] == YES) {
+ shouldReadCharacters = YES;
+ } else {
+ //we are not interested in this element
+ shouldReadCharacters = NO;
+ return;
+ }
+
+ if (shouldReadCharacters == YES) {
+ textCurrentElement = [NSMutableString new];
+ isCustom = [elementName isEqualToString:@"meta:user-defined"];
+ if (isCustom == YES) {
+ customAttribute = [[attributeDict objectForKey:@"meta:name"] retain];
+ //NSLog(customAttribute);
+ }
+ }
+
+ //NSLog(@"start element %@", elementName);
+}
+
+- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
+{
+// NSLog(@"</%@>", elementName);
+ if (shouldReadCharacters == YES) {
+ NSString *mdiName = nil;
+ if (isCustom == YES) {
+ mdiName = (NSString*)[metaXML2MDIKeys objectForKey:customAttribute];
+ } else {
+ mdiName = (NSString*)[metaXML2MDIKeys objectForKey:elementName];
+ }
+ //NSLog(@"mdiName: %@", mdiName);
+
+ if (mdiName == nil) {
+ return;
+ }
+
+ if ([singleValueXMLElements containsObject:elementName] == YES) {
+ [metaValues setObject:textCurrentElement forKey:mdiName];
+ } else {
+ // must be multi-value
+ NSMutableArray *arr = [metaValues objectForKey:mdiName];
+ if (arr == nil) {
+ // we have no array yet, create it
+ arr = [[NSMutableArray new] autorelease];
+ // and store it
+ [metaValues setObject:arr forKey:mdiName];
+ }
+ // only store an element once, no need for duplicates
+ if ([arr containsObject:textCurrentElement] == NO) {
+ [arr addObject:textCurrentElement];
+ }
+ }
+ // cleanup part 1
+ [textCurrentElement release];
+ if (customAttribute != nil) {
+ [customAttribute release];
+ }
+ }
+
+ //cleanup part 2
+ shouldReadCharacters = NO;
+ isCustom = NO;
+}
+
+- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
+{
+// NSLog(@"%@", string);
+ if (shouldReadCharacters == NO) {
+ return;
+ }
+
+ // this delegate method might be called several times for a single element,
+ // so we have to collect the received data
+ [textCurrentElement appendString:string];
+
+ //NSLog(@"chars read: %@", string);
+}
+
+- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError
+{
+ //NSLog(@"parsing finished with error");
+ NSLog([NSString stringWithFormat:@"Error %i, Description: %@, Line: %i, Column: %i", [parseError code],
+ [[parser parserError] localizedDescription], [parser lineNumber],
+ [parser columnNumber]]);
+}
+
+@end
diff --git a/extensions/source/macosx/spotlight/OOoSpotlightImporter.h b/extensions/source/macosx/spotlight/OOoSpotlightImporter.h
new file mode 100644
index 000000000000..d4a8b5e2cdd6
--- /dev/null
+++ b/extensions/source/macosx/spotlight/OOoSpotlightImporter.h
@@ -0,0 +1,50 @@
+/*************************************************************************
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* $RCSfile: OOoSpotlightImporter.h,v $
+*
+* $Revision: 1.2 $
+*
+* last change: $Author: kz $ $Date: 2007-10-09 15:05:10 $
+*
+* The Contents of this file are made available subject to
+* the terms of GNU Lesser General Public License Version 2.1.
+*
+*
+* GNU Lesser General Public License Version 2.1
+* =============================================
+* Copyright 2005 by Sun Microsystems, Inc.
+* 901 San Antonio Road, Palo Alto, CA 94303, USA
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License version 2.1, as published by the Free Software Foundation.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+* MA 02111-1307 USA
+*
+*************************************************************************/
+
+#import <Cocoa/Cocoa.h>
+
+#include "unzip.h" //for unzFile
+
+@interface OOoSpotlightImporter : NSObject {
+}
+
+- (BOOL)importDocument:(NSString*)pathToFile contentType:(NSString*)contentTypeUTI attributes:(NSMutableDictionary*)attributes;
+
+- (unzFile)openZipFileAtPath:(NSString*)pathToFile;
+
+- (NSData*)metaDataFileFromZip:(unzFile)unzipFile;
+
+- (NSData*)contentDataFileFromZip:(unzFile)unzipFile;
+@end
diff --git a/extensions/source/macosx/spotlight/OOoSpotlightImporter.m b/extensions/source/macosx/spotlight/OOoSpotlightImporter.m
new file mode 100644
index 000000000000..cba67b71f327
--- /dev/null
+++ b/extensions/source/macosx/spotlight/OOoSpotlightImporter.m
@@ -0,0 +1,239 @@
+/*************************************************************************
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* $RCSfile: OOoSpotlightImporter.m,v $
+*
+* $Revision: 1.2 $
+*
+* last change: $Author: kz $ $Date: 2007-10-09 15:05:20 $
+*
+* The Contents of this file are made available subject to
+* the terms of GNU Lesser General Public License Version 2.1.
+*
+*
+* GNU Lesser General Public License Version 2.1
+* =============================================
+* Copyright 2005 by Sun Microsystems, Inc.
+* 901 San Antonio Road, Palo Alto, CA 94303, USA
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License version 2.1, as published by the Free Software Foundation.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+* MA 02111-1307 USA
+*
+*************************************************************************/
+
+#import "OOoSpotlightImporter.h"
+#import "OOoMetaDataParser.h"
+#import "OOoContentDataParser.h"
+
+#define CASESENSITIVITY (0)
+#define BUFFER_SIZE (4096)
+
+/* a dictionary to hold the UTIs */
+static NSDictionary *uti2kind;
+
+@implementation OOoSpotlightImporter
+
+/* initialize is only called once the first time this class is loaded */
++ (void)initialize
+{
+ static BOOL isInitialized = NO;
+ if (isInitialized == NO) {
+ NSMutableDictionary *temp = [NSMutableDictionary new];
+ [temp setObject:@"OpenOffice.org 1.0 Text" forKey:@"org.openoffice.text"];
+ [temp setObject:@"OpenDocument Text" forKey:@"org.oasis.opendocument.text"];
+ [temp setObject:@"OpenOffice.org 1.0 Spreadsheet" forKey:@"org.openoffice.spreadsheet"];
+ [temp setObject:@"OpenDocument Spreadsheet" forKey:@"org.oasis.opendocument.spreadsheet"];
+ [temp setObject:@"OpenOffice.org 1.0 Presentation" forKey:@"org.openoffice.presentation"];
+ [temp setObject:@"OpenDocument Presentation" forKey:@"org.oasis.opendocument.presentation"];
+ [temp setObject:@"OpenOffice.org 1.0 Drawing" forKey:@"org.openoffice.graphics"];
+ [temp setObject:@"OpenDocument Drawing" forKey:@"org.oasis.opendocument.graphics"];
+ [temp setObject:@"OpenOffice.org 1.0 Master" forKey:@"org.openoffice.text-master"];
+ [temp setObject:@"OpenDocument Master" forKey:@"org.oasis.opendocument.text-master"];
+ [temp setObject:@"OpenOffice.org 1.0 Formula" forKey:@"org.openoffice.formula"];
+ [temp setObject:@"OpenDocument Formula" forKey:@"org.oasis.opendocument.formula"];
+ [temp setObject:@"OpenOffice.org 1.0 Text Template" forKey:@"org.openoffice.text-template"];
+ [temp setObject:@"OpenDocument Text Template" forKey:@"org.oasis.opendocument.text-template"];
+ [temp setObject:@"OpenOffice.org 1.0 Spreadsheet Template" forKey:@"org.openoffice.spreadsheet-template"];
+ [temp setObject:@"OpenDocument Spreadsheet Template" forKey:@"org.oasis.opendocument.spreadsheet-template"];
+ [temp setObject:@"OpenOffice.org 1.0 Presentation Template" forKey:@"org.openoffice.presentation-template"];
+ [temp setObject:@"OpenDocument Presentation Template" forKey:@"org.oasis.opendocument.presentation-template"];
+ [temp setObject:@"OpenOffice.org 1.0 Drawing Template" forKey:@"org.openoffice.graphics-template"];
+ [temp setObject:@"OpenDocument Drawing Template" forKey:@"org.oasis.opendocument.graphics-template"];
+ [temp setObject:@"OpenOffice.org 1.0 Database" forKey:@"org.openoffice.database"];
+ [temp setObject:@"OpenDocument Chart" forKey:@"org.oasis.opendocument.chart"];
+
+ uti2kind = [[NSDictionary dictionaryWithDictionary:temp] retain];
+ [temp release];
+
+ isInitialized = YES;
+ }
+}
+
+/* importDocument is the real starting point for our plugin */
+- (BOOL)importDocument:(NSString*)pathToFile contentType:(NSString*)contentTypeUTI attributes:(NSMutableDictionary*)attributes
+{
+ //NSLog(contentTypeUTI);
+ //NSLog(pathToFile);
+
+ NSString *itemKind = [uti2kind objectForKey:contentTypeUTI];
+ if (itemKind != nil) {
+ [attributes setObject:itemKind forKey:(NSString*)kMDItemKind];
+ }
+
+ //first check to see if this is a valid zipped file that contains a file "meta.xml"
+ unzFile unzipFile = [self openZipFileAtPath:pathToFile];
+
+ //
+ if (unzipFile == nil) {
+ //NSLog(@"zip file not open");
+ return YES;
+ }
+
+ //first get the metadata
+ NSData *metaData = [self metaDataFileFromZip:unzipFile];
+ if (metaData == nil) {
+ unzClose(unzipFile);
+ return YES;
+ }
+
+ [metaData retain];
+
+ OOoMetaDataParser *parser = [OOoMetaDataParser new];
+ //parse and extract the data
+ [parser parseXML:metaData into:attributes];
+
+ [metaData release];
+ [parser release];
+
+ //and now get the content
+ NSData *contentData = [self contentDataFileFromZip:unzipFile];
+ if (contentData == nil) {
+ unzClose(unzipFile);
+ return YES;
+ }
+
+ [contentData retain];
+
+ OOoContentDataParser *parser2 = [OOoContentDataParser new];
+ //parse and extract the data
+ [parser2 parseXML:contentData into:attributes];
+
+ [contentData release];
+ [parser2 release];
+
+ unzClose(unzipFile);
+
+ return YES;
+}
+
+/* openZipFileAtPath returns the file as a valid data structure or nil otherwise*/
+- (unzFile)openZipFileAtPath:(NSString*)pathToFile
+{
+ unzFile unzipFile = nil;
+
+ const char *zipfilename = [pathToFile UTF8String];
+
+ if (zipfilename != nil)
+ {
+ unzipFile = unzOpen(zipfilename);
+ }
+
+ if (unzipFile == nil)
+ {
+ //NSLog(@"Cannot open %s",zipfilename);
+ return nil;
+ }
+
+ //NSLog(@"%s opened",zipfilename);
+
+ return unzipFile;
+}
+
+/* metaDataFileFromZip extracts the file meta.xml from the zip file and returns it as an NSData* structure
+ or nil if the metadata is not present */
+- (NSData*) metaDataFileFromZip:(unzFile)unzipFile
+{
+ //search and set the cursor to meta.xml
+ if (unzLocateFile(unzipFile, "meta.xml", CASESENSITIVITY) != UNZ_OK) {
+ //we hit an error, do cleanup
+ unzCloseCurrentFile(unzipFile);
+ return nil;
+ }
+
+ //open the current file
+ if (unzOpenCurrentFile(unzipFile) != UNZ_OK) {
+ //we hit an error, do cleanup
+ unzCloseCurrentFile(unzipFile);
+ unzClose(unzipFile);
+ return nil;
+ }
+
+ NSMutableData *data = [NSMutableData new];
+
+ unsigned buffer[BUFFER_SIZE];
+ int bytesRead = 0;
+ while ((bytesRead = unzReadCurrentFile(unzipFile, buffer, sizeof(buffer))) > 0) {
+ //append the data until we are finished
+ [data appendData:[NSData dataWithBytes:(const void *)buffer length:bytesRead]];
+ }
+
+ //we no longer need the file, so close it
+ unzCloseCurrentFile(unzipFile);
+
+ NSData *returnValue = [NSData dataWithData:data];
+ [data release];
+
+ return returnValue;
+}
+
+/* contentDataFileFromZip extracts the file content.xml from the zip file and returns it as an NSData* structure
+ or nil if the metadata is not present */
+- (NSData*) contentDataFileFromZip:(unzFile)unzipFile
+{
+ //search and set the cursor to content.xml
+ if (unzLocateFile(unzipFile, "content.xml", CASESENSITIVITY) != UNZ_OK) {
+ //we hit an error, do cleanup
+ unzCloseCurrentFile(unzipFile);
+ return nil;
+ }
+
+ //open the current file
+ if (unzOpenCurrentFile(unzipFile) != UNZ_OK) {
+ //we hit an error, do cleanup
+ unzCloseCurrentFile(unzipFile);
+ unzClose(unzipFile);
+ return nil;
+ }
+
+ NSMutableData *data = [NSMutableData new];
+
+ unsigned buffer[BUFFER_SIZE];
+ int bytesRead = 0;
+ while ((bytesRead = unzReadCurrentFile(unzipFile, buffer, sizeof(buffer))) > 0) {
+ //append the data
+ [data appendData:[NSData dataWithBytes:(const void *)buffer length:bytesRead]];
+ }
+
+ //we no longer need the file, so close it
+ unzCloseCurrentFile(unzipFile);
+
+ NSData *returnValue = [NSData dataWithData:data];
+ [data release];
+
+ return returnValue;
+}
+
+
+@end