Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

detect JSON or XML

  • Loading branch information...
commit e0989b2fe095cd8194868f48e7deddd1e0afccd9 1 parent e6e082a
@youknowone authored
View
28 VisualJSON.xcodeproj/project.pbxproj
@@ -36,10 +36,12 @@
3868F7981629EAB200C31163 /* VJDocument.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 38A1C036157E15240034EDC4 /* VJDocument.xcdatamodeld */; };
3868F7991629EAC000C31163 /* IdealCocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 38255618157C9AE90099CC24 /* IdealCocoa.framework */; };
3868F79B1629EAE300C31163 /* IdealCocoa.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = 38255618157C9AE90099CC24 /* IdealCocoa.framework */; };
- 3868F79E1629EDCF00C31163 /* VJJsonDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 3868F79D1629EDCF00C31163 /* VJJsonDataSource.m */; };
- 3868F7A11629F12200C31163 /* VXXMLDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 3868F7A01629F12200C31163 /* VXXMLDataSource.m */; };
+ 3868F79E1629EDCF00C31163 /* VJJsonDocumentDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 3868F79D1629EDCF00C31163 /* VJJsonDocumentDelegate.m */; };
+ 3868F7A11629F12200C31163 /* VJXMLDocumentDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 3868F7A01629F12200C31163 /* VJXMLDocumentDelegate.m */; };
3868F7A21629F23D00C31163 /* VJDocument.xib in Resources */ = {isa = PBXBuildFile; fileRef = 382554D3157BE3550099CC24 /* VJDocument.xib */; };
3868F7A31629F23D00C31163 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 382554D6157BE3550099CC24 /* MainMenu.xib */; };
+ 3868F7A4162B1AAC00C31163 /* VJXMLDocumentDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 3868F7A01629F12200C31163 /* VJXMLDocumentDelegate.m */; };
+ 3868F7A5162B1AC500C31163 /* ObjectXML.m in Sources */ = {isa = PBXBuildFile; fileRef = 3868F72E1629E87F00C31163 /* ObjectXML.m */; };
388227E515924E6F000AB63D /* IdealCocoa.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = 38255618157C9AE90099CC24 /* IdealCocoa.framework */; };
38A1C035157DD7030034EDC4 /* VJRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 38A1C034157DD7030034EDC4 /* VJRequest.m */; };
38A1C038157E15240034EDC4 /* VJDocument.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 38A1C036157E15240034EDC4 /* VJDocument.xcdatamodeld */; };
@@ -162,10 +164,10 @@
3868F73B1629E8E700C31163 /* VisualXML.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = VisualXML.app; sourceTree = BUILT_PRODUCTS_DIR; };
3868F75C1629E8E800C31163 /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; };
3868F7941629EA0400C31163 /* VisualXML-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "VisualXML-Info.plist"; sourceTree = "<group>"; };
- 3868F79C1629EDCF00C31163 /* VJJsonDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VJJsonDataSource.h; sourceTree = "<group>"; };
- 3868F79D1629EDCF00C31163 /* VJJsonDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VJJsonDataSource.m; sourceTree = "<group>"; };
- 3868F79F1629F12200C31163 /* VXXMLDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VXXMLDataSource.h; sourceTree = "<group>"; };
- 3868F7A01629F12200C31163 /* VXXMLDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VXXMLDataSource.m; sourceTree = "<group>"; };
+ 3868F79C1629EDCF00C31163 /* VJJsonDocumentDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VJJsonDocumentDelegate.h; sourceTree = "<group>"; };
+ 3868F79D1629EDCF00C31163 /* VJJsonDocumentDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VJJsonDocumentDelegate.m; sourceTree = "<group>"; };
+ 3868F79F1629F12200C31163 /* VJXMLDocumentDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VJXMLDocumentDelegate.h; sourceTree = "<group>"; };
+ 3868F7A01629F12200C31163 /* VJXMLDocumentDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VJXMLDocumentDelegate.m; sourceTree = "<group>"; };
38A1C033157DD7030034EDC4 /* VJRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VJRequest.h; sourceTree = "<group>"; };
38A1C034157DD7030034EDC4 /* VJRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VJRequest.m; sourceTree = "<group>"; };
38A1C037157E15240034EDC4 /* VJDocument.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = VJDocument.xcdatamodel; sourceTree = "<group>"; };
@@ -259,8 +261,8 @@
children = (
38255565157C94C50099CC24 /* JsonElement.h */,
38255566157C94C50099CC24 /* JsonElement.m */,
- 3868F79C1629EDCF00C31163 /* VJJsonDataSource.h */,
- 3868F79D1629EDCF00C31163 /* VJJsonDataSource.m */,
+ 3868F79C1629EDCF00C31163 /* VJJsonDocumentDelegate.h */,
+ 3868F79D1629EDCF00C31163 /* VJJsonDocumentDelegate.m */,
382554C5157BE3550099CC24 /* Supporting Files */,
);
path = VisualJSON;
@@ -374,8 +376,8 @@
isa = PBXGroup;
children = (
3868F7941629EA0400C31163 /* VisualXML-Info.plist */,
- 3868F79F1629F12200C31163 /* VXXMLDataSource.h */,
- 3868F7A01629F12200C31163 /* VXXMLDataSource.m */,
+ 3868F79F1629F12200C31163 /* VJXMLDocumentDelegate.h */,
+ 3868F7A01629F12200C31163 /* VJXMLDocumentDelegate.m */,
);
path = VisualXML;
sourceTree = "<group>";
@@ -548,7 +550,9 @@
38A1C035157DD7030034EDC4 /* VJRequest.m in Sources */,
38A1C038157E15240034EDC4 /* VJDocument.xcdatamodeld in Sources */,
385E84F71597839F001562F6 /* AppDelegate.m in Sources */,
- 3868F79E1629EDCF00C31163 /* VJJsonDataSource.m in Sources */,
+ 3868F79E1629EDCF00C31163 /* VJJsonDocumentDelegate.m in Sources */,
+ 3868F7A4162B1AAC00C31163 /* VJXMLDocumentDelegate.m in Sources */,
+ 3868F7A5162B1AC500C31163 /* ObjectXML.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -572,7 +576,7 @@
3868F78E1629E8F900C31163 /* AppDelegate.m in Sources */,
3868F7911629E90200C31163 /* ObjectXML.m in Sources */,
3868F7981629EAB200C31163 /* VJDocument.xcdatamodeld in Sources */,
- 3868F7A11629F12200C31163 /* VXXMLDataSource.m in Sources */,
+ 3868F7A11629F12200C31163 /* VJXMLDocumentDelegate.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
9 VisualJSON/VJDocument.h
@@ -11,7 +11,9 @@
@class VJDocument;
-@protocol VJDocumentDataSource <NSObject>
+@protocol VJDocumentDelegate <NSObject>
+
+- (BOOL)document:(VJDocument *)document dataIsValid:(NSString *)rawData;
- (id)document:(VJDocument *)document structuredDataFromRawDataString:(NSString *)rawData;
- (NSString *)document:(VJDocument *)document prettyTextFromData:(id)data;
@@ -24,10 +26,9 @@
@end
-FOUNDATION_EXTERN id<VJDocumentDataSource> VJDocumentDefaultDataSource();
@interface VJDocument : NSPersistentDocument<NSMatrixDelegate> {
- id<VJDocumentDataSource> dataSource;
+ id<VJDocumentDelegate> _delegate;
NSString *_header;
NSString *_method;
@@ -62,6 +63,8 @@ FOUNDATION_EXTERN id<VJDocumentDataSource> VJDocumentDefaultDataSource();
NSThread *visualizeThread;
}
+@property(retain) id delegate;
+
@property(retain) NSString *address;
@property(retain) NSString *header;
@property(retain) NSString *method;
View
28 VisualJSON/VJDocument.m
@@ -9,6 +9,9 @@
#import "VJDocument.h"
#import "VJRequest.h"
+#import "VJJsonDocumentDelegate.h"
+#import "VJXMLDocumentDelegate.h"
+
@interface VJDocument()
- (BOOL)setMetadataForStoreAtURL:(NSURL *)URL;
@@ -17,6 +20,7 @@ - (BOOL)setMetadataForStoreAtURL:(NSURL *)URL;
@implementation VJDocument
+@synthesize delegate=_delegate;
@synthesize headerItems=_headerItems, querydataItems=_querydataItems;
@synthesize addressTextField=_addressTextField, methodMatrix=_methodMatrix, methodTextField=_methodTextField, querydataTextField=_querydataTextField, contentTextField=_contentTextField;
@synthesize dataOutlineView=_dataOutlineView, dataTextView=_dataTextView;
@@ -31,8 +35,6 @@ - (NSString *)defaultHeader {
- (void)awakeFromNib {
[super awakeFromNib];
-
- self->dataSource = [VJDocumentDefaultDataSource() retain];
self.querydata = self.request.querydata;
self.method = self.request.method;
@@ -153,7 +155,7 @@ - (void)dealloc {
self.request = nil;
self.drawer = nil;
- [self->dataSource release];
+ self.delegate = nil;
[super dealloc];
}
@@ -412,8 +414,14 @@ - (void)visualizeBackground {
if (x) {
[x release];
}
+
+ if ([[VJXMLDocumentDelegate sharedObject] document:self dataIsValid:self.content]) {
+ self.delegate = [VJXMLDocumentDelegate sharedObject];
+ } else {
+ self.delegate = [VJJsonDocumentDelegate sharedObject];
+ }
- x = [[self->dataSource document:self structuredDataFromRawDataString:self.content] retain];
+ x = [[self.delegate document:self structuredDataFromRawDataString:self.content] retain];
@synchronized(self) {
tempData = x;
}
@@ -428,7 +436,7 @@ - (void)visualizeFinished {
}
[self.dataOutlineView reloadData];
- self.dataTextView.string = [self->dataSource document:self prettyTextFromData:self.data];
+ self.dataTextView.string = [self.delegate document:self prettyTextFromData:self.data];
}
- (void)toggleDrawer:(id)sender {
@@ -450,30 +458,30 @@ - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id
if (item == nil) {
return 1;
}
- return (NSInteger)[self->dataSource document:self outlineChildrenCountForItem:item];
+ return (NSInteger)[self.delegate document:self outlineChildrenCountForItem:item];
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
if (item == nil) {
return YES;
}
- return [self->dataSource document:self outlineIsItemExpandable:item];
+ return [self.delegate document:self outlineIsItemExpandable:item];
}
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
if (item == nil) {
return self.data;
}
- return [self->dataSource document:self outlineChild:index ofItem:item];
+ return [self.delegate document:self outlineChild:index ofItem:item];
}
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
if (item == nil) item = self.data;
NSString *title = [tableColumn.headerCell title];
if ([title isEqualToString:@"node"]) {
- return [self->dataSource document:self outlineTitleForItem:item];
+ return [self.delegate document:self outlineTitleForItem:item];
} else if ([title isEqualToString:@"description"]) {
- return [self->dataSource document:self outlineDescriptionForItem:item];
+ return [self.delegate document:self outlineDescriptionForItem:item];
} else {
ICAssert(NO);
}
View
6 VisualXML/VXXMLDataSource.h → VisualJSON/VJJsonDocumentDelegate.h
@@ -1,5 +1,5 @@
//
-// VXXMLDataSource.h
+// VJJsonDocumentDelegate.h
// VisualJSON
//
// Created by youknowone on 12. 10. 14..
@@ -8,6 +8,8 @@
#import "VJDocument.h"
-@interface VXXMLDataSource : NSObject<VJDocumentDataSource>
+@interface VJJsonDocumentDelegate : NSObject<VJDocumentDelegate>
+
++ (id)sharedObject;
@end
View
36 VisualJSON/VJJsonDataSource.m → VisualJSON/VJJsonDocumentDelegate.m
@@ -1,5 +1,5 @@
//
-// VJJsonDataSource.m
+// VJJsonDocumentDelegate.m
// VisualJSON
//
// Created by youknowone on 12. 10. 14..
@@ -9,13 +9,27 @@
#import "JSONKit.h"
#import "JsonElement.h"
-#import "VJJsonDataSource.h"
+#import "VJJsonDocumentDelegate.h"
-id<VJDocumentDataSource> VJDocumentDefaultDataSource() {
- return [[[VJJsonDataSource alloc] init] autorelease];
+id<VJDocumentDelegate> VJDocumentDefaultDataSource() {
+ return [[[VJJsonDocumentDelegate alloc] init] autorelease];
}
-@implementation VJJsonDataSource
+@implementation VJJsonDocumentDelegate
+
+- (BOOL)document:(VJDocument *)document dataIsValid:(NSString *)rawData {
+ NSInteger index = 0;
+ unichar chr;
+ do {
+ if (index >= rawData.length) {
+ return NO;
+ }
+ chr = [rawData characterAtIndex:index];
+ index += 1;
+ } while ([[NSCharacterSet whitespaceAndNewlineCharacterSet] characterIsMember:chr]);
+
+ return chr == '[' || chr == '{';
+}
- (id)document:(VJDocument *)document structuredDataFromRawDataString:(NSString *)rawData {
return [JsonElement elementWithObject:rawData.objectFromJSONString];
@@ -45,4 +59,16 @@ - (id)document:(VJDocument *)document outlineChild:(NSInteger)index ofItem:(id)i
return [item childAtIndex:index];
}
+id VJJsonDocumentDelegateSharedObject = nil;
+
++ (void)initialize {
+ if (self == [VJJsonDocumentDelegate class]) {
+ VJJsonDocumentDelegateSharedObject = [[self alloc] init];
+ }
+}
+
++ (id)sharedObject {
+ return VJJsonDocumentDelegateSharedObject;
+}
+
@end
View
6 VisualJSON/VJJsonDataSource.h → VisualXML/VJXMLDocumentDelegate.h
@@ -1,5 +1,5 @@
//
-// VJJsonDataSource.h
+// VJXMLDocumentDelegate.h
// VisualJSON
//
// Created by youknowone on 12. 10. 14..
@@ -8,6 +8,8 @@
#import "VJDocument.h"
-@interface VJJsonDataSource : NSObject<VJDocumentDataSource>
+@interface VJXMLDocumentDelegate : NSObject<VJDocumentDelegate>
+
++ (id)sharedObject;
@end
View
34 VisualXML/VXXMLDataSource.m → VisualXML/VJXMLDocumentDelegate.m
@@ -1,5 +1,5 @@
//
-// VXXMLDataSource.m
+// VJXMLDocumentDelegate.m
// VisualJSON
//
// Created by youknowone on 12. 10. 14..
@@ -8,13 +8,23 @@
#import "ObjectXML.h"
-#import "VXXMLDataSource.h"
+#import "VJXMLDocumentDelegate.h"
-id<VJDocumentDataSource> VJDocumentDefaultDataSource() {
- return [[[VXXMLDataSource alloc] init] autorelease];
-}
+@implementation VJXMLDocumentDelegate
+
+- (BOOL)document:(VJDocument *)document dataIsValid:(NSString *)rawData {
+ NSInteger index = 0;
+ unichar chr;
+ do {
+ if (index >= rawData.length) {
+ return NO;
+ }
+ chr = [rawData characterAtIndex:index];
+ index += 1;
+ } while ([[NSCharacterSet whitespaceAndNewlineCharacterSet] characterIsMember:chr]);
-@implementation VXXMLDataSource
+ return chr == '<';
+}
- (id)document:(VJDocument *)document structuredDataFromRawDataString:(NSString *)rawData {
return [OXNode nodeWithString:rawData];
@@ -44,4 +54,16 @@ - (id)document:(VJDocument *)document outlineChild:(NSInteger)index ofItem:(id)i
return [[item children] objectAtIndex:index];
}
+id VJXMLDocumentDelegateSharedObject = nil;
+
++ (void)initialize {
+ if (self == [VJXMLDocumentDelegate class]) {
+ VJXMLDocumentDelegateSharedObject = [[self alloc] init];
+ }
+}
+
++ (id)sharedObject {
+ return VJXMLDocumentDelegateSharedObject;
+}
+
@end
Please sign in to comment.
Something went wrong with that request. Please try again.