Permalink
Browse files

Adding more formatting and syntax highlighting ContentTypes

  • Loading branch information...
1 parent ac4a24e commit 4f3316b50f51b3d16aa4a593db5197c415848df2 @mmattozzi committed Sep 16, 2012
Showing with 22 additions and 9 deletions.
  1. +5 −4 CocoaRestClientAppDelegate.h
  2. +7 −4 CocoaRestClientAppDelegate.m
  3. +10 −1 HighlightedTextView.m
@@ -86,11 +86,12 @@ extern NSString* const RESPONSE_TIMEOUT;
NSMenuItem *syntaxHighlightingMenuItem;
NSMenuItem *reGetResponseMenuItem;
- @private
- CRCRequest *lastRequest;
+ @private CRCRequest *lastRequest;
- @private
- NSSet *requestMethodsWithBody;
+ @private NSSet *requestMethodsWithBody;
+
+ @private NSArray *xmlContentTypes;
+ @private NSArray *jsonContentTypes;
}
@@ -106,6 +106,11 @@ - (id) init {
[headersTable addObject:row];
[row release];
+ xmlContentTypes = [NSArray arrayWithObjects:@"application/xml", @"application/atom+xml", @"application/rss+xml",
+ @"text/xml", @"application/soap+xml", @"application/xml-dtd", nil];
+
+ jsonContentTypes = [NSArray arrayWithObjects:@"application/json", nil];
+
[self loadDataFromDisk];
exportRequestsController = [[ExportRequestsController alloc] initWithWindowNibName:@"ExportRequests"];
@@ -497,9 +502,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
BOOL needToPrintPlain = YES;
if (contentType != NULL) {
- if ([contentType isEqualToString:@"application/atom+xml"] ||
- [contentType isEqualToString:@"application/rss+xml"] ||
- [contentType isEqualToString:@"application/xml"]) {
+ if ([xmlContentTypes containsObject:contentType]) {
NSLog(@"Formatting XML");
NSError *error;
NSXMLDocument *responseXML = [[NSXMLDocument alloc] initWithData:receivedData options:NSXMLDocumentTidyXML error:&error];
@@ -508,7 +511,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
}
[responseText setString:[responseXML XMLStringWithOptions:NSXMLNodePrettyPrint]];
needToPrintPlain = NO;
- } else if ([contentType isEqualToString:@"application/json"]) {
+ } else if ([jsonContentTypes containsObject:contentType]) {
NSLog(@"Formatting JSON");
SBJSON *parser = [[SBJSON alloc] init];
[parser setHumanReadable:YES];
View
@@ -19,7 +19,16 @@ -(void) initHighlightedFrame {
@"XML", @"application/xml",
@"HTML", @"text/html",
@"XML", @"application/atom+xml",
- @"Javascript", @"application/x-javascript",
+ @"JavaScript", @"application/x-javascript",
+ @"CSS", @"text/css",
+ @"JavaScript", @"text/javascript",
+ @"PDF", @"application/pdf",
+ @"XML", @"application/rss+xml",
+ @"XML", @"text/xml",
+ @"PostScript", @"application/postscript",
+ @"XML", @"application/soap+xml",
+ @"HTML", @"application/xhtml+xml",
+ @"XML", @"application/xml-dtd",
nil];
//

0 comments on commit 4f3316b

Please sign in to comment.