Revision: 4028
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4028&view=rev
Author:   hofman
Date:     2008-06-18 14:31:49 -0700 (Wed, 18 Jun 2008)

Log Message:
-----------
Allow creating different EA managers with different prefixes for the segment 
management.

Modified Paths:
--------------
    trunk/SkimNotes/SKNExtendedAttributeManager.h
    trunk/SkimNotes/SKNExtendedAttributeManager.m

Modified: trunk/SkimNotes/SKNExtendedAttributeManager.h
===================================================================
--- trunk/SkimNotes/SKNExtendedAttributeManager.h       2008-06-18 17:51:03 UTC 
(rev 4027)
+++ trunk/SkimNotes/SKNExtendedAttributeManager.h       2008-06-18 21:31:49 UTC 
(rev 4028)
@@ -44,7 +44,12 @@
     @abstract    Provides an Objective-C wrapper for the low-level BSD 
functions dealing with file attributes.
     @discussion  (comprehensive description)
 */
[EMAIL PROTECTED] SKNExtendedAttributeManager : NSObject
[EMAIL PROTECTED] SKNExtendedAttributeManager : NSObject {
+    NSString *namePrefix;
+    NSString *uniqueKey;
+    NSString *wrapperKey;
+    NSString *fragmentsKey;
+}
 
 /*!
     @method     sharedManager
@@ -55,6 +60,15 @@
 + (id)sharedManager;
 
 /*!
+    @method     initWithPrefix:
+    @abstract   Initializes a new extended attribute manager with keys and 
attribute name prefixes used for segments determined by a prefix.
+    @discussion The prefix should only contain characters that are valid in 
attribute names.
+    @param      prefix Defaults to "skim-app.sourcesforge.net", which is the 
prefix used by Skim.
+    @result     (description)
+*/
+- (id)initWithPrefix:(NSString *)prefix;
+
+/*!
     @method     extendedAttributeNamesAtPath:traverseLink:
     @abstract   Return a list of extended attributes for the given file.
     @discussion Calls <tt>listxattr(2)</tt> to determine all of the extended 
attributes, and returns them as

Modified: trunk/SkimNotes/SKNExtendedAttributeManager.m
===================================================================
--- trunk/SkimNotes/SKNExtendedAttributeManager.m       2008-06-18 17:51:03 UTC 
(rev 4027)
+++ trunk/SkimNotes/SKNExtendedAttributeManager.m       2008-06-18 21:31:49 UTC 
(rev 4028)
@@ -38,10 +38,6 @@
 
 #define MAX_XATTR_LENGTH    2048
 #define UNIQUE_VALUE        [[NSProcessInfo processInfo] globallyUniqueString]
-#define NAME_PREFIX         @"net_sourceforge_skim-app_"
-#define UNIQUE_KEY          @"net_sourceforge_skim-app_unique_key"
-#define WRAPPER_KEY         @"net_sourceforge_skim-app_has_wrapper"
-#define FRAGMENTS_KEY       @"net_sourceforge_skim-app_number_of_fragments"
 
 static NSString *SKNErrorDomain = @"SKNErrorDomain";
 
@@ -67,16 +63,29 @@
 
 - (id)init;
 {
-    self = [super init];
-    if (sharedManager) {
-        [self release];
-        self = [sharedManager retain];
-    } else {
-        sharedManager = self;
+    return [self initWithPrefix:@"net_sourceforge_skim-app"];
+}
+
+- (id)initWithPrefix:(NSString *)prefix;
+{
+    if (self = [super init]) {
+        namePrefix = [[NSString alloc] initWithFormat:@"[EMAIL PROTECTED]", 
prefix];
+        uniqueKey = [[NSString alloc] initWithFormat:@"[EMAIL PROTECTED]", 
prefix];
+        wrapperKey = [[NSString alloc] initWithFormat:@"[EMAIL PROTECTED]", 
prefix];
+        fragmentsKey = [[NSString alloc] initWithFormat:@"[EMAIL PROTECTED]", 
prefix];
+        
     }
     return self;
 }
 
+- (void)dealloc {
+    [namePrefix release];
+    [uniqueKey release];
+    [wrapperKey release];
+    [fragmentsKey release];
+    [super dealloc];
+}
+
 - (NSArray *)extendedAttributeNamesAtPath:(NSString *)path 
traverseLink:(BOOL)follow error:(NSError **)error;
 {
     const char *fsPath = [path fileSystemRepresentation];
@@ -208,10 +217,10 @@
         plist = [NSPropertyListSerialization propertyListFromData:attribute 
mutabilityOption:NSPropertyListImmutable format:&format 
errorDescription:&errorString];
     
     // even if it's a plist, it may not be a dictionary or have the key we're 
looking for
-    if (plist && [plist respondsToSelector:@selector(objectForKey:)] && 
[[plist objectForKey:WRAPPER_KEY] boolValue]) {
+    if (plist && [plist respondsToSelector:@selector(objectForKey:)] && 
[[plist objectForKey:wrapperKey] boolValue]) {
         
-        NSString *uniqueValue = [plist objectForKey:UNIQUE_KEY];
-        unsigned int i, numberOfFragments = [[plist 
objectForKey:FRAGMENTS_KEY] unsignedIntValue];
+        NSString *uniqueValue = [plist objectForKey:uniqueKey];
+        unsigned int i, numberOfFragments = [[plist objectForKey:fragmentsKey] 
unsignedIntValue];
         NSString *name;
 
         NSMutableData *buffer = [NSMutableData data];
@@ -280,9 +289,9 @@
         value = [self bzip2:value];
         
         // this will be a unique identifier for the set of keys we're about to 
write (appending a counter to the UUID)
-        NSString *uniqueValue = [NAME_PREFIX 
stringByAppendingString:UNIQUE_VALUE];
+        NSString *uniqueValue = [namePrefix 
stringByAppendingString:UNIQUE_VALUE];
         unsigned numberOfFragments = ([value length] / MAX_XATTR_LENGTH) + 
([value length] % MAX_XATTR_LENGTH ? 1 : 0);
-        NSDictionary *wrapper = [NSDictionary 
dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], WRAPPER_KEY, 
uniqueValue, UNIQUE_KEY, [NSNumber numberWithUnsignedInt:numberOfFragments], 
FRAGMENTS_KEY, nil];
+        NSDictionary *wrapper = [NSDictionary 
dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], wrapperKey, 
UNIQUE_VALUE, uniqueKey, [NSNumber numberWithUnsignedInt:numberOfFragments], 
fragmentsKey, nil];
         NSData *wrapperData = [NSPropertyListSerialization 
dataFromPropertyList:wrapper format:NSPropertyListBinaryFormat_v1_0 
errorDescription:NULL];
         NSParameterAssert([wrapperData length] < MAX_XATTR_LENGTH && 
[wrapperData length] > 0);
         
@@ -383,10 +392,10 @@
                 plist = [NSPropertyListSerialization 
propertyListFromData:attribute mutabilityOption:NSPropertyListImmutable 
format:&format errorDescription:&errorString];
             
             // even if it's a plist, it may not be a dictionary or have the 
key we're looking for
-            if (plist && [plist respondsToSelector:@selector(objectForKey:)] 
&& [[plist objectForKey:WRAPPER_KEY] boolValue]) {
+            if (plist && [plist respondsToSelector:@selector(objectForKey:)] 
&& [[plist objectForKey:wrapperKey] boolValue]) {
                 
-                NSString *uniqueValue = [plist objectForKey:UNIQUE_KEY];
-                unsigned int i, numberOfFragments = [[plist 
objectForKey:FRAGMENTS_KEY] unsignedIntValue];
+                NSString *uniqueValue = [plist objectForKey:uniqueKey];
+                unsigned int i, numberOfFragments = [[plist 
objectForKey:fragmentsKey] unsignedIntValue];
                 NSString *name;
                 
                 // remove the sub attributes


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to