]> err.no Git - sope/blob - sope-xml/DOM/DOMBuilderFactory.m
fixed some comments
[sope] / sope-xml / DOM / DOMBuilderFactory.m
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 #include "DOMBuilderFactory.h"
23 #include <DOM/DOMSaxBuilder.h>
24 #include <SaxObjC/SaxXMLReader.h>
25 #include <SaxObjC/SaxXMLReaderFactory.h>
26 #include "common.h"
27
28 @implementation DOMBuilderFactory
29
30 static id factory = nil;
31
32 + (id)standardDOMBuilderFactory {
33   if (factory == nil)
34     factory = [[self alloc] init];
35   return factory;
36 }
37
38 /* primary method */
39
40 - (id<NSObject,DOMBuilder>)createDOMBuilderWithXmlReader:(id<SaxXMLReader>)_r {
41   DOMSaxBuilder *builder;
42
43   if (_r == nil)
44     return nil;
45   
46   builder = [[DOMSaxBuilder alloc] initWithXMLReader:_r];
47   return [builder autorelease];
48 }
49
50 /* reader constructors */
51
52 - (SaxXMLReaderFactory *)readerFactory {
53   return [SaxXMLReaderFactory standardXMLReaderFactory];
54 }
55
56 - (id<NSObject,DOMBuilder>)createDOMBuilder {
57   id<SaxXMLReader> reader;
58   
59   if ((reader = [[self readerFactory] createXMLReader]) == nil) {
60     NSLog(@"%s:%i: could not create default DOM builder "
61           @"because no SAX default reader could be constructed.",
62           __PRETTY_FUNCTION__, __LINE__);
63     return nil;
64   }
65   
66   return [self createDOMBuilderWithXmlReader:reader];
67 }
68 - (id<NSObject,DOMBuilder>)createDOMBuilderWithName:(NSString *)_name {
69   id<SaxXMLReader> reader;
70
71   if ((reader = [[self readerFactory] createXMLReaderWithName:_name]) == nil) {
72     NSLog(@"%s:%i: could not create DOM builder '%@' "
73           @"because no SAX reader named '%@' could be constructed.",
74           __PRETTY_FUNCTION__, __LINE__,
75           _name, _name);
76     return nil;
77   }
78   
79   return [self createDOMBuilderWithXmlReader:reader];
80 }
81 - (id<NSObject,DOMBuilder>)createDOMBuilderForMimeType:(NSString *)_mtype {
82   id<SaxXMLReader> reader;
83
84   reader = [[self readerFactory] createXMLReaderForMimeType:_mtype];
85   if (reader == nil) {
86     NSLog(@"%s:%i: could not create DOM builder for MIME type '%@' "
87           @"because no SAX proper reader could be constructed.",
88           __PRETTY_FUNCTION__, __LINE__, _mtype);
89     return nil;
90   }
91   
92   return [self createDOMBuilderWithXmlReader:reader];
93 }
94
95 - (NSArray *)availableDOMBuilders {
96   return [NSArray arrayWithObject:@"DOMSaxBuilder"];
97 }
98
99 @end /* DOMBuilderFactory */