LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / xmloff / source / text / XMLIndexUserSourceContext.cxx
blob392e8b72bc5feaddea36441edac9da69f3fd3581
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "XMLIndexUserSourceContext.hxx"
21 #include <com/sun/star/beans/XPropertySet.hpp>
22 #include <sax/tools/converter.hxx>
23 #include "XMLIndexTemplateContext.hxx"
24 #include <xmloff/xmlictxt.hxx>
25 #include <xmloff/xmlimp.hxx>
26 #include <xmloff/xmlnamespace.hxx>
27 #include <xmloff/xmltoken.hxx>
28 #include <rtl/ustring.hxx>
31 using ::com::sun::star::beans::XPropertySet;
32 using ::com::sun::star::uno::Reference;
33 using ::com::sun::star::uno::Any;
34 using ::com::sun::star::xml::sax::XAttributeList;
35 using ::xmloff::token::IsXMLToken;
36 using namespace ::xmloff::token;
38 XMLIndexUserSourceContext::XMLIndexUserSourceContext(
39 SvXMLImport& rImport,
40 Reference<XPropertySet> & rPropSet) :
41 XMLIndexSourceBaseContext(rImport,
42 rPropSet, true),
43 bUseObjects(false),
44 bUseGraphic(false),
45 bUseMarks(false),
46 bUseTables(false),
47 bUseFrames(false),
48 bUseLevelFromSource(false),
49 bUseLevelParagraphStyles(false)
53 XMLIndexUserSourceContext::~XMLIndexUserSourceContext()
57 void XMLIndexUserSourceContext::ProcessAttribute(const sax_fastparser::FastAttributeList::FastAttributeIter & aIter)
59 bool bTmp(false);
61 switch (aIter.getToken())
63 case XML_ELEMENT(TEXT, XML_USE_INDEX_MARKS):
64 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
66 bUseMarks = bTmp;
68 break;
70 case XML_ELEMENT(TEXT, XML_USE_OBJECTS):
71 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
73 bUseObjects = bTmp;
75 break;
77 case XML_ELEMENT(TEXT, XML_USE_GRAPHICS):
78 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
80 bUseGraphic = bTmp;
82 break;
84 case XML_ELEMENT(TEXT, XML_USE_TABLES):
85 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
87 bUseTables = bTmp;
89 break;
91 case XML_ELEMENT(TEXT, XML_USE_FLOATING_FRAMES):
92 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
94 bUseFrames = bTmp;
96 break;
98 case XML_ELEMENT(TEXT, XML_COPY_OUTLINE_LEVELS):
99 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
101 bUseLevelFromSource = bTmp;
103 break;
105 case XML_ELEMENT(TEXT, XML_USE_INDEX_SOURCE_STYLES):
106 if (::sax::Converter::convertBool(bTmp, aIter.toView()))
108 bUseLevelParagraphStyles = bTmp;
110 break;
112 case XML_ELEMENT(TEXT, XML_INDEX_NAME):
113 sIndexName = aIter.toString();
114 break;
116 default:
117 XMLIndexSourceBaseContext::ProcessAttribute(aIter);
118 break;
122 void XMLIndexUserSourceContext::endFastElement(sal_Int32 nElement)
124 rIndexPropertySet->setPropertyValue("CreateFromEmbeddedObjects", css::uno::Any(bUseObjects));
125 rIndexPropertySet->setPropertyValue("CreateFromGraphicObjects", css::uno::Any(bUseGraphic));
126 rIndexPropertySet->setPropertyValue("UseLevelFromSource", css::uno::Any(bUseLevelFromSource));
127 rIndexPropertySet->setPropertyValue("CreateFromMarks", css::uno::Any(bUseMarks));
128 rIndexPropertySet->setPropertyValue("CreateFromTables", css::uno::Any(bUseTables));
129 rIndexPropertySet->setPropertyValue("CreateFromTextFrames", css::uno::Any(bUseFrames));
130 rIndexPropertySet->setPropertyValue("CreateFromLevelParagraphStyles", css::uno::Any(bUseLevelParagraphStyles));
132 if( !sIndexName.isEmpty() )
134 rIndexPropertySet->setPropertyValue("UserIndexName", css::uno::Any(sIndexName));
137 XMLIndexSourceBaseContext::endFastElement(nElement);
140 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLIndexUserSourceContext::createFastChildContext(
141 sal_Int32 nElement,
142 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
144 if ( nElement == XML_ELEMENT(TEXT, XML_USER_INDEX_ENTRY_TEMPLATE) )
146 return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet,
147 aSvLevelNameTOCMap,
148 XML_OUTLINE_LEVEL,
149 aLevelStylePropNameTOCMap,
150 aAllowedTokenTypesUser);
152 else
154 return XMLIndexSourceBaseContext::createFastChildContext(nElement,
155 xAttrList);
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */