]> err.no Git - sope/blob - Recycler/NGObjDOM/ODRGenericTag.m
fixed a warning
[sope] / Recycler / NGObjDOM / ODRGenericTag.m
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #include <NGObjDOM/ODRGenericTag.h>
24 #include "common.h"
25
26 @implementation ODRGenericTag
27
28 - (void)_appendAttributesOfNode:(id)_domNode
29   toResponse:(WOResponse *)_response
30   inContext:(WOContext *)_ctx
31 {
32   id attrs;
33   id<DOMAttr> attr;
34   NSString *nsuri, *prefix;
35   
36   prefix = [_domNode prefix];
37   nsuri  = [_domNode namespaceURI];
38
39   if ([nsuri length] > 0) {
40     id parentNode;
41     BOOL doNS;
42
43     doNS = YES;
44     
45     if ((parentNode = [_domNode parentNode])) {
46       if ([parentNode nodeType] == DOM_ELEMENT_NODE) {
47         if ([[parentNode namespaceURI] isEqualToString:nsuri]) {
48           NSString *pp;
49           
50           pp = [parentNode prefix];
51           
52           if ((pp == nil) && (prefix == nil))
53             doNS = NO;
54           else if ([pp isEqualToString:prefix])
55             doNS = NO;
56         }
57       }
58     }
59
60     if (doNS) {
61       [_response appendContentString:@" xmlns"];
62       if ([prefix length] > 0) {
63         [_response appendContentString:@":"];
64         [_response appendContentString:prefix];
65       }
66       [_response appendContentString:@"='"];
67       [_response appendContentString:nsuri];
68       [_response appendContentString:@"'"];
69     }
70   }
71   
72   if ((attrs = [(id)[_domNode attributes] objectEnumerator]) == nil)
73     return;
74   
75   while ((attr = [attrs nextObject])) {
76     NSString *attrURI  = nil;
77     NSString *attrName = nil;
78     
79     attrURI = [attr namespaceURI];
80     if ([attrURI length] > 0) {
81       if ([attrURI isEqualToString:nsuri]) {
82         if ([prefix length] > 0)
83           attrName = [NSString stringWithFormat:@"%@:%@", prefix, [attr name]];
84         else
85           attrName = [attr name];
86       }
87       else {
88         /* different namespace */
89         NSLog(@"WARNING(%s): tag '%@'(ns=%@) different namespace %@ ..",
90               __PRETTY_FUNCTION__,
91               [_domNode tagName], [_domNode namespaceURI], attrURI);
92       }
93     }
94     else
95       attrName = [attr name];
96     
97     [_response appendContentString:@" "];
98     [_response appendContentString:attrName];
99     [_response appendContentString:@"='"];
100     [_response appendContentHTMLAttributeValue:[attr value]];
101     [_response appendContentString:@"'"];
102   }
103 }
104
105 - (void)appendNode:(id)_domNode
106   toResponse:(WOResponse *)_response
107   inContext:(WOContext *)_context
108 {
109   if ([_domNode nodeType] != DOM_ELEMENT_NODE) {
110     [super appendNode:_domNode toResponse:_response inContext:_context];
111     return;
112   }
113   
114   [_response appendContentString:@"<"];
115   if ([[_domNode prefix] length] > 0) {
116     [_response appendContentString:[_domNode prefix]];
117     [_response appendContentString:@":"];
118   }
119   [_response appendContentString:[_domNode tagName]];
120     
121   [self _appendAttributesOfNode:_domNode
122         toResponse:_response
123         inContext:_context];
124     
125   if (![_domNode hasChildNodes]) {
126     [_response appendContentString:@" />"];
127   }
128   else {
129     [_response appendContentString:@">"];
130
131     /* children */
132     [self appendChildNodes:[_domNode childNodes]
133           toResponse:_response
134           inContext:_context];
135     
136     [_response appendContentString:@"</"];
137     if ([[_domNode prefix] length] > 0) {
138       [_response appendContentString:[_domNode prefix]];
139       [_response appendContentString:@":"];
140     }
141     [_response appendContentString:[_domNode tagName]];
142     [_response appendContentString:@">"];
143   }
144 }
145
146 @end /* ODRGenericTag */