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>
26 #include <xmloff/namespacemap.hxx>
27 #include <xmloff/xmlerror.hxx>
28 
29 #include <algorithm>
30 
32 
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.getToken(), aIter.toString() );
49 }
50 
51 css::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  {
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 
71 static bool lcl_IsWhiteSpace( sal_Unicode c )
72 {
73  return c == ' '
74  || c == u'\x0009'
75  || c == u'\x000A'
76  || c == u'\x000D';
77 }
78 
79 void 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 ) )
88 }
89 
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:59
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
sal_uInt16 sal_Unicode
#define XMLERROR_UNKNOWN_ELEMENT
Definition: xmlerror.hxx:63
static bool lcl_IsWhiteSpace(sal_Unicode c)
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
float u
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 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...
static const OUString & getNameFromToken(sal_Int32 nToken)
Definition: xmlimp.cxx:1994
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:45
virtual SvXMLImportContext * HandleChild(sal_Int32 nElementToken, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)=0
will be called for each child element
void SetError(sal_Int32 nId, const css::uno::Sequence< OUString > &rMsgParams, const OUString &rExceptionMessage, const css::uno::Reference< css::xml::sax::XLocator > &rLocator)
Record an error condition that occurred during import.
TokenContext(SvXMLImport &rImport)
virtual void HandleAttribute(sal_Int32 nAttributeToken, const OUString &rValue)=0
will be called for each attribute
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...
#define XMLERROR_UNKNOWN_CHARACTERS
Definition: xmlerror.hxx:64