~ubuntu-branches/ubuntu/edgy/sope/edgy

« back to all changes in this revision

Viewing changes to sope-xml/SaxObjC/SaxNamespaceSupport.h

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Ley
  • Date: 2005-08-19 16:53:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050819165331-hs683wz1osm708pw
Tags: upstream-4.4rc.2
ImportĀ upstreamĀ versionĀ 4.4rc.2

Show diffs side-by-side

added added

removed removed

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