--- /dev/null
+2005-08-01 Helge Hess <helge.hess@opengroupware.org>
+
+ * started CoreData demo
--- /dev/null
+# SLog config
+
+<LocationMatch "^/CoreDataBlog*">
+SetHandler ngobjweb-adaptor
+SetAppPort 20000
+</LocationMatch>
+
+<LocationMatch "^/CoreDataBlog.woa/WebServerResources/*">
+SetHandler ngobjweb-adaptor
+SetAppPort 20000
+</LocationMatch>
+
--- /dev/null
+/*
+ Copyright (C) 2005 SKYRIX Software AG
+ Copyright (C) 2005 by Scott Stevenson
+
+ This file is part of SOPE.
+
+ SOPE is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ SOPE 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 SOPE; see the file COPYING. If not, write to the
+ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+*/
+
+#include "WOCoreDataApplication.h"
+
+@interface CoreDataBlog : WOCoreDataApplication
+{
+}
+
+@end
+
+#include "common.h"
+
+@implementation CoreDataBlog
+
+- (id)init {
+ if ((self = [super init]) != nil) {
+ [self logWithFormat:@"Store coordinator: %@",
+ [self defaultPersistentStoreType]];
+ }
+ return self;
+}
+
+- (NSString *)applicationSupportFolder {
+ // TODO: simplify that
+ unsigned char path[1024];
+ NSString *p;
+ FSRef foundRef;
+ OSErr err;
+
+ err = FSFindFolder(kUserDomain, kApplicationSupportFolderType,
+ kDontCreateFolder, &foundRef);
+ if (err != noErr) {
+ [self errorWithFormat:@"Can't find application support folder."];
+ return nil;
+ }
+
+ FSRefMakePath(&foundRef, path, sizeof(path));
+ p = [NSString stringWithUTF8String:(char *)path]; // TODO: is UTF-8 ok?
+ p = [p stringByAppendingPathComponent:@"BlogDemo"];
+ return p;
+}
+
+- (NSURL *)defaultPersistentStoreURL {
+ NSString *s;
+
+ s = @"BlogDemo.xml";
+ s = [[self applicationSupportFolder] stringByAppendingPathComponent:s];
+ return [NSURL fileURLWithPath:s];
+}
+
+@end /* CoreDataBlog */
+
+
+/* starting the app */
+
+int main(int argc, char **argv, char **env) {
+ NSAutoreleasePool *pool;
+
+ pool = [[NSAutoreleasePool alloc] init];
+#if LIB_FOUNDATION_LIBRARY
+ [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
+#endif
+
+ WOApplicationMain(@"CoreDataBlog", argc, (void*)argv);
+
+ [pool release];
+ return 0;
+}
--- /dev/null
+# GNUstep makefile
+
+-include ../../../config.make
+include $(GNUSTEP_MAKEFILES)/common.make
+
+WOAPP_NAME = CoreDataBlog
+
+CoreDataBlog_OBJC_FILES += \
+ WOCoreDataApplication.m \
+ WOSession+CoreData.m \
+ \
+ CoreDataBlog.m \
+ Session.m \
+ Main.m
+
+CoreDataBlog_COMPONENTS += Main.wo
+
+CoreDataBlog_COREDATA_MODELS += \
+ BlogDemo_DataModel.xcdatamodel
+
+-include GNUmakefile.preamble
+include $(GNUSTEP_MAKEFILES)/woapp.make
+-include GNUmakefile.postamble
--- /dev/null
+# compilation targets
+
+compile-coredata-models :: $($(WOAPP_NAME)_MOM_FILES)
+
+clean ::
+ rm -f $(patsubst %.xcdatamodel,%.mom,$($(WOAPP_NAME)_COREDATA_MODELS))
+
+
+# this is triggered by woapp.make
+woapp-resource-files :: compile-coredata-models
+
+
+MOMC="/Library/Application Support/Apple/Developer Tools/Plug-ins/XDCoreDataModel.xdplugin/Contents/Resources/momc"
+
+# rule for compilation of CoreData models
+%.mom :: %.xcdatamodel
+ $(MOMC) $< $@
--- /dev/null
+# compile settings
+
+
+# CoreData files
+
+$(WOAPP_NAME)_MOM_FILES += \
+ $(patsubst %.xcdatamodel,%.mom,$($(WOAPP_NAME)_COREDATA_MODELS))
+
+$(WOAPP_NAME)_RESOURCE_FILES += \
+ $($(WOAPP_NAME)_MOM_FILES)
+
+
+# static references required for Mach linker
+
+ADDITIONAL_LDFLAGS += \
+ -framework CoreData \
+ -framework CoreServices
+
+ADDITIONAL_TOOL_LIBS += \
+ -lEOControl \
+ -lDOM -lXmlRpc -lSaxObjC
+
+ADDITIONAL_LIB_DIRS += -L/usr/local/lib -L/usr/lib
--- /dev/null
+/*
+ Copyright (C) 2005 SKYRIX Software AG
+
+ This file is part of SOPE.
+
+ SOPE is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ SOPE 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 SOPE; see the file COPYING. If not, write to the
+ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+*/
+
+#include <NGObjWeb/WOComponent.h>
+
+@class NSArray;
+
+@interface Main : WOComponent
+{
+}
+
+@end
+
+#include "common.h"
+
+@implementation Main
+
+- (id)initWithContext:(id)_ctx {
+ if ((self = [super initWithContext:_ctx])) {
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [super dealloc];
+}
+
+/* accessors */
+
+
+@end /* Main */
--- /dev/null
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+ <head>
+ <title>SOPE CoreData Test</title>
+ </head>
+
+ <body>
+ <h1>SOPE CoreData Test</h1>
+
+Ctx: <#Test/><br />
+
+<hr />
+ <#Entities>
+ <li><#Entity/></li>
+ </#Entities>
+<hr />
+ <#Posts>
+ <li><#Post/></li>
+ </#Posts>
+
+ <hr>
+ <address
+ ><a href="mailto:helge.hess@opengroupware.org">Helge Hess</a></address>
+ </body>
+</html>
--- /dev/null
+/* bind template to controller */
+
+Test: WOString {
+ value = session.defaultManagedObjectContext;
+}
+
+Entities: WORepetition {
+ list = session.defaultManagedObjectContext.persistentStoreCoordinator.managedObjectModel.entities;
+ item = item;
+}
+
+Entity: WOString {
+ value = item.name;
+}
+
+
+Posts: WORepetition {
+ list = session.posts;
+ item = item;
+}
+
+Post: WOString {
+ value = item.title;
+}
--- /dev/null
+CoreDataBlog
+============
+
+A sample SOPE application which access some CoreData storage.
+
+Works on the same data like:
+ http://www.cocoadevcentral.com/articles/000085.php
--- /dev/null
+/*
+ Copyright (C) 2005 SKYRIX Software AG
+
+ This file is part of SOPE.
+
+ SOPE is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ SOPE 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 SOPE; see the file COPYING. If not, write to the
+ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+*/
+
+#include <NGObjWeb/WOSession.h>
+
+@interface Session : WOSession
+@end
+
+#include "WOSession+CoreData.h"
+#include "WOCoreDataApplication.h"
+#include "common.h"
+
+@implementation Session
+
+- (NSArray *)posts {
+ NSFetchRequest *fs;
+ NSArray *a;
+ NSError *error = nil;
+
+ fs = [[[NSFetchRequest alloc] init] autorelease];
+
+ [fs setEntity:[[[[self application] managedObjectModel]
+ entitiesByName] objectForKey:@"Post"]];
+ [self logWithFormat:@"entity: %@", [fs entity]];
+
+ a = [[self defaultManagedObjectContext] executeFetchRequest:fs error:&error];
+ [self logWithFormat:@"a: %@", a];
+
+ if (error != nil)
+ [self errorWithFormat:@"FETCH FAILED: %@", error];
+
+ return a;
+}
+
+@end /* Session */
--- /dev/null
+/*
+ Copyright (C) 2005 SKYRIX Software AG
+
+ This file is part of SOPE.
+
+ SOPE is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ SOPE 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 SOPE; see the file COPYING. If not, write to the
+ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+*/
+
+#ifndef __WOCoreDataApplication_H__
+#define __WOCoreDataApplication_H__
+
+#include <NGObjWeb/WOApplication.h>
+
+@class NSString, NSURL;
+@class NSManagedObjectContext, NSManagedObjectModel;
+@class NSPersistentStoreCoordinator;
+
+@interface WOCoreDataApplication : WOApplication
+{
+ NSManagedObjectModel *managedObjectModel;
+ NSPersistentStoreCoordinator *storeCoordinator;
+}
+
+/* accessors */
+
+- (NSManagedObjectModel *)managedObjectModel;
+- (NSPersistentStoreCoordinator *)persistentStoreCoordinator;
+
+/* locating the default store */
+
+- (NSString *)applicationSupportFolder;
+- (NSURL *)defaultPersistentStoreURL;
+- (NSString *)defaultPersistentStoreType;
+
+/* creating editing contexts */
+
+- (NSManagedObjectContext *)createManagedObjectContext;
+
+@end
+
+#endif /* __WOCoreDataApplication_H__ */
--- /dev/null
+/*
+ Copyright (C) 2005 SKYRIX Software AG
+
+ This file is part of SOPE.
+
+ SOPE is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ SOPE 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 SOPE; see the file COPYING. If not, write to the
+ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+*/
+
+#include "WOCoreDataApplication.h"
+#include "common.h"
+
+@implementation WOCoreDataApplication
+
+- (void)dealloc {
+ [self->storeCoordinator release];
+ [self->managedObjectModel release];
+ [super dealloc];
+}
+
+/* accessors */
+
+- (NSManagedObjectModel *)managedObjectModel {
+ NSMutableSet *allBundles;
+
+ if (self->managedObjectModel != nil)
+ return [self->managedObjectModel isNotNull] ? self->managedObjectModel:nil;
+
+ allBundles = [[NSMutableSet alloc] initWithCapacity:16];
+ [allBundles addObject:[NSBundle mainBundle]];
+ [allBundles addObject:[NSBundle allFrameworks]];
+
+ /* 'nil' says: just scan the mainbundle */
+ self->managedObjectModel =
+ [[NSManagedObjectModel mergedModelFromBundles:nil] retain];
+
+ [allBundles release]; allBundles = nil;
+
+ if (self->managedObjectModel == nil)
+ [self errorWithFormat:@"Could not create the managed object model!"];
+
+ return self->managedObjectModel;
+}
+
+- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
+ NSFileManager *fileManager;
+ NSError *error;
+ BOOL ok;
+
+ if (self->storeCoordinator != nil)
+ return [self->storeCoordinator isNotNull] ? self->storeCoordinator : nil;
+
+ /* create support folder */
+
+ fileManager = [NSFileManager defaultManager];
+ if (![fileManager fileExistsAtPath:[self applicationSupportFolder]
+ isDirectory:NULL] ) {
+ [fileManager createDirectoryAtPath:[self applicationSupportFolder]
+ attributes:nil];
+ }
+
+ /* create store coordinator */
+
+ self->storeCoordinator =
+ [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:
+ [self managedObjectModel]];
+
+ ok = [self->storeCoordinator
+ addPersistentStoreWithType:[self defaultPersistentStoreType]
+ configuration:nil
+ URL:[self defaultPersistentStoreURL]
+ options:nil error:&error] != nil ? YES : NO;
+ if (!ok) {
+ [self errorWithFormat:
+ @"Failed to create persistent store coordinator: %@", error];
+
+ [self->storeCoordinator release]; self->storeCoordinator = nil;
+
+ self->storeCoordinator = [[NSNull null] retain];
+ return nil;
+ }
+
+ return self->storeCoordinator;
+}
+
+/* locating the default store */
+
+- (NSString *)applicationSupportFolder {
+ unsigned char path[1024];
+ NSString *p;
+ FSRef foundRef;
+ OSErr err;
+
+ err = FSFindFolder(kUserDomain, kApplicationSupportFolderType,
+ kDontCreateFolder, &foundRef);
+ if (err != noErr) {
+ [self errorWithFormat:@"Can't find application support folder."];
+ return nil;
+ }
+
+ FSRefMakePath(&foundRef, path, sizeof(path));
+ p = [NSString stringWithUTF8String:(char *)path]; // TODO: is UTF-8 ok?
+ p = [p stringByAppendingPathComponent:[self name]];
+ return p;
+}
+
+- (NSURL *)defaultPersistentStoreURL {
+ NSString *s;
+
+ s = [[self name] stringByDeletingPathExtension];
+ s = [s stringByAppendingPathExtension:@"xml"];
+ s = [[self applicationSupportFolder] stringByAppendingPathComponent:s];
+ return [NSURL fileURLWithPath:s];
+}
+- (NSString *)defaultPersistentStoreType {
+ return [[[self defaultPersistentStoreURL] path] hasSuffix:@".xml"]
+ ? NSXMLStoreType : NSSQLiteStoreType;
+}
+
+/* creating editing contexts */
+
+- (NSManagedObjectContext *)createManagedObjectContext {
+ NSManagedObjectContext *ctx;
+
+ ctx = [[[NSManagedObjectContext alloc] init] autorelease];
+ [ctx setPersistentStoreCoordinator:[self persistentStoreCoordinator]];
+ return ctx;
+}
+
+@end /* WOCoreDataApplication */
--- /dev/null
+/*
+ Copyright (C) 2005 SKYRIX Software AG
+
+ This file is part of SOPE.
+
+ SOPE is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ SOPE 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 SOPE; see the file COPYING. If not, write to the
+ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+*/
+
+#ifndef __WOSession_CoreData_H__
+#define __WOSession_CoreData_H__
+
+#include <NGObjWeb/WOSession.h>
+
+@class NSManagedObjectContext;
+
+@interface WOSession(CoreData)
+
+- (void)setDefaultManagedObjectContext:(NSManagedObjectContext *)_ctx;
+- (NSManagedObjectContext *)defaultManagedObjectContext;
+
+@end
+
+#endif /* __WOSession_CoreData_H__ */
--- /dev/null
+/*
+ Copyright (C) 2005 SKYRIX Software AG
+
+ This file is part of SOPE.
+
+ SOPE is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ SOPE 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 SOPE; see the file COPYING. If not, write to the
+ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+*/
+
+#include "WOSession+CoreData.h"
+#include "WOCoreDataApplication.h"
+#include "common.h"
+
+@implementation WOSession(CoreData)
+
+static NSString *NSManagedObjectContextKey = @"NSManagedObjectContext";
+
+- (void)setDefaultManagedObjectContext:(NSManagedObjectContext *)_ctx {
+ if ([_ctx isNotNull])
+ [self setObject:_ctx forKey:NSManagedObjectContextKey];
+ else
+ [self removeObjectForKey:NSManagedObjectContextKey];
+}
+
+- (NSManagedObjectContext *)defaultManagedObjectContext {
+ NSManagedObjectContext *ctx;
+
+ if ([(ctx = [self objectForKey:NSManagedObjectContextKey]) isNotNull])
+ return ctx;
+
+ if ((ctx = [[self application] createManagedObjectContext]) == nil) {
+ [self errorWithFormat:
+ @"Failed to create NSManagedObjectContext for session!"];
+ return nil;
+ }
+
+ [self setObject:ctx forKey:NSManagedObjectContextKey];
+ return ctx;
+}
+
+@end /* WOSession(CoreData) */
+
--- /dev/null
+
+#import <Foundation/Foundation.h>
+#include <NGObjWeb/NGObjWeb.h>
+
+#import <CoreData/CoreData.h>