1 /*************************************************************************
2 *
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
6 *
7 * OpenOffice.org - a multi-platform office productivity suite
8 *
9 * This file is part of OpenOffice.org.
10 *
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
14 *
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org.  If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
25 *
26 ************************************************************************/
27 
28 #include "precompiled_configmgr.hxx"
29 #include "sal/config.h"
30 
31 #include "com/sun/star/container/NoSuchElementException.hpp"
32 #include "com/sun/star/uno/RuntimeException.hpp"
33 #include "osl/diagnose.h"
34 #include "sal/types.h"
35 #include "xmlreader/span.hxx"
36 #include "xmlreader/xmlreader.hxx"
37 
38 #include "parsemanager.hxx"
39 #include "parser.hxx"
40 
41 namespace configmgr {
42 
43 namespace {
44 
45 namespace css = com::sun::star;
46 
47 }
48 
49 ParseManager::ParseManager(
50     rtl::OUString const & url, rtl::Reference< Parser > const & parser)
51     SAL_THROW((
52         css::container::NoSuchElementException, css::uno::RuntimeException)):
53     reader_(url), parser_(parser)
54 {
55     OSL_ASSERT(parser.is());
56     int id;
57     id = reader_.registerNamespaceIri(
58         xmlreader::Span(
59             RTL_CONSTASCII_STRINGPARAM("http://openoffice.org/2001/registry")));
60     OSL_ASSERT(id == NAMESPACE_OOR);
61     id = reader_.registerNamespaceIri(
62         xmlreader::Span(
63             RTL_CONSTASCII_STRINGPARAM("http://www.w3.org/2001/XMLSchema")));
64     OSL_ASSERT(id == NAMESPACE_XS);
65     id = reader_.registerNamespaceIri(
66         xmlreader::Span(
67             RTL_CONSTASCII_STRINGPARAM(
68                 "http://www.w3.org/2001/XMLSchema-instance")));
69     OSL_ASSERT(id == NAMESPACE_XSI);
70 }
71 
72 bool ParseManager::parse() {
73     for (;;) {
74         switch (itemData_.is()
75                 ? xmlreader::XmlReader::RESULT_BEGIN
76                 : reader_.nextItem(
77                     parser_->getTextMode(), &itemData_, &itemNamespaceId_))
78         {
79         case xmlreader::XmlReader::RESULT_BEGIN:
80             if (!parser_->startElement(reader_, itemNamespaceId_, itemData_))
81             {
82                 return false;
83             }
84             break;
85         case xmlreader::XmlReader::RESULT_END:
86             parser_->endElement(reader_);
87             break;
88         case xmlreader::XmlReader::RESULT_TEXT:
89             parser_->characters(itemData_);
90             break;
91         case xmlreader::XmlReader::RESULT_DONE:
92             return true;
93         }
94         itemData_.clear();
95     }
96 }
97 
98 ParseManager::~ParseManager() {}
99 
100 }
101