LibreOffice Module xmloff (master) 1
TokenContext.cxx
Go to the documentation of this file.
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#include <sal/log.hxx>
22
23#include "TokenContext.hxx"
24#include <xmloff/xmltkmap.hxx>
25#include <xmloff/xmlimp.hxx>
27#include <xmloff/xmlerror.hxx>
28
29#include <algorithm>
30
32
33TokenContext::TokenContext( SvXMLImport& rImport )
34 : SvXMLImportContext( rImport )
35{
36}
37
39 sal_Int32 /*nElement*/,
40 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
41{
42 // iterate over attributes
43 // - if in map: call HandleAttribute
44 // - xmlns:... : ignore
45 // - other: warning
46
47 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
48 HandleAttribute( aIter );
49}
50
51css::uno::Reference< css::xml::sax::XFastContextHandler > TokenContext::createFastChildContext(
52 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
53{
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 )
58 {
59 GetImport().SetError( XMLERROR_UNKNOWN_ELEMENT, SvXMLImport::getNameFromToken( nElement ) );
60 }
61 return pContext;
62}
63
64 css::uno::Reference< css::xml::sax::XFastContextHandler > TokenContext::createUnknownChildContext(
65 const OUString& Namespace, const OUString& Name, const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
66{
67 GetImport().SetError( XMLERROR_UNKNOWN_ELEMENT, Namespace + " " + Name );
68 return nullptr;
69}
70
72{
73 return c == ' '
74 || c == u'\x0009'
75 || c == u'\x000A'
76 || c == u'\x000D';
77}
78
79void TokenContext::characters( const OUString& rCharacters )
80{
81 // get iterators for string data
82 const sal_Unicode* pBegin = rCharacters.getStr();
83 const sal_Unicode* pEnd = &( pBegin[ rCharacters.getLength() ] );
84
85 // raise error if non-whitespace character is found
86 if( !::std::all_of( pBegin, pEnd, lcl_IsWhiteSpace ) )
87 GetImport().SetError( XMLERROR_UNKNOWN_CHARACTERS, rCharacters );
88}
89
90/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool lcl_IsWhiteSpace(sal_Unicode c)
This class deliberately does not support XWeak, to improve performance when loading large documents.
Definition: xmlictxt.hxx:48
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:60
virtual SvXMLImportContext * HandleChild(sal_Int32 nElementToken, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)=0
will be called for each child element
virtual void SAL_CALL characters(const OUString &rChars) override
Create a warning for all non-namespace character content.
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createUnknownChildContext(const OUString &Namespace, const OUString &Name, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
TokenContext(SvXMLImport &rImport)
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
call HandleAttribute for each attribute in the token map; create a warning for all others.
virtual void HandleAttribute(const sax_fastparser::FastAttributeList::FastAttributeIter &aIter)=0
will be called for each attribute
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
call HandleChild for each child element in the token map; create a warning for all others.
float u
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
OUString Name
sal_uInt16 sal_Unicode
#define XMLERROR_UNKNOWN_ELEMENT
Definition: xmlerror.hxx:63
#define XMLERROR_UNKNOWN_CHARACTERS
Definition: xmlerror.hxx:64