HTTPDynamicFileResponse.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #import <Foundation/Foundation.h>
  2. #import "HTTPResponse.h"
  3. #import "HTTPAsyncFileResponse.h"
  4. /**
  5. * This class is designed to assist with dynamic content.
  6. * Imagine you have a file that you want to make dynamic:
  7. *
  8. * <html>
  9. * <body>
  10. * <h1>ComputerName Control Panel</h1>
  11. * ...
  12. * <li>System Time: SysTime</li>
  13. * </body>
  14. * </html>
  15. *
  16. * Now you could generate the entire file in Objective-C,
  17. * but this would be a horribly tedious process.
  18. * Beside, you want to design the file with professional tools to make it look pretty.
  19. *
  20. * So all you have to do is escape your dynamic content like this:
  21. *
  22. * ...
  23. * <h1>%%ComputerName%% Control Panel</h1>
  24. * ...
  25. * <li>System Time: %%SysTime%%</li>
  26. *
  27. * And then you create an instance of this class with:
  28. *
  29. * - separator = @"%%"
  30. * - replacementDictionary = { "ComputerName"="Black MacBook", "SysTime"="2010-04-30 03:18:24" }
  31. *
  32. * This class will then perform the replacements for you, on the fly, as it reads the file data.
  33. * This class is also asynchronous, so it will perform the file IO using its own GCD queue.
  34. *
  35. * All keys for the replacementDictionary must be NSString's.
  36. * Values for the replacementDictionary may be NSString's, or any object that
  37. * returns what you want when its description method is invoked.
  38. **/
  39. @interface HTTPDynamicFileResponse : HTTPAsyncFileResponse
  40. {
  41. NSData *separator;
  42. NSDictionary *replacementDict;
  43. }
  44. - (id)initWithFilePath:(NSString *)filePath
  45. forConnection:(HTTPConnection *)connection
  46. separator:(NSString *)separatorStr
  47. replacementDictionary:(NSDictionary *)dictionary;
  48. @end