/*
- Copyright (C) 2000-2004 SKYRIX Software AG
+ Copyright (C) 2000-2005 SKYRIX Software AG
- This file is part of OpenGroupware.org.
+ This file is part of SOPE.
- OGo is free software; you can redistribute it and/or modify it under
+ SOPE is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
- OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+ SOPE 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 Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
- License along with OGo; see the file COPYING. If not, write to the
+ License along with SOPE; see the file COPYING. If not, write to the
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
-// $Id$
#include "WOHyperlink.h"
#include <NGObjWeb/WOApplication.h>
#include <NGObjWeb/WOResourceManager.h>
#include <NGExtensions/NSString+Ext.h>
-#include "common.h"
+#include "decommon.h"
static Class NSURLClass = Nil;
/* accessors */
-- (WOElement *)template {
+- (id)template {
return self->template;
}
-// ******************** responder ********************
+/* handle requests */
-- (void)takeValuesFromRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
+- (void)takeValuesFromRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
/* links can take form values !!!! (for query-parameters) */
- if (self->queryParameters) {
+ if (self->queryParameters != nil) {
/* apply values to ?style parameters */
WOComponent *sComponent = [_ctx component];
NSEnumerator *keys;
NSString *key;
-
+
keys = [self->queryParameters keyEnumerator];
- while ((key = [keys nextObject])) {
+ while ((key = [keys nextObject]) != nil) {
id assoc, value;
-
+
assoc = [self->queryParameters objectForKey:key];
if ([assoc isValueSettable]) {
- value = [_req formValueForKey:key];
+ value = [_rq formValueForKey:key];
[assoc setValue:value inComponent:sComponent];
}
}
}
- [self->template takeValuesFromRequest:_req inContext:_ctx];
+ [self->template takeValuesFromRequest:_rq inContext:_ctx];
}
-- (id)invokeActionForRequest:(WORequest *)_request
- inContext:(WOContext *)_ctx
-{
- if (self->disabled) {
+- (id)invokeActionForRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
+ if (self->disabled != nil) {
if ([self->disabled boolValueInComponent:[_ctx component]])
return nil;
}
if (![[_ctx elementID] isEqualToString:[_ctx senderID]])
/* link is not the active element */
- return [self->template invokeActionForRequest:_request inContext:_ctx];
+ return [self->template invokeActionForRequest:_rq inContext:_ctx];
/* link is active */
[[_ctx session] logWithFormat:@"%@[0x%08X]: no action/page set !",
if (!((uFi != nil) || (uUri != nil)))
return;
- languages = [_ctx hasSession]
- ? [[_ctx session] languages]
- : [[_ctx request] browserLanguages];
+ languages = [_ctx resourceLookupLanguages];
WOResponse_AddCString(_resp, "<img src=\"");
WOResponse_AddChar(_resp, '"');
[self appendExtraAttributesToResponse:_resp inContext:_ctx];
- WOResponse_AddCString(_resp, " />");
+
+ WOResponse_AddEmptyCloseParens(_resp, _ctx);
}
- (void)appendToResponse:(WOResponse *)_response inContext:(WOContext *)_ctx {
WOResponse_AddCString(_response, "<a href=\"");
if ([self _appendHrefToResponse:_response inContext:_ctx]) {
- queryString = [self queryStringForQueryDictionary:
- [self->queryDictionary valueInComponent:sComponent]
- andQueryParameters:self->queryParameters
- inContext:_ctx];
+ queryString = [self queryStringForQueryDictionary:
+ [self->queryDictionary valueInComponent:sComponent]
+ andQueryParameters:self->queryParameters
+ inContext:_ctx];
}
if (self->fragmentIdentifier) {
[self appendExtraAttributesToResponse:_response inContext:_ctx];
if (self->otherTagString) {
- NSString *s;
-
- s = [self->otherTagString stringValueInComponent:[_ctx component]];
- WOResponse_AddString(_response, s);
+ WOResponse_AddChar(_response, ' ');
+ WOResponse_AddString(_response,
+ [self->otherTagString stringValueInComponent:
+ [_ctx component]]);
}
[_response appendContentCharacter:'>'];
@end /* _WOComplexHyperlink */
+
@implementation _WOHrefHyperlink
static BOOL debugStaticLinks = NO;
/* URI generation */
+- (BOOL)shouldRewriteURLString:(NSString *)_s inContext:(WOContext *)_ctx {
+ // TODO: we need a binding to disable rewriting!
+ if ([_s hasPrefix:@"mailto:"])
+ return NO;
+ if ([_s hasPrefix:@"javascript:"])
+ return NO;
+ return YES;
+}
+
- (BOOL)_appendHrefToResponse:(WOResponse *)_r inContext:(WOContext *)_ctx {
NSString *s;
id hrefValue;
if (hrefValue == nil)
return NO;
-
+
if ([hrefValue isKindOfClass:NSURLClass]) {
s = [hrefValue stringValueRelativeToURL:base];
}
else {
s = [hrefValue stringValue];
- if (!([s hasPrefix:@"mailto:"] || [s hasPrefix:@"javascript:"])) {
+ if ([self shouldRewriteURLString:s inContext:_ctx]) {
if ([s isAbsoluteURL]) {
// TODO: why are we doing this? we could just pass through the string?
// => probably to generate relative links
url = [NSURLClass URLWithString:s];
}
else if (base != nil) {
- url = [NSURLClass URLWithString:s relativeToURL:base];
+ /* avoid creating a new URL for ".", just return the base */
+ url = [s isEqualToString:@"."]
+ ? base
+ : [NSURLClass URLWithString:s relativeToURL:base];
}
else {
[self logWithFormat:@"WARNING: missing base URL in context ..."];
s, base];
return NO;
}
+
s = [url stringValueRelativeToURL:base];
}
}
@end /* _WOHrefHyperlink */
+
@implementation _WOActionHyperlink
- (id)initWithName:(NSString *)_name
/* dynamic invocation */
-- (id)invokeActionForRequest:(WORequest *)_request
+- (id)invokeActionForRequest:(WORequest *)_rq
inContext:(WOContext *)_ctx
{
if (self->disabled) {
if (![[_ctx elementID] isEqualToString:[_ctx senderID]])
/* link is not the active element */
- return [self->template invokeActionForRequest:_request inContext:_ctx];
+ return [self->template invokeActionForRequest:_rq inContext:_ctx];
/* link is active */
return [self executeAction:self->action inContext:_ctx];
@end /* _WOActionHyperlink */
+
@implementation _WOPageHyperlink
- (id)initWithName:(NSString *)_name
[super dealloc];
}
-/* actions */
+/* handle request */
-- (id)invokeActionForRequest:(WORequest *)_request
- inContext:(WOContext *)_ctx
-{
+- (id)invokeActionForRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
WOComponent *page;
NSString *name;
if (![[_ctx elementID] isEqualToString:[_ctx senderID]])
/* link is not the active element */
- return [self->template invokeActionForRequest:_request inContext:_ctx];
+ return [self->template invokeActionForRequest:_rq inContext:_ctx];
/* link is the active element */
return page;
}
-- (BOOL)_appendHrefToResponse:(WOResponse *)_response
- inContext:(WOContext *)_ctx
-{
+/* generate response */
+
+- (BOOL)_appendHrefToResponse:(WOResponse *)_r inContext:(WOContext *)_ctx {
/*
Profiling:
87% -componentActionURL
13% NSString dataUsingEncoding(appendContentString!)
TODO(prof): use addcstring
*/
- WOResponse_AddString(_response, [_ctx componentActionURL]);
+ WOResponse_AddString(_r, [_ctx componentActionURL]);
return YES;
}
@end /* _WOPageHyperlink */
+
@implementation _WODirectActionHyperlink
- (id)initWithName:(NSString *)_name
[super dealloc];
}
-/* href */
+/* handle requests */
- (void)takeValuesFromRequest:(WORequest *)_req inContext:(WOContext *)_ctx {
/* DA links can *never* take form values !!!! */
[self->template takeValuesFromRequest:_req inContext:_ctx];
}
-- (id)invokeActionForRequest:(WORequest *)_request
- inContext:(WOContext *)_ctx
-{
+- (id)invokeActionForRequest:(WORequest *)_rq inContext:(WOContext *)_ctx {
/* DA links can *never* invoke an action !!!! */
- return [self->template invokeActionForRequest:_request inContext:_ctx];
+ return [self->template invokeActionForRequest:_rq inContext:_ctx];
}
-- (BOOL)_appendHrefToResponse:(WOResponse *)_response
+/* generate response */
+
+- (BOOL)_appendHrefToResponse:(WOResponse *)_r
inContext:(WOContext *)_ctx
{
WOComponent *sComponent;
}
}
- WOResponse_AddString(_response,
+ WOResponse_AddString(_r,
[_ctx directActionURLForActionNamed:daName
queryDictionary:qd]);
return NO;