]> err.no Git - sope/blob - sope-xml/SaxObjC/SaxNamespaceSupport.h
removed linking against scripting libs
[sope] / sope-xml / SaxObjC / SaxNamespaceSupport.h
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 #ifndef __SaxNamespaceSupport_H__
24 #define __SaxNamespaceSupport_H__
25
26 #import <Foundation/NSObject.h>
27
28 @class NSString, NSEnumerator, NSArray;
29
30 /*
31   New in SAX2, defined in helpers/NamespaceSupport
32
33   Encapsulate Namespace logic for use by SAX drivers. 
34
35   This class encapsulates the logic of Namespace processing: it tracks
36   the declarations currently in force for each context and automatically
37   processing raw XML 1.0 names into their Namespace parts.
38
39   Namespace support objects are reusable, but the reset method must be
40   invoked between each session.
41
42   Here is a simple session:
43   
44       String parts[] = new String[3];
45       SaxNamespaceSupport support;
46
47       support = [[SaxNamespaceSupport alloc] init];
48       
49       [support pushContext];
50       [support declarePrefix:@""   uri:@"http://www.w3.org/1999/xhtml"];
51       [support declarePrefix:@"dc" uri:@"http://www.purl.org/dc#"];
52       
53       String parts[] = support.processName("p", parts, false);
54       System.out.println("Namespace URI: " + parts[0]);
55       System.out.println("Local name: " + parts[1]);
56       System.out.println("Raw name: " + parts[2]);
57      
58       String parts[] = support.processName("dc:title", parts, false);
59       System.out.println("Namespace URI: " + parts[0]);
60       System.out.println("Local name: " + parts[1]);
61       System.out.println("Raw name: " + parts[2]);
62      
63       [support popContext];
64  
65   Note that this class is optimized for the use case where most elements
66   do not contain Namespace declarations: if the same prefix/URI mapping
67   is repeated for each context (for example), this class will be somewhat
68   less efficient.
69 */
70
71 extern NSString *SaxXMLNS;
72
73 @interface SaxNamespaceSupport : NSObject
74 {
75 @private
76 }
77
78 /* start a new ns context */
79 - (void)pushContext;
80
81 /* revert to previous ns context */
82 - (void)popContext;
83
84 /* Declare a Namespace prefix. */
85 - (BOOL)declarePrefix:(NSString *)_prefix uri:(NSString *)_uri;
86
87 /* Return an enumeration of all prefixes declared in this context. */
88 - (NSEnumerator *)prefixEnumerator;
89
90 /* Look up a prefix and get the currently-mapped Namespace URI. */
91 - (NSString *)getUriForPrefix:(NSString *)_prefix;
92
93 /* Reset this Namespace support object for reuse. */
94 - (void)reset;
95
96 /*
97   Process a raw XML 1.0 name.
98   
99   This method processes a raw XML 1.0 name in the current context by
100   removing the prefix and looking it up among the prefixes currently
101   declared. The return value will be the array supplied by the caller,
102   filled in as follows:
103
104     parts[0] The Namespace URI, or an empty string if none is in use. 
105     parts[1] The local name (without prefix). 
106     parts[2] The original raw name.
107     
108   All of the strings in the array will be internalized. If the raw name
109   has a prefix that has not been declared, then the return value will be
110   null.
111
112   Note that attribute names are processed differently than element names:
113   an unprefixed element name will received the default Namespace (if any),
114   while an unprefixed element name will not.
115 */
116 - (NSArray *)processName:(NSString *)_rawName
117   parts:(NSArray *)_parts
118   isAttribute:(BOOL)_isAttribute;
119
120 @end
121
122 #endif /* __SaxNamespaceSupport_H__ */