├── .gitignore ├── EPubReader.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── hr.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── hr.xcuserdatad │ └── xcschemes │ ├── EPubReader.xcscheme │ └── xcschememanagement.plist ├── EPubReader ├── AppDelegate.h ├── AppDelegate.m ├── Default-568h@2x.png ├── Default.png ├── Default@2x.png ├── EPubReader-Info.plist ├── EPubReader-Prefix.pch ├── EPubVC.h ├── EPubVC.m ├── ViewController.h ├── ViewController.m ├── en.lproj │ ├── InfoPlist.strings │ └── MainStoryboard.storyboard ├── main.m └── 沧海.epub ├── Libraries ├── Category │ ├── NSData+Addition.h │ ├── NSData+Addition.m │ ├── NSDate+Addition.h │ ├── NSDate+Addition.m │ ├── NSFileManager+ Addition.m │ ├── NSFileManager+Addition.h │ ├── NSString+Addition.h │ ├── NSString+Addition.m │ ├── UIAlertView+Addition.h │ ├── UIAlertView+Addition.m │ ├── UIColor+Addition.h │ ├── UIColor+Addition.m │ ├── UIImage+Addition.h │ ├── UIImage+Addition.m │ ├── UIView+Animation.h │ ├── UIView+Animation.m │ ├── UIView+Frame.h │ ├── UIView+Frame.m │ ├── UIView+Layer.h │ └── UIView+Layer.m ├── EPubReader │ ├── EPubBook.h │ ├── EPubBook.m │ ├── EPubBookmark.h │ ├── EPubBookmark.m │ ├── EPubBookmarkManager.h │ ├── EPubBookmarkManager.m │ ├── EPubChapter.h │ ├── EPubChapter.m │ ├── EPubChapterListView.h │ ├── EPubChapterListView.m │ ├── EPubConfig.h │ ├── EPubController.h │ ├── EPubController.m │ ├── EPubView.h │ └── EPubView.m ├── FMDB │ ├── FMDatabase.h │ ├── FMDatabase.m │ ├── FMDatabaseAdditions.h │ ├── FMDatabaseAdditions.m │ ├── FMDatabasePool.h │ ├── FMDatabasePool.m │ ├── FMDatabaseQueue.h │ ├── FMDatabaseQueue.m │ ├── FMResultSet.h │ └── FMResultSet.m ├── MBProgressHUD │ ├── MBProgressHUD.h │ ├── MBProgressHUD.m │ ├── MBPromptHUD.h │ └── MBPromptHUD.m ├── TouchXML │ ├── CXHTMLDocument.h │ ├── CXHTMLDocument.m │ ├── CXMLDocument.h │ ├── CXMLDocument.m │ ├── CXMLDocument_PrivateExtensions.h │ ├── CXMLDocument_PrivateExtensions.m │ ├── CXMLElement.h │ ├── CXMLElement.m │ ├── CXMLElement_CreationExtensions.h │ ├── CXMLElement_CreationExtensions.m │ ├── CXMLElement_ElementTreeExtensions.h │ ├── CXMLElement_ElementTreeExtensions.m │ ├── CXMLNamespaceNode.h │ ├── CXMLNamespaceNode.m │ ├── CXMLNode.h │ ├── CXMLNode.m │ ├── CXMLNode_PrivateExtensions.h │ ├── CXMLNode_PrivateExtensions.m │ ├── CXMLNode_XPathExtensions.h │ ├── CXMLNode_XPathExtensions.m │ ├── Creation │ │ ├── CXMLDocument_CreationExtensions.h │ │ ├── CXMLDocument_CreationExtensions.m │ │ ├── CXMLNode_CreationExtensions.h │ │ └── CXMLNode_CreationExtensions.m │ ├── Tidy │ │ ├── CTidy.h │ │ └── CTidy.m │ └── TouchXML.h └── ZipArchive │ ├── ZipArchive.h │ ├── ZipArchive.m │ └── minizip │ ├── ChangeLogUnzip │ ├── Makefile │ ├── crypt.h │ ├── ioapi.c │ ├── ioapi.h │ ├── mztools.c │ ├── mztools.h │ ├── unzip.c │ ├── unzip.h │ ├── zip.c │ └── zip.h └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | *.xcworkspace 13 | !default.xcworkspace 14 | xcuserdata 15 | profile 16 | *.moved-aside 17 | DerivedData 18 | .idea/ 19 | -------------------------------------------------------------------------------- /EPubReader.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /EPubReader.xcodeproj/project.xcworkspace/xcuserdata/hr.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/EPubReader/b3d76e39973a39de070a70763301034ba246d40d/EPubReader.xcodeproj/project.xcworkspace/xcuserdata/hr.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /EPubReader.xcodeproj/xcuserdata/hr.xcuserdatad/xcschemes/EPubReader.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 51 | 52 | 58 | 59 | 60 | 61 | 62 | 63 | 69 | 70 | 76 | 77 | 78 | 79 | 81 | 82 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /EPubReader.xcodeproj/xcuserdata/hr.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | EPubReader.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 253195551703E6DD00BD0A7D 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /EPubReader/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // EPubReader 4 | // 5 | // Created by line0 on 13-3-28. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /EPubReader/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // EPubReader 4 | // 5 | // Created by line0 on 13-3-28. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @implementation AppDelegate 12 | 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 14 | { 15 | // Override point for customization after application launch. 16 | return YES; 17 | } 18 | 19 | - (void)applicationWillResignActive:(UIApplication *)application 20 | { 21 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 22 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 23 | } 24 | 25 | - (void)applicationDidEnterBackground:(UIApplication *)application 26 | { 27 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 28 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 29 | } 30 | 31 | - (void)applicationWillEnterForeground:(UIApplication *)application 32 | { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | - (void)applicationDidBecomeActive:(UIApplication *)application 37 | { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application 42 | { 43 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /EPubReader/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/EPubReader/b3d76e39973a39de070a70763301034ba246d40d/EPubReader/Default-568h@2x.png -------------------------------------------------------------------------------- /EPubReader/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/EPubReader/b3d76e39973a39de070a70763301034ba246d40d/EPubReader/Default.png -------------------------------------------------------------------------------- /EPubReader/Default@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/EPubReader/b3d76e39973a39de070a70763301034ba246d40d/EPubReader/Default@2x.png -------------------------------------------------------------------------------- /EPubReader/EPubReader-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | makeLaugh.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIMainStoryboardFile 28 | MainStoryboard 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /EPubReader/EPubReader-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'EPubReader' target in the 'EPubReader' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_5_0 8 | #warning "This project uses features only available in iOS SDK 5.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /EPubReader/EPubVC.h: -------------------------------------------------------------------------------- 1 | // 2 | // EPubVC.h 3 | // FuYin 4 | // 5 | // Created by line0 on 13-3-4. 6 | // Copyright (c) 2013年 wsk. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface EPubVC : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /EPubReader/EPubVC.m: -------------------------------------------------------------------------------- 1 | // 2 | // EPubVC.m 3 | // FuYin 4 | // 5 | // Created by line0 on 13-3-4. 6 | // Copyright (c) 2013年 wsk. All rights reserved. 7 | // 8 | 9 | #import "EPubVC.h" 10 | #import "EPubController.h" 11 | 12 | @interface EPubVC () 13 | @property (strong, nonatomic) EPubController *epubController; 14 | 15 | @end 16 | 17 | @implementation EPubVC 18 | 19 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 20 | { 21 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 22 | if (self) 23 | { } 24 | return self; 25 | } 26 | 27 | - (void)viewDidLoad 28 | { 29 | [super viewDidLoad]; 30 | 31 | UIBarButtonItem *rightItem1 = [[UIBarButtonItem alloc] initWithTitle:@"书签" style:UIBarButtonItemStylePlain target:self action:@selector(addBookmark)]; 32 | UIBarButtonItem *rightItem2 = [[UIBarButtonItem alloc] initWithTitle:@"目录" style:UIBarButtonItemStyleBordered target:self action:@selector(showChapterList)]; 33 | self.navigationItem.rightBarButtonItems = @[rightItem1, rightItem2]; 34 | 35 | NSString *bookPath = [[NSBundle mainBundle] pathForResource:@"沧海" ofType:@"epub"]; 36 | self.epubController = [[EPubController alloc] init]; 37 | [self.epubController openBook:bookPath atView:self.view withPageFrame:self.view.bounds]; 38 | } 39 | 40 | - (void)didReceiveMemoryWarning 41 | { 42 | [super didReceiveMemoryWarning]; 43 | // Dispose of any resources that can be recreated. 44 | } 45 | 46 | - (void)viewWillAppear:(BOOL)animated 47 | { 48 | [super viewWillAppear:animated]; 49 | 50 | self.navigationController.navigationBarHidden = NO; 51 | } 52 | 53 | - (void)viewWillDisappear:(BOOL)animated 54 | { 55 | [super viewWillDisappear:animated]; 56 | 57 | self.navigationController.navigationBarHidden = YES; 58 | } 59 | 60 | - (void)addBookmark 61 | { 62 | [self.epubController addBookmark]; 63 | } 64 | 65 | - (void)showChapterList 66 | { 67 | static BOOL open = NO; 68 | if (!open) 69 | { 70 | [self.epubController showChapterListAtView:self.view withFrame:self.view.bounds]; 71 | open = YES; 72 | } 73 | else 74 | { 75 | [self.epubController hideChapterListView]; 76 | open = NO; 77 | } 78 | } 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /EPubReader/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // EPubReader 4 | // 5 | // Created by line0 on 13-3-28. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /EPubReader/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // EPubReader 4 | // 5 | // Created by line0 on 13-3-28. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | @interface ViewController () 12 | 13 | @end 14 | 15 | @implementation ViewController 16 | 17 | - (void)viewDidLoad 18 | { 19 | [super viewDidLoad]; 20 | 21 | self.navigationController.navigationBarHidden = YES; 22 | } 23 | 24 | - (void)didReceiveMemoryWarning 25 | { 26 | [super didReceiveMemoryWarning]; 27 | // Dispose of any resources that can be recreated. 28 | } 29 | 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /EPubReader/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /EPubReader/en.lproj/MainStoryboard.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /EPubReader/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // EPubReader 4 | // 5 | // Created by line0 on 13-3-28. 6 | // Copyright (c) 2013年 makeLaugh. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "AppDelegate.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /EPubReader/沧海.epub: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laughmaker/EPubReader/b3d76e39973a39de070a70763301034ba246d40d/EPubReader/沧海.epub -------------------------------------------------------------------------------- /Libraries/Category/NSData+Addition.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSData+Addition.h 3 | // Line0 4 | // 5 | // Created by line0 on 12-12-5. 6 | // Copyright (c) 2012年 line0. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSData (Addition) 12 | - (NSData *)dataWithObject:(id)object; 13 | - (id)convertDataToObject; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Libraries/Category/NSData+Addition.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSData+Addition.m 3 | // Line0 4 | // 5 | // Created by line0 on 12-12-5. 6 | // Copyright (c) 2012年 line0. All rights reserved. 7 | // 8 | 9 | #import "NSData+Addition.h" 10 | 11 | @implementation NSData (Addition) 12 | 13 | - (NSData *)dataWithObject:(id)object 14 | { 15 | NSData *data = [NSKeyedArchiver archivedDataWithRootObject:object]; 16 | return data; 17 | } 18 | 19 | - (id)convertDataToObject 20 | { 21 | NSArray *array = [NSKeyedUnarchiver unarchiveObjectWithData:self]; 22 | return array; 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Libraries/Category/NSDate+Addition.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSDate+HW.h 3 | // StringDemo 4 | // 5 | // Created by 何 振东 on 12-10-11. 6 | // Copyright (c) 2012年 wsk. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSDate (Addition) 12 | 13 | /** 14 | * 将日期转化为字符串。 15 | * @param format:转化格式,形如@"yyyy年MM月dd日hh时mm分ss秒"。 16 | * return 返回转化后的字符串。 17 | */ 18 | - (NSString *)convertDateToStringWithFormat:(NSString *)format; 19 | 20 | /** 21 | * 将字符串转化为日期。 22 | * @param string:给定的字符串日期。 23 | * @param format:转化格式,形如@"yyyy年MM月dd日hh时mm分ss秒"。日期格式要和string格式一致,否则会为空。 24 | * return 返回转化后的日期。 25 | */ 26 | - (NSDate *)convertStringToDate:(NSString *)string format:(NSString *)format; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Libraries/Category/NSDate+Addition.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSDate+HW.m 3 | // StringDemo 4 | // 5 | // Created by 何 振东 on 12-10-11. 6 | // Copyright (c) 2012年 wsk. All rights reserved. 7 | // 8 | 9 | #import "NSDate+Addition.h" 10 | 11 | @implementation NSDate (Addition) 12 | 13 | - (NSString *)convertDateToStringWithFormat:(NSString *)format 14 | { 15 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 16 | [dateFormatter setDateFormat:format]; 17 | // NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"GMT"]; 18 | // [dateFormatter setTimeZone:timeZone]; 19 | NSString *dateStr = [dateFormatter stringFromDate:self]; 20 | return dateStr; 21 | } 22 | 23 | - (NSDate *)convertStringToDate:(NSString *)string format:(NSString *)format 24 | { 25 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 26 | [dateFormatter setTimeZone:[NSTimeZone localTimeZone]]; 27 | [dateFormatter setDateFormat:format]; 28 | // NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"GMT"]; 29 | // [dateFormatter setTimeZone:timeZone]; 30 | NSDate *date = [dateFormatter dateFromString:string]; 31 | return date; 32 | } 33 | 34 | - (NSDate *)cc_dateByMovingToBeginningOfDay 35 | { 36 | unsigned int flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit; 37 | NSDateComponents* parts = [[NSCalendar currentCalendar] components:flags fromDate:self]; 38 | [parts setHour:0]; 39 | [parts setMinute:0]; 40 | [parts setSecond:0]; 41 | return [[NSCalendar currentCalendar] dateFromComponents:parts]; 42 | } 43 | 44 | - (NSDate *)cc_dateByMovingToEndOfDay 45 | { 46 | unsigned int flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit; 47 | NSDateComponents* parts = [[NSCalendar currentCalendar] components:flags fromDate:self]; 48 | [parts setHour:23]; 49 | [parts setMinute:59]; 50 | [parts setSecond:59]; 51 | return [[NSCalendar currentCalendar] dateFromComponents:parts]; 52 | } 53 | 54 | - (NSDate *)cc_dateByMovingToFirstDayOfTheMonth 55 | { 56 | NSDate *d = nil; 57 | BOOL ok = [[NSCalendar currentCalendar] rangeOfUnit:NSMonthCalendarUnit startDate:&d interval:NULL forDate:self]; 58 | NSAssert1(ok, @"Failed to calculate the first day the month based on %@", self); 59 | return d; 60 | } 61 | 62 | - (NSDate *)cc_dateByMovingToFirstDayOfThePreviousMonth 63 | { 64 | NSDateComponents *c = [[NSDateComponents alloc] init]; 65 | c.month = -1; 66 | return [[[NSCalendar currentCalendar] dateByAddingComponents:c toDate:self options:0] cc_dateByMovingToFirstDayOfTheMonth]; 67 | } 68 | 69 | - (NSDate *)cc_dateByMovingToFirstDayOfTheFollowingMonth 70 | { 71 | NSDateComponents *c = [[NSDateComponents alloc] init]; 72 | c.month = 1; 73 | return [[[NSCalendar currentCalendar] dateByAddingComponents:c toDate:self options:0] cc_dateByMovingToFirstDayOfTheMonth]; 74 | } 75 | 76 | - (NSDateComponents *)cc_componentsForMonthDayAndYear 77 | { 78 | return [[NSCalendar currentCalendar] components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:self]; 79 | } 80 | 81 | - (NSUInteger)cc_weekday 82 | { 83 | return [[NSCalendar currentCalendar] ordinalityOfUnit:NSDayCalendarUnit inUnit:NSWeekCalendarUnit forDate:self]; 84 | } 85 | 86 | - (NSUInteger)cc_numberOfDaysInMonth 87 | { 88 | return [[NSCalendar currentCalendar] rangeOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit forDate:self].length; 89 | } 90 | 91 | 92 | @end 93 | -------------------------------------------------------------------------------- /Libraries/Category/NSFileManager+ Addition.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSFileManager+HW.m 3 | // StringDemo 4 | // 5 | // Created by 何 振东 on 12-10-11. 6 | // Copyright (c) 2012年 wsk. All rights reserved. 7 | // 8 | 9 | #import "NSFileManager+Addition.h" 10 | 11 | @implementation NSFileManager (Addition) 12 | 13 | + (BOOL)createFolder:(NSString *)folder atPath:(NSString *)path 14 | { 15 | NSString *savePath = [path stringByAppendingPathComponent:folder]; 16 | NSFileManager *fileManager = [NSFileManager defaultManager]; 17 | BOOL isDirectory; 18 | BOOL exist = [fileManager fileExistsAtPath:savePath isDirectory:&isDirectory]; 19 | NSError *error = nil; 20 | if (!exist || !isDirectory) 21 | { 22 | [fileManager createDirectoryAtPath:savePath withIntermediateDirectories:YES attributes:nil error:&error]; 23 | } 24 | 25 | return [fileManager fileExistsAtPath:savePath isDirectory:&isDirectory]; 26 | } 27 | 28 | + (BOOL)saveData:(NSData *)data withName:(NSString *)name atPath:(NSString *)path 29 | { 30 | if (data && name && path) 31 | { 32 | NSString *filePath = [path stringByAppendingPathComponent:name]; 33 | return [data writeToFile:filePath atomically:YES]; 34 | } 35 | 36 | return NO; 37 | } 38 | 39 | + (NSData *)findFile:(NSString *)fileName atPath:(NSString *)path 40 | { 41 | NSData *data = nil; 42 | if (fileName && path) 43 | { 44 | NSFileManager *fileManager = [NSFileManager defaultManager]; 45 | NSString *filePath = [path stringByAppendingPathComponent:fileName]; 46 | 47 | if ([fileManager fileExistsAtPath:filePath]) 48 | { 49 | data = [NSData dataWithContentsOfFile:filePath]; 50 | } 51 | } 52 | 53 | return data; 54 | } 55 | 56 | + (BOOL)deleteFile:(NSString *)fileName atPath:(NSString *)path 57 | { 58 | NSFileManager *fileManager = [NSFileManager defaultManager]; 59 | NSString *filePath = [path stringByAppendingPathComponent:fileName]; 60 | NSError *error; 61 | BOOL success = [fileManager removeItemAtPath:filePath error:&error]; 62 | return success; 63 | } 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /Libraries/Category/NSFileManager+Addition.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSFileManager+HW.h 3 | // StringDemo 4 | // 5 | // Created by 何 振东 on 12-10-11. 6 | // Copyright (c) 2012年 wsk. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSFileManager (Addition) 12 | 13 | /** 14 | * 在相应目录下创建一个文件夹。 15 | * @param folder:文件夹名。 16 | * @param path:文件夹所在路径。 17 | * return 成功返回YES,失败返回NO。若已存在直接返回YES。 18 | */ 19 | + (BOOL)createFolder:(NSString *)folder atPath:(NSString *)path; 20 | 21 | /** 22 | * 保存文件到相应路径下。 23 | * @param data:要保存的数据。 24 | * @param name:要保存的文件名,如a.txt等。 25 | * @param path:文件保存的路径目录。 26 | * return 成功返回YES,失败返回NO。 27 | */ 28 | + (BOOL)saveData:(NSData *)data withName:(NSString *)name atPath:(NSString *)path; 29 | 30 | /** 31 | * 查找并返回文件。 32 | * @param fileName:要查找的文件名。 33 | * @param path:文件所在的目录。 34 | * return 成功返回文件,失败返回nil。 35 | */ 36 | + (NSData *)findFile:(NSString *)fileName atPath:(NSString *)path; 37 | 38 | /** 39 | * 删除文件。 40 | * @param fileName:要删除的文件名。 41 | * @param path:文件所在的目录。 42 | * return 成功返回YES,失败返回NO。 43 | */ 44 | + (BOOL)deleteFile:(NSString *)fileName atPath:(NSString *)path; 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /Libraries/Category/NSString+Addition.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+HW.h 3 | // StringDemo 4 | // 5 | // Created by 何 振东 on 12-10-11. 6 | // Copyright (c) 2012年 wsk. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSString (Addition) 12 | 13 | /** 14 | * 计算字符串的字数。 15 | * @param string:输入字符串。 16 | * return 返回输入字符串的字数。 17 | */ 18 | - (int)wordsCount; 19 | 20 | - (NSString *)URLDecodedString; 21 | - (NSString *)URLEncodedString; 22 | - (NSString *)encodeStringWithUTF8; 23 | - (NSUInteger)byteLengthWithEncoding:(NSStringEncoding)encoding; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Libraries/Category/NSString+Addition.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+HW.m 3 | // StringDemo 4 | // 5 | // Created by 何 振东 on 12-10-11. 6 | // Copyright (c) 2012年 wsk. All rights reserved. 7 | // 8 | 9 | #import "NSString+Addition.h" 10 | 11 | @implementation NSString (Addition) 12 | 13 | - (int)wordsCount 14 | { 15 | int i,n = [self length], l = 0, a = 0, b = 0; 16 | unichar c; 17 | for(i = 0;i < n; i++) 18 | { 19 | c = [self characterAtIndex:i]; 20 | if(isblank(c)) 21 | { 22 | b++; 23 | }else if(isascii(c)) 24 | { 25 | a++; 26 | }else{ 27 | l++; 28 | } 29 | } 30 | if(a == 0 && l == 0) return 0; 31 | return l + (int)ceilf((float)(a + b) / 2.0); 32 | } 33 | 34 | - (NSString *)URLEncodedString 35 | { 36 | NSString *result = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, 37 | (CFStringRef)self, 38 | NULL, 39 | CFSTR("!*'();:@&=+$,/?%#[]"), 40 | kCFStringEncodingUTF8)); 41 | return result; 42 | } 43 | 44 | - (NSString *)URLDecodedString 45 | { 46 | NSString *result = (NSString *)CFBridgingRelease(CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, 47 | (CFStringRef)self, 48 | CFSTR(""), 49 | kCFStringEncodingUTF8)); 50 | return result; 51 | } 52 | 53 | - (NSString *)encodeStringWithUTF8 54 | { 55 | NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingISOLatin1); 56 | const char *c = [self cStringUsingEncoding:encoding]; 57 | NSString *str = [NSString stringWithCString:c encoding:NSUTF8StringEncoding]; 58 | 59 | return str; 60 | } 61 | 62 | - (NSUInteger)byteLengthWithEncoding:(NSStringEncoding)encoding 63 | { 64 | if (!self) 65 | { 66 | return 0; 67 | } 68 | 69 | const char *byte = [self cStringUsingEncoding:encoding]; 70 | return strlen(byte); 71 | } 72 | 73 | @end 74 | -------------------------------------------------------------------------------- /Libraries/Category/UIAlertView+Addition.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIAlertView+Addition.h 3 | // Line0 4 | // 5 | // Created by line0 on 12-12-4. 6 | // Copyright (c) 2012年 line0. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIAlertView (Addition) 12 | + (void)showAlertViewWithTitle:(NSString *)title message:(NSString *)msg; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /Libraries/Category/UIAlertView+Addition.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIAlertView+Addition.m 3 | // Line0 4 | // 5 | // Created by line0 on 12-12-4. 6 | // Copyright (c) 2012年 line0. All rights reserved. 7 | // 8 | 9 | #import "UIAlertView+Addition.h" 10 | 11 | @implementation UIAlertView (Addition) 12 | 13 | + (void)showAlertViewWithTitle:(NSString *)title message:(NSString *)msg 14 | { 15 | UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title 16 | message:msg 17 | delegate:nil 18 | cancelButtonTitle:@"确定" 19 | otherButtonTitles:nil, nil]; 20 | [alertView show]; 21 | } 22 | 23 | 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Libraries/Category/UIColor+Addition.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+WSK.h 3 | // CTCockpit 4 | // 5 | // Created by 何 振东 on 12-9-26. 6 | // 7 | // 8 | 9 | #import 10 | 11 | @interface UIColor (Addition) 12 | 13 | /** 14 | * 根据RGB返回UIColor。 15 | * @param red、green、blue:范围0—255。 16 | * @param alpha:透明度。 17 | * return UIColor。 18 | */ 19 | + (UIColor *)red:(int)red green:(int)green blue:(int)blue alpha:(CGFloat)alpha; 20 | 21 | /** 22 | * 根据UIColor返回RGB数组。 23 | * @param color:传递的参数。 24 | * return RGB数组 25 | */ 26 | + (NSArray *)convertColorToRBG:(UIColor *)color; 27 | 28 | /** 29 | * 根据十六进制颜色值返回UIColor。 30 | * @param hexColor:十六进制颜色值。 31 | * return UIColor。 32 | */ 33 | + (UIColor *)convertHexColorToUIColor:(NSInteger)hexColor; 34 | 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /Libraries/Category/UIColor+Addition.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+WSK.m 3 | // CTCockpit 4 | // 5 | // Created by 何 振东 on 12-9-26. 6 | // 7 | // 8 | 9 | #import "UIColor+Addition.h" 10 | 11 | @implementation UIColor (Addition) 12 | 13 | + (UIColor *)red:(int)red green:(int)green blue:(int)blue alpha:(CGFloat)alpha 14 | { 15 | UIColor *color = [UIColor colorWithRed:red/255.f green:green/255.f blue:blue/255.f alpha:alpha]; 16 | return color; 17 | } 18 | 19 | + (NSArray *)convertColorToRBG:(UIColor *)uicolor 20 | { 21 | CGColorRef color = [uicolor CGColor]; 22 | int numComponents = CGColorGetNumberOfComponents(color); 23 | NSArray *array = nil; 24 | 25 | if (numComponents == 4) 26 | { 27 | int rValue, gValue, bValue; 28 | const CGFloat *components = CGColorGetComponents(color); 29 | rValue = (int)(components[0] * 255); 30 | gValue = (int)(components[1] * 255); 31 | bValue = (int)(components[2] * 255); 32 | 33 | array = [NSArray arrayWithObjects:[NSNumber numberWithInt:rValue], [NSNumber numberWithInt:gValue], [NSNumber numberWithInt:bValue], nil]; 34 | } 35 | 36 | return array; 37 | } 38 | 39 | UIColor* UIColorFromHex(NSInteger colorInHex) 40 | { 41 | // colorInHex should be value like 0xFFFFFF 42 | return [UIColor colorWithRed:((float) ((colorInHex & 0xFF0000) >> 16)) / 0xFF 43 | green:((float) ((colorInHex & 0xFF00) >> 8)) / 0xFF 44 | blue:((float) (colorInHex & 0xFF)) / 0xFF 45 | alpha:1.0]; 46 | } 47 | 48 | + (UIColor *)convertHexColorToUIColor:(NSInteger)hexColor 49 | { 50 | return [UIColor colorWithRed:((float) ((hexColor & 0xFF0000) >> 16)) / 0xFF 51 | green:((float) ((hexColor & 0xFF00) >> 8)) / 0xFF 52 | blue:((float) (hexColor & 0xFF)) / 0xFF 53 | alpha:1.0]; 54 | } 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /Libraries/Category/UIImage+Addition.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+WSK.h 3 | // CorePlotDemo 4 | // 5 | // Created by 何 振东 on 12-9-26. 6 | // Copyright (c) 2012年 开趣. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIImage (kai) 12 | 13 | /** 14 | * 抓取屏幕。 15 | * @param scale:屏幕放大倍数,1为原尺寸。 16 | * return 屏幕后的Image。 17 | */ 18 | + (UIImage *)grabScreenWithScale:(CGFloat)scale; 19 | 20 | /** 21 | * 抓取UIView及其子类。 22 | * @param view: UIView及其子类。 23 | * @param scale:屏幕放大倍数,1为原尺寸。 24 | * return 抓取图片后的Image。 25 | */ 26 | + (UIImage *)grabImageWithView:(UIView *)view scale:(CGFloat)scale; 27 | 28 | /** 29 | * 合并两个Image。 30 | * @param image1、image2: 两张图片。 31 | * @param frame1、frame2:两张图片放置的位置。 32 | * @param size:返回图片的尺寸。 33 | * return 合并后的两个图片的Image。 34 | */ 35 | + (UIImage *)mergeWithImage1:(UIImage *)image1 image2:(UIImage *)image2 frame1:(CGRect)frame1 frame2:(CGRect)frame2 size:(CGSize)size; 36 | 37 | /** 38 | * 把一个Image盖在另一个Image上面。 39 | * @param image: 底图。 40 | * @param mask:盖在上面的图。 41 | * return Image。 42 | */ 43 | + (UIImage *)maskImage:(UIImage *)image withMask:(UIImage *)mask; 44 | 45 | /** 46 | * 把一个Image尺寸缩放到另一个尺寸。 47 | * @param view: UIView及其子类。 48 | * @param scale:屏幕放大倍数,1为原尺寸。 49 | * return 尺寸更改后的Image。 50 | */ 51 | + (UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)size; 52 | 53 | 54 | 55 | /** 56 | * 改变一个Image的色彩。 57 | * @param image: 被改变的Image。 58 | * @param color: 要改变的目标色彩。 59 | * return 色彩更改后的Image。 60 | */ 61 | +(UIImage *)colorizeImage:(UIImage *)image withColor:(UIColor *)color; 62 | 63 | //按frame裁减图片 64 | + (UIImage *)captureView:(UIView *)view frame:(CGRect)frame; 65 | 66 | 67 | 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /Libraries/Category/UIImage+Addition.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+WSK.m 3 | // CorePlotDemo 4 | // 5 | // Created by 何 振东 on 12-9-26. 6 | // Copyright (c) 2012年 开趣. All rights reserved. 7 | // 8 | 9 | #import "UIImage+Addition.h" 10 | #import "QuartzCore/QuartzCore.h" 11 | 12 | @implementation UIImage (kai) 13 | 14 | + (UIImage *)grabScreenWithScale:(CGFloat)scale 15 | { 16 | UIWindow *screenWindow = [[UIApplication sharedApplication] keyWindow]; 17 | // UIGraphicsBeginImageContext(screenWindow.frame.size); 18 | UIGraphicsBeginImageContextWithOptions(screenWindow.frame.size, YES, scale); 19 | [screenWindow.layer renderInContext:UIGraphicsGetCurrentContext()]; 20 | UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 21 | UIGraphicsEndImageContext(); 22 | 23 | return image; 24 | } 25 | 26 | + (UIImage *)grabImageWithView:(UIView *)view scale:(CGFloat)scale 27 | { 28 | UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, scale); 29 | [view.layer renderInContext:UIGraphicsGetCurrentContext()]; 30 | UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 31 | UIGraphicsEndImageContext(); 32 | // UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); 33 | 34 | return image; 35 | } 36 | 37 | + (UIImage *)captureView:(UIView *)view frame:(CGRect)frame 38 | { 39 | UIGraphicsBeginImageContext(view.frame.size); 40 | CGContextRef context = UIGraphicsGetCurrentContext(); 41 | [view.layer renderInContext:context]; 42 | UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); 43 | UIGraphicsEndImageContext(); 44 | CGImageRef ref = CGImageCreateWithImageInRect(img.CGImage, frame); 45 | UIImage *i = [UIImage imageWithCGImage:ref]; 46 | CGImageRelease(ref); 47 | return i; 48 | } 49 | 50 | + (UIImage *)mergeWithImage1:(UIImage*)image1 image2:(UIImage *)image2 frame1:(CGRect)frame1 frame2:(CGRect)frame2 size:(CGSize)size{ 51 | UIGraphicsBeginImageContext(size); 52 | [image1 drawInRect:frame1 blendMode:kCGBlendModeLuminosity alpha:1.0]; 53 | [image2 drawInRect:frame2 blendMode:kCGBlendModeLuminosity alpha:0.2]; 54 | UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 55 | UIGraphicsEndImageContext(); 56 | 57 | return image; 58 | } 59 | 60 | + (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)mask{ 61 | CGImageRef imgRef = [image CGImage]; 62 | CGImageRef maskRef = [mask CGImage]; 63 | CGImageRef actualMask = CGImageMaskCreate(CGImageGetWidth(maskRef), 64 | CGImageGetHeight(maskRef), 65 | CGImageGetBitsPerComponent(maskRef), 66 | CGImageGetBitsPerPixel(maskRef), 67 | CGImageGetBytesPerRow(maskRef), 68 | CGImageGetDataProvider(maskRef), NULL, true); 69 | CGImageRef masked = CGImageCreateWithMask(imgRef, actualMask); 70 | UIImage *resultImg = [UIImage imageWithCGImage:masked]; 71 | CGImageRelease(actualMask); 72 | CGImageRelease(masked); 73 | 74 | return resultImg; 75 | } 76 | 77 | + (UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)size 78 | { 79 | UIGraphicsBeginImageContext(size); 80 | [image drawInRect:CGRectMake(0, 0, size.width, size.height)]; 81 | UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext(); 82 | UIGraphicsEndImageContext(); 83 | return scaledImage; 84 | } 85 | 86 | +(UIImage *)colorizeImage:(UIImage *)image withColor:(UIColor *)color 87 | { 88 | UIGraphicsBeginImageContext(image.size); 89 | CGContextRef ctx = UIGraphicsGetCurrentContext(); 90 | CGRect area = CGRectMake(0, 0, image.size.width, image.size.height); 91 | CGContextScaleCTM(ctx, 1, -1); 92 | CGContextTranslateCTM(ctx, 0, -area.size.height); 93 | CGContextSaveGState(ctx); 94 | CGContextClipToMask(ctx, area, image.CGImage); 95 | [color set]; 96 | CGContextFillRect(ctx, area); 97 | CGContextRestoreGState(ctx); 98 | CGContextSetBlendMode(ctx, kCGBlendModeMultiply); 99 | CGContextDrawImage(ctx, area, image.CGImage); 100 | UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 101 | UIGraphicsEndImageContext(); 102 | 103 | return newImage; 104 | } 105 | 106 | 107 | @end 108 | -------------------------------------------------------------------------------- /Libraries/Category/UIView+Animation.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+Animation.h 3 | // StringDemo 4 | // 5 | // Created by 何 振东 on 12-10-11. 6 | // Copyright (c) 2012年 wsk. All rights reserved. 7 | // 8 | 9 | /** 10 | * direction取值:kCATransitionFromTop kCATransitionFromBottom 11 | * kCATransitionFromLeft kCATransitionFromRight 12 | */ 13 | 14 | #define kCameraEffectOpen @"cameraIrisHollowOpen" 15 | #define kCameraEffectClose @"cameraIrisHollowClose" 16 | 17 | 18 | #import 19 | #import "QuartzCore/QuartzCore.h" 20 | 21 | @interface UIView (Animation) 22 | 23 | //揭开 24 | + (void)animationReveal:(UIView *)view direction:(NSString *)direction; 25 | 26 | //渐隐渐消 27 | + (void)animationFade:(UIView *)view; 28 | 29 | //翻转 30 | + (void)animationFlip:(UIView *)view direction:(NSString *)direction; 31 | 32 | //旋转缩放 33 | + (void)animationRotateAndScaleEffects:(UIView *)view;//各种旋转缩放效果。 34 | + (void)animationRotateAndScaleDownUp:(UIView *)view;//旋转同时缩小放大效果 35 | 36 | //push 37 | + (void)animationPush:(UIView *)view direction:(NSString *)direction; 38 | 39 | //Curl UnCurl 40 | + (void)animationCurl:(UIView *)view direction:(NSString *)direction; 41 | + (void)animationUnCurl:(UIView *)view direction:(NSString *)direction; 42 | 43 | //Move 44 | + (void)animationMove:(UIView *)view direction:(NSString *)direction; 45 | 46 | //立方体 47 | + (void)animationCube:(UIView *)view direction:(NSString *)direction; 48 | 49 | //水波纹 50 | + (void)animationRippleEffect:(UIView *)view; 51 | 52 | //相机开合 53 | + (void)animationCameraEffect:(UIView *)view type:(NSString *)type; 54 | 55 | //吸收 56 | + (void)animationSuckEffect:(UIView *)view; 57 | 58 | + (void)animationBounceOut:(UIView *)view; 59 | + (void)animationBounceIn:(UIView *)view; 60 | + (void)animationBounce:(UIView *)view; 61 | 62 | 63 | 64 | @end 65 | -------------------------------------------------------------------------------- /Libraries/Category/UIView+Frame.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+Frame.h 3 | // StringDemo 4 | // 5 | // Created by 何 振东 on 12-10-11. 6 | // Copyright (c) 2012年 wsk. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIView (Frame) 12 | 13 | /** 14 | * 返回UIView及其子类的位置和尺寸。分别为左、右边界在X轴方向上的距离,上、下边界在Y轴上的距离,View的宽和高。 15 | */ 16 | 17 | @property(nonatomic) CGFloat left; 18 | @property(nonatomic) CGFloat right; 19 | @property(nonatomic) CGFloat top; 20 | @property(nonatomic) CGFloat bottom; 21 | @property(nonatomic) CGFloat width; 22 | @property(nonatomic) CGFloat height; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /Libraries/Category/UIView+Frame.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+Frame.m 3 | // StringDemo 4 | // 5 | // Created by 何 振东 on 12-10-11. 6 | // Copyright (c) 2012年 wsk. All rights reserved. 7 | // 8 | 9 | #import "UIView+Frame.h" 10 | 11 | @implementation UIView (Frame) 12 | 13 | - (CGFloat)left 14 | { 15 | return self.frame.origin.x; 16 | } 17 | 18 | - (void)setLeft:(CGFloat)x 19 | { 20 | CGRect frame = self.frame; 21 | frame.origin.x = x; 22 | self.frame = frame; 23 | } 24 | 25 | - (CGFloat)right 26 | { 27 | return self.frame.origin.x + self.frame.size.width; 28 | } 29 | 30 | - (void)setRight:(CGFloat)right 31 | { 32 | CGRect frame = self.frame; 33 | frame.origin.x = right - frame.size.width; 34 | self.frame = frame; 35 | } 36 | 37 | - (CGFloat)top 38 | { 39 | return self.frame.origin.y; 40 | } 41 | 42 | - (void)setTop:(CGFloat)y 43 | { 44 | CGRect frame = self.frame; 45 | frame.origin.y = y; 46 | self.frame = frame; 47 | } 48 | 49 | - (CGFloat)bottom 50 | { 51 | return self.frame.origin.y + self.frame.size.height; 52 | } 53 | 54 | - (void)setBottom:(CGFloat)bottom 55 | { 56 | CGRect frame = self.frame; 57 | frame.origin.y = bottom - frame.size.height; 58 | self.frame = frame; 59 | } 60 | 61 | - (CGFloat)width 62 | { 63 | return self.frame.size.width; 64 | } 65 | 66 | - (void)setWidth:(CGFloat)width 67 | { 68 | CGRect frame = self.frame; 69 | frame.size.width = width; 70 | self.frame = frame; 71 | } 72 | 73 | - (CGFloat)height 74 | { 75 | return self.frame.size.height; 76 | } 77 | 78 | - (void)setHeight:(CGFloat)height 79 | { 80 | CGRect frame = self.frame; 81 | frame.size.height = height; 82 | self.frame = frame; 83 | } 84 | 85 | @end 86 | -------------------------------------------------------------------------------- /Libraries/Category/UIView+Layer.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+WSK.h 3 | // CorePlotDemo 4 | // 5 | // Created by 何 振东 on 12-9-26. 6 | // Copyright (c) 2012年 开趣. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UIView (Layer) 12 | 13 | /** 14 | * 产生一个Image的倒影,并把这个倒影图片加在一个View上面。 15 | * @param image:被倒影的原图。 16 | * @param frame:盖在上面的图。 17 | * @param opacity:倒影的透明度,0为完全透明,即倒影不可见;1为完全不透明。 18 | * @param view:倒影加载在上面。 19 | * return 产生倒影后的View。 20 | */ 21 | + (UIView *)reflectImage:(UIImage *)image withFrame:(CGRect)frame opacity:(CGFloat)opacity atView:(UIView *)view; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Libraries/Category/UIView+Layer.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+WSK.m 3 | // CorePlotDemo 4 | // 5 | // Created by 何 振东 on 12-9-26. 6 | // Copyright (c) 2012年 开趣. All rights reserved. 7 | // 8 | 9 | #import "UIView+Layer.h" 10 | #import "QuartzCore/QuartzCore.h" 11 | 12 | #define DEGREES_TO_RADIANS(d) (d * M_PI / 180) 13 | 14 | @implementation UIView (Layer) 15 | 16 | 17 | + (UIView *)reflectImage:(UIImage *)image withFrame:(CGRect)frame opacity:(CGFloat)opacity atView:(UIView *)view 18 | { 19 | // Image Layer 20 | CALayer *imageLayer = [CALayer layer]; 21 | imageLayer.contents = (id)image.CGImage; 22 | imageLayer.frame = frame; 23 | // imageLayer.borderColor = [UIColor darkGrayColor].CGColor; 24 | // imageLayer.borderWidth = 6.0; 25 | [view.layer addSublayer:imageLayer]; 26 | 27 | // Reflection Layer 28 | CALayer *reflectionLayer = [CALayer layer]; 29 | reflectionLayer.contents = imageLayer.contents; 30 | reflectionLayer.frame = CGRectMake(imageLayer.frame.origin.x, imageLayer.frame.origin.y + imageLayer.frame.size.height, imageLayer.frame.size.width, imageLayer.frame.size.height); 31 | // reflectionLayer.borderColor = imageLayer.borderColor; 32 | // reflectionLayer.borderWidth = imageLayer.borderWidth; 33 | reflectionLayer.opacity = opacity; 34 | // Transform X by 180 degrees 35 | [reflectionLayer setValue:[NSNumber numberWithFloat:DEGREES_TO_RADIANS(180)] forKeyPath:@"transform.rotation.x"]; 36 | 37 | // Gradient Layer - Use as mask 38 | CAGradientLayer *gradientLayer = [CAGradientLayer layer]; 39 | gradientLayer.bounds = reflectionLayer.bounds; 40 | gradientLayer.position = CGPointMake(reflectionLayer.bounds.size.width / 2, reflectionLayer.bounds.size.height * 0.5); 41 | gradientLayer.colors = [NSArray arrayWithObjects:(id)[[UIColor clearColor] CGColor],(id)[[UIColor whiteColor] CGColor], nil]; 42 | gradientLayer.startPoint = CGPointMake(0.5, 0.6); 43 | gradientLayer.endPoint = CGPointMake(0.5, 1.0); 44 | 45 | // Add gradient layer as a mask 46 | reflectionLayer.mask = gradientLayer; 47 | [view.layer addSublayer:reflectionLayer]; 48 | 49 | return view; 50 | } 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /Libraries/EPubReader/EPubBook.h: -------------------------------------------------------------------------------- 1 | // 2 | // EPub 3 | // 4 | // Created by line0 on 13-3-4. 5 | // Copyright (c) 2013年 wsk. All rights reserved. 6 | // 7 | 8 | #import 9 | #import "TouchXML.h" 10 | 11 | //解析EPub,返回书的章节集合等属性 12 | 13 | 14 | @interface EPubBook : NSObject 15 | //书名 16 | @property (nonatomic, readonly) NSString *bookName; 17 | //章节集合数目 18 | @property (nonatomic, readonly) NSArray *spineArray; 19 | //书文件路径 20 | @property (nonatomic, readonly) NSString *bookPath; 21 | //判断是否解析成功 22 | @property (nonatomic, readonly) BOOL parseSucceed; 23 | //解压后书的基目录 24 | @property (nonatomic, readonly) NSString *bookBasePath; 25 | 26 | - (id)initWithEPubBookPath:(NSString *)bookPath; 27 | 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /Libraries/EPubReader/EPubBook.m: -------------------------------------------------------------------------------- 1 | // 2 | // EPub.m 3 | // 4 | // Created by line0 on 13-3-4. 5 | // Copyright (c) 2013年 wsk. All rights reserved. 6 | // 7 | 8 | #import "EPubBook.h" 9 | #import "ZipArchive.h" 10 | #import "EPubChapter.h" 11 | #import "EPubConfig.h" 12 | 13 | @interface EPubBook () 14 | @property (readonly, nonatomic) NSString *opfPath; 15 | @property (readonly, nonatomic) NSString *ncxPath; 16 | 17 | @end 18 | 19 | @implementation EPubBook 20 | 21 | - (id)initWithEPubBookPath:(NSString *)bookPath 22 | { 23 | if((self = [super init])) 24 | { 25 | _bookPath = bookPath; 26 | int loc1 = [bookPath rangeOfString:@"/" options:NSBackwardsSearch].location + 1; 27 | int loc2 = [bookPath rangeOfString:@"." options:NSBackwardsSearch].location; 28 | int len = loc2 - loc1; 29 | _bookName = [bookPath substringWithRange:NSMakeRange(loc1, len)]; 30 | _spineArray = [[NSMutableArray alloc] init]; 31 | } 32 | 33 | [self unzipBook]; 34 | [self parseManifestFile]; 35 | [self parseOPFFile]; 36 | 37 | return self; 38 | } 39 | 40 | - (BOOL)unzipBook 41 | { 42 | ZipArchive *zipArchive = [[ZipArchive alloc] init]; 43 | if( [zipArchive UnzipOpenFile:self.bookPath]) 44 | { 45 | NSString *strPath=[NSString stringWithFormat:@"%@/%@",kDocuments, self.bookName]; 46 | NSFileManager *filemanager=[[NSFileManager alloc] init]; 47 | if (![filemanager fileExistsAtPath:strPath]) 48 | { 49 | BOOL ret = [zipArchive UnzipFileTo:[NSString stringWithFormat:@"%@/",strPath] overWrite:YES]; 50 | if( NO ==ret ) 51 | { 52 | NSLog(@"解压失败"); 53 | } 54 | [zipArchive UnzipCloseFile]; 55 | 56 | return ret; 57 | } 58 | else 59 | { 60 | return YES; 61 | } 62 | } 63 | 64 | return NO; 65 | } 66 | 67 | - (void)parseManifestFile 68 | { 69 | NSString *manifestFilePath = [NSString stringWithFormat:@"%@/%@/META-INF/container.xml", kDocuments, self.bookName]; 70 | NSFileManager *fileManager = [[NSFileManager alloc] init]; 71 | if ([fileManager fileExistsAtPath:manifestFilePath]) 72 | { 73 | NSURL *filePathUrl = [NSURL fileURLWithPath:manifestFilePath]; 74 | CXMLDocument *manifestFile = [[CXMLDocument alloc] initWithContentsOfURL:filePathUrl options:0 error:nil]; 75 | CXMLNode *opfPath = [manifestFile nodeForXPath:@"//@full-path[1]" error:nil]; 76 | _opfPath = [NSString stringWithFormat:@"%@/%@/%@", kDocuments, self.bookName, [opfPath stringValue]] ; 77 | } 78 | else 79 | { 80 | _opfPath = nil; 81 | } 82 | } 83 | 84 | - (void)parseOPFFile 85 | { 86 | NSURL *opfPathUrl = [NSURL fileURLWithPath:self.opfPath]; 87 | CXMLDocument *opfFile = [[CXMLDocument alloc] initWithContentsOfURL:opfPathUrl options:0 error:nil]; 88 | NSDictionary *opfNamespaceMapings = [NSDictionary dictionaryWithObject:@"http://www.idpf.org/2007/opf" forKey:@"opf"]; 89 | NSArray *itemsArray = [opfFile nodesForXPath:@"//opf:item" namespaceMappings:opfNamespaceMapings error:nil]; 90 | 91 | NSString *ncxFileName; 92 | NSMutableDictionary *itemDictionary = [[NSMutableDictionary alloc] init]; 93 | for (CXMLElement *element in itemsArray) 94 | { 95 | [itemDictionary setValue:[[element attributeForName:@"href"] stringValue] forKey:[[element attributeForName:@"id"] stringValue]]; 96 | NSString *mediaType = [[element attributeForName:@"media-type"] stringValue]; 97 | if([mediaType isEqualToString:@"application/x-dtbncx+xml"]) 98 | { 99 | ncxFileName = [[element attributeForName:@"href"] stringValue]; 100 | } 101 | 102 | if([mediaType isEqualToString:@"application/xhtml+xml"]) 103 | { 104 | ncxFileName = [[element attributeForName:@"href"] stringValue]; 105 | } 106 | } 107 | 108 | int lastSlash = [self.opfPath rangeOfString:@"/" options:NSBackwardsSearch].location; 109 | _bookBasePath = [self.opfPath substringToIndex:(lastSlash + 1)]; 110 | _ncxPath = [NSString stringWithFormat:@"%@%@", _bookBasePath, ncxFileName]; 111 | NSURL *ncxPathUrl = [NSURL fileURLWithPath:self.ncxPath]; 112 | CXMLDocument *ncxToc = [[CXMLDocument alloc] initWithContentsOfURL:ncxPathUrl options:0 error:nil]; 113 | NSMutableDictionary *titleDictionary = [[NSMutableDictionary alloc] init]; 114 | for (CXMLElement *element in itemsArray) 115 | { 116 | NSString *href = [[element attributeForName:@"href"] stringValue]; 117 | NSString *xpath = [NSString stringWithFormat:@"//ncx:content[@src='%@']/../ncx:navLabel/ncx:text", href]; 118 | NSDictionary *ncxNamespaceMappings = [NSDictionary dictionaryWithObject:@"http://www.daisy.org/z3986/2005/ncx/" forKey:@"ncx"]; 119 | NSArray *navPoints = [ncxToc nodesForXPath:xpath namespaceMappings:ncxNamespaceMappings error:nil]; 120 | if([navPoints count] != 0) 121 | { 122 | CXMLElement *titleElement = [navPoints objectAtIndex:0]; 123 | [titleDictionary setValue:[titleElement stringValue] forKey:href]; 124 | } 125 | } 126 | 127 | NSArray *itemRefsArray = [opfFile nodesForXPath:@"//opf:itemref" namespaceMappings:opfNamespaceMapings error:nil]; 128 | NSMutableArray *tmpArray = [[NSMutableArray alloc] init]; 129 | int count = 0; 130 | for (CXMLElement *element in itemRefsArray) 131 | { 132 | NSString *chapHref = [itemDictionary valueForKey:[[element attributeForName:@"idref"] stringValue]]; 133 | NSString *spinePath = [NSString stringWithFormat:@"%@%@", self.bookBasePath, chapHref]; 134 | NSString *spineTitle = [titleDictionary valueForKey:chapHref]; 135 | EPubChapter *chapter = [[EPubChapter alloc] init]; 136 | [chapter setSpineIndex:count]; 137 | [chapter setSpinePath:spinePath]; 138 | [chapter setTitle:spineTitle]; 139 | count++; 140 | [tmpArray addObject:chapter]; 141 | } 142 | 143 | _spineArray = [NSArray arrayWithArray:tmpArray]; 144 | _parseSucceed = self.spineArray.count > 0; 145 | } 146 | 147 | 148 | 149 | @end 150 | -------------------------------------------------------------------------------- /Libraries/EPubReader/EPubBookmark.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by line0 on 13-3-4. 3 | // Copyright (c) 2013年 wsk. All rights reserved. 4 | // 5 | 6 | //本类定义书签的数据结构 7 | 8 | #import 9 | 10 | @interface EPubBookmark : NSObject 11 | 12 | @property (nonatomic, readonly) NSInteger bookmarkID; //书签的ID号,用以对书签的修改. 13 | @property (nonatomic, strong) NSString *markName; //书签名,取当前章节标题 14 | @property (nonatomic, strong) NSString *description; //书签描述,截取当前页的开始20个字符 15 | @property (nonatomic, strong) NSDate *addTime; //添加书签的时间 16 | @property (nonatomic, assign) NSInteger pageIndexInSpine; //此页在章节中的索引值,从0开始 17 | @property (nonatomic, assign) NSInteger spineIndex; //书签所在章节索引值,从0开始 18 | 19 | - (id)initWithBookmarkID:(NSInteger)bookmarkID; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /Libraries/EPubReader/EPubBookmark.m: -------------------------------------------------------------------------------- 1 | // 2 | // Created by line0 on 13-3-4. 3 | // Copyright (c) 2013年 wsk. All rights reserved. 4 | // 5 | 6 | #import "EPubBookmark.h" 7 | 8 | #define kMarkName @"kmarkName" 9 | #define kAddTime @"addTime" 10 | #define kPageIndexInSpine @"pageIndexInSpine" 11 | #define kSpineIndex @"spineIndex" 12 | #define kBookmarkID @"bookmarkID" 13 | #define kDescription @"description" 14 | 15 | @implementation EPubBookmark 16 | 17 | - (id)initWithBookmarkID:(NSInteger)bookmarkID 18 | { 19 | self = [self init]; 20 | _bookmarkID = bookmarkID; 21 | return self; 22 | } 23 | 24 | - (void)encodeWithCoder:(NSCoder *)encoder 25 | { 26 | [encoder encodeObject:self.markName forKey:kMarkName]; 27 | [encoder encodeObject:self.description forKey:kDescription]; 28 | [encoder encodeObject:self.addTime forKey:kAddTime]; 29 | [encoder encodeInteger:self.pageIndexInSpine forKey:kPageIndexInSpine]; 30 | [encoder encodeInteger:self.spineIndex forKey:kSpineIndex]; 31 | [encoder encodeInteger:self.bookmarkID forKey:kBookmarkID]; 32 | } 33 | 34 | - (id)initWithCoder:(NSCoder *)decoder 35 | { 36 | self = [super init]; 37 | if (self) 38 | { 39 | self.markName = [decoder decodeObjectForKey:kMarkName]; 40 | self.addTime = [decoder decodeObjectForKey:kAddTime]; 41 | self.pageIndexInSpine = [decoder decodeIntegerForKey:kPageIndexInSpine]; 42 | self.spineIndex = [decoder decodeIntegerForKey:kSpineIndex]; 43 | _bookmarkID = [decoder decodeIntegerForKey:kBookmarkID]; 44 | self.description = [decoder decodeObjectForKey:kDescription]; 45 | } 46 | 47 | return self; 48 | } 49 | 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /Libraries/EPubReader/EPubBookmarkManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // BookMarkManager.h 3 | // FuYin 4 | // 5 | // Created by line0 on 13-3-9. 6 | // Copyright (c) 2013年 wsk. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "EPubBookmark.h" 11 | 12 | //书签管理器,所有书的书签存在一个数据库里,不同的书签存在一个独立的表里,bookName作为书签表的名字。 13 | 14 | @interface EPubBookmarkManager : NSObject 15 | 16 | - (id)initWithBookName:(NSString *)bookName; 17 | 18 | - (BOOL)addBookmark:(EPubBookmark *)bookmark; 19 | - (BOOL)deleteBookmark:(EPubBookmark *)bookmark; 20 | - (NSArray *)allBookmark; 21 | - (EPubBookmark *)lastBookmark; 22 | - (NSInteger)lastBookmarkID; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /Libraries/EPubReader/EPubBookmarkManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // BookMarkManager.m 3 | // FuYin 4 | // 5 | // Created by line0 on 13-3-9. 6 | // Copyright (c) 2013年 wsk. All rights reserved. 7 | // 8 | 9 | #import "EPubBookmarkManager.h" 10 | #import "FMDatabase.h" 11 | #import "NSDate+Addition.h" 12 | #import "EPubConfig.h" 13 | 14 | 15 | @interface EPubBookmarkManager () 16 | @property (strong, nonatomic) FMDatabase *db; 17 | @property (strong, nonatomic) NSString *tableName; 18 | 19 | @end 20 | 21 | @implementation EPubBookmarkManager 22 | 23 | - (id)initWithBookName:(NSString *)bookName 24 | { 25 | self = [self init]; 26 | self.tableName = bookName; 27 | self.db = [FMDatabase databaseWithPath:kEPubDBPath]; 28 | [self creatBookmarkTable]; 29 | 30 | return self; 31 | } 32 | 33 | - (BOOL)creatBookmarkTable 34 | { 35 | NSString *sqlKey = @"bookmarkID integer primary key, bookmark blob"; 36 | BOOL result = NO; 37 | if ([self.db open]) 38 | { 39 | NSString *sql = [NSString stringWithFormat:@"create table if not exists %@ (%@)", self.tableName, sqlKey]; 40 | result = [self.db executeUpdate:sql]; 41 | if ([self.db hadError]) 42 | NSLog(@"error:%@", [self.db lastError]); 43 | } 44 | [self.db close]; 45 | 46 | return result; 47 | } 48 | 49 | - (NSInteger)lastBookmarkID 50 | { 51 | NSString *sql = [NSString stringWithFormat:@"SELECT bookmarkID FROM %@", self.tableName]; 52 | FMResultSet *resultSet = nil; 53 | NSInteger bookmarkID = 0; 54 | if ([self.db open]) 55 | { 56 | resultSet = [self.db executeQuery:sql]; 57 | if ([self.db hadError]) 58 | NSLog(@"error:%@", [self.db lastError]); 59 | } 60 | 61 | while ([resultSet next]) 62 | bookmarkID = [resultSet intForColumn:@"bookmarkID"]; 63 | [self.db close]; 64 | 65 | return bookmarkID; 66 | } 67 | 68 | - (BOOL)addBookmark:(EPubBookmark *)bookmark 69 | { 70 | NSData *bookMarkData = [NSKeyedArchiver archivedDataWithRootObject:bookmark]; 71 | NSString *sql = [NSString stringWithFormat:@"INSERT INTO %@ (bookmark) VALUES (?)", self.tableName]; 72 | BOOL result = NO; 73 | if ([self.db open]) 74 | { 75 | result = [self.db executeUpdate:sql, bookMarkData]; 76 | if ([self.db hadError]) 77 | NSLog(@"error:%@", [self.db lastError]); 78 | } 79 | [self.db close]; 80 | return result; 81 | } 82 | 83 | - (BOOL)deleteBookmark:(EPubBookmark *)bookmark 84 | { 85 | NSInteger bookmarkID = bookmark.bookmarkID; 86 | NSString *sql = [NSString stringWithFormat:@"DELETE FROM %@ WHERE bookmarkID = %d", self.tableName, bookmarkID]; 87 | BOOL result = NO; 88 | if ([self.db open]) 89 | { 90 | result = [self.db executeUpdate:sql]; 91 | if ([self.db hadError]) 92 | NSLog(@"error:%@", [self.db lastError]); 93 | } 94 | [self.db close]; 95 | 96 | return result; 97 | } 98 | 99 | - (EPubBookmark *)lastBookmark 100 | { 101 | NSArray *bookmarks = [self allBookmark]; 102 | return [bookmarks lastObject]; 103 | } 104 | 105 | - (NSArray *)allBookmark 106 | { 107 | NSString *sql = [NSString stringWithFormat:@"SELECT %@ FROM %@", @"bookmark", self.tableName]; 108 | FMResultSet *resultSet = nil; 109 | NSMutableArray *resultArray = [NSMutableArray array]; 110 | if ([self.db open]) 111 | { 112 | resultSet = [self.db executeQuery:sql]; 113 | if ([self.db hadError]) 114 | NSLog(@"error:%@", [self.db lastError]); 115 | } 116 | 117 | while ([resultSet next]) 118 | { 119 | NSData *data = [resultSet objectForColumnName:@"bookmark"]; 120 | EPubBookmark *bookmark = [NSKeyedUnarchiver unarchiveObjectWithData:data]; 121 | [resultArray addObject:bookmark]; 122 | } 123 | [self.db close]; 124 | 125 | return resultArray; 126 | } 127 | 128 | @end 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /Libraries/EPubReader/EPubChapter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Chapter.h 3 | // 4 | // Created by line0 on 13-3-4. 5 | // Copyright (c) 2013年 wsk. All rights reserved. 6 | // 7 | 8 | 9 | #import 10 | 11 | //本类定义章节的数据结构,所有属性都在解析EPub文档时初始化写入。 12 | 13 | @interface EPubChapter : NSObject 14 | //章节的标题、目录完整路径、章节在整本书中的索引位置 15 | @property (nonatomic, strong) NSString *title; 16 | @property (nonatomic, strong) NSString *spinePath; 17 | @property (nonatomic, assign) NSInteger spineIndex; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Libraries/EPubReader/EPubChapter.m: -------------------------------------------------------------------------------- 1 | // 2 | // Chapter.m 3 | // 4 | // Created by line0 on 13-3-4. 5 | // Copyright (c) 2013年 wsk. All rights reserved. 6 | // 7 | 8 | #import "EPubChapter.h" 9 | 10 | @implementation EPubChapter 11 | 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Libraries/EPubReader/EPubChapterListView.h: -------------------------------------------------------------------------------- 1 | // 2 | // ChapterListView.h 3 | // FuYin 4 | // 5 | // Created by line0 on 13-3-4. 6 | // Copyright (c) 2013年 wsk. All rights reserved. 7 | // 8 | 9 | @class EPubChapter; 10 | @protocol ChapterListViewDelegate 11 | 12 | @required 13 | - (void)selectChapter:(EPubChapter *)chapter; 14 | 15 | @end 16 | 17 | 18 | //显示章节列表 19 | 20 | #import 21 | 22 | @interface EPubChapterListView : UIView 23 | @property (weak, nonatomic) id delegate; 24 | 25 | //显示章节视图 26 | @property (strong, nonatomic, readonly) UITableView *tableView; 27 | //章节数组 28 | @property (strong, nonatomic, readonly) NSMutableArray *spineArray; 29 | 30 | - (id)initWithFrame:(CGRect)frame andSpineArray:(NSArray *)spineArray; 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /Libraries/EPubReader/EPubChapterListView.m: -------------------------------------------------------------------------------- 1 | // 2 | // ChapterListView.m 3 | // FuYin 4 | // 5 | // Created by line0 on 13-3-4. 6 | // Copyright (c) 2013年 wsk. All rights reserved. 7 | // 8 | 9 | #import "EPubChapterListView.h" 10 | #import "EPubChapter.h" 11 | 12 | #define kChapterListCellIdentifer @"chapterListCellIdentifer" 13 | 14 | @interface EPubChapterListView () 15 | 16 | 17 | @end 18 | 19 | @implementation EPubChapterListView 20 | 21 | - (id)initWithFrame:(CGRect)frame andSpineArray:(NSArray *)spineArray 22 | { 23 | self = [self initWithFrame:frame]; 24 | 25 | _spineArray = [spineArray mutableCopy]; 26 | 27 | _tableView = [[UITableView alloc] initWithFrame:self.bounds style:UITableViewStylePlain]; 28 | [self.tableView setDelegate:self]; 29 | [self.tableView setDataSource:self]; 30 | [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:kChapterListCellIdentifer]; 31 | [self addSubview:self.tableView]; 32 | 33 | return self; 34 | } 35 | 36 | - (id)initWithFrame:(CGRect)frame 37 | { 38 | self = [super initWithFrame:frame]; 39 | if (self) 40 | { } 41 | return self; 42 | } 43 | 44 | 45 | #pragma mark - TableView Delegate && DataSource 46 | 47 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 48 | { 49 | return self.spineArray.count; 50 | } 51 | 52 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 53 | { 54 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kChapterListCellIdentifer]; 55 | EPubChapter *chapter = [self.spineArray objectAtIndex:indexPath.row]; 56 | [cell.textLabel setFont:[UIFont boldSystemFontOfSize:14]]; 57 | [cell.textLabel setText:chapter.title]; 58 | return cell; 59 | } 60 | 61 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 62 | { 63 | EPubChapter *chapter = [self.spineArray objectAtIndex:indexPath.row]; 64 | [self.delegate selectChapter:chapter]; 65 | } 66 | 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /Libraries/EPubReader/EPubConfig.h: -------------------------------------------------------------------------------- 1 | // 2 | // EPubDefine.h 3 | // 4 | // Created by line0 on 13-3-4. 5 | // Copyright (c) 2013年 wsk. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | #define kAPPName [[[NSBundle mainBundle]infoDictionary] objectForKey:@"CFBundleDisplayName"] 11 | #define kDocuments [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] 12 | 13 | //数据库地址,用于保存书签等 14 | #define kEPubDBPath [NSString stringWithFormat:@"%@/%@", kDocuments, @"EPub.db"] 15 | 16 | -------------------------------------------------------------------------------- /Libraries/EPubReader/EPubController.h: -------------------------------------------------------------------------------- 1 | // 2 | // EPubController 3 | // 4 | // Created by line0 on 13-3-4. 5 | // Copyright (c) 2013年 wsk. All rights reserved. 6 | // 7 | 8 | 9 | //EPub阅读控制器,所有的操作都应该通过本类的接口来完成。 10 | 11 | #import 12 | 13 | @class EPubBook; 14 | @class EPubView; 15 | @class EPubChapter; 16 | @class EPubBookmark; 17 | @class EPubChapterListView; 18 | @class EPubBookMarkManager; 19 | 20 | @interface EPubController : NSObject 21 | //已加载的epub书。 22 | @property (nonatomic, readonly) EPubBook *epubBook; 23 | //EPub阅读视图。 24 | @property (nonatomic, readonly) EPubView *epubView; 25 | //EPub章节列表视图 26 | @property (nonatomic, readonly) EPubChapterListView *chapterListView; 27 | 28 | //当前章节在书中的索引值,从0开始 29 | @property (nonatomic, readonly) int currentSpineIndex; 30 | //书籍总页数,等于所有章节页数之和 31 | @property (nonatomic, readonly) int totalPagesCount; 32 | 33 | 34 | //打开、关闭书籍 35 | - (void)openBook:(NSString *)bookPath atView:(UIView *)view withPageFrame:(CGRect)pageFrame; 36 | - (void)closeBook; 37 | 38 | //显示、隐藏章节列表 39 | - (void)showChapterListAtView:(UIView *)view withFrame:(CGRect)rect; 40 | - (void)hideChapterListView; 41 | 42 | ////控制文本字号增减 43 | //- (void)increaseTextFontSize:(NSInteger)size; 44 | //- (void)decreaseTextFontSize:(NSInteger)size; 45 | 46 | //跳转到当前章节的某一页 47 | - (void)gotoPageInCurrentSpine:(int)pageIndex; 48 | - (void)gotoPage:(int)pageIndex inSpine:(int)spineIndex; 49 | 50 | - (void)addBookmark; 51 | - (void)deleteBookmark:(EPubBookmark *)bookmark; 52 | 53 | 54 | @end 55 | 56 | 57 | -------------------------------------------------------------------------------- /Libraries/EPubReader/EPubController.m: -------------------------------------------------------------------------------- 1 | // 2 | // DetailViewController.m 3 | // 4 | // Created by line0 on 13-3-4. 5 | // Copyright (c) 2013年 wsk. All rights reserved. 6 | // 7 | 8 | #import "EPubController.h" 9 | #import "EPubChapter.h" 10 | #import "EPubBook.h" 11 | #import "EPubView.h" 12 | #import "MBProgressHUD.h" 13 | #import "MBPromptHUD.h" 14 | #import "EPubChapterListView.h" 15 | #import "EPubBookmarkManager.h" 16 | 17 | 18 | @interface EPubController() 19 | //展示EPubView的父视图 20 | @property (strong, readonly) UIView *epubParentView; 21 | //跳转页码 22 | @property (assign, nonatomic) NSInteger gotoPage; 23 | @property (strong, nonatomic) EPubBookmarkManager *bookmarkManager; 24 | 25 | 26 | @end 27 | 28 | 29 | @implementation EPubController 30 | 31 | 32 | #pragma mark - Loading 33 | 34 | - (void)showLoadingView 35 | { 36 | MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.epubParentView animated:YES]; 37 | [hud setDimBackground:YES]; 38 | [hud setLabelText:@"请稍等..."]; 39 | [hud setOpacity:0.4]; 40 | } 41 | 42 | - (void)hideLoadingView 43 | { 44 | [MBProgressHUD hideAllHUDsForView:self.epubParentView animated:YES]; 45 | } 46 | 47 | 48 | #pragma mark - Epub 49 | 50 | - (void)openBook:(NSString *)bookPath atView:(UIView *)view withPageFrame:(CGRect)pageFrame 51 | { 52 | _epubParentView = view; 53 | _epubBook = [[EPubBook alloc] initWithEPubBookPath:bookPath]; 54 | if (_epubBook.parseSucceed) 55 | { 56 | if (!_epubView) 57 | { 58 | [self showLoadingView]; 59 | 60 | _epubView = [[EPubView alloc] initWithFrame:pageFrame]; 61 | [self.epubView setDelegate:self]; 62 | [self.epubView loadChapter:[self.epubBook.spineArray objectAtIndex:0]]; 63 | [view addSubview:self.epubView]; 64 | } 65 | [self.epubView setHidden:NO]; 66 | } 67 | 68 | self.bookmarkManager = [[EPubBookmarkManager alloc] initWithBookName:self.epubBook.bookName]; 69 | } 70 | 71 | - (void)closeBook 72 | { 73 | [self.epubView setHidden:YES]; 74 | _epubBook = nil; 75 | _epubView = nil; 76 | _epubParentView = nil; 77 | _currentSpineIndex = 0; 78 | _totalPagesCount = 0; 79 | self.bookmarkManager = nil; 80 | } 81 | 82 | - (void)showChapterListAtView:(UIView *)view withFrame:(CGRect)rect 83 | { 84 | if (!_chapterListView) 85 | { 86 | _chapterListView = [[EPubChapterListView alloc] initWithFrame:rect andSpineArray:self.epubBook.spineArray]; 87 | [self.chapterListView setDelegate:self]; 88 | [view addSubview:self.chapterListView]; 89 | } 90 | [self.chapterListView setFrame:rect]; 91 | [self.chapterListView setHidden:NO]; 92 | } 93 | 94 | - (void)hideChapterListView 95 | { 96 | [self.chapterListView setHidden:YES]; 97 | } 98 | 99 | 100 | #pragma mark - ChapterListView Delegate 101 | 102 | - (void)selectChapter:(EPubChapter *)chapter 103 | { 104 | [self gotoPage:0 inSpine:chapter.spineIndex]; 105 | 106 | [self hideChapterListView]; 107 | } 108 | 109 | 110 | #pragma mark - EPubView Delegate Method 111 | 112 | - (void)gotoPrevSpine 113 | { 114 | if (_currentSpineIndex > 0) 115 | { 116 | [self gotoPage:0 inSpine:--_currentSpineIndex]; 117 | } 118 | } 119 | 120 | - (void)gotoNextSpine 121 | { 122 | if (_currentSpineIndex < self.epubBook.spineArray.count - 1) 123 | [self gotoPage:0 inSpine:++_currentSpineIndex]; 124 | } 125 | 126 | - (void)epubViewLoadFinished 127 | { 128 | [self hideLoadingView]; 129 | 130 | if (self.epubView.next) 131 | [self gotoPageInCurrentSpine:0]; 132 | else 133 | [self gotoPageInCurrentSpine:self.epubView.pageCount - 1]; 134 | } 135 | 136 | 137 | #pragma mark - Read Control 138 | 139 | - (void)gotoPageInCurrentSpine:(int)pageIndex 140 | { 141 | [self.epubView gotoPage:pageIndex]; 142 | } 143 | 144 | - (void)gotoPage:(int)pageIndex inSpine:(int)spineIndex 145 | { 146 | _currentSpineIndex = spineIndex; 147 | self.gotoPage = pageIndex; 148 | Chapter *chapter = [self.epubBook.spineArray objectAtIndex:spineIndex]; 149 | [self.epubView loadChapter:chapter]; 150 | 151 | [self showLoadingView]; 152 | } 153 | 154 | 155 | #pragma mark - BookMark 156 | 157 | - (void)addBookmark 158 | { 159 | NSInteger lastbookmarkID = [self.bookmarkManager lastBookmarkID]; 160 | EPubBookmark *bookmark = [[EPubBookmark alloc] initWithBookmarkID:lastbookmarkID + 1]; 161 | bookmark.markName = @"杀身成仁,舍身取义"; 162 | bookmark.addTime = [NSDate date]; 163 | bookmark.pageIndexInSpine = 2; 164 | bookmark.spineIndex = 3; 165 | [self.bookmarkManager addBookmark:bookmark]; 166 | 167 | NSLog(@"bookmarkName:%@", [self.bookmarkManager lastBookmark].markName); 168 | } 169 | 170 | - (void)deleteBookmark:(EPubBookmark *)bookmark 171 | { 172 | 173 | } 174 | 175 | 176 | @end 177 | -------------------------------------------------------------------------------- /Libraries/EPubReader/EPubView.h: -------------------------------------------------------------------------------- 1 | // 2 | // EPubView.h 3 | // 4 | // Created by line0 on 13-3-4. 5 | // Copyright (c) 2013年 wsk. All rights reserved. 6 | // 7 | 8 | //本类用来装载要显示的章节,因为一次装载整本书,会导致第一次加载时间过长。对本类的控制应通过EPubController类来操作。 9 | 10 | #import 11 | @class Chapter; 12 | 13 | @protocol EPubViewDelegate 14 | 15 | @required 16 | - (void)gotoPrevSpine; 17 | - (void)gotoNextSpine; 18 | 19 | @optional 20 | - (void)epubViewLoadFinished; 21 | 22 | @end 23 | 24 | 25 | @interface EPubView : UIView 26 | @property (nonatomic, weak) id delegate; 27 | //用来承载文本 28 | @property (nonatomic, readonly) UIWebView *webView; 29 | //当前显示的章节 30 | @property (nonatomic, readonly) Chapter *chapter; 31 | 32 | //当前页在当前章节的索引值,从0开始 33 | @property (nonatomic, readonly) int currentPageIndex; 34 | //当前章节的页数 35 | @property (nonatomic, readonly) int pageCount; 36 | //文字字号大小 37 | @property (nonatomic, assign) int fontSize; 38 | 39 | //判断手势是上一章还是下一章,默认为YES,即为下一章。 40 | @property (nonatomic, readonly, getter = isNext) BOOL next; 41 | 42 | 43 | //装载章节 44 | - (void)loadChapter:(Chapter *)chapter; 45 | - (void)gotoPage:(int)pageIndex; 46 | - (void)setFontSize:(int)fontSize; 47 | 48 | 49 | @end 50 | 51 | 52 | -------------------------------------------------------------------------------- /Libraries/EPubReader/EPubView.m: -------------------------------------------------------------------------------- 1 | // 2 | // EPubView.m 3 | // 4 | // Created by line0 on 13-3-4. 5 | // Copyright (c) 2013年 wsk. All rights reserved. 6 | // 7 | 8 | #import "EPubView.h" 9 | #import "EPubChapter.h" 10 | 11 | 12 | @interface EPubView () 13 | @property (assign, nonatomic) CGPoint touchBeginPoint; 14 | 15 | @end 16 | 17 | 18 | @implementation EPubView 19 | 20 | - (id)initWithFrame:(CGRect)frame 21 | { 22 | self = [super initWithFrame:frame]; 23 | if (self) 24 | { 25 | self.backgroundColor = [UIColor orangeColor]; 26 | _webView = [[UIWebView alloc] initWithFrame:self.bounds]; 27 | _webView.delegate = self; 28 | _webView.scrollView.alwaysBounceHorizontal = YES; 29 | _webView.scrollView.alwaysBounceVertical = NO; 30 | _webView.scrollView.bounces = YES; 31 | _webView.scrollView.showsVerticalScrollIndicator = NO; 32 | _webView.scrollView.showsHorizontalScrollIndicator = NO; 33 | _webView.scrollView.delegate = self; 34 | _webView.scrollView.pagingEnabled = YES; 35 | _webView.backgroundColor = [UIColor clearColor]; 36 | _webView.scrollView.backgroundColor = [UIColor clearColor]; 37 | [self addSubview:self.webView]; 38 | 39 | _fontSize = 100; 40 | _next = YES; 41 | } 42 | return self; 43 | } 44 | 45 | - (void)loadChapter:(EPubChapter *)chapter 46 | { 47 | NSURL *url = [NSURL fileURLWithPath:chapter.spinePath]; 48 | [self.webView loadRequest:[NSURLRequest requestWithURL:url]]; 49 | } 50 | 51 | - (void)gotoPage:(int)pageIndex 52 | { 53 | _currentPageIndex = pageIndex; 54 | float pageOffset = pageIndex * self.webView.bounds.size.width; 55 | [self.webView.scrollView setContentOffset:CGPointMake(pageOffset, 0) animated:NO];; 56 | } 57 | 58 | - (void)setFontSize:(int)fontSize 59 | { 60 | 61 | if(_fontSize <= 200 || _fontSize >= 50) 62 | { 63 | _fontSize = fontSize; 64 | [self loadChapter:self.chapter]; 65 | } 66 | } 67 | 68 | 69 | #pragma mark - WebView Delegate Method 70 | 71 | - (void)webViewDidFinishLoad:(UIWebView *)theWebView 72 | { 73 | NSString *varMySheet = @"var mySheet = document.styleSheets[0];"; 74 | NSString *addCSSRule = @"function addCSSRule(selector, newRule) {" 75 | "if (mySheet.addRule) {" 76 | "mySheet.addRule(selector, newRule);" // For Internet Explorer 77 | "} else {" 78 | "ruleIndex = mySheet.cssRules.length;" 79 | "mySheet.insertRule(selector + '{' + newRule + ';}', ruleIndex);" // For Firefox, Chrome, etc. 80 | "}" 81 | "}"; 82 | 83 | NSString *insertRule1 = [NSString stringWithFormat:@"addCSSRule('html', 'padding: 10px; height: %fpx; -webkit-column-gap: 20px; -webkit-column-width: %fpx;')", self.webView.frame.size.height - 20, self.webView.frame.size.width - 20]; 84 | NSString *insertRule2 = [NSString stringWithFormat:@"addCSSRule('p', 'text-align: justify;')"]; 85 | NSString *setTextSizeRule = [NSString stringWithFormat:@"addCSSRule('body', '-webkit-text-size-adjust: %d%%;')", _fontSize]; 86 | 87 | [self.webView stringByEvaluatingJavaScriptFromString:varMySheet]; 88 | [self.webView stringByEvaluatingJavaScriptFromString:addCSSRule]; 89 | [self.webView stringByEvaluatingJavaScriptFromString:insertRule1]; 90 | [self.webView stringByEvaluatingJavaScriptFromString:insertRule2]; 91 | [self.webView stringByEvaluatingJavaScriptFromString:setTextSizeRule]; 92 | 93 | int totalWidth = [[self.webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollWidth"] intValue]; 94 | _pageCount = ceil(totalWidth / self.webView.bounds.size.width); 95 | _currentPageIndex = 0; 96 | if ([self.delegate respondsToSelector:@selector(epubViewLoadFinished)]) 97 | { 98 | [self.delegate epubViewLoadFinished]; 99 | } 100 | } 101 | 102 | 103 | #pragma mark - ScrollView Delegate Method 104 | 105 | - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView 106 | { 107 | self.touchBeginPoint = scrollView.contentOffset; 108 | } 109 | 110 | - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView 111 | { 112 | CGFloat pageWidth = scrollView.frame.size.width; 113 | _currentPageIndex = ceil(scrollView.contentOffset.x / pageWidth); 114 | 115 | CGPoint touchEndPoint = scrollView.contentOffset; 116 | _next = self.touchBeginPoint.x > touchEndPoint.x + 5; 117 | 118 | if (!self.next) 119 | { 120 | if (_currentPageIndex == 0) 121 | { 122 | [self.delegate gotoPrevSpine]; 123 | } 124 | } 125 | else 126 | { 127 | if(_currentPageIndex + 1 == _pageCount) 128 | { 129 | [self.delegate gotoNextSpine]; 130 | } 131 | } 132 | } 133 | 134 | 135 | @end 136 | -------------------------------------------------------------------------------- /Libraries/FMDB/FMDatabase.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "sqlite3.h" 3 | #import "FMResultSet.h" 4 | #import "FMDatabasePool.h" 5 | 6 | 7 | #if ! __has_feature(objc_arc) 8 | #define FMDBAutorelease(__v) ([__v autorelease]); 9 | #define FMDBReturnAutoreleased FMDBAutorelease 10 | 11 | #define FMDBRetain(__v) ([__v retain]); 12 | #define FMDBReturnRetained FMDBRetain 13 | 14 | #define FMDBRelease(__v) ([__v release]); 15 | 16 | #define FMDBDispatchQueueRelease(__v) (dispatch_release(__v)); 17 | #else 18 | // -fobjc-arc 19 | #define FMDBAutorelease(__v) 20 | #define FMDBReturnAutoreleased(__v) (__v) 21 | 22 | #define FMDBRetain(__v) 23 | #define FMDBReturnRetained(__v) (__v) 24 | 25 | #define FMDBRelease(__v) 26 | 27 | #if TARGET_OS_IPHONE 28 | // Compiling for iOS 29 | #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 30 | // iOS 6.0 or later 31 | #define FMDBDispatchQueueRelease(__v) 32 | #else 33 | // iOS 5.X or earlier 34 | #define FMDBDispatchQueueRelease(__v) (dispatch_release(__v)); 35 | #endif 36 | #else 37 | // Compiling for Mac OS X 38 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 39 | // Mac OS X 10.8 or later 40 | #define FMDBDispatchQueueRelease(__v) 41 | #else 42 | // Mac OS X 10.7 or earlier 43 | #define FMDBDispatchQueueRelease(__v) (dispatch_release(__v)); 44 | #endif 45 | #endif 46 | #endif 47 | 48 | 49 | @interface FMDatabase : NSObject { 50 | 51 | sqlite3* _db; 52 | NSString* _databasePath; 53 | BOOL _logsErrors; 54 | BOOL _crashOnErrors; 55 | BOOL _traceExecution; 56 | BOOL _checkedOut; 57 | BOOL _shouldCacheStatements; 58 | BOOL _isExecutingStatement; 59 | BOOL _inTransaction; 60 | int _busyRetryTimeout; 61 | 62 | NSMutableDictionary *_cachedStatements; 63 | NSMutableSet *_openResultSets; 64 | NSMutableSet *_openFunctions; 65 | 66 | } 67 | 68 | 69 | @property (atomic, assign) BOOL traceExecution; 70 | @property (atomic, assign) BOOL checkedOut; 71 | @property (atomic, assign) int busyRetryTimeout; 72 | @property (atomic, assign) BOOL crashOnErrors; 73 | @property (atomic, assign) BOOL logsErrors; 74 | @property (atomic, retain) NSMutableDictionary *cachedStatements; 75 | 76 | 77 | + (id)databaseWithPath:(NSString*)inPath; 78 | - (id)initWithPath:(NSString*)inPath; 79 | 80 | - (BOOL)open; 81 | #if SQLITE_VERSION_NUMBER >= 3005000 82 | - (BOOL)openWithFlags:(int)flags; 83 | #endif 84 | - (BOOL)close; 85 | - (BOOL)goodConnection; 86 | - (void)clearCachedStatements; 87 | - (void)closeOpenResultSets; 88 | - (BOOL)hasOpenResultSets; 89 | 90 | // encryption methods. You need to have purchased the sqlite encryption extensions for these to work. 91 | - (BOOL)setKey:(NSString*)key; 92 | - (BOOL)rekey:(NSString*)key; 93 | 94 | - (NSString *)databasePath; 95 | 96 | - (NSString*)lastErrorMessage; 97 | 98 | - (int)lastErrorCode; 99 | - (BOOL)hadError; 100 | - (NSError*)lastError; 101 | 102 | - (sqlite_int64)lastInsertRowId; 103 | 104 | - (sqlite3*)sqliteHandle; 105 | 106 | - (BOOL)update:(NSString*)sql withErrorAndBindings:(NSError**)outErr, ...; 107 | - (BOOL)executeUpdate:(NSString*)sql, ...; 108 | - (BOOL)executeUpdateWithFormat:(NSString *)format, ...; 109 | - (BOOL)executeUpdate:(NSString*)sql withArgumentsInArray:(NSArray *)arguments; 110 | - (BOOL)executeUpdate:(NSString*)sql withParameterDictionary:(NSDictionary *)arguments; 111 | 112 | - (FMResultSet *)executeQuery:(NSString*)sql, ...; 113 | - (FMResultSet *)executeQueryWithFormat:(NSString*)format, ...; 114 | - (FMResultSet *)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray *)arguments; 115 | - (FMResultSet *)executeQuery:(NSString *)sql withParameterDictionary:(NSDictionary *)arguments; 116 | 117 | - (BOOL)rollback; 118 | - (BOOL)commit; 119 | - (BOOL)beginTransaction; 120 | - (BOOL)beginDeferredTransaction; 121 | - (BOOL)inTransaction; 122 | - (BOOL)shouldCacheStatements; 123 | - (void)setShouldCacheStatements:(BOOL)value; 124 | 125 | #if SQLITE_VERSION_NUMBER >= 3007000 126 | - (BOOL)startSavePointWithName:(NSString*)name error:(NSError**)outErr; 127 | - (BOOL)releaseSavePointWithName:(NSString*)name error:(NSError**)outErr; 128 | - (BOOL)rollbackToSavePointWithName:(NSString*)name error:(NSError**)outErr; 129 | - (NSError*)inSavePoint:(void (^)(BOOL *rollback))block; 130 | #endif 131 | 132 | + (BOOL)isSQLiteThreadSafe; 133 | + (NSString*)sqliteLibVersion; 134 | 135 | - (int)changes; 136 | 137 | - (void)makeFunctionNamed:(NSString*)name maximumArguments:(int)count withBlock:(void (^)(sqlite3_context *context, int argc, sqlite3_value **argv))block; 138 | 139 | @end 140 | 141 | @interface FMStatement : NSObject { 142 | sqlite3_stmt *_statement; 143 | NSString *_query; 144 | long _useCount; 145 | } 146 | 147 | @property (atomic, assign) long useCount; 148 | @property (atomic, retain) NSString *query; 149 | @property (atomic, assign) sqlite3_stmt *statement; 150 | 151 | - (void)close; 152 | - (void)reset; 153 | 154 | @end 155 | 156 | -------------------------------------------------------------------------------- /Libraries/FMDB/FMDatabaseAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // FMDatabaseAdditions.h 3 | // fmkit 4 | // 5 | // Created by August Mueller on 10/30/05. 6 | // Copyright 2005 Flying Meat Inc.. All rights reserved. 7 | // 8 | 9 | #import 10 | @interface FMDatabase (FMDatabaseAdditions) 11 | 12 | 13 | - (int)intForQuery:(NSString*)objs, ...; 14 | - (long)longForQuery:(NSString*)objs, ...; 15 | - (BOOL)boolForQuery:(NSString*)objs, ...; 16 | - (double)doubleForQuery:(NSString*)objs, ...; 17 | - (NSString*)stringForQuery:(NSString*)objs, ...; 18 | - (NSData*)dataForQuery:(NSString*)objs, ...; 19 | - (NSDate*)dateForQuery:(NSString*)objs, ...; 20 | 21 | // Notice that there's no dataNoCopyForQuery:. 22 | // That would be a bad idea, because we close out the result set, and then what 23 | // happens to the data that we just didn't copy? Who knows, not I. 24 | 25 | 26 | - (BOOL)tableExists:(NSString*)tableName; 27 | - (FMResultSet*)getSchema; 28 | - (FMResultSet*)getTableSchema:(NSString*)tableName; 29 | 30 | - (BOOL)columnExists:(NSString*)columnName inTableWithName:(NSString*)tableName; 31 | 32 | - (BOOL)validateSQL:(NSString*)sql error:(NSError**)error; 33 | 34 | // deprecated - use columnExists:inTableWithName: instead. 35 | - (BOOL)columnExists:(NSString*)tableName columnName:(NSString*)columnName __attribute__ ((deprecated)); 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /Libraries/FMDB/FMDatabaseAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // FMDatabaseAdditions.m 3 | // fmkit 4 | // 5 | // Created by August Mueller on 10/30/05. 6 | // Copyright 2005 Flying Meat Inc.. All rights reserved. 7 | // 8 | 9 | #import "FMDatabase.h" 10 | #import "FMDatabaseAdditions.h" 11 | 12 | @interface FMDatabase (PrivateStuff) 13 | - (FMResultSet *)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray*)arrayArgs orDictionary:(NSDictionary *)dictionaryArgs orVAList:(va_list)args; 14 | @end 15 | 16 | @implementation FMDatabase (FMDatabaseAdditions) 17 | 18 | #define RETURN_RESULT_FOR_QUERY_WITH_SELECTOR(type, sel) \ 19 | va_list args; \ 20 | va_start(args, query); \ 21 | FMResultSet *resultSet = [self executeQuery:query withArgumentsInArray:0x00 orDictionary:0x00 orVAList:args]; \ 22 | va_end(args); \ 23 | if (![resultSet next]) { return (type)0; } \ 24 | type ret = [resultSet sel:0]; \ 25 | [resultSet close]; \ 26 | [resultSet setParentDB:nil]; \ 27 | return ret; 28 | 29 | 30 | - (NSString*)stringForQuery:(NSString*)query, ... { 31 | RETURN_RESULT_FOR_QUERY_WITH_SELECTOR(NSString *, stringForColumnIndex); 32 | } 33 | 34 | - (int)intForQuery:(NSString*)query, ... { 35 | RETURN_RESULT_FOR_QUERY_WITH_SELECTOR(int, intForColumnIndex); 36 | } 37 | 38 | - (long)longForQuery:(NSString*)query, ... { 39 | RETURN_RESULT_FOR_QUERY_WITH_SELECTOR(long, longForColumnIndex); 40 | } 41 | 42 | - (BOOL)boolForQuery:(NSString*)query, ... { 43 | RETURN_RESULT_FOR_QUERY_WITH_SELECTOR(BOOL, boolForColumnIndex); 44 | } 45 | 46 | - (double)doubleForQuery:(NSString*)query, ... { 47 | RETURN_RESULT_FOR_QUERY_WITH_SELECTOR(double, doubleForColumnIndex); 48 | } 49 | 50 | - (NSData*)dataForQuery:(NSString*)query, ... { 51 | RETURN_RESULT_FOR_QUERY_WITH_SELECTOR(NSData *, dataForColumnIndex); 52 | } 53 | 54 | - (NSDate*)dateForQuery:(NSString*)query, ... { 55 | RETURN_RESULT_FOR_QUERY_WITH_SELECTOR(NSDate *, dateForColumnIndex); 56 | } 57 | 58 | 59 | - (BOOL)tableExists:(NSString*)tableName { 60 | 61 | tableName = [tableName lowercaseString]; 62 | 63 | FMResultSet *rs = [self executeQuery:@"select [sql] from sqlite_master where [type] = 'table' and lower(name) = ?", tableName]; 64 | 65 | //if at least one next exists, table exists 66 | BOOL returnBool = [rs next]; 67 | 68 | //close and free object 69 | [rs close]; 70 | 71 | return returnBool; 72 | } 73 | 74 | /* 75 | get table with list of tables: result colums: type[STRING], name[STRING],tbl_name[STRING],rootpage[INTEGER],sql[STRING] 76 | check if table exist in database (patch from OZLB) 77 | */ 78 | - (FMResultSet*)getSchema { 79 | 80 | //result colums: type[STRING], name[STRING],tbl_name[STRING],rootpage[INTEGER],sql[STRING] 81 | FMResultSet *rs = [self executeQuery:@"SELECT type, name, tbl_name, rootpage, sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE type != 'meta' AND name NOT LIKE 'sqlite_%' ORDER BY tbl_name, type DESC, name"]; 82 | 83 | return rs; 84 | } 85 | 86 | /* 87 | get table schema: result colums: cid[INTEGER], name,type [STRING], notnull[INTEGER], dflt_value[],pk[INTEGER] 88 | */ 89 | - (FMResultSet*)getTableSchema:(NSString*)tableName { 90 | 91 | //result colums: cid[INTEGER], name,type [STRING], notnull[INTEGER], dflt_value[],pk[INTEGER] 92 | FMResultSet *rs = [self executeQuery:[NSString stringWithFormat: @"PRAGMA table_info('%@')", tableName]]; 93 | 94 | return rs; 95 | } 96 | 97 | - (BOOL)columnExists:(NSString*)columnName inTableWithName:(NSString*)tableName { 98 | 99 | BOOL returnBool = NO; 100 | 101 | tableName = [tableName lowercaseString]; 102 | columnName = [columnName lowercaseString]; 103 | 104 | FMResultSet *rs = [self getTableSchema:tableName]; 105 | 106 | //check if column is present in table schema 107 | while ([rs next]) { 108 | if ([[[rs stringForColumn:@"name"] lowercaseString] isEqualToString:columnName]) { 109 | returnBool = YES; 110 | break; 111 | } 112 | } 113 | 114 | //If this is not done FMDatabase instance stays out of pool 115 | [rs close]; 116 | 117 | return returnBool; 118 | } 119 | 120 | #pragma clang diagnostic push 121 | #pragma clang diagnostic ignored "-Wdeprecated-implementations" 122 | 123 | - (BOOL)columnExists:(NSString*)tableName columnName:(NSString*)columnName __attribute__ ((deprecated)) { 124 | return [self columnExists:columnName inTableWithName:tableName]; 125 | } 126 | 127 | #pragma clang diagnostic pop 128 | 129 | - (BOOL)validateSQL:(NSString*)sql error:(NSError**)error { 130 | sqlite3_stmt *pStmt = NULL; 131 | BOOL validationSucceeded = YES; 132 | BOOL keepTrying = YES; 133 | int numberOfRetries = 0; 134 | 135 | while (keepTrying == YES) { 136 | keepTrying = NO; 137 | int rc = sqlite3_prepare_v2(_db, [sql UTF8String], -1, &pStmt, 0); 138 | if (rc == SQLITE_BUSY || rc == SQLITE_LOCKED) { 139 | keepTrying = YES; 140 | usleep(20); 141 | 142 | if (_busyRetryTimeout && (numberOfRetries++ > _busyRetryTimeout)) { 143 | NSLog(@"%s:%d Database busy (%@)", __FUNCTION__, __LINE__, [self databasePath]); 144 | NSLog(@"Database busy"); 145 | } 146 | } 147 | else if (rc != SQLITE_OK) { 148 | validationSucceeded = NO; 149 | if (error) { 150 | *error = [NSError errorWithDomain:NSCocoaErrorDomain 151 | code:[self lastErrorCode] 152 | userInfo:[NSDictionary dictionaryWithObject:[self lastErrorMessage] 153 | forKey:NSLocalizedDescriptionKey]]; 154 | } 155 | } 156 | } 157 | 158 | sqlite3_finalize(pStmt); 159 | 160 | return validationSucceeded; 161 | } 162 | 163 | @end 164 | -------------------------------------------------------------------------------- /Libraries/FMDB/FMDatabasePool.h: -------------------------------------------------------------------------------- 1 | // 2 | // FMDatabasePool.h 3 | // fmdb 4 | // 5 | // Created by August Mueller on 6/22/11. 6 | // Copyright 2011 Flying Meat Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "sqlite3.h" 11 | 12 | /* 13 | 14 | ***README OR SUFFER*** 15 | Before using FMDatabasePool, please consider using FMDatabaseQueue instead. 16 | 17 | If you really really really know what you're doing and FMDatabasePool is what 18 | you really really need (ie, you're using a read only database), OK you can use 19 | it. But just be careful not to deadlock! 20 | 21 | For an example on deadlocking, search for: 22 | ONLY_USE_THE_POOL_IF_YOU_ARE_DOING_READS_OTHERWISE_YOULL_DEADLOCK_USE_FMDATABASEQUEUE_INSTEAD 23 | in the main.m file. 24 | 25 | */ 26 | 27 | 28 | 29 | @class FMDatabase; 30 | 31 | @interface FMDatabasePool : NSObject { 32 | NSString *_path; 33 | 34 | dispatch_queue_t _lockQueue; 35 | 36 | NSMutableArray *_databaseInPool; 37 | NSMutableArray *_databaseOutPool; 38 | 39 | __unsafe_unretained id _delegate; 40 | 41 | NSUInteger _maximumNumberOfDatabasesToCreate; 42 | } 43 | 44 | @property (atomic, retain) NSString *path; 45 | @property (atomic, assign) id delegate; 46 | @property (atomic, assign) NSUInteger maximumNumberOfDatabasesToCreate; 47 | 48 | + (id)databasePoolWithPath:(NSString*)aPath; 49 | - (id)initWithPath:(NSString*)aPath; 50 | 51 | - (NSUInteger)countOfCheckedInDatabases; 52 | - (NSUInteger)countOfCheckedOutDatabases; 53 | - (NSUInteger)countOfOpenDatabases; 54 | - (void)releaseAllDatabases; 55 | 56 | - (void)inDatabase:(void (^)(FMDatabase *db))block; 57 | 58 | - (void)inTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block; 59 | - (void)inDeferredTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block; 60 | 61 | #if SQLITE_VERSION_NUMBER >= 3007000 62 | // NOTE: you can not nest these, since calling it will pull another database out of the pool and you'll get a deadlock. 63 | // If you need to nest, use FMDatabase's startSavePointWithName:error: instead. 64 | - (NSError*)inSavePoint:(void (^)(FMDatabase *db, BOOL *rollback))block; 65 | #endif 66 | 67 | @end 68 | 69 | 70 | @interface NSObject (FMDatabasePoolDelegate) 71 | 72 | - (BOOL)databasePool:(FMDatabasePool*)pool shouldAddDatabaseToPool:(FMDatabase*)database; 73 | 74 | @end 75 | 76 | -------------------------------------------------------------------------------- /Libraries/FMDB/FMDatabasePool.m: -------------------------------------------------------------------------------- 1 | // 2 | // FMDatabasePool.m 3 | // fmdb 4 | // 5 | // Created by August Mueller on 6/22/11. 6 | // Copyright 2011 Flying Meat Inc. All rights reserved. 7 | // 8 | 9 | #import "FMDatabasePool.h" 10 | #import "FMDatabase.h" 11 | 12 | @interface FMDatabasePool() 13 | 14 | - (void)pushDatabaseBackInPool:(FMDatabase*)db; 15 | - (FMDatabase*)db; 16 | 17 | @end 18 | 19 | 20 | @implementation FMDatabasePool 21 | @synthesize path=_path; 22 | @synthesize delegate=_delegate; 23 | @synthesize maximumNumberOfDatabasesToCreate=_maximumNumberOfDatabasesToCreate; 24 | 25 | 26 | + (id)databasePoolWithPath:(NSString*)aPath { 27 | return FMDBReturnAutoreleased([[self alloc] initWithPath:aPath]); 28 | } 29 | 30 | - (id)initWithPath:(NSString*)aPath { 31 | 32 | self = [super init]; 33 | 34 | if (self != nil) { 35 | _path = [aPath copy]; 36 | _lockQueue = dispatch_queue_create([[NSString stringWithFormat:@"fmdb.%@", self] UTF8String], NULL); 37 | _databaseInPool = FMDBReturnRetained([NSMutableArray array]); 38 | _databaseOutPool = FMDBReturnRetained([NSMutableArray array]); 39 | } 40 | 41 | return self; 42 | } 43 | 44 | - (void)dealloc { 45 | 46 | _delegate = 0x00; 47 | FMDBRelease(_path); 48 | FMDBRelease(_databaseInPool); 49 | FMDBRelease(_databaseOutPool); 50 | 51 | if (_lockQueue) { 52 | FMDBDispatchQueueRelease(_lockQueue); 53 | _lockQueue = 0x00; 54 | } 55 | #if ! __has_feature(objc_arc) 56 | [super dealloc]; 57 | #endif 58 | } 59 | 60 | 61 | - (void)executeLocked:(void (^)(void))aBlock { 62 | dispatch_sync(_lockQueue, aBlock); 63 | } 64 | 65 | - (void)pushDatabaseBackInPool:(FMDatabase*)db { 66 | 67 | if (!db) { // db can be null if we set an upper bound on the # of databases to create. 68 | return; 69 | } 70 | 71 | [self executeLocked:^() { 72 | 73 | if ([_databaseInPool containsObject:db]) { 74 | [[NSException exceptionWithName:@"Database already in pool" reason:@"The FMDatabase being put back into the pool is already present in the pool" userInfo:nil] raise]; 75 | } 76 | 77 | [_databaseInPool addObject:db]; 78 | [_databaseOutPool removeObject:db]; 79 | 80 | }]; 81 | } 82 | 83 | - (FMDatabase*)db { 84 | 85 | __block FMDatabase *db; 86 | 87 | [self executeLocked:^() { 88 | db = [_databaseInPool lastObject]; 89 | 90 | if (db) { 91 | [_databaseOutPool addObject:db]; 92 | [_databaseInPool removeLastObject]; 93 | } 94 | else { 95 | 96 | if (_maximumNumberOfDatabasesToCreate) { 97 | NSUInteger currentCount = [_databaseOutPool count] + [_databaseInPool count]; 98 | 99 | if (currentCount >= _maximumNumberOfDatabasesToCreate) { 100 | NSLog(@"Maximum number of databases (%ld) has already been reached!", (long)currentCount); 101 | return; 102 | } 103 | } 104 | 105 | db = [FMDatabase databaseWithPath:_path]; 106 | } 107 | 108 | //This ensures that the db is opened before returning 109 | if ([db open]) { 110 | if ([_delegate respondsToSelector:@selector(databasePool:shouldAddDatabaseToPool:)] && ![_delegate databasePool:self shouldAddDatabaseToPool:db]) { 111 | [db close]; 112 | db = 0x00; 113 | } 114 | else { 115 | //It should not get added in the pool twice if lastObject was found 116 | if (![_databaseOutPool containsObject:db]) { 117 | [_databaseOutPool addObject:db]; 118 | } 119 | } 120 | } 121 | else { 122 | NSLog(@"Could not open up the database at path %@", _path); 123 | db = 0x00; 124 | } 125 | }]; 126 | 127 | return db; 128 | } 129 | 130 | - (NSUInteger)countOfCheckedInDatabases { 131 | 132 | __block NSUInteger count; 133 | 134 | [self executeLocked:^() { 135 | count = [_databaseInPool count]; 136 | }]; 137 | 138 | return count; 139 | } 140 | 141 | - (NSUInteger)countOfCheckedOutDatabases { 142 | 143 | __block NSUInteger count; 144 | 145 | [self executeLocked:^() { 146 | count = [_databaseOutPool count]; 147 | }]; 148 | 149 | return count; 150 | } 151 | 152 | - (NSUInteger)countOfOpenDatabases { 153 | __block NSUInteger count; 154 | 155 | [self executeLocked:^() { 156 | count = [_databaseOutPool count] + [_databaseInPool count]; 157 | }]; 158 | 159 | return count; 160 | } 161 | 162 | - (void)releaseAllDatabases { 163 | [self executeLocked:^() { 164 | [_databaseOutPool removeAllObjects]; 165 | [_databaseInPool removeAllObjects]; 166 | }]; 167 | } 168 | 169 | - (void)inDatabase:(void (^)(FMDatabase *db))block { 170 | 171 | FMDatabase *db = [self db]; 172 | 173 | block(db); 174 | 175 | [self pushDatabaseBackInPool:db]; 176 | } 177 | 178 | - (void)beginTransaction:(BOOL)useDeferred withBlock:(void (^)(FMDatabase *db, BOOL *rollback))block { 179 | 180 | BOOL shouldRollback = NO; 181 | 182 | FMDatabase *db = [self db]; 183 | 184 | if (useDeferred) { 185 | [db beginDeferredTransaction]; 186 | } 187 | else { 188 | [db beginTransaction]; 189 | } 190 | 191 | 192 | block(db, &shouldRollback); 193 | 194 | if (shouldRollback) { 195 | [db rollback]; 196 | } 197 | else { 198 | [db commit]; 199 | } 200 | 201 | [self pushDatabaseBackInPool:db]; 202 | } 203 | 204 | - (void)inDeferredTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block { 205 | [self beginTransaction:YES withBlock:block]; 206 | } 207 | 208 | - (void)inTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block { 209 | [self beginTransaction:NO withBlock:block]; 210 | } 211 | #if SQLITE_VERSION_NUMBER >= 3007000 212 | - (NSError*)inSavePoint:(void (^)(FMDatabase *db, BOOL *rollback))block { 213 | 214 | static unsigned long savePointIdx = 0; 215 | 216 | NSString *name = [NSString stringWithFormat:@"savePoint%ld", savePointIdx++]; 217 | 218 | BOOL shouldRollback = NO; 219 | 220 | FMDatabase *db = [self db]; 221 | 222 | NSError *err = 0x00; 223 | 224 | if (![db startSavePointWithName:name error:&err]) { 225 | [self pushDatabaseBackInPool:db]; 226 | return err; 227 | } 228 | 229 | block(db, &shouldRollback); 230 | 231 | if (shouldRollback) { 232 | [db rollbackToSavePointWithName:name error:&err]; 233 | } 234 | else { 235 | [db releaseSavePointWithName:name error:&err]; 236 | } 237 | 238 | [self pushDatabaseBackInPool:db]; 239 | 240 | return err; 241 | } 242 | #endif 243 | 244 | @end 245 | -------------------------------------------------------------------------------- /Libraries/FMDB/FMDatabaseQueue.h: -------------------------------------------------------------------------------- 1 | // 2 | // FMDatabasePool.h 3 | // fmdb 4 | // 5 | // Created by August Mueller on 6/22/11. 6 | // Copyright 2011 Flying Meat Inc. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "sqlite3.h" 11 | 12 | @class FMDatabase; 13 | 14 | @interface FMDatabaseQueue : NSObject { 15 | NSString *_path; 16 | dispatch_queue_t _queue; 17 | FMDatabase *_db; 18 | } 19 | 20 | @property (atomic, retain) NSString *path; 21 | 22 | + (id)databaseQueueWithPath:(NSString*)aPath; 23 | - (id)initWithPath:(NSString*)aPath; 24 | - (void)close; 25 | 26 | - (void)inDatabase:(void (^)(FMDatabase *db))block; 27 | 28 | - (void)inTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block; 29 | - (void)inDeferredTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block; 30 | 31 | #if SQLITE_VERSION_NUMBER >= 3007000 32 | // NOTE: you can not nest these, since calling it will pull another database out of the pool and you'll get a deadlock. 33 | // If you need to nest, use FMDatabase's startSavePointWithName:error: instead. 34 | - (NSError*)inSavePoint:(void (^)(FMDatabase *db, BOOL *rollback))block; 35 | #endif 36 | 37 | @end 38 | 39 | -------------------------------------------------------------------------------- /Libraries/FMDB/FMDatabaseQueue.m: -------------------------------------------------------------------------------- 1 | // 2 | // FMDatabasePool.m 3 | // fmdb 4 | // 5 | // Created by August Mueller on 6/22/11. 6 | // Copyright 2011 Flying Meat Inc. All rights reserved. 7 | // 8 | 9 | #import "FMDatabaseQueue.h" 10 | #import "FMDatabase.h" 11 | 12 | /* 13 | 14 | Note: we call [self retain]; before using dispatch_sync, just incase 15 | FMDatabaseQueue is released on another thread and we're in the middle of doing 16 | something in dispatch_sync 17 | 18 | */ 19 | 20 | @implementation FMDatabaseQueue 21 | 22 | @synthesize path = _path; 23 | 24 | + (id)databaseQueueWithPath:(NSString*)aPath { 25 | 26 | FMDatabaseQueue *q = [[self alloc] initWithPath:aPath]; 27 | 28 | FMDBAutorelease(q); 29 | 30 | return q; 31 | } 32 | 33 | - (id)initWithPath:(NSString*)aPath { 34 | 35 | self = [super init]; 36 | 37 | if (self != nil) { 38 | 39 | _db = [FMDatabase databaseWithPath:aPath]; 40 | FMDBRetain(_db); 41 | 42 | if (![_db open]) { 43 | NSLog(@"Could not create database queue for path %@", aPath); 44 | FMDBRelease(self); 45 | return 0x00; 46 | } 47 | 48 | _path = FMDBReturnRetained(aPath); 49 | 50 | _queue = dispatch_queue_create([[NSString stringWithFormat:@"fmdb.%@", self] UTF8String], NULL); 51 | } 52 | 53 | return self; 54 | } 55 | 56 | - (void)dealloc { 57 | 58 | FMDBRelease(_db); 59 | FMDBRelease(_path); 60 | 61 | if (_queue) { 62 | FMDBDispatchQueueRelease(_queue); 63 | _queue = 0x00; 64 | } 65 | #if ! __has_feature(objc_arc) 66 | [super dealloc]; 67 | #endif 68 | } 69 | 70 | - (void)close { 71 | FMDBRetain(self); 72 | dispatch_sync(_queue, ^() { 73 | [_db close]; 74 | FMDBRelease(_db); 75 | _db = 0x00; 76 | }); 77 | FMDBRelease(self); 78 | } 79 | 80 | - (FMDatabase*)database { 81 | if (!_db) { 82 | _db = FMDBReturnRetained([FMDatabase databaseWithPath:_path]); 83 | 84 | if (![_db open]) { 85 | NSLog(@"FMDatabaseQueue could not reopen database for path %@", _path); 86 | FMDBRelease(_db); 87 | _db = 0x00; 88 | return 0x00; 89 | } 90 | } 91 | 92 | return _db; 93 | } 94 | 95 | - (void)inDatabase:(void (^)(FMDatabase *db))block { 96 | FMDBRetain(self); 97 | 98 | dispatch_sync(_queue, ^() { 99 | 100 | FMDatabase *db = [self database]; 101 | block(db); 102 | 103 | if ([db hasOpenResultSets]) { 104 | NSLog(@"Warning: there is at least one open result set around after performing [FMDatabaseQueue inDatabase:]"); 105 | } 106 | }); 107 | 108 | FMDBRelease(self); 109 | } 110 | 111 | 112 | - (void)beginTransaction:(BOOL)useDeferred withBlock:(void (^)(FMDatabase *db, BOOL *rollback))block { 113 | FMDBRetain(self); 114 | dispatch_sync(_queue, ^() { 115 | 116 | BOOL shouldRollback = NO; 117 | 118 | if (useDeferred) { 119 | [[self database] beginDeferredTransaction]; 120 | } 121 | else { 122 | [[self database] beginTransaction]; 123 | } 124 | 125 | block([self database], &shouldRollback); 126 | 127 | if (shouldRollback) { 128 | [[self database] rollback]; 129 | } 130 | else { 131 | [[self database] commit]; 132 | } 133 | }); 134 | 135 | FMDBRelease(self); 136 | } 137 | 138 | - (void)inDeferredTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block { 139 | [self beginTransaction:YES withBlock:block]; 140 | } 141 | 142 | - (void)inTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block { 143 | [self beginTransaction:NO withBlock:block]; 144 | } 145 | 146 | #if SQLITE_VERSION_NUMBER >= 3007000 147 | - (NSError*)inSavePoint:(void (^)(FMDatabase *db, BOOL *rollback))block { 148 | 149 | static unsigned long savePointIdx = 0; 150 | __block NSError *err = 0x00; 151 | FMDBRetain(self); 152 | dispatch_sync(_queue, ^() { 153 | 154 | NSString *name = [NSString stringWithFormat:@"savePoint%ld", savePointIdx++]; 155 | 156 | BOOL shouldRollback = NO; 157 | 158 | if ([[self database] startSavePointWithName:name error:&err]) { 159 | 160 | block([self database], &shouldRollback); 161 | 162 | if (shouldRollback) { 163 | [[self database] rollbackToSavePointWithName:name error:&err]; 164 | } 165 | else { 166 | [[self database] releaseSavePointWithName:name error:&err]; 167 | } 168 | 169 | } 170 | }); 171 | FMDBRelease(self); 172 | return err; 173 | } 174 | #endif 175 | 176 | @end 177 | -------------------------------------------------------------------------------- /Libraries/FMDB/FMResultSet.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "sqlite3.h" 3 | 4 | #ifndef __has_feature // Optional. 5 | #define __has_feature(x) 0 // Compatibility with non-clang compilers. 6 | #endif 7 | 8 | #ifndef NS_RETURNS_NOT_RETAINED 9 | #if __has_feature(attribute_ns_returns_not_retained) 10 | #define NS_RETURNS_NOT_RETAINED __attribute__((ns_returns_not_retained)) 11 | #else 12 | #define NS_RETURNS_NOT_RETAINED 13 | #endif 14 | #endif 15 | 16 | @class FMDatabase; 17 | @class FMStatement; 18 | 19 | @interface FMResultSet : NSObject 20 | { 21 | FMDatabase *_parentDB; 22 | FMStatement *_statement; 23 | 24 | NSString *_query; 25 | NSMutableDictionary *_columnNameToIndexMap; 26 | } 27 | 28 | @property (atomic, retain) NSString *query; 29 | @property (readonly) NSMutableDictionary *columnNameToIndexMap; 30 | @property (atomic, retain) FMStatement *statement; 31 | 32 | + (id)resultSetWithStatement:(FMStatement *)statement usingParentDatabase:(FMDatabase*)aDB; 33 | 34 | - (void)close; 35 | 36 | - (void)setParentDB:(FMDatabase *)newDb; 37 | 38 | - (BOOL)next; 39 | - (BOOL)hasAnotherRow; 40 | 41 | - (int)columnCount; 42 | 43 | - (int)columnIndexForName:(NSString*)columnName; 44 | - (NSString*)columnNameForIndex:(int)columnIdx; 45 | 46 | - (int)intForColumn:(NSString*)columnName; 47 | - (int)intForColumnIndex:(int)columnIdx; 48 | 49 | - (long)longForColumn:(NSString*)columnName; 50 | - (long)longForColumnIndex:(int)columnIdx; 51 | 52 | - (long long int)longLongIntForColumn:(NSString*)columnName; 53 | - (long long int)longLongIntForColumnIndex:(int)columnIdx; 54 | 55 | - (unsigned long long int)unsignedLongLongIntForColumn:(NSString*)columnName; 56 | - (unsigned long long int)unsignedLongLongIntForColumnIndex:(int)columnIdx; 57 | 58 | - (BOOL)boolForColumn:(NSString*)columnName; 59 | - (BOOL)boolForColumnIndex:(int)columnIdx; 60 | 61 | - (double)doubleForColumn:(NSString*)columnName; 62 | - (double)doubleForColumnIndex:(int)columnIdx; 63 | 64 | - (NSString*)stringForColumn:(NSString*)columnName; 65 | - (NSString*)stringForColumnIndex:(int)columnIdx; 66 | 67 | - (NSDate*)dateForColumn:(NSString*)columnName; 68 | - (NSDate*)dateForColumnIndex:(int)columnIdx; 69 | 70 | - (NSData*)dataForColumn:(NSString*)columnName; 71 | - (NSData*)dataForColumnIndex:(int)columnIdx; 72 | 73 | - (const unsigned char *)UTF8StringForColumnIndex:(int)columnIdx; 74 | - (const unsigned char *)UTF8StringForColumnName:(NSString*)columnName; 75 | 76 | // returns one of NSNumber, NSString, NSData, or NSNull 77 | - (id)objectForColumnName:(NSString*)columnName; 78 | - (id)objectForColumnIndex:(int)columnIdx; 79 | 80 | - (id)objectForKeyedSubscript:(NSString *)columnName; 81 | - (id)objectAtIndexedSubscript:(int)columnIdx; 82 | 83 | /* 84 | If you are going to use this data after you iterate over the next row, or after you close the 85 | result set, make sure to make a copy of the data first (or just use dataForColumn:/dataForColumnIndex:) 86 | If you don't, you're going to be in a world of hurt when you try and use the data. 87 | */ 88 | - (NSData*)dataNoCopyForColumn:(NSString*)columnName NS_RETURNS_NOT_RETAINED; 89 | - (NSData*)dataNoCopyForColumnIndex:(int)columnIdx NS_RETURNS_NOT_RETAINED; 90 | 91 | - (BOOL)columnIndexIsNull:(int)columnIdx; 92 | - (BOOL)columnIsNull:(NSString*)columnName; 93 | 94 | 95 | /* Returns a dictionary of the row results mapped to case sensitive keys of the column names. */ 96 | - (NSDictionary*)resultDictionary; 97 | 98 | /* Please use resultDictionary instead. Also, beware that resultDictionary is case sensitive! */ 99 | - (NSDictionary*)resultDict __attribute__ ((deprecated)); 100 | 101 | - (void)kvcMagic:(id)object; 102 | 103 | 104 | @end 105 | 106 | -------------------------------------------------------------------------------- /Libraries/MBProgressHUD/MBPromptHUD.h: -------------------------------------------------------------------------------- 1 | // 2 | // MBPromptHUD.h 3 | // HuiGouTong 4 | // 5 | // Created by 何 振东 on 12-9-21. 6 | // Copyright (c) 2012年 何 振东. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MBProgressHUD.h" 11 | 12 | @interface MBPromptHUD : NSObject 13 | 14 | + (void)showPrompt:(NSString *)prompt atView:(UIView *)view; 15 | 16 | - (void)showPrompt:(UIImage *)image withFrame:(CGRect)frame atView2:(UIView *)view; 17 | 18 | + (MBPromptHUD *)sharedMBPromptHUD; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Libraries/MBProgressHUD/MBPromptHUD.m: -------------------------------------------------------------------------------- 1 | // 2 | // MBPromptHUD.m 3 | // HuiGouTong 4 | // 5 | // Created by 何 振东 on 12-9-21. 6 | // Copyright (c) 2012年 何 振东. All rights reserved. 7 | // 8 | 9 | #import "MBPromptHUD.h" 10 | 11 | @interface MBPromptHUD () 12 | 13 | @property (retain, nonatomic) UIImageView *alertImgView; 14 | @end 15 | 16 | @implementation MBPromptHUD 17 | @synthesize alertImgView; 18 | 19 | 20 | + (void)showPrompt:(NSString *)prompt atView:(UIView *)view 21 | { 22 | MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES]; 23 | 24 | hud.mode = MBProgressHUDModeText; 25 | hud.labelText = prompt; 26 | hud.margin = 10.f; 27 | hud.yOffset = -85.f; 28 | hud.opacity = 0.4; 29 | hud.removeFromSuperViewOnHide = YES; 30 | [hud hide:YES afterDelay:1.15]; 31 | } 32 | 33 | - (id)init 34 | { 35 | self = [super init]; 36 | if (self) 37 | { 38 | alertImgView = [[UIImageView alloc] init]; 39 | self.alertImgView.backgroundColor = [[UIColor darkTextColor] colorWithAlphaComponent:0.6]; 40 | } 41 | return self; 42 | } 43 | 44 | 45 | + (MBPromptHUD *)sharedMBPromptHUD 46 | { 47 | static MBPromptHUD *promptHUD = nil; 48 | 49 | @synchronized(self) 50 | { 51 | if (!promptHUD) 52 | { 53 | promptHUD = [[MBPromptHUD alloc] init]; 54 | } 55 | } 56 | 57 | return promptHUD; 58 | } 59 | 60 | - (void)showPrompt:(UIImage *)image withFrame:(CGRect)frame atView2:(UIView *)view{ 61 | 62 | self.alertImgView.frame = frame; 63 | self.alertImgView.image = image; 64 | [view addSubview:self.alertImgView]; 65 | 66 | [UIView beginAnimations:nil context:nil]; 67 | self.alertImgView.alpha = 1.0f; 68 | [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 69 | [UIView setAnimationDuration:2.0f]; 70 | [UIView commitAnimations]; 71 | 72 | [self performSelector:@selector(hidePromptView) withObject:nil afterDelay:2.0]; 73 | } 74 | - (void)hidePromptView 75 | { 76 | [UIView beginAnimations:nil context:nil]; 77 | self.alertImgView.alpha = 0.0; 78 | [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 79 | [UIView setAnimationDuration:2.0f]; 80 | [UIView commitAnimations]; 81 | } 82 | 83 | 84 | @end 85 | -------------------------------------------------------------------------------- /Libraries/TouchXML/CXHTMLDocument.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXHTMLDocument.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 03/07/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLDocument.h" 33 | 34 | 35 | @interface CXHTMLDocument : CXMLDocument { 36 | 37 | } 38 | 39 | - (id)initWithXHTMLData:(NSData *)inData encoding:(NSStringEncoding)encoding options:(NSUInteger)inOptions error:(NSError **)outError; 40 | - (id)initWithXHTMLString:(NSString *)inString options:(NSUInteger)inOptions error:(NSError **)outError; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /Libraries/TouchXML/CXHTMLDocument.m: -------------------------------------------------------------------------------- 1 | // 2 | // CXHTMLDocument.m 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 03/07/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | // This is an experiment to see if we can utilize the HTMLParser functionality 33 | // of libXML to serve as a XHTML parser, I question if this is a good idea or not 34 | // need to test some of the following 35 | // [-] How are xml namespaces handled 36 | // [-] Can we support DTD 37 | // [-] 38 | 39 | #import "CXHTMLDocument.h" 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #import "CXMLNode_PrivateExtensions.h" 47 | #import "CXMLElement.h" 48 | 49 | #if TOUCHXMLUSETIDY 50 | #import "CTidy.h" 51 | #endif /* TOUCHXMLUSETIDY */ 52 | 53 | @implementation CXHTMLDocument 54 | 55 | 56 | // Differs from initWithXMLString by using libXML's HTML parser, which automatically decodes XHTML/HTML entities found within the document 57 | // which eliminates the need to resanitize strings extracted from the document 58 | // libXML treats a htmlDocPtr the same as xmlDocPtr 59 | - (id)initWithXHTMLString:(NSString *)inString options:(NSUInteger)inOptions error:(NSError **)outError 60 | { 61 | #pragma unused (inOptions) 62 | if ((self = [super init]) != NULL) 63 | { 64 | NSError *theError = NULL; 65 | 66 | htmlDocPtr theDoc = htmlParseDoc(BAD_CAST[inString UTF8String], xmlGetCharEncodingName(XML_CHAR_ENCODING_UTF8)); 67 | if (theDoc != NULL) 68 | { 69 | // TODO: change code to not depend on XPATH, should be a task simple enough to do 70 | // alternatively see if we can prevent the HTML parser from adding implied tags 71 | 72 | xmlXPathContextPtr xpathContext = xmlXPathNewContext (theDoc); 73 | 74 | xmlXPathObjectPtr xpathObject = NULL; 75 | if (xpathContext) 76 | xpathObject = xmlXPathEvalExpression (BAD_CAST("/html/body"), xpathContext); 77 | 78 | xmlNodePtr bodyNode = NULL; 79 | if (xpathObject && xpathObject->nodesetval->nodeMax) 80 | bodyNode = xpathObject->nodesetval->nodeTab[0]; 81 | 82 | // TODO: Determine if this is sufficient to handle memory in libXML, is the old root removed / deleted, etc 83 | if (bodyNode) 84 | xmlDocSetRootElement(theDoc, bodyNode->children); 85 | 86 | _node = (xmlNodePtr)theDoc; 87 | NSAssert(_node->_private == NULL, @"TODO"); 88 | _node->_private = (__bridge void *)self; // Note. NOT retained (TODO think more about _private usage) 89 | 90 | if (xpathObject) 91 | xmlXPathFreeObject (xpathObject); 92 | 93 | if (xpathContext) 94 | xmlXPathFreeContext (xpathContext); 95 | } 96 | else 97 | { 98 | xmlErrorPtr theLastErrorPtr = xmlGetLastError(); 99 | NSDictionary *theUserInfo = [NSDictionary dictionaryWithObjectsAndKeys: 100 | theLastErrorPtr ? [NSString stringWithUTF8String:theLastErrorPtr->message] : @"unknown", NSLocalizedDescriptionKey, 101 | NULL]; 102 | 103 | theError = [NSError errorWithDomain:@"CXMLErrorDomain" code:1 userInfo:theUserInfo]; 104 | 105 | xmlResetLastError(); 106 | } 107 | 108 | if (outError) 109 | { 110 | *outError = theError; 111 | } 112 | 113 | if (theError != NULL) 114 | { 115 | self = NULL; 116 | } 117 | } 118 | return(self); 119 | } 120 | 121 | - (id)initWithXHTMLData:(NSData *)inData encoding:(NSStringEncoding)encoding options:(NSUInteger)inOptions error:(NSError **)outError 122 | { 123 | #pragma unused (inOptions) 124 | if ((self = [super init]) != NULL) 125 | { 126 | NSError *theError = NULL; 127 | 128 | if (theError == NULL) 129 | { 130 | xmlDocPtr theDoc = NULL; 131 | if (inData && inData.length > 0) 132 | { 133 | CFStringEncoding cfenc = CFStringConvertNSStringEncodingToEncoding(encoding); 134 | CFStringRef cfencstr = CFStringConvertEncodingToIANACharSetName(cfenc); 135 | const char *enc = CFStringGetCStringPtr(cfencstr, 0); 136 | theDoc = htmlReadMemory([inData bytes], [inData length], NULL, enc, HTML_PARSE_NONET | HTML_PARSE_NOBLANKS | HTML_PARSE_NOWARNING); 137 | } 138 | 139 | if (theDoc != NULL) 140 | { 141 | _node = (xmlNodePtr)theDoc; 142 | _node->_private = (__bridge void *)self; // Note. NOT retained (TODO think more about _private usage) 143 | } 144 | else 145 | { 146 | theError = [NSError errorWithDomain:@"CXMLErrorDomain" code:-1 userInfo:NULL]; 147 | } 148 | } 149 | 150 | if (outError) 151 | { 152 | *outError = theError; 153 | } 154 | 155 | if (theError != NULL) 156 | { 157 | self = NULL; 158 | } 159 | } 160 | return(self); 161 | } 162 | 163 | @end 164 | -------------------------------------------------------------------------------- /Libraries/TouchXML/CXMLDocument.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLDocument.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 03/07/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLNode.h" 33 | 34 | enum { 35 | CXMLDocumentTidyHTML = 1 << 9, // Based on NSXMLDocumentTidyHTML 36 | CXMLDocumentTidyXML = 1 << 10, // Based on NSXMLDocumentTidyXML 37 | }; 38 | 39 | @class CXMLElement; 40 | 41 | @interface CXMLDocument : CXMLNode { 42 | NSMutableSet *nodePool; 43 | } 44 | 45 | - (id)initWithData:(NSData *)inData options:(NSUInteger)inOptions error:(NSError **)outError; 46 | - (id)initWithData:(NSData *)inData encoding:(NSStringEncoding)encoding options:(NSUInteger)inOptions error:(NSError **)outError; 47 | - (id)initWithXMLString:(NSString *)inString options:(NSUInteger)inOptions error:(NSError **)outError; 48 | - (id)initWithContentsOfURL:(NSURL *)inURL options:(NSUInteger)inOptions error:(NSError **)outError; 49 | - (id)initWithContentsOfURL:(NSURL *)inURL encoding:(NSStringEncoding)encoding options:(NSUInteger)inOptions error:(NSError **)outError; 50 | 51 | //- (NSString *)characterEncoding; 52 | //- (NSString *)version; 53 | //- (BOOL)isStandalone; 54 | //- (CXMLDocumentContentKind)documentContentKind; 55 | //- (NSString *)MIMEType; 56 | //- (CXMLDTD *)DTD; 57 | 58 | - (CXMLElement *)rootElement; 59 | 60 | - (NSData *)XMLData; 61 | - (NSData *)XMLDataWithOptions:(NSUInteger)options; 62 | 63 | //- (id)objectByApplyingXSLT:(NSData *)xslt arguments:(NSDictionary *)arguments error:(NSError **)error; 64 | //- (id)objectByApplyingXSLTString:(NSString *)xslt arguments:(NSDictionary *)arguments error:(NSError **)error; 65 | //- (id)objectByApplyingXSLTAtURL:(NSURL *)xsltURL arguments:(NSDictionary *)argument error:(NSError **)error; 66 | 67 | - (id)XMLStringWithOptions:(NSUInteger)options; 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /Libraries/TouchXML/CXMLDocument_PrivateExtensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLDocument_PrivateExtensions.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 03/07/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLDocument.h" 33 | 34 | #include 35 | 36 | @interface CXMLDocument (CXMLDocument_PrivateExtensions) 37 | 38 | //- (id)initWithLibXmlParserContext:(xmlParserCtxtPtr)inContext options:(NSUInteger)inOptions error:(NSError **)outError; 39 | 40 | - (NSMutableSet *)nodePool; 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /Libraries/TouchXML/CXMLDocument_PrivateExtensions.m: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLDocument_PrivateExtensions.m 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 03/07/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLDocument_PrivateExtensions.h" 33 | 34 | @implementation CXMLDocument (CXMLDocument_PrivateExtensions) 35 | 36 | /* 37 | - (id)initWithLibXmlParserContext:(xmlParserCtxtPtr)inContext options:(NSUInteger)inOptions error:(NSError **)outError 38 | { 39 | 40 | xmlParseDocument(inContext); 41 | 42 | } 43 | */ 44 | 45 | - (NSMutableSet *)nodePool 46 | { 47 | if (nodePool == NULL) 48 | { 49 | nodePool = [[NSMutableSet alloc] init]; 50 | } 51 | return(nodePool); 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /Libraries/TouchXML/CXMLElement.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLElement.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 03/07/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLNode.h" 33 | 34 | // NSXMLElement 35 | @interface CXMLElement : CXMLNode { 36 | 37 | } 38 | 39 | - (NSArray *)elementsForName:(NSString *)name; 40 | - (NSArray *)elementsForLocalName:(NSString *)localName URI:(NSString *)URI; 41 | 42 | - (NSArray *)attributes; 43 | - (CXMLNode *)attributeForName:(NSString *)name; 44 | - (CXMLNode *)attributeForLocalName:(NSString *)localName URI:(NSString *)URI; 45 | 46 | - (NSArray *)namespaces; 47 | - (CXMLNode *)namespaceForPrefix:(NSString *)name; 48 | - (CXMLNode *)resolveNamespaceForName:(NSString *)name; 49 | - (NSString *)resolvePrefixForNamespaceURI:(NSString *)namespaceURI; 50 | 51 | //- (NSString*)_XMLStringWithOptions:(NSUInteger)options appendingToString:(NSMutableString*)str; 52 | @end 53 | -------------------------------------------------------------------------------- /Libraries/TouchXML/CXMLElement_CreationExtensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLElement_CreationExtensions.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 04/01/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLElement.h" 33 | 34 | @interface CXMLElement (CXMLElement_CreationExtensions) 35 | 36 | - (void)addChild:(CXMLNode *)inNode; 37 | 38 | - (void)addNamespace:(CXMLNode *)inNamespace; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /Libraries/TouchXML/CXMLElement_CreationExtensions.m: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLElement_CreationExtensions.m 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 04/01/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLElement_CreationExtensions.h" 33 | 34 | @implementation CXMLElement (CXMLElement_CreationExtensions) 35 | 36 | - (void)addChild:(CXMLNode *)inNode 37 | { 38 | NSAssert(inNode->_node->doc == NULL, @"Cannot addChild with a node that already is part of a document. Copy it first!"); 39 | NSAssert(self->_node != NULL, @"_node should not be null"); 40 | NSAssert(inNode->_node != NULL, @"_node should not be null"); 41 | xmlAddChild(self->_node, inNode->_node); 42 | // now XML element is tracked by document, do not release on dealloc 43 | inNode->_freeNodeOnRelease = NO; 44 | } 45 | 46 | - (void)addNamespace:(CXMLNode *)inNamespace 47 | { 48 | xmlSetNs(self->_node, (xmlNsPtr)inNamespace->_node); 49 | } 50 | 51 | - (void)setStringValue:(NSString *)inStringValue 52 | { 53 | NSAssert(inStringValue != NULL, @"CXMLElement setStringValue should not be null"); 54 | xmlNodePtr theContentNode = xmlNewText((const xmlChar *)[inStringValue UTF8String]); 55 | NSAssert(self->_node != NULL, @"_node should not be null"); 56 | xmlAddChild(self->_node, theContentNode); 57 | } 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /Libraries/TouchXML/CXMLElement_ElementTreeExtensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLElement_ElementTreeExtensions.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 11/14/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLElement.h" 33 | 34 | 35 | @interface CXMLElement (CXMLElement_ElementTreeExtensions) 36 | 37 | - (CXMLElement *)subelement:(NSString *)inName; 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /Libraries/TouchXML/CXMLElement_ElementTreeExtensions.m: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLElement_ElementTreeExtensions.m 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 11/14/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLElement_ElementTreeExtensions.h" 33 | 34 | #import "CXMLElement_CreationExtensions.h" 35 | #import "CXMLNode_CreationExtensions.h" 36 | 37 | @implementation CXMLElement (CXMLElement_ElementTreeExtensions) 38 | 39 | - (CXMLElement *)subelement:(NSString *)inName; 40 | { 41 | CXMLElement *theSubelement = [CXMLNode elementWithName:inName]; 42 | [self addChild:theSubelement]; 43 | return(theSubelement); 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /Libraries/TouchXML/CXMLNamespaceNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLNamespaceNode.h 3 | // TouchXML 4 | // 5 | // Created by Jonathan Wight on 1/1/2000. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import 33 | #import "CXMLNode.h" 34 | #import "CXMLElement.h" 35 | 36 | @interface CXMLNamespaceNode : CXMLNode { 37 | 38 | NSString *_prefix; 39 | NSString *_uri; 40 | CXMLElement *_parent; 41 | } 42 | 43 | - (id) initWithPrefix:(NSString *)prefix URI:(NSString *)uri parentElement:(CXMLElement *)parent; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Libraries/TouchXML/CXMLNamespaceNode.m: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLNamespaceNode.m 3 | // TouchXML 4 | // 5 | // Created by Jonathan Wight on 1/1/2000. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLNamespaceNode.h" 33 | 34 | @implementation CXMLNamespaceNode 35 | 36 | #pragma mark - 37 | #pragma mark Init and dealloc 38 | 39 | - (id) initWithPrefix:(NSString *)prefix URI:(NSString *)uri parentElement:(CXMLElement *)parent 40 | { 41 | if ((self = [super init]) != NULL) 42 | { 43 | _prefix = [prefix copy]; 44 | _uri = [uri copy]; 45 | _parent = parent; // Don't retain parent 46 | } 47 | 48 | return self; 49 | } 50 | 51 | - (void) dealloc 52 | { 53 | _prefix = nil; 54 | _uri = nil; 55 | _parent = nil; // Parent not retained 56 | 57 | } 58 | 59 | #pragma mark - 60 | #pragma mark Overidden methods 61 | 62 | // NB: We need to override every method that relies on _node as namespaces in libXML don't have a xmlNode 63 | 64 | - (CXMLNodeKind)kind 65 | { 66 | return CXMLNamespaceKind; 67 | } 68 | 69 | - (NSString *)name 70 | { 71 | return _prefix ? [_prefix copy] : @""; 72 | } 73 | 74 | - (NSString *)stringValue 75 | { 76 | return _uri ? [_uri copy] : @""; 77 | } 78 | 79 | - (NSUInteger)index 80 | { 81 | return 0; // TODO: Write tets, Fix 82 | } 83 | 84 | - (NSUInteger)level 85 | { 86 | return _parent ? [_parent level] + 1 : 2; 87 | } 88 | 89 | - (CXMLDocument *)rootDocument 90 | { 91 | return [_parent rootDocument]; 92 | } 93 | 94 | - (CXMLNode *)parent 95 | { 96 | return _parent; 97 | } 98 | 99 | - (NSUInteger)childCount 100 | { 101 | return 0; 102 | } 103 | 104 | - (NSArray *)children 105 | { 106 | return nil; 107 | } 108 | 109 | - (CXMLNode *)childAtIndex:(NSUInteger)index 110 | { 111 | return nil; 112 | } 113 | 114 | - (CXMLNode *)previousSibling 115 | { 116 | return nil; // TODO: Write tets, Fix 117 | } 118 | 119 | - (CXMLNode *)nextSibling 120 | { 121 | return nil; // TODO: Write tets, Fix 122 | } 123 | 124 | //- (CXMLNode *)previousNode; 125 | //- (CXMLNode *)nextNode; 126 | //- (NSString *)XPath; 127 | 128 | - (NSString *)localName 129 | { 130 | return [self name]; 131 | } 132 | 133 | - (NSString *)prefix 134 | { 135 | return @""; 136 | } 137 | 138 | - (NSString *)URI 139 | { 140 | return nil; 141 | } 142 | 143 | //+ (NSString *)localNameForName:(NSString *)name; 144 | //+ (NSString *)prefixForName:(NSString *)name; 145 | //+ (CXMLNode *)predefinedNamespaceForPrefix:(NSString *)name; 146 | 147 | - (NSString *)description 148 | { 149 | if (_prefix && [_prefix length] > 0) 150 | return [NSString stringWithFormat:@"xmlns:%@=\"%@\"", _prefix, _uri]; 151 | 152 | return [NSString stringWithFormat:@"xmlns=\"%@\"", _uri]; 153 | } 154 | 155 | - (NSString *)XMLString 156 | { 157 | return [self description]; 158 | } 159 | 160 | - (NSString *)XMLStringWithOptions:(NSUInteger)options 161 | { 162 | return [self description]; 163 | } 164 | 165 | //- (NSString *)canonicalXMLStringPreservingComments:(BOOL)comments; 166 | 167 | - (NSArray *)nodesForXPath:(NSString *)xpath error:(NSError **)error 168 | { 169 | return nil; 170 | } 171 | 172 | @end 173 | -------------------------------------------------------------------------------- /Libraries/TouchXML/CXMLNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLNode.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 03/07/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import 33 | 34 | #include 35 | 36 | typedef enum { 37 | CXMLInvalidKind = 0, 38 | CXMLElementKind = XML_ELEMENT_NODE, 39 | CXMLAttributeKind = XML_ATTRIBUTE_NODE, 40 | CXMLTextKind = XML_TEXT_NODE, 41 | CXMLProcessingInstructionKind = XML_PI_NODE, 42 | CXMLCommentKind = XML_COMMENT_NODE, 43 | CXMLNotationDeclarationKind = XML_NOTATION_NODE, 44 | CXMLDTDKind = XML_DTD_NODE, 45 | CXMLElementDeclarationKind = XML_ELEMENT_DECL, 46 | CXMLAttributeDeclarationKind = XML_ATTRIBUTE_DECL, 47 | CXMLEntityDeclarationKind = XML_ENTITY_DECL, 48 | CXMLNamespaceKind = XML_NAMESPACE_DECL, 49 | } CXMLNodeKind; 50 | 51 | @class CXMLDocument; 52 | 53 | // NSXMLNode 54 | @interface CXMLNode : NSObject { 55 | xmlNodePtr _node; 56 | BOOL _freeNodeOnRelease; 57 | } 58 | 59 | - (CXMLNodeKind)kind; 60 | - (NSString *)name; 61 | - (NSString *)stringValue; 62 | - (NSUInteger)index; 63 | - (NSUInteger)level; 64 | - (CXMLDocument *)rootDocument; 65 | - (CXMLNode *)parent; 66 | - (NSUInteger)childCount; 67 | - (NSArray *)children; 68 | - (CXMLNode *)childAtIndex:(NSUInteger)index; 69 | - (CXMLNode *)previousSibling; 70 | - (CXMLNode *)nextSibling; 71 | //- (CXMLNode *)previousNode; 72 | //- (CXMLNode *)nextNode; 73 | //- (NSString *)XPath; 74 | - (NSString *)localName; 75 | - (NSString *)prefix; 76 | - (NSString *)URI; 77 | + (NSString *)localNameForName:(NSString *)name; 78 | + (NSString *)prefixForName:(NSString *)name; 79 | + (CXMLNode *)predefinedNamespaceForPrefix:(NSString *)name; 80 | - (NSString *)description; 81 | - (NSString *)XMLString; 82 | - (NSString *)XMLStringWithOptions:(NSUInteger)options; 83 | //- (NSString *)canonicalXMLStringPreservingComments:(BOOL)comments; 84 | - (NSArray *)nodesForXPath:(NSString *)xpath error:(NSError **)error; 85 | @end 86 | -------------------------------------------------------------------------------- /Libraries/TouchXML/CXMLNode_PrivateExtensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLNode_PrivateExtensions.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 03/07/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLNode.h" 33 | 34 | @interface CXMLNode (CXMLNode_PrivateExtensions) 35 | 36 | @property (readonly, nonatomic, assign) xmlNodePtr node; 37 | 38 | - (id)initWithLibXMLNode:(xmlNodePtr)inLibXMLNode freeOnDealloc:(BOOL)infreeOnDealloc; 39 | 40 | + (id)nodeWithLibXMLNode:(xmlNodePtr)inLibXMLNode freeOnDealloc:(BOOL)infreeOnDealloc; 41 | 42 | - (void)invalidate; 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /Libraries/TouchXML/CXMLNode_PrivateExtensions.m: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLNode_PrivateExtensions.m 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 03/07/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLNode_PrivateExtensions.h" 33 | 34 | #import "CXMLElement.h" 35 | #import "CXMLDocument_PrivateExtensions.h" 36 | 37 | @implementation CXMLNode (CXMLNode_PrivateExtensions) 38 | 39 | - (id)initWithLibXMLNode:(xmlNodePtr)inLibXMLNode freeOnDealloc:(BOOL)infreeOnDealloc 40 | { 41 | if (inLibXMLNode == NULL) 42 | return nil; 43 | 44 | if ((self = [super init]) != NULL) 45 | { 46 | _node = inLibXMLNode; 47 | _freeNodeOnRelease = infreeOnDealloc; 48 | } 49 | return(self); 50 | } 51 | 52 | + (id)nodeWithLibXMLNode:(xmlNodePtr)inLibXMLNode freeOnDealloc:(BOOL)infreeOnDealloc 53 | { 54 | // TODO more checking. 55 | if (inLibXMLNode == NULL) 56 | return nil; 57 | 58 | if (inLibXMLNode->_private) 59 | return((__bridge id)inLibXMLNode->_private); 60 | 61 | Class theClass = [CXMLNode class]; 62 | switch (inLibXMLNode->type) 63 | { 64 | case XML_ELEMENT_NODE: 65 | theClass = [CXMLElement class]; 66 | break; 67 | case XML_DOCUMENT_NODE: 68 | theClass = [CXMLDocument class]; 69 | break; 70 | case XML_ATTRIBUTE_NODE: 71 | case XML_TEXT_NODE: 72 | case XML_CDATA_SECTION_NODE: 73 | case XML_COMMENT_NODE: 74 | break; 75 | default: 76 | NSAssert1(NO, @"TODO Unhandled type (%d).", inLibXMLNode->type); 77 | return(NULL); 78 | } 79 | 80 | CXMLNode *theNode = [[theClass alloc] initWithLibXMLNode:inLibXMLNode freeOnDealloc:infreeOnDealloc]; 81 | 82 | 83 | if (inLibXMLNode->doc != NULL) 84 | { 85 | CXMLDocument *theXMLDocument = (__bridge CXMLDocument *)inLibXMLNode->doc->_private; 86 | if (theXMLDocument != NULL) 87 | { 88 | NSAssert([theXMLDocument isKindOfClass:[CXMLDocument class]] == YES, @"TODO"); 89 | 90 | [[theXMLDocument nodePool] addObject:theNode]; 91 | 92 | theNode->_node->_private = (__bridge void *)theNode; 93 | } 94 | } 95 | return(theNode); 96 | } 97 | 98 | - (xmlNodePtr)node 99 | { 100 | return(_node); 101 | } 102 | 103 | - (void)invalidate; 104 | { 105 | if (_node) 106 | { 107 | if (_node->_private == (__bridge void *)self) 108 | _node->_private = NULL; 109 | 110 | if (_freeNodeOnRelease) 111 | { 112 | xmlUnlinkNode(_node); 113 | xmlFreeNode(_node); 114 | } 115 | 116 | _node = NULL; 117 | } 118 | } 119 | 120 | @end 121 | -------------------------------------------------------------------------------- /Libraries/TouchXML/CXMLNode_XPathExtensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLNode_XPathExtensions.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 04/01/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLNode.h" 33 | 34 | @interface CXMLNode (CXMLNode_XPathExtensions) 35 | 36 | - (NSArray *)nodesForXPath:(NSString *)xpath namespaceMappings:(NSDictionary *)inNamespaceMappings error:(NSError **)error; 37 | - (CXMLNode *)nodeForXPath:(NSString *)xpath error:(NSError **)outError; 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /Libraries/TouchXML/CXMLNode_XPathExtensions.m: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLNode_XPathExtensions.m 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 04/01/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLNode_XPathExtensions.h" 33 | 34 | #import "CXMLDocument.h" 35 | #import "CXMLNode_PrivateExtensions.h" 36 | 37 | #include 38 | #include 39 | 40 | @implementation CXMLNode (CXMLNode_NamespaceExtensions) 41 | 42 | - (NSArray *)nodesForXPath:(NSString *)xpath namespaceMappings:(NSDictionary *)inNamespaceMappings error:(NSError **)error; 43 | { 44 | #pragma unused (error) 45 | 46 | NSAssert(_node != NULL, @"TODO"); 47 | 48 | NSArray *theResult = NULL; 49 | 50 | xmlXPathContextPtr theXPathContext = xmlXPathNewContext(_node->doc); 51 | theXPathContext->node = _node; 52 | 53 | for (NSString *thePrefix in inNamespaceMappings) 54 | { 55 | xmlXPathRegisterNs(theXPathContext, (xmlChar *)[thePrefix UTF8String], (xmlChar *)[[inNamespaceMappings objectForKey:thePrefix] UTF8String]); 56 | } 57 | 58 | // TODO considering putting xmlChar <-> UTF8 into a NSString category 59 | xmlXPathObjectPtr theXPathObject = xmlXPathEvalExpression((const xmlChar *)[xpath UTF8String], theXPathContext); 60 | if (xmlXPathNodeSetIsEmpty(theXPathObject->nodesetval)) 61 | theResult = [NSArray array]; // TODO better to return NULL? 62 | else 63 | { 64 | NSMutableArray *theArray = [NSMutableArray array]; 65 | int N; 66 | for (N = 0; N < theXPathObject->nodesetval->nodeNr; N++) 67 | { 68 | xmlNodePtr theNode = theXPathObject->nodesetval->nodeTab[N]; 69 | [theArray addObject:[CXMLNode nodeWithLibXMLNode:theNode freeOnDealloc:NO]]; 70 | } 71 | 72 | theResult = theArray; 73 | } 74 | 75 | xmlXPathFreeObject(theXPathObject); 76 | 77 | xmlXPathFreeContext(theXPathContext); 78 | return(theResult); 79 | } 80 | 81 | - (CXMLNode *)nodeForXPath:(NSString *)xpath error:(NSError **)outError 82 | { 83 | return([[self nodesForXPath:xpath error:outError] lastObject]); 84 | } 85 | 86 | @end 87 | -------------------------------------------------------------------------------- /Libraries/TouchXML/Creation/CXMLDocument_CreationExtensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLDocument_CreationExtensions.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 11/11/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLDocument.h" 33 | 34 | @interface CXMLDocument (CXMLDocument_CreationExtensions) 35 | 36 | //- (void)setVersion:(NSString *)version; //primitive 37 | //- (void)setStandalone:(BOOL)standalone; //primitive 38 | //- (void)setDocumentContentKind:(CXMLDocumentContentKind)kind; //primitive 39 | //- (void)setMIMEType:(NSString *)MIMEType; //primitive 40 | //- (void)setDTD:(CXMLDTD *)documentTypeDeclaration; //primitive 41 | //- (void)setRootElement:(CXMLNode *)root; 42 | - (void)insertChild:(CXMLNode *)child atIndex:(NSUInteger)index; 43 | //- (void)insertChildren:(NSArray *)children atIndex:(NSUInteger)index; 44 | //- (void)removeChildAtIndex:(NSUInteger)index; //primitive 45 | //- (void)setChildren:(NSArray *)children; //primitive 46 | - (void)addChild:(CXMLNode *)child; 47 | //- (void)replaceChildAtIndex:(NSUInteger)index withNode:(CXMLNode *)node; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /Libraries/TouchXML/Creation/CXMLDocument_CreationExtensions.m: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLDocument_CreationExtensions.m 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 11/11/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLDocument_CreationExtensions.h" 33 | 34 | #import "CXMLElement.h" 35 | #import "CXMLNode_PrivateExtensions.h" 36 | #import "CXMLDocument_PrivateExtensions.h" 37 | 38 | @implementation CXMLDocument (CXMLDocument_CreationExtensions) 39 | 40 | - (void)insertChild:(CXMLNode *)child atIndex:(NSUInteger)index 41 | { 42 | [self.nodePool addObject:child]; 43 | 44 | CXMLNode *theCurrentNode = [self.children objectAtIndex:index]; 45 | xmlAddPrevSibling(theCurrentNode->_node, child->_node); 46 | } 47 | 48 | - (void)addChild:(CXMLNode *)child 49 | { 50 | [self.nodePool addObject:child]; 51 | 52 | xmlAddChild(self->_node, child->_node); 53 | } 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /Libraries/TouchXML/Creation/CXMLNode_CreationExtensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLNode_CreationExtensions.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 04/01/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLNode.h" 33 | 34 | @class CXMLElement; 35 | 36 | @interface CXMLNode (CXMLNode_CreationExtensions) 37 | 38 | //- (id)initWithKind:(NSXMLNodeKind)kind; 39 | //- (id)initWithKind:(NSXMLNodeKind)kind options:(NSUInteger)options; //primitive 40 | + (id)document; 41 | + (id)documentWithRootElement:(CXMLElement *)element; 42 | + (id)elementWithName:(NSString *)name; 43 | + (id)elementWithName:(NSString *)name URI:(NSString *)URI; 44 | + (id)elementWithName:(NSString *)name stringValue:(NSString *)string; 45 | //+ (id)elementWithName:(NSString *)name children:(NSArray *)children attributes:(NSArray *)attributes; 46 | //+ (id)attributeWithName:(NSString *)name stringValue:(NSString *)stringValue; 47 | //+ (id)attributeWithName:(NSString *)name URI:(NSString *)URI stringValue:(NSString *)stringValue; 48 | + (id)namespaceWithName:(NSString *)name stringValue:(NSString *)stringValue; 49 | + (id)processingInstructionWithName:(NSString *)name stringValue:(NSString *)stringValue; 50 | //+ (id)commentWithStringValue:(NSString *)stringValue; 51 | //+ (id)textWithStringValue:(NSString *)stringValue; 52 | //+ (id)DTDNodeWithXMLString:(NSString *)string; 53 | 54 | - (void)setStringValue:(NSString *)inStringValue; 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /Libraries/TouchXML/Creation/CXMLNode_CreationExtensions.m: -------------------------------------------------------------------------------- 1 | // 2 | // CXMLNode_CreationExtensions.m 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 04/01/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLNode_CreationExtensions.h" 33 | 34 | #import "CXMLDocument.h" 35 | #import "CXMLElement.h" 36 | #import "CXMLNode_PrivateExtensions.h" 37 | #import "CXMLDocument_PrivateExtensions.h" 38 | #import "CXMLNamespaceNode.h" 39 | 40 | @implementation CXMLNode (CXMLNode_CreationExtensions) 41 | 42 | + (id)document; 43 | { 44 | xmlDocPtr theDocumentNode = xmlNewDoc((const xmlChar *)"1.0"); 45 | NSAssert(theDocumentNode != NULL, @"xmlNewDoc failed"); 46 | CXMLDocument *theDocument = [[CXMLDocument alloc] initWithLibXMLNode:(xmlNodePtr)theDocumentNode freeOnDealloc:NO]; 47 | return(theDocument); 48 | } 49 | 50 | + (id)documentWithRootElement:(CXMLElement *)element; 51 | { 52 | xmlDocPtr theDocumentNode = xmlNewDoc((const xmlChar *)"1.0"); 53 | NSAssert(theDocumentNode != NULL, @"xmlNewDoc failed"); 54 | xmlDocSetRootElement(theDocumentNode, element.node); 55 | CXMLDocument *theDocument = [[CXMLDocument alloc] initWithLibXMLNode:(xmlNodePtr)theDocumentNode freeOnDealloc:NO]; 56 | [theDocument.nodePool addObject:element]; 57 | return(theDocument); 58 | } 59 | 60 | + (id)elementWithName:(NSString *)name 61 | { 62 | xmlNodePtr theElementNode = xmlNewNode(NULL, (const xmlChar *)[name UTF8String]); 63 | CXMLElement *theElement = [[CXMLElement alloc] initWithLibXMLNode:(xmlNodePtr)theElementNode freeOnDealloc:NO]; 64 | return(theElement); 65 | } 66 | 67 | + (id)elementWithName:(NSString *)name URI:(NSString *)URI 68 | { 69 | xmlNodePtr theElementNode = xmlNewNode(NULL, (const xmlChar *)[name UTF8String]); 70 | xmlNsPtr theNSNode = xmlNewNs(theElementNode, (const xmlChar *)[URI UTF8String], NULL); 71 | theElementNode->ns = theNSNode; 72 | 73 | CXMLElement *theElement = [[CXMLElement alloc] initWithLibXMLNode:(xmlNodePtr)theElementNode freeOnDealloc:NO]; 74 | return(theElement); 75 | } 76 | 77 | + (id)elementWithName:(NSString *)name stringValue:(NSString *)string 78 | { 79 | xmlNodePtr theElementNode = xmlNewNode(NULL, (const xmlChar *)[name UTF8String]); 80 | CXMLElement *theElement = [[CXMLElement alloc] initWithLibXMLNode:(xmlNodePtr)theElementNode freeOnDealloc:NO]; 81 | theElement.stringValue = string; 82 | return(theElement); 83 | } 84 | 85 | + (id)namespaceWithName:(NSString *)name stringValue:(NSString *)stringValue 86 | { 87 | return [[CXMLNamespaceNode alloc] initWithPrefix:name URI:stringValue parentElement:nil]; 88 | } 89 | 90 | + (id)processingInstructionWithName:(NSString *)name stringValue:(NSString *)stringValue; 91 | { 92 | xmlNodePtr theNode = xmlNewPI((const xmlChar *)[name UTF8String], (const xmlChar *)[stringValue UTF8String]); 93 | NSAssert(theNode != NULL, @"xmlNewPI failed"); 94 | CXMLNode *theNodeObject = [[CXMLNode alloc] initWithLibXMLNode:theNode freeOnDealloc:NO]; 95 | return(theNodeObject); 96 | } 97 | 98 | - (void)setStringValue:(NSString *)inStringValue 99 | { 100 | NSAssert(_node->type == XML_TEXT_NODE, @"CNode setStringValue only implemented for text nodes"); 101 | xmlNodeSetContent(_node, (const xmlChar *)[inStringValue UTF8String]); 102 | } 103 | 104 | @end 105 | 106 | -------------------------------------------------------------------------------- /Libraries/TouchXML/Tidy/CTidy.h: -------------------------------------------------------------------------------- 1 | // 2 | // CTidy.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 03/07/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #ifdef TOUCHXMLUSETIDY 33 | 34 | #import 35 | 36 | #include "tidy.h" 37 | #include "buffio.h" 38 | 39 | typedef enum { 40 | TidyFormat_HTML, 41 | TidyFormat_XML, 42 | TidyFormat_XHTML, 43 | } CTidyFormat; 44 | 45 | @interface CTidy : NSObject { 46 | } 47 | 48 | + (CTidy *)tidy; 49 | 50 | - (NSData *)tidyData:(NSData *)inData inputFormat:(CTidyFormat)inInputFormat outputFormat:(CTidyFormat)inOutputFormat encoding:(const char *)encoding diagnostics:(NSString **)outDiagnostics error:(NSError **)outError; 51 | - (NSString *)tidyString:(NSString *)inString inputFormat:(CTidyFormat)inInputFormat outputFormat:(CTidyFormat)inOutputFormat encoding:(const char *)encoding diagnostics:(NSString **)outDiagnostics error:(NSError **)outError; 52 | 53 | @end 54 | 55 | #endif /* TOUCHXMLUSETIDY */ 56 | -------------------------------------------------------------------------------- /Libraries/TouchXML/Tidy/CTidy.m: -------------------------------------------------------------------------------- 1 | // 2 | // CTidy.m 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 03/07/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #ifdef TOUCHXMLUSETIDY 33 | 34 | #import "CTidy.h" 35 | 36 | @interface CTidy () 37 | @end 38 | 39 | #pragma mark - 40 | 41 | @implementation CTidy 42 | 43 | + (CTidy *)tidy 44 | { 45 | return([[[self alloc] init] autorelease]); 46 | } 47 | 48 | - (NSData *)tidyData:(NSData *)inData inputFormat:(CTidyFormat)inInputFormat outputFormat:(CTidyFormat)inOutputFormat encoding:(const char*)encoding diagnostics:(NSString **)outDiagnostics error:(NSError **)outError 49 | { 50 | TidyDoc theTidyDocument = tidyCreate(); 51 | 52 | int theResultCode = 0; 53 | 54 | // Set input format if input is XML (xhtml & html are the tidy 'default') 55 | if (inInputFormat == TidyFormat_XML) 56 | { 57 | theResultCode = tidyOptSetBool(theTidyDocument, TidyXmlTags, YES); 58 | NSAssert(theResultCode >= 0, @"tidyOptSetBool() should return 0"); 59 | } 60 | 61 | // Set output format 62 | TidyOptionId theOutputValue = TidyXmlOut; 63 | if (inOutputFormat == TidyFormat_HTML) 64 | theOutputValue = TidyHtmlOut; 65 | else if (inOutputFormat == TidyFormat_XHTML) 66 | theOutputValue = TidyXhtmlOut; 67 | theResultCode = tidyOptSetBool(theTidyDocument, theOutputValue, YES); 68 | NSAssert(theResultCode >= 0, @"tidyOptSetBool() should return 0"); 69 | 70 | // Force output even if errors found 71 | theResultCode = tidyOptSetBool(theTidyDocument, TidyForceOutput, YES); 72 | NSAssert(theResultCode >= 0, @"tidyOptSetBool() should return 0"); 73 | 74 | // Set encoding - same for input and output 75 | theResultCode = tidySetInCharEncoding(theTidyDocument, encoding) 76 | NSAssert(theResultCode >= 0, @"tidySetInCharEncoding() should return 0"); 77 | theResultCode = tidySetOutCharEncoding(theTidyDocument, encoding); 78 | NSAssert(theResultCode >= 0, @"tidySetOutCharEncoding() should return 0"); 79 | 80 | // Create an error buffer 81 | TidyBuffer theErrorBuffer; 82 | tidyBufInit(&theErrorBuffer); 83 | theResultCode = tidySetErrorBuffer(theTidyDocument, &theErrorBuffer); 84 | NSAssert(theResultCode >= 0, @"tidySetErrorBuffer() should return 0"); 85 | 86 | // ############################################################################# 87 | 88 | // Create an input buffer and copy input to it (TODO uses 2X memory == bad!) 89 | TidyBuffer theInputBuffer; 90 | tidyBufAlloc(&theInputBuffer, [inData length]); 91 | memcpy(theInputBuffer.bp, [inData bytes], [inData length]); 92 | theInputBuffer.size = [inData length]; 93 | 94 | // Parse the data. 95 | theResultCode = tidyParseBuffer(theTidyDocument, &theInputBuffer); 96 | if (theResultCode < 0) 97 | { 98 | if (outError) 99 | { 100 | NSDictionary *theUserInfo = [NSDictionary dictionaryWithObjectsAndKeys: 101 | [NSString stringWithUTF8String:(char *)theErrorBuffer.bp], NSLocalizedDescriptionKey, 102 | NULL]; 103 | *outError = [NSError errorWithDomain:@"TODO_DOMAIN" code:theResultCode userInfo:theUserInfo]; 104 | } 105 | return(NO); 106 | } 107 | 108 | // Clean up input buffer. 109 | tidyBufFree(&theInputBuffer); 110 | 111 | // Repair the data 112 | theResultCode = tidyCleanAndRepair(theTidyDocument); 113 | if (theResultCode < 0) 114 | { 115 | return(NULL); 116 | } 117 | 118 | //theResultCode = tidyRunDiagnostics(theTidyDocument); 119 | 120 | // 121 | TidyBuffer theOutputBuffer; 122 | tidyBufInit(&theOutputBuffer); 123 | theResultCode = tidySaveBuffer(theTidyDocument, &theOutputBuffer); 124 | if (theResultCode < 0) 125 | return(NULL); 126 | NSAssert(theOutputBuffer.bp != NULL, @"The buffer should not be null."); 127 | NSData *theOutput = [NSData dataWithBytes:theOutputBuffer.bp length:theOutputBuffer.size]; 128 | tidyBufFree(&theOutputBuffer); 129 | 130 | // 131 | if (outDiagnostics && theErrorBuffer.bp != NULL) 132 | { 133 | NSData *theErrorData = [NSData dataWithBytes:theErrorBuffer.bp length:theErrorBuffer.size]; 134 | *outDiagnostics = [[[NSString alloc] initWithData:theErrorData encoding:NSUTF8StringEncoding] autorelease]; 135 | } 136 | tidyBufFree(&theErrorBuffer); 137 | 138 | // ############################################################################# 139 | 140 | tidyRelease(theTidyDocument); 141 | 142 | return(theOutput); 143 | } 144 | 145 | - (NSString *)tidyString:(NSString *)inString inputFormat:(CTidyFormat)inInputFormat outputFormat:(CTidyFormat)inOutputFormat encoding:(const char*)encoding diagnostics:(NSString **)outDiagnostics error:(NSError **)outError 146 | { 147 | TidyDoc theTidyDocument = tidyCreate(); 148 | 149 | int theResultCode = 0; 150 | 151 | // Set input format if input is XML (xhtml & html are the tidy 'default') 152 | if (inInputFormat == TidyFormat_XML) 153 | { 154 | theResultCode = tidyOptSetBool(theTidyDocument, TidyXmlTags, YES); 155 | NSAssert(theResultCode >= 0, @"tidyOptSetBool() should return 0"); 156 | } 157 | 158 | // Set output format 159 | TidyOptionId theOutputValue = TidyXmlOut; 160 | if (inOutputFormat == TidyFormat_HTML) 161 | theOutputValue = TidyHtmlOut; 162 | else if (inOutputFormat == TidyFormat_XHTML) 163 | theOutputValue = TidyXhtmlOut; 164 | theResultCode = tidyOptSetBool(theTidyDocument, theOutputValue, YES); 165 | NSAssert(theResultCode >= 0, @"tidyOptSetBool() should return 0"); 166 | 167 | // Force output even if errors found 168 | theResultCode = tidyOptSetBool(theTidyDocument, TidyForceOutput, YES); 169 | NSAssert(theResultCode >= 0, @"tidyOptSetBool() should return 0"); 170 | 171 | // Set encoding - same for input and output 172 | theResultCode = tidySetInCharEncoding(theTidyDocument, encoding) 173 | NSAssert(theResultCode >= 0, @"tidySetInCharEncoding() should return 0"); 174 | theResultCode = tidySetOutCharEncoding(theTidyDocument, encoding); 175 | NSAssert(theResultCode >= 0, @"tidySetOutCharEncoding() should return 0"); 176 | 177 | // Create an error buffer 178 | TidyBuffer theErrorBuffer; 179 | tidyBufInit(&theErrorBuffer); 180 | theResultCode = tidySetErrorBuffer(theTidyDocument, &theErrorBuffer); 181 | NSAssert(theResultCode >= 0, @"tidySetErrorBuffer() should return 0"); 182 | 183 | // ############################################################################# 184 | 185 | // Parse the data. 186 | theResultCode = tidyParseString(theTidyDocument, [inString UTF8String]); 187 | if (theResultCode < 0) 188 | { 189 | if (outError) 190 | { 191 | NSDictionary *theUserInfo = [NSDictionary dictionaryWithObjectsAndKeys: 192 | [NSString stringWithUTF8String:(char *)theErrorBuffer.bp], NSLocalizedDescriptionKey, 193 | NULL]; 194 | *outError = [NSError errorWithDomain:@"TODO_DOMAIN" code:theResultCode userInfo:theUserInfo]; 195 | } 196 | return(NO); 197 | } 198 | 199 | // Repair the data 200 | theResultCode = tidyCleanAndRepair(theTidyDocument); 201 | if (theResultCode < 0) 202 | { 203 | return(NULL); 204 | } 205 | 206 | //theResultCode = tidyRunDiagnostics(theTidyDocument); 207 | 208 | // 209 | uint theBufferLength = 0; 210 | 211 | theResultCode = tidySaveString(theTidyDocument, NULL, &theBufferLength); 212 | 213 | NSMutableData *theOutputBuffer = [NSMutableData dataWithLength:theBufferLength]; 214 | 215 | theResultCode = tidySaveString(theTidyDocument, [theOutputBuffer mutableBytes], &theBufferLength); 216 | 217 | NSString *theString = [[[NSString alloc] initWithData:theOutputBuffer encoding:NSUTF8StringEncoding] autorelease]; 218 | 219 | // 220 | if (outDiagnostics && theErrorBuffer.bp != NULL) 221 | { 222 | NSData *theErrorData = [NSData dataWithBytes:theErrorBuffer.bp length:theErrorBuffer.size]; 223 | *outDiagnostics = [[[NSString alloc] initWithData:theErrorData encoding:NSUTF8StringEncoding] autorelease]; 224 | } 225 | tidyBufFree(&theErrorBuffer); 226 | 227 | // ############################################################################# 228 | 229 | tidyRelease(theTidyDocument); 230 | 231 | return(theString); 232 | } 233 | 234 | @end 235 | 236 | #endif /* TOUCHXMLUSETIDY */ 237 | -------------------------------------------------------------------------------- /Libraries/TouchXML/TouchXML.h: -------------------------------------------------------------------------------- 1 | // 2 | // TouchXML.h 3 | // TouchCode 4 | // 5 | // Created by Jonathan Wight on 07/11/08. 6 | // Copyright 2011 toxicsoftware.com. All rights reserved. 7 | // 8 | // Redistribution and use in source and binary forms, with or without modification, are 9 | // permitted provided that the following conditions are met: 10 | // 11 | // 1. Redistributions of source code must retain the above copyright notice, this list of 12 | // conditions and the following disclaimer. 13 | // 14 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 15 | // of conditions and the following disclaimer in the documentation and/or other materials 16 | // provided with the distribution. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY TOXICSOFTWARE.COM ``AS IS'' AND ANY EXPRESS OR IMPLIED 19 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 | // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TOXICSOFTWARE.COM OR 21 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | // 28 | // The views and conclusions contained in the software and documentation are those of the 29 | // authors and should not be interpreted as representing official policies, either expressed 30 | // or implied, of toxicsoftware.com. 31 | 32 | #import "CXMLDocument.h" 33 | #import "CXMLDocument_CreationExtensions.h" 34 | #import "CXMLElement.h" 35 | #import "CXMLElement_CreationExtensions.h" 36 | #import "CXMLElement_ElementTreeExtensions.h" 37 | #import "CXMLNode.h" 38 | #import "CXMLNode_CreationExtensions.h" 39 | #import "CXMLNode_XPathExtensions.h" 40 | -------------------------------------------------------------------------------- /Libraries/ZipArchive/ZipArchive.h: -------------------------------------------------------------------------------- 1 | /** 2 | // @header ZipArchive.h 3 | // 4 | // An objective C wrapper for minizip and libz for creating and exanding ZIP files. 5 | // 6 | // @author Created by aish on 08-9-11. 7 | // acsolu@gmail.com 8 | // @copyright Copyright 2008 Inc. All rights reserved. 9 | // 10 | */ 11 | 12 | 13 | #include "minizip/zip.h" 14 | #include "minizip/unzip.h" 15 | 16 | 17 | /** 18 | a block that is called from UnzipFileTo:overwrite:withProgressBlock: where the percentage of 19 | files processed (as an integer from 0 to 100), the number of files processed so far and the 20 | total number of files in the archive is called after each file is processed. 21 | */ 22 | typedef void(^ZipArchiveProgressUpdateBlock)(int percentage, int filesProcessed, int numFiles); 23 | 24 | /** 25 | @protocol 26 | @discussion methods for a delegate to receive error notifications and control overwriting of files 27 | */ 28 | 29 | @protocol ZipArchiveDelegate 30 | @optional 31 | 32 | /** 33 | @brief Delegate method to be notified of errors 34 | 35 | ZipArchive calls this selector on the delegate when errors are encountered. 36 | 37 | @param msg a string describing the error. 38 | @result void 39 | */ 40 | 41 | -(void) ErrorMessage:(NSString*) msg; 42 | 43 | /** 44 | @brief Delegate method to determine if a file should be replaced 45 | 46 | When an zip file is being expanded and a file is about to be replaced, this selector 47 | is called on the delegate to notify that file is about to be replaced. The delegate method 48 | should return YES to overwrite the file, or NO to skip it. 49 | 50 | @param file - path to the file to be overwritten. 51 | @result a BOOL - YES to replace, NO to skip 52 | */ 53 | 54 | -(BOOL) OverWriteOperation:(NSString*) file; 55 | 56 | @end 57 | 58 | /** 59 | @class 60 | @brief An object that can create zip files and expand existing ones. 61 | This class provides methods to create a zip file (optionally with a password) and 62 | add files to that zip archive. 63 | 64 | It also provides methods to expand an existing archive file (optionally with a password), 65 | and extract the files. 66 | */ 67 | 68 | @interface ZipArchive : NSObject { 69 | @private 70 | zipFile _zipFile; 71 | unzFile _unzFile; 72 | 73 | int _numFiles; 74 | NSString* _password; 75 | id _delegate; 76 | ZipArchiveProgressUpdateBlock _progressBlock; 77 | 78 | NSArray* _unzippedFiles; 79 | } 80 | 81 | /** a delegate object conforming to ZipArchiveDelegate protocol */ 82 | @property (nonatomic, retain) id delegate; 83 | @property (nonatomic, readonly) int numFiles; 84 | @property (nonatomic, copy) ZipArchiveProgressUpdateBlock progressBlock; 85 | 86 | /** an array of files that were successfully expanded. Available after calling UnzipFileTo:overWrite: */ 87 | @property (nonatomic, readonly) NSArray* unzippedFiles; 88 | 89 | -(BOOL) CreateZipFile2:(NSString*) zipFile; 90 | -(BOOL) CreateZipFile2:(NSString*) zipFile Password:(NSString*) password; 91 | -(BOOL) addFileToZip:(NSString*) file newname:(NSString*) newname; 92 | -(BOOL) CloseZipFile2; 93 | 94 | -(BOOL) UnzipOpenFile:(NSString*) zipFile; 95 | -(BOOL) UnzipOpenFile:(NSString*) zipFile Password:(NSString*) password; 96 | -(BOOL) UnzipFileTo:(NSString*) path overWrite:(BOOL) overwrite; 97 | -(BOOL) UnzipCloseFile; 98 | -(NSArray*) getZipFileContents; // list the contents of the zip archive. must be called after UnzipOpenFile 99 | 100 | @end 101 | -------------------------------------------------------------------------------- /Libraries/ZipArchive/minizip/ChangeLogUnzip: -------------------------------------------------------------------------------- 1 | Change in 1.01e (12 feb 05) 2 | - Fix in zipOpen2 for globalcomment (Rolf Kalbermatter) 3 | - Fix possible memory leak in unzip.c (Zoran Stevanovic) 4 | 5 | Change in 1.01b (20 may 04) 6 | - Integrate patch from Debian package (submited by Mark Brown) 7 | - Add tools mztools from Xavier Roche 8 | 9 | Change in 1.01 (8 may 04) 10 | - fix buffer overrun risk in unzip.c (Xavier Roche) 11 | - fix a minor buffer insecurity in minizip.c (Mike Whittaker) 12 | 13 | Change in 1.00: (10 sept 03) 14 | - rename to 1.00 15 | - cosmetic code change 16 | 17 | Change in 0.22: (19 May 03) 18 | - crypting support (unless you define NOCRYPT) 19 | - append file in existing zipfile 20 | 21 | Change in 0.21: (10 Mar 03) 22 | - bug fixes 23 | 24 | Change in 0.17: (27 Jan 02) 25 | - bug fixes 26 | 27 | Change in 0.16: (19 Jan 02) 28 | - Support of ioapi for virtualize zip file access 29 | 30 | Change in 0.15: (19 Mar 98) 31 | - fix memory leak in minizip.c 32 | 33 | Change in 0.14: (10 Mar 98) 34 | - fix bugs in minizip.c sample for zipping big file 35 | - fix problem in month in date handling 36 | - fix bug in unzlocal_GetCurrentFileInfoInternal in unzip.c for 37 | comment handling 38 | 39 | Change in 0.13: (6 Mar 98) 40 | - fix bugs in zip.c 41 | - add real minizip sample 42 | 43 | Change in 0.12: (4 Mar 98) 44 | - add zip.c and zip.h for creates .zip file 45 | - fix change_file_date in miniunz.c for Unix (Jean-loup Gailly) 46 | - fix miniunz.c for file without specific record for directory 47 | 48 | Change in 0.11: (3 Mar 98) 49 | - fix bug in unzGetCurrentFileInfo for get extra field and comment 50 | - enhance miniunz sample, remove the bad unztst.c sample 51 | 52 | Change in 0.10: (2 Mar 98) 53 | - fix bug in unzReadCurrentFile 54 | - rename unzip* to unz* function and structure 55 | - remove Windows-like hungary notation variable name 56 | - modify some structure in unzip.h 57 | - add somes comment in source 58 | - remove unzipGetcCurrentFile function 59 | - replace ZUNZEXPORT by ZEXPORT 60 | - add unzGetLocalExtrafield for get the local extrafield info 61 | - add a new sample, miniunz.c 62 | 63 | Change in 0.4: (25 Feb 98) 64 | - suppress the type unzipFileInZip. 65 | Only on file in the zipfile can be open at the same time 66 | - fix somes typo in code 67 | - added tm_unz structure in unzip_file_info (date/time in readable format) 68 | -------------------------------------------------------------------------------- /Libraries/ZipArchive/minizip/Makefile: -------------------------------------------------------------------------------- 1 | CC=cc 2 | CFLAGS=-O -I../.. 3 | 4 | UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a 5 | ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a 6 | 7 | .c.o: 8 | $(CC) -c $(CFLAGS) $*.c 9 | 10 | all: miniunz minizip 11 | 12 | miniunz: $(UNZ_OBJS) 13 | $(CC) $(CFLAGS) -o $@ $(UNZ_OBJS) 14 | 15 | minizip: $(ZIP_OBJS) 16 | $(CC) $(CFLAGS) -o $@ $(ZIP_OBJS) 17 | 18 | test: miniunz minizip 19 | ./minizip test readme.txt 20 | ./miniunz -l test.zip 21 | mv readme.txt readme.old 22 | ./miniunz test.zip 23 | 24 | clean: 25 | /bin/rm -f *.o *~ minizip miniunz 26 | -------------------------------------------------------------------------------- /Libraries/ZipArchive/minizip/crypt.h: -------------------------------------------------------------------------------- 1 | /* crypt.h -- base code for crypt/uncrypt ZIPfile 2 | 3 | 4 | Version 1.01h, December 28th, 2009 5 | 6 | Copyright (C) 1998-2009 Gilles Vollant 7 | 8 | This code is a modified version of crypting code in Infozip distribution 9 | 10 | The encryption/decryption parts of this source code (as opposed to the 11 | non-echoing password parts) were originally written in Europe. The 12 | whole source package can be freely distributed, including from the USA. 13 | (Prior to January 2000, re-export from the US was a violation of US law.) 14 | 15 | This encryption code is a direct transcription of the algorithm from 16 | Roger Schlafly, described by Phil Katz in the file appnote.txt. This 17 | file (appnote.txt) is distributed with the PKZIP program (even in the 18 | version without encryption capabilities). 19 | 20 | If you don't need crypting in your application, just define symbols 21 | NOCRYPT and NOUNCRYPT. 22 | 23 | This code support the "Traditional PKWARE Encryption". 24 | 25 | The new AES encryption added on Zip format by Winzip (see the page 26 | http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong 27 | Encryption is not supported. 28 | */ 29 | 30 | #define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) 31 | 32 | /*********************************************************************** 33 | * Return the next byte in the pseudo-random sequence 34 | */ 35 | static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab) 36 | { 37 | unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an 38 | * unpredictable manner on 16-bit systems; not a problem 39 | * with any known compiler so far, though */ 40 | 41 | temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; 42 | return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); 43 | } 44 | 45 | /*********************************************************************** 46 | * Update the encryption keys with the next byte of plain text 47 | */ 48 | static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c) 49 | { 50 | (*(pkeys+0)) = CRC32((*(pkeys+0)), c); 51 | (*(pkeys+1)) += (*(pkeys+0)) & 0xff; 52 | (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; 53 | { 54 | register int keyshift = (int)((*(pkeys+1)) >> 24); 55 | (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); 56 | } 57 | return c; 58 | } 59 | 60 | 61 | /*********************************************************************** 62 | * Initialize the encryption keys and the random header according to 63 | * the given password. 64 | */ 65 | static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab) 66 | { 67 | *(pkeys+0) = 305419896L; 68 | *(pkeys+1) = 591751049L; 69 | *(pkeys+2) = 878082192L; 70 | while (*passwd != '\0') { 71 | update_keys(pkeys,pcrc_32_tab,(int)*passwd); 72 | passwd++; 73 | } 74 | } 75 | 76 | #define zdecode(pkeys,pcrc_32_tab,c) \ 77 | (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) 78 | 79 | #define zencode(pkeys,pcrc_32_tab,c,t) \ 80 | (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) 81 | 82 | #ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED 83 | 84 | #define RAND_HEAD_LEN 12 85 | /* "last resort" source for second part of crypt seed pattern */ 86 | # ifndef ZCR_SEED2 87 | # define ZCR_SEED2 3141592654UL /* use PI as default pattern */ 88 | # endif 89 | 90 | static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting) 91 | const char *passwd; /* password string */ 92 | unsigned char *buf; /* where to write header */ 93 | int bufSize; 94 | unsigned long* pkeys; 95 | const unsigned long* pcrc_32_tab; 96 | unsigned long crcForCrypting; 97 | { 98 | int n; /* index in random header */ 99 | int t; /* temporary */ 100 | int c; /* random byte */ 101 | unsigned char header[RAND_HEAD_LEN-2]; /* random header */ 102 | static unsigned calls = 0; /* ensure different random header each time */ 103 | 104 | if (bufSize> 7) & 0xff; 119 | header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); 120 | } 121 | /* Encrypt random header (last two bytes is high word of crc) */ 122 | init_keys(passwd, pkeys, pcrc_32_tab); 123 | for (n = 0; n < RAND_HEAD_LEN-2; n++) 124 | { 125 | buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); 126 | } 127 | buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); 128 | buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); 129 | return n; 130 | } 131 | 132 | #endif 133 | -------------------------------------------------------------------------------- /Libraries/ZipArchive/minizip/ioapi.c: -------------------------------------------------------------------------------- 1 | /* ioapi.c -- IO base function header for compress/uncompress .zip 2 | files using zlib + zip or unzip API 3 | 4 | Version 1.01h, December 28th, 2009 5 | 6 | Copyright (C) 1998-2009 Gilles Vollant 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "zlib.h" 14 | #include "ioapi.h" 15 | 16 | 17 | 18 | /* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ 19 | 20 | #ifndef SEEK_CUR 21 | #define SEEK_CUR 1 22 | #endif 23 | 24 | #ifndef SEEK_END 25 | #define SEEK_END 2 26 | #endif 27 | 28 | #ifndef SEEK_SET 29 | #define SEEK_SET 0 30 | #endif 31 | 32 | voidpf ZCALLBACK fopen_file_func OF(( 33 | voidpf opaque, 34 | const char* filename, 35 | int mode)); 36 | 37 | uLong ZCALLBACK fread_file_func OF(( 38 | voidpf opaque, 39 | voidpf stream, 40 | void* buf, 41 | uLong size)); 42 | 43 | uLong ZCALLBACK fwrite_file_func OF(( 44 | voidpf opaque, 45 | voidpf stream, 46 | const void* buf, 47 | uLong size)); 48 | 49 | long ZCALLBACK ftell_file_func OF(( 50 | voidpf opaque, 51 | voidpf stream)); 52 | 53 | long ZCALLBACK fseek_file_func OF(( 54 | voidpf opaque, 55 | voidpf stream, 56 | uLong offset, 57 | int origin)); 58 | 59 | int ZCALLBACK fclose_file_func OF(( 60 | voidpf opaque, 61 | voidpf stream)); 62 | 63 | int ZCALLBACK ferror_file_func OF(( 64 | voidpf opaque, 65 | voidpf stream)); 66 | 67 | 68 | voidpf ZCALLBACK fopen_file_func (opaque, filename, mode) 69 | voidpf opaque; 70 | const char* filename; 71 | int mode; 72 | { 73 | FILE* file = NULL; 74 | const char* mode_fopen = NULL; 75 | if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) 76 | mode_fopen = "rb"; 77 | else 78 | if (mode & ZLIB_FILEFUNC_MODE_EXISTING) 79 | mode_fopen = "r+b"; 80 | else 81 | if (mode & ZLIB_FILEFUNC_MODE_CREATE) 82 | mode_fopen = "wb"; 83 | 84 | if ((filename!=NULL) && (mode_fopen != NULL)) 85 | file = fopen(filename, mode_fopen); 86 | return file; 87 | } 88 | 89 | 90 | uLong ZCALLBACK fread_file_func (opaque, stream, buf, size) 91 | voidpf opaque; 92 | voidpf stream; 93 | void* buf; 94 | uLong size; 95 | { 96 | uLong ret; 97 | ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); 98 | return ret; 99 | } 100 | 101 | 102 | uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size) 103 | voidpf opaque; 104 | voidpf stream; 105 | const void* buf; 106 | uLong size; 107 | { 108 | uLong ret; 109 | ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); 110 | return ret; 111 | } 112 | 113 | long ZCALLBACK ftell_file_func (opaque, stream) 114 | voidpf opaque; 115 | voidpf stream; 116 | { 117 | long ret; 118 | ret = ftell((FILE *)stream); 119 | return ret; 120 | } 121 | 122 | long ZCALLBACK fseek_file_func (opaque, stream, offset, origin) 123 | voidpf opaque; 124 | voidpf stream; 125 | uLong offset; 126 | int origin; 127 | { 128 | int fseek_origin=0; 129 | long ret; 130 | switch (origin) 131 | { 132 | case ZLIB_FILEFUNC_SEEK_CUR : 133 | fseek_origin = SEEK_CUR; 134 | break; 135 | case ZLIB_FILEFUNC_SEEK_END : 136 | fseek_origin = SEEK_END; 137 | break; 138 | case ZLIB_FILEFUNC_SEEK_SET : 139 | fseek_origin = SEEK_SET; 140 | break; 141 | default: return -1; 142 | } 143 | ret = 0; 144 | if (fseek((FILE *)stream, offset, fseek_origin) != 0) 145 | ret = -1; 146 | return ret; 147 | } 148 | 149 | int ZCALLBACK fclose_file_func (opaque, stream) 150 | voidpf opaque; 151 | voidpf stream; 152 | { 153 | int ret; 154 | ret = fclose((FILE *)stream); 155 | return ret; 156 | } 157 | 158 | int ZCALLBACK ferror_file_func (opaque, stream) 159 | voidpf opaque; 160 | voidpf stream; 161 | { 162 | int ret; 163 | ret = ferror((FILE *)stream); 164 | return ret; 165 | } 166 | 167 | void fill_fopen_filefunc (pzlib_filefunc_def) 168 | zlib_filefunc_def* pzlib_filefunc_def; 169 | { 170 | pzlib_filefunc_def->zopen_file = fopen_file_func; 171 | pzlib_filefunc_def->zread_file = fread_file_func; 172 | pzlib_filefunc_def->zwrite_file = fwrite_file_func; 173 | pzlib_filefunc_def->ztell_file = ftell_file_func; 174 | pzlib_filefunc_def->zseek_file = fseek_file_func; 175 | pzlib_filefunc_def->zclose_file = fclose_file_func; 176 | pzlib_filefunc_def->zerror_file = ferror_file_func; 177 | pzlib_filefunc_def->opaque = NULL; 178 | } 179 | -------------------------------------------------------------------------------- /Libraries/ZipArchive/minizip/ioapi.h: -------------------------------------------------------------------------------- 1 | /* ioapi.h -- IO base function header for compress/uncompress .zip 2 | files using zlib + zip or unzip API 3 | 4 | Version 1.01h, December 28th, 2009 5 | 6 | Copyright (C) 1998-2009 Gilles Vollant 7 | */ 8 | 9 | #ifndef _ZLIBIOAPI_H 10 | #define _ZLIBIOAPI_H 11 | 12 | 13 | #define ZLIB_FILEFUNC_SEEK_CUR (1) 14 | #define ZLIB_FILEFUNC_SEEK_END (2) 15 | #define ZLIB_FILEFUNC_SEEK_SET (0) 16 | 17 | #define ZLIB_FILEFUNC_MODE_READ (1) 18 | #define ZLIB_FILEFUNC_MODE_WRITE (2) 19 | #define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) 20 | 21 | #define ZLIB_FILEFUNC_MODE_EXISTING (4) 22 | #define ZLIB_FILEFUNC_MODE_CREATE (8) 23 | 24 | 25 | #ifndef ZCALLBACK 26 | 27 | #if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) 28 | #define ZCALLBACK CALLBACK 29 | #else 30 | #define ZCALLBACK 31 | #endif 32 | #endif 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); 39 | typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); 40 | typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); 41 | typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); 42 | typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); 43 | typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); 44 | typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); 45 | 46 | typedef struct zlib_filefunc_def_s 47 | { 48 | open_file_func zopen_file; 49 | read_file_func zread_file; 50 | write_file_func zwrite_file; 51 | tell_file_func ztell_file; 52 | seek_file_func zseek_file; 53 | close_file_func zclose_file; 54 | testerror_file_func zerror_file; 55 | voidpf opaque; 56 | } zlib_filefunc_def; 57 | 58 | 59 | 60 | void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); 61 | 62 | #define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size)) 63 | #define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size)) 64 | #define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream)) 65 | #define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode)) 66 | #define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream)) 67 | #define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream)) 68 | 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | #endif 75 | 76 | -------------------------------------------------------------------------------- /Libraries/ZipArchive/minizip/mztools.c: -------------------------------------------------------------------------------- 1 | /* 2 | Additional tools for Minizip 3 | Code: Xavier Roche '2004 4 | License: Same as ZLIB (www.gzip.org) 5 | */ 6 | 7 | /* Code */ 8 | #include 9 | #include 10 | #include 11 | #include "zlib.h" 12 | #include "unzip.h" 13 | 14 | #define READ_8(adr) ((unsigned char)*(adr)) 15 | #define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) ) 16 | #define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) ) 17 | 18 | #define WRITE_8(buff, n) do { \ 19 | *((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \ 20 | } while(0) 21 | #define WRITE_16(buff, n) do { \ 22 | WRITE_8((unsigned char*)(buff), n); \ 23 | WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \ 24 | } while(0) 25 | #define WRITE_32(buff, n) do { \ 26 | WRITE_16((unsigned char*)(buff), (n) & 0xffff); \ 27 | WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \ 28 | } while(0) 29 | 30 | extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered) 31 | const char* file; 32 | const char* fileOut; 33 | const char* fileOutTmp; 34 | uLong* nRecovered; 35 | uLong* bytesRecovered; 36 | { 37 | int err = Z_OK; 38 | FILE* fpZip = fopen(file, "rb"); 39 | FILE* fpOut = fopen(fileOut, "wb"); 40 | FILE* fpOutCD = fopen(fileOutTmp, "wb"); 41 | if (fpZip != NULL && fpOut != NULL) { 42 | int entries = 0; 43 | uLong totalBytes = 0; 44 | char header[30]; 45 | char filename[256]; 46 | char extra[1024]; 47 | int offset = 0; 48 | int offsetCD = 0; 49 | while ( fread(header, 1, 30, fpZip) == 30 ) { 50 | int currentOffset = offset; 51 | 52 | /* File entry */ 53 | if (READ_32(header) == 0x04034b50) { 54 | unsigned int version = READ_16(header + 4); 55 | unsigned int gpflag = READ_16(header + 6); 56 | unsigned int method = READ_16(header + 8); 57 | unsigned int filetime = READ_16(header + 10); 58 | unsigned int filedate = READ_16(header + 12); 59 | unsigned int crc = READ_32(header + 14); /* crc */ 60 | unsigned int cpsize = READ_32(header + 18); /* compressed size */ 61 | unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */ 62 | unsigned int fnsize = READ_16(header + 26); /* file name length */ 63 | unsigned int extsize = READ_16(header + 28); /* extra field length */ 64 | filename[0] = extra[0] = '\0'; 65 | 66 | /* Header */ 67 | if (fwrite(header, 1, 30, fpOut) == 30) { 68 | offset += 30; 69 | } else { 70 | err = Z_ERRNO; 71 | break; 72 | } 73 | 74 | /* Filename */ 75 | if (fnsize > 0) { 76 | if (fread(filename, 1, fnsize, fpZip) == fnsize) { 77 | if (fwrite(filename, 1, fnsize, fpOut) == fnsize) { 78 | offset += fnsize; 79 | } else { 80 | err = Z_ERRNO; 81 | break; 82 | } 83 | } else { 84 | err = Z_ERRNO; 85 | break; 86 | } 87 | } else { 88 | err = Z_STREAM_ERROR; 89 | break; 90 | } 91 | 92 | /* Extra field */ 93 | if (extsize > 0) { 94 | if (fread(extra, 1, extsize, fpZip) == extsize) { 95 | if (fwrite(extra, 1, extsize, fpOut) == extsize) { 96 | offset += extsize; 97 | } else { 98 | err = Z_ERRNO; 99 | break; 100 | } 101 | } else { 102 | err = Z_ERRNO; 103 | break; 104 | } 105 | } 106 | 107 | /* Data */ 108 | { 109 | int dataSize = cpsize; 110 | if (dataSize == 0) { 111 | dataSize = uncpsize; 112 | } 113 | if (dataSize > 0) { 114 | char* data = malloc(dataSize); 115 | if (data != NULL) { 116 | if ((int)fread(data, 1, dataSize, fpZip) == dataSize) { 117 | if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) { 118 | offset += dataSize; 119 | totalBytes += dataSize; 120 | } else { 121 | err = Z_ERRNO; 122 | } 123 | } else { 124 | err = Z_ERRNO; 125 | } 126 | free(data); 127 | if (err != Z_OK) { 128 | break; 129 | } 130 | } else { 131 | err = Z_MEM_ERROR; 132 | break; 133 | } 134 | } 135 | } 136 | 137 | /* Central directory entry */ 138 | { 139 | char header[46]; 140 | char* comment = ""; 141 | int comsize = (int) strlen(comment); 142 | WRITE_32(header, 0x02014b50); 143 | WRITE_16(header + 4, version); 144 | WRITE_16(header + 6, version); 145 | WRITE_16(header + 8, gpflag); 146 | WRITE_16(header + 10, method); 147 | WRITE_16(header + 12, filetime); 148 | WRITE_16(header + 14, filedate); 149 | WRITE_32(header + 16, crc); 150 | WRITE_32(header + 20, cpsize); 151 | WRITE_32(header + 24, uncpsize); 152 | WRITE_16(header + 28, fnsize); 153 | WRITE_16(header + 30, extsize); 154 | WRITE_16(header + 32, comsize); 155 | WRITE_16(header + 34, 0); /* disk # */ 156 | WRITE_16(header + 36, 0); /* int attrb */ 157 | WRITE_32(header + 38, 0); /* ext attrb */ 158 | WRITE_32(header + 42, currentOffset); 159 | /* Header */ 160 | if (fwrite(header, 1, 46, fpOutCD) == 46) { 161 | offsetCD += 46; 162 | 163 | /* Filename */ 164 | if (fnsize > 0) { 165 | if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) { 166 | offsetCD += fnsize; 167 | } else { 168 | err = Z_ERRNO; 169 | break; 170 | } 171 | } else { 172 | err = Z_STREAM_ERROR; 173 | break; 174 | } 175 | 176 | /* Extra field */ 177 | if (extsize > 0) { 178 | if (fwrite(extra, 1, extsize, fpOutCD) == extsize) { 179 | offsetCD += extsize; 180 | } else { 181 | err = Z_ERRNO; 182 | break; 183 | } 184 | } 185 | 186 | /* Comment field */ 187 | if (comsize > 0) { 188 | if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) { 189 | offsetCD += comsize; 190 | } else { 191 | err = Z_ERRNO; 192 | break; 193 | } 194 | } 195 | 196 | 197 | } else { 198 | err = Z_ERRNO; 199 | break; 200 | } 201 | } 202 | 203 | /* Success */ 204 | entries++; 205 | 206 | } else { 207 | break; 208 | } 209 | } 210 | 211 | /* Final central directory */ 212 | { 213 | int entriesZip = entries; 214 | char header[22]; 215 | char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools"; 216 | int comsize = (int) strlen(comment); 217 | if (entriesZip > 0xffff) { 218 | entriesZip = 0xffff; 219 | } 220 | WRITE_32(header, 0x06054b50); 221 | WRITE_16(header + 4, 0); /* disk # */ 222 | WRITE_16(header + 6, 0); /* disk # */ 223 | WRITE_16(header + 8, entriesZip); /* hack */ 224 | WRITE_16(header + 10, entriesZip); /* hack */ 225 | WRITE_32(header + 12, offsetCD); /* size of CD */ 226 | WRITE_32(header + 16, offset); /* offset to CD */ 227 | WRITE_16(header + 20, comsize); /* comment */ 228 | 229 | /* Header */ 230 | if (fwrite(header, 1, 22, fpOutCD) == 22) { 231 | 232 | /* Comment field */ 233 | if (comsize > 0) { 234 | if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) { 235 | err = Z_ERRNO; 236 | } 237 | } 238 | 239 | } else { 240 | err = Z_ERRNO; 241 | } 242 | } 243 | 244 | /* Final merge (file + central directory) */ 245 | fclose(fpOutCD); 246 | if (err == Z_OK) { 247 | fpOutCD = fopen(fileOutTmp, "rb"); 248 | if (fpOutCD != NULL) { 249 | int nRead; 250 | char buffer[8192]; 251 | while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) { 252 | if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) { 253 | err = Z_ERRNO; 254 | break; 255 | } 256 | } 257 | fclose(fpOutCD); 258 | } 259 | } 260 | 261 | /* Close */ 262 | fclose(fpZip); 263 | fclose(fpOut); 264 | 265 | /* Wipe temporary file */ 266 | (void)remove(fileOutTmp); 267 | 268 | /* Number of recovered entries */ 269 | if (err == Z_OK) { 270 | if (nRecovered != NULL) { 271 | *nRecovered = entries; 272 | } 273 | if (bytesRecovered != NULL) { 274 | *bytesRecovered = totalBytes; 275 | } 276 | } 277 | } else { 278 | err = Z_STREAM_ERROR; 279 | } 280 | return err; 281 | } 282 | -------------------------------------------------------------------------------- /Libraries/ZipArchive/minizip/mztools.h: -------------------------------------------------------------------------------- 1 | /* 2 | Additional tools for Minizip 3 | Code: Xavier Roche '2004 4 | License: Same as ZLIB (www.gzip.org) 5 | */ 6 | 7 | #ifndef _zip_tools_H 8 | #define _zip_tools_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #ifndef _ZLIB_H 15 | #include "zlib.h" 16 | #endif 17 | 18 | #include "unzip.h" 19 | 20 | /* Repair a ZIP file (missing central directory) 21 | file: file to recover 22 | fileOut: output file after recovery 23 | fileOutTmp: temporary file name used for recovery 24 | */ 25 | extern int ZEXPORT unzRepair(const char* file, 26 | const char* fileOut, 27 | const char* fileOutTmp, 28 | uLong* nRecovered, 29 | uLong* bytesRecovered); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | EPubReader 2 | 3 | EPubReader阅读器:Libraries里的EPubReader为Epub的解析部分,其它的(Category、FMDB、TouchXML、ZipArchive等)为支持的类库。 4 | 5 | 根目录下的EPubReader为写的Demo,Demo基于StoryBoard。 6 | 整个项目基于ARC,需要iOS 5.0以上。 7 | 8 | * **EPubController**是对外的接口,所有的操作通过EPubController来完成。 9 | 10 | * **EPubBook**为EPub书籍解析类,读取EPub书籍,解析相关信息。 11 | 12 | * **EPubChapter**存储相关章节信息,相关信息在解析时写入。 13 | 14 | * **EPubBookmark**为书签信息,由EPubBookmarkManager来管理。 15 | 16 | * **EPubChapterListView**为章节列表。 17 | 18 | * **EPubView**为阅读视图,展示相关章节详细内容; 一次展示一章。 19 | 20 | * **EPubConfig**为相关宏定义。 21 | 22 | * **/Libraries**里的/EPubReader为Epub的解析部分,(Category、FMDB、TouchXML、ZipArchive等)为支持的类库。 23 | 24 | * **/EPubReader**为写的Demo,Demo为基于StoryBoard。 25 | 26 | --- 27 | 28 | **目前完成的功能:** 29 | 30 | 1.解析EPub书籍的相关属性。 31 | 2.阅读及进度控制。 32 | 3.书签的保存读取等。 33 | 34 | **待完成功能:** 35 | 36 | 1.阅读进度计算 37 | 2.整本书加载阅读,替换为每次只加载单章。 38 | 3.其它更多功能。 39 | 40 | 41 | Required:iOS 5.0 42 | --------------------------------------------------------------------------------