| 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 "TokenContext.hxx" |
| 23 |
#include <xmloff/xmlimp.hxx> |
| 24 |
#include <xmloff/xmlerror.hxx> |
| 25 |
|
| 26 |
#include <algorithm> |
| 27 |
|
| 28 |
using com::sun::star::uno::Reference; |
| 29 |
|
| 30 |
TokenContext::TokenContext( SvXMLImport& rImport ) |
| 31 |
: SvXMLImportContext( rImport ) |
| 32 |
{ |
| 33 |
} |
| 34 |
|
| 35 |
void TokenContext::startFastElement( |
| 36 |
sal_Int32 /*nElement*/, |
| 37 |
const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) |
| 38 |
{ |
| 39 |
// iterate over attributes |
| 40 |
// - if in map: call HandleAttribute |
| 41 |
// - xmlns:... : ignore |
| 42 |
// - other: warning |
| 43 |
|
| 44 |
for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) ) |
| 45 |
HandleAttribute( aIter ); |
| 46 |
} |
| 47 |
|
| 48 |
css::uno::Reference< css::xml::sax::XFastContextHandler > TokenContext::createFastChildContext( |
| 49 |
sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) |
| 50 |
{ |
| 51 |
// call handle child, and pass down arguments |
| 52 |
SvXMLImportContext* pContext = HandleChild( nElement, xAttrList ); |
| 53 |
// error handling: create default context and generate warning |
| 54 |
if( pContext == nullptr ) |
| 55 |
{ |
| 56 |
GetImport().SetError( XMLERROR_UNKNOWN_ELEMENT, SvXMLImport::getNameFromToken( nElement ) ); |
| 57 |
} |
| 58 |
return pContext; |
| 59 |
} |
| 60 |
|
| 61 |
css::uno::Reference< css::xml::sax::XFastContextHandler > TokenContext::createUnknownChildContext( |
| 62 |
const OUString& Namespace, const OUString& Name, const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) |
| 63 |
{ |
| 64 |
GetImport().SetError( XMLERROR_UNKNOWN_ELEMENT, Namespace + " " + Name ); |
| 65 |
return nullptr; |
| 66 |
} |
| 67 |
|
| 68 |
static bool lcl_IsWhiteSpace( sal_Unicode c ) |
| 69 |
{ |
| 70 |
return c == ' ' |
| 71 |
|| c == u'\x0009' |
| 72 |
|| c == u'\x000A' |
| 73 |
|| c == u'\x000D'; |
| 74 |
} |
| 75 |
|
| 76 |
void TokenContext::characters( const OUString& rCharacters ) |
| 77 |
{ |
| 78 |
// get iterators for string data |
| 79 |
const sal_Unicode* pBegin = rCharacters.getStr(); |
| 80 |
const sal_Unicode* pEnd = &( pBegin[ rCharacters.getLength() ] ); |
| 81 |
|
| 82 |
// raise error if non-whitespace character is found |
| 83 |
if( !::std::all_of( pBegin, pEnd, lcl_IsWhiteSpace ) ) |
| 84 |
GetImport().SetError( XMLERROR_UNKNOWN_CHARACTERS, rCharacters ); |
| 85 |
} |
| 86 |
|
| 87 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |