1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
21 #include <sal/log.hxx>
23 #include "TokenContext.hxx"
24 #include <xmloff/xmltkmap.hxx>
25 #include <xmloff/xmlimp.hxx>
26 #include <xmloff/namespacemap.hxx>
27 #include <xmloff/xmlerror.hxx>
31 using com::sun::star::uno::Reference
;
33 TokenContext::TokenContext( SvXMLImport
& rImport
)
34 : SvXMLImportContext( rImport
)
38 void TokenContext::startFastElement(
39 sal_Int32
/*nElement*/,
40 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
42 // iterate over attributes
43 // - if in map: call HandleAttribute
44 // - xmlns:... : ignore
47 for( auto& aIter
: sax_fastparser::castToFastAttributeList(xAttrList
) )
48 HandleAttribute( aIter
.getToken(), aIter
.toString() );
51 css::uno::Reference
< css::xml::sax::XFastContextHandler
> TokenContext::createFastChildContext(
52 sal_Int32 nElement
, const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
)
54 // call handle child, and pass down arguments
55 SvXMLImportContext
* pContext
= HandleChild( nElement
, xAttrList
);
56 // error handling: create default context and generate warning
57 if( pContext
== nullptr )
59 GetImport().SetError( XMLERROR_UNKNOWN_ELEMENT
, SvXMLImport::getNameFromToken( nElement
) );
64 static bool lcl_IsWhiteSpace( sal_Unicode c
)
72 void TokenContext::characters( const OUString
& rCharacters
)
74 // get iterators for string data
75 const sal_Unicode
* pBegin
= rCharacters
.getStr();
76 const sal_Unicode
* pEnd
= &( pBegin
[ rCharacters
.getLength() ] );
78 // raise error if non-whitespace character is found
79 if( !::std::all_of( pBegin
, pEnd
, lcl_IsWhiteSpace
) )
80 GetImport().SetError( XMLERROR_UNKNOWN_CHARACTERS
, rCharacters
);
83 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */