1*3a7cf181SAndrew Rist /**************************************************************
2*3a7cf181SAndrew Rist  *
3*3a7cf181SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*3a7cf181SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*3a7cf181SAndrew Rist  * distributed with this work for additional information
6*3a7cf181SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*3a7cf181SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*3a7cf181SAndrew Rist  * "License"); you may not use this file except in compliance
9*3a7cf181SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*3a7cf181SAndrew Rist  *
11*3a7cf181SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*3a7cf181SAndrew Rist  *
13*3a7cf181SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*3a7cf181SAndrew Rist  * software distributed under the License is distributed on an
15*3a7cf181SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*3a7cf181SAndrew Rist  * KIND, either express or implied.  See the License for the
17*3a7cf181SAndrew Rist  * specific language governing permissions and limitations
18*3a7cf181SAndrew Rist  * under the License.
19*3a7cf181SAndrew Rist  *
20*3a7cf181SAndrew Rist  *************************************************************/
21*3a7cf181SAndrew Rist 
22*3a7cf181SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_configmgr.hxx"
25cdf0e10cSrcweir #include "sal/config.h"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "com/sun/star/container/NoSuchElementException.hpp"
28cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
29cdf0e10cSrcweir #include "osl/diagnose.h"
30cdf0e10cSrcweir #include "sal/types.h"
31cdf0e10cSrcweir #include "xmlreader/span.hxx"
32cdf0e10cSrcweir #include "xmlreader/xmlreader.hxx"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include "parsemanager.hxx"
35cdf0e10cSrcweir #include "parser.hxx"
36cdf0e10cSrcweir 
37cdf0e10cSrcweir namespace configmgr {
38cdf0e10cSrcweir 
39cdf0e10cSrcweir namespace {
40cdf0e10cSrcweir 
41cdf0e10cSrcweir namespace css = com::sun::star;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir }
44cdf0e10cSrcweir 
ParseManager(rtl::OUString const & url,rtl::Reference<Parser> const & parser)45cdf0e10cSrcweir ParseManager::ParseManager(
46cdf0e10cSrcweir     rtl::OUString const & url, rtl::Reference< Parser > const & parser)
47cdf0e10cSrcweir     SAL_THROW((
48cdf0e10cSrcweir         css::container::NoSuchElementException, css::uno::RuntimeException)):
49cdf0e10cSrcweir     reader_(url), parser_(parser)
50cdf0e10cSrcweir {
51cdf0e10cSrcweir     OSL_ASSERT(parser.is());
52cdf0e10cSrcweir     int id;
53cdf0e10cSrcweir     id = reader_.registerNamespaceIri(
54cdf0e10cSrcweir         xmlreader::Span(
55cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("http://openoffice.org/2001/registry")));
56cdf0e10cSrcweir     OSL_ASSERT(id == NAMESPACE_OOR);
57cdf0e10cSrcweir     id = reader_.registerNamespaceIri(
58cdf0e10cSrcweir         xmlreader::Span(
59cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM("http://www.w3.org/2001/XMLSchema")));
60cdf0e10cSrcweir     OSL_ASSERT(id == NAMESPACE_XS);
61cdf0e10cSrcweir     id = reader_.registerNamespaceIri(
62cdf0e10cSrcweir         xmlreader::Span(
63cdf0e10cSrcweir             RTL_CONSTASCII_STRINGPARAM(
64cdf0e10cSrcweir                 "http://www.w3.org/2001/XMLSchema-instance")));
65cdf0e10cSrcweir     OSL_ASSERT(id == NAMESPACE_XSI);
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
parse()68cdf0e10cSrcweir bool ParseManager::parse() {
69cdf0e10cSrcweir     for (;;) {
70cdf0e10cSrcweir         switch (itemData_.is()
71cdf0e10cSrcweir                 ? xmlreader::XmlReader::RESULT_BEGIN
72cdf0e10cSrcweir                 : reader_.nextItem(
73cdf0e10cSrcweir                     parser_->getTextMode(), &itemData_, &itemNamespaceId_))
74cdf0e10cSrcweir         {
75cdf0e10cSrcweir         case xmlreader::XmlReader::RESULT_BEGIN:
76cdf0e10cSrcweir             if (!parser_->startElement(reader_, itemNamespaceId_, itemData_))
77cdf0e10cSrcweir             {
78cdf0e10cSrcweir                 return false;
79cdf0e10cSrcweir             }
80cdf0e10cSrcweir             break;
81cdf0e10cSrcweir         case xmlreader::XmlReader::RESULT_END:
82cdf0e10cSrcweir             parser_->endElement(reader_);
83cdf0e10cSrcweir             break;
84cdf0e10cSrcweir         case xmlreader::XmlReader::RESULT_TEXT:
85cdf0e10cSrcweir             parser_->characters(itemData_);
86cdf0e10cSrcweir             break;
87cdf0e10cSrcweir         case xmlreader::XmlReader::RESULT_DONE:
88cdf0e10cSrcweir             return true;
89cdf0e10cSrcweir         }
90cdf0e10cSrcweir         itemData_.clear();
91cdf0e10cSrcweir     }
92cdf0e10cSrcweir }
93cdf0e10cSrcweir 
~ParseManager()94cdf0e10cSrcweir ParseManager::~ParseManager() {}
95cdf0e10cSrcweir 
96cdf0e10cSrcweir }
97