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