LibreOffice Module xmloff (master)  1
XMLAutoMarkFileContext.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 
21 #include <xmloff/xmlimp.hxx>
22 #include <rtl/ustring.hxx>
23 #include <xmloff/nmspmap.hxx>
24 #include <xmloff/xmlnmspe.hxx>
25 #include <xmloff/xmltoken.hxx>
26 #include <com/sun/star/frame/XModel.hpp>
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <com/sun/star/xml/sax/XAttributeList.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 
31 
32 using ::com::sun::star::uno::Any;
33 using ::com::sun::star::uno::Reference;
34 using ::com::sun::star::uno::UNO_QUERY;
35 using ::com::sun::star::xml::sax::XAttributeList;
36 using ::com::sun::star::beans::XPropertySet;
37 
40 
41 
43  SvXMLImport& rImport,
44  sal_uInt16 nPrefix,
45  const OUString& rLocalName) :
46  SvXMLImportContext(rImport, nPrefix, rLocalName)
47 {
48 }
49 
51 {
52 }
53 
54 
56  const Reference<XAttributeList> & xAttrList)
57 {
58  // scan for text:alphabetical-index-auto-mark-file attribute, and if
59  // found set value with the document
60 
61  sal_Int16 nLength = xAttrList->getLength();
62  for( sal_Int16 i = 0; i < nLength; i++ )
63  {
64  OUString sLocalName;
65  sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
66  GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
67 
68  if ( ( XML_NAMESPACE_XLINK == nPrefix ) &&
69  IsXMLToken(sLocalName, XML_HREF) )
70  {
71  Any aAny;
72  aAny <<= GetImport().GetAbsoluteReference( xAttrList->getValueByIndex(i) );
73  Reference<XPropertySet> xPropertySet(
74  GetImport().GetModel(), UNO_QUERY );
75  if (xPropertySet.is())
76  {
77  xPropertySet->setPropertyValue( "IndexAutoMarkFileURL", aAny );
78  }
79  }
80  }
81 }
82 
83 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3422
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:62
SvXMLNamespaceMap & GetNamespaceMap()
Definition: xmlimp.hxx:397
XMLAutoMarkFileContext(SvXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLocalName)
int i
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
constexpr sal_uInt16 XML_NAMESPACE_XLINK
Definition: xmlnmspe.hxx:35
virtual ~XMLAutoMarkFileContext() override
OUString GetAbsoluteReference(const OUString &rValue) const
Definition: xmlimp.cxx:1686
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
StartElement is called after a context has been constructed and before an elements context is parsed...
sal_Int32 nLength
Definition: xmltoken.cxx:36