mirror of
https://github.com/gnustep/libs-gsweb.git
synced 2025-02-22 19:21:23 +00:00
added NSObject+XML for monitor support
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@30166 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b12e41e555
commit
e50dd9cb94
3 changed files with 215 additions and 0 deletions
|
@ -8,6 +8,7 @@
|
|||
* small cleanups
|
||||
* GSWUtils.m EONull -> NSNull
|
||||
* GSWApplication+Defaults.m, GSWPrivate.h additions for Monitoring
|
||||
* added NSObject+XML.?
|
||||
|
||||
2010-04-14 David Wetzel <dave@turbocat.de>
|
||||
Apache2/GNUmakefile.in
|
||||
|
|
59
GSWeb.framework/NSObject+XML.h
Normal file
59
GSWeb.framework/NSObject+XML.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
/** NSObject+XML.h - <title>GSWeb: NSObject+XML</title>
|
||||
|
||||
Copyright (C) 2010 Free Software Foundation, Inc.
|
||||
|
||||
Written by: David Wetzel <dave@turbocat.de>
|
||||
Date: Feb 2010
|
||||
|
||||
$Revision: 1.17 $
|
||||
$Date: 2004/12/31 14:33:16 $
|
||||
|
||||
This file is part of the GNUstep Web Library.
|
||||
|
||||
<license>
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
</license>
|
||||
**/
|
||||
|
||||
#ifndef _NSObject_GSWXML_
|
||||
#define _NSObject_GSWXML_
|
||||
|
||||
#include <Foundation/NSObject.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
|
||||
@interface NSObject (GSWXML)
|
||||
- (NSString*) encodeXMLPrefix;
|
||||
|
||||
- (NSString*) encodeXMLSuffix;
|
||||
|
||||
- (NSString*) encodeXML;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface NSArray (GSWXML)
|
||||
- (NSString*) encodeXMLRootObjectForKey:(NSString*) key;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface NSDictionary (GSWXML)
|
||||
- (NSString*) encodeXMLRootObjectForKey:(NSString*) key;
|
||||
|
||||
@end
|
||||
|
||||
#endif // _NSObject_GSWXML_
|
155
GSWeb.framework/NSObject+XML.m
Normal file
155
GSWeb.framework/NSObject+XML.m
Normal file
|
@ -0,0 +1,155 @@
|
|||
/** NSObject+XML.m - <title>GSWeb: NSObject+XML</title>
|
||||
|
||||
Copyright (C) 2010 Free Software Foundation, Inc.
|
||||
|
||||
Written by: David Wetzel <dave@turbocat.de>
|
||||
Date: Feb 2010
|
||||
|
||||
$Revision: 1.17 $
|
||||
$Date: 2004/12/31 14:33:16 $
|
||||
|
||||
This file is part of the GNUstep Web Library.
|
||||
|
||||
<license>
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
</license>
|
||||
**/
|
||||
|
||||
#include "NSObject+XML.h"
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSEnumerator.h>
|
||||
|
||||
|
||||
@implementation NSObject (GSWXML)
|
||||
|
||||
|
||||
/*
|
||||
<element type="NSString">atlantis.local: wotaskd may not be accessed through a Web server - Access Denied</element>
|
||||
|
||||
*/
|
||||
|
||||
- (NSString*) encodeXMLPrefix
|
||||
{
|
||||
return [NSString stringWithFormat:@"<element type=\"%@\">\n", [self className]];
|
||||
}
|
||||
|
||||
- (NSString*) encodeXMLSuffix
|
||||
{
|
||||
return @"</element>\n";
|
||||
}
|
||||
|
||||
|
||||
- (NSString*) encodeXML
|
||||
{
|
||||
NSMutableString * contentStr = [NSMutableString string];
|
||||
|
||||
[contentStr appendString:[self encodeXMLPrefix]];
|
||||
|
||||
[contentStr appendString:[NSString stringWithFormat:@"%@", self]];
|
||||
|
||||
[contentStr appendString:[self encodeXMLSuffix]];
|
||||
|
||||
return contentStr;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSArray (GSWXML)
|
||||
|
||||
|
||||
/*
|
||||
<errorResponse type="NSArray">
|
||||
<element type="NSString">atlantis.local: wotaskd may not be accessed through a Web server - Access Denied</element>
|
||||
</errorResponse>
|
||||
|
||||
*/
|
||||
|
||||
|
||||
- (NSString*) encodeXMLRootObjectForKey:(NSString*) key
|
||||
{
|
||||
NSString * prefixStr = nil;
|
||||
NSString * suffixStr = nil;
|
||||
NSEnumerator * myEnumer = [self objectEnumerator];
|
||||
NSMutableString * contentStr = [NSMutableString string];
|
||||
id currentObj = nil;
|
||||
|
||||
|
||||
if (!key) {
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"key is missing"];
|
||||
}
|
||||
|
||||
prefixStr = [NSString stringWithFormat:@"<%@ type=\"%@\">\n", key, [self className]];
|
||||
[contentStr appendString:prefixStr];
|
||||
|
||||
suffixStr = [NSString stringWithFormat:@"</%@>\n", key];
|
||||
|
||||
|
||||
while ((currentObj = [myEnumer nextObject])) {
|
||||
[contentStr appendString:[currentObj encodeXML]];
|
||||
}
|
||||
|
||||
[contentStr appendString:suffixStr];
|
||||
|
||||
return contentStr;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSDictionary (GSWXML)
|
||||
|
||||
|
||||
/*
|
||||
<monitorResponse type="NSDictionary">
|
||||
<errorResponse type="NSArray">
|
||||
<element type="NSString">atlantis.local: wotaskd may not be accessed through a Web server - Access Denied</element>
|
||||
</errorResponse>
|
||||
</monitorResponse>
|
||||
|
||||
*/
|
||||
|
||||
|
||||
- (NSString*) encodeXMLRootObjectForKey:(NSString*) key
|
||||
{
|
||||
NSString * prefixStr = nil;
|
||||
NSString * suffixStr = nil;
|
||||
NSEnumerator * keyEnumer = [self keyEnumerator];
|
||||
NSMutableString * contentStr = [NSMutableString string];
|
||||
NSString * currentKey = nil;
|
||||
|
||||
|
||||
if (!key) {
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"key is missing"];
|
||||
}
|
||||
|
||||
prefixStr = [NSString stringWithFormat:@"<%@ type=\"%@\">\n", key, [self className]];
|
||||
[contentStr appendString:prefixStr];
|
||||
|
||||
suffixStr = [NSString stringWithFormat:@"</%@>\n", key];
|
||||
|
||||
|
||||
while ((currentKey = [keyEnumer nextObject])) {
|
||||
[contentStr appendString:[[self objectForKey:currentKey] encodeXMLRootObjectForKey:currentKey]];
|
||||
}
|
||||
|
||||
[contentStr appendString:suffixStr];
|
||||
|
||||
return contentStr;
|
||||
}
|
||||
|
||||
@end
|
||||
|
Loading…
Reference in a new issue