Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <sal/config.h>
21 :
22 : #include <cassert>
23 : #include <set>
24 :
25 : #include <com/sun/star/container/NoSuchElementException.hpp>
26 : #include <com/sun/star/uno/RuntimeException.hpp>
27 : #include <sal/types.h>
28 : #include <xmlreader/span.hxx>
29 : #include <xmlreader/xmlreader.hxx>
30 :
31 : #include "parsemanager.hxx"
32 : #include "parser.hxx"
33 :
34 : namespace configmgr {
35 :
36 8599 : ParseManager::ParseManager(
37 : OUString const & url, rtl::Reference< Parser > const & parser)
38 8599 : : reader_(url), parser_(parser), itemNamespaceId_(-1)
39 : {
40 : assert(parser.is());
41 : int id;
42 : id = reader_.registerNamespaceIri(
43 : xmlreader::Span(
44 8531 : RTL_CONSTASCII_STRINGPARAM("http://openoffice.org/2001/registry")));
45 : assert(id == NAMESPACE_OOR);
46 : id = reader_.registerNamespaceIri(
47 : xmlreader::Span(
48 8531 : RTL_CONSTASCII_STRINGPARAM("http://www.w3.org/2001/XMLSchema")));
49 : assert(id == NAMESPACE_XS);
50 : id = reader_.registerNamespaceIri(
51 : xmlreader::Span(
52 : RTL_CONSTASCII_STRINGPARAM(
53 8531 : "http://www.w3.org/2001/XMLSchema-instance")));
54 : assert(id == NAMESPACE_XSI);
55 : (void)id;
56 8531 : }
57 :
58 13484 : bool ParseManager::parse(std::set< OUString > const * existingDependencies) {
59 13484 : sal_uInt32 startTime( osl_getGlobalTimer() );
60 : for (;;) {
61 90440865 : switch (itemData_.is()
62 : ? xmlreader::XmlReader::RESULT_BEGIN
63 : : reader_.nextItem(
64 45217956 : parser_->getTextMode(), &itemData_, &itemNamespaceId_))
65 : {
66 : case xmlreader::XmlReader::RESULT_BEGIN:
67 38226900 : if (!parser_->startElement(
68 19113450 : reader_, itemNamespaceId_, itemData_, existingDependencies))
69 : {
70 : SAL_INFO("configmgr", "parsing " << reader_.getUrl() << " took " << (osl_getGlobalTimer() - startTime) << " ms, fail");
71 4953 : return false;
72 : }
73 19108497 : break;
74 : case xmlreader::XmlReader::RESULT_END:
75 19108497 : parser_->endElement(reader_);
76 19108497 : break;
77 : case xmlreader::XmlReader::RESULT_TEXT:
78 6992431 : parser_->characters(itemData_);
79 6992431 : break;
80 : case xmlreader::XmlReader::RESULT_DONE:
81 : SAL_INFO("configmgr", "parsing " << reader_.getUrl() << " took " << (osl_getGlobalTimer() - startTime) << " ms, success");
82 8531 : return true;
83 : }
84 45209425 : itemData_.clear();
85 45209425 : }
86 : }
87 :
88 17062 : ParseManager::~ParseManager() {}
89 :
90 : }
91 :
92 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|