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 "XMLIndexSourceBaseContext.hxx"
21 #include <com/sun/star/beans/XPropertySet.hpp>
22 #include <com/sun/star/container/XIndexReplace.hpp>
23 #include "XMLIndexTemplateContext.hxx"
24 #include "XMLIndexTitleTemplateContext.hxx"
25 #include "XMLIndexTOCStylesContext.hxx"
26 #include <xmloff/xmlictxt.hxx>
27 #include <xmloff/xmlimp.hxx>
28 #include <xmloff/txtimp.hxx>
29 #include <xmloff/xmlnmspe.hxx>
30 #include <xmloff/nmspmap.hxx>
31 #include <xmloff/xmltoken.hxx>
32 #include <sax/tools/converter.hxx>
33 #include <rtl/ustring.hxx>
37 using namespace ::xmloff::token
;
39 using ::com::sun::star::beans::XPropertySet
;
40 using ::com::sun::star::uno::Reference
;
41 using ::com::sun::star::uno::Any
;
42 using ::com::sun::star::xml::sax::XAttributeList
;
44 const sal_Char sAPI_CreateFromChapter
[] = "CreateFromChapter";
45 const sal_Char sAPI_IsRelativeTabstops
[] = "IsRelativeTabstops";
47 static const SvXMLTokenMapEntry aIndexSourceTokenMap
[] =
51 XML_TOK_INDEXSOURCE_OUTLINE_LEVEL
},
54 XML_TOK_INDEXSOURCE_USE_INDEX_MARKS
},
57 XML_TOK_INDEXSOURCE_INDEX_SCOPE
},
59 XML_RELATIVE_TAB_STOP_POSITION
,
60 XML_TOK_INDEXSOURCE_RELATIVE_TABS
} ,
62 XML_USE_OTHER_OBJECTS
,
63 XML_TOK_INDEXSOURCE_USE_OTHER_OBJECTS
},
65 XML_USE_SPREADSHEET_OBJECTS
,
66 XML_TOK_INDEXSOURCE_USE_SHEET
},
68 XML_USE_CHART_OBJECTS
,
69 XML_TOK_INDEXSOURCE_USE_CHART
},
72 XML_TOK_INDEXSOURCE_USE_DRAW
},
74 XML_USE_IMAGE_OBJECTS
,
75 XML_TOK_INDEXSOURCE_USE_IMAGE
},
78 XML_TOK_INDEXSOURCE_USE_MATH
},
80 XML_MAIN_ENTRY_STYLE_NAME
,
81 XML_TOK_INDEXSOURCE_MAIN_ENTRY_STYLE
},
84 XML_TOK_INDEXSOURCE_IGNORE_CASE
},
86 XML_ALPHABETICAL_SEPARATORS
,
87 XML_TOK_INDEXSOURCE_SEPARATORS
},
90 XML_TOK_INDEXSOURCE_COMBINE_ENTRIES
},
92 XML_COMBINE_ENTRIES_WITH_DASH
,
93 XML_TOK_INDEXSOURCE_COMBINE_WITH_DASH
},
95 XML_USE_KEYS_AS_ENTRIES
,
96 XML_TOK_INDEXSOURCE_KEYS_AS_ENTRIES
},
98 XML_COMBINE_ENTRIES_WITH_PP
,
99 XML_TOK_INDEXSOURCE_COMBINE_WITH_PP
},
100 { XML_NAMESPACE_TEXT
,
101 XML_CAPITALIZE_ENTRIES
,
102 XML_TOK_INDEXSOURCE_CAPITALIZE
},
103 { XML_NAMESPACE_TEXT
,
105 XML_TOK_INDEXSOURCE_USE_OBJECTS
},
106 { XML_NAMESPACE_TEXT
,
108 XML_TOK_INDEXSOURCE_USE_GRAPHICS
},
109 { XML_NAMESPACE_TEXT
,
111 XML_TOK_INDEXSOURCE_USE_TABLES
},
112 { XML_NAMESPACE_TEXT
,
113 XML_USE_FLOATING_FRAMES
,
114 XML_TOK_INDEXSOURCE_USE_FRAMES
},
115 { XML_NAMESPACE_TEXT
,
116 XML_COPY_OUTLINE_LEVELS
,
117 XML_TOK_INDEXSOURCE_COPY_OUTLINE_LEVELS
},
118 { XML_NAMESPACE_TEXT
,
120 XML_TOK_INDEXSOURCE_USE_CAPTION
},
121 { XML_NAMESPACE_TEXT
,
122 XML_CAPTION_SEQUENCE_NAME
,
123 XML_TOK_INDEXSOURCE_SEQUENCE_NAME
},
124 { XML_NAMESPACE_TEXT
,
125 XML_CAPTION_SEQUENCE_FORMAT
,
126 XML_TOK_INDEXSOURCE_SEQUENCE_FORMAT
},
127 { XML_NAMESPACE_TEXT
,
129 XML_TOK_INDEXSOURCE_COMMA_SEPARATED
},
130 { XML_NAMESPACE_TEXT
,
131 XML_USE_INDEX_SOURCE_STYLES
,
132 XML_TOK_INDEXSOURCE_USE_INDEX_SOURCE_STYLES
},
133 { XML_NAMESPACE_TEXT
, XML_SORT_ALGORITHM
,
134 XML_TOK_INDEXSOURCE_SORT_ALGORITHM
},
135 { XML_NAMESPACE_STYLE
, XML_RFC_LANGUAGE_TAG
, XML_TOK_INDEXSOURCE_RFC_LANGUAGE_TAG
},
136 { XML_NAMESPACE_FO
, XML_LANGUAGE
, XML_TOK_INDEXSOURCE_LANGUAGE
},
137 { XML_NAMESPACE_FO
, XML_SCRIPT
, XML_TOK_INDEXSOURCE_SCRIPT
},
138 { XML_NAMESPACE_FO
, XML_COUNTRY
, XML_TOK_INDEXSOURCE_COUNTRY
},
139 { XML_NAMESPACE_TEXT
, XML_INDEX_NAME
, XML_TOK_INDEXSOURCE_USER_INDEX_NAME
},
140 { XML_NAMESPACE_TEXT
,
141 XML_USE_OUTLINE_LEVEL
,
142 XML_TOK_INDEXSOURCE_USE_OUTLINE_LEVEL
},
148 TYPEINIT1( XMLIndexSourceBaseContext
, SvXMLImportContext
);
150 XMLIndexSourceBaseContext::XMLIndexSourceBaseContext(
151 SvXMLImport
& rImport
,
153 const OUString
& rLocalName
,
154 Reference
<XPropertySet
> & rPropSet
,
156 : SvXMLImportContext(rImport
, nPrfx
, rLocalName
)
157 , sCreateFromChapter(sAPI_CreateFromChapter
)
158 , sIsRelativeTabstops(sAPI_IsRelativeTabstops
)
159 , bUseLevelFormats(bLevelFormats
)
160 , bChapterIndex(false)
161 , bRelativeTabs(true)
162 , rIndexPropertySet(rPropSet
)
166 XMLIndexSourceBaseContext::~XMLIndexSourceBaseContext()
170 void XMLIndexSourceBaseContext::StartElement(
171 const Reference
<XAttributeList
> & xAttrList
)
173 SvXMLTokenMap
aTokenMap(aIndexSourceTokenMap
);
175 // process attributes
176 sal_Int16 nLength
= xAttrList
->getLength();
177 for(sal_Int16 i
=0; i
<nLength
; i
++)
179 // map to IndexSourceParamEnum
181 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
182 GetKeyByAttrName( xAttrList
->getNameByIndex(i
), &sLocalName
);
183 sal_uInt16 nToken
= aTokenMap
.Get(nPrefix
, sLocalName
);
186 ProcessAttribute((enum IndexSourceParamEnum
)nToken
,
187 xAttrList
->getValueByIndex(i
));
191 void XMLIndexSourceBaseContext::ProcessAttribute(
192 enum IndexSourceParamEnum eParam
,
193 const OUString
& rValue
)
197 case XML_TOK_INDEXSOURCE_INDEX_SCOPE
:
198 if ( IsXMLToken( rValue
, XML_CHAPTER
) )
200 bChapterIndex
= true;
204 case XML_TOK_INDEXSOURCE_RELATIVE_TABS
:
207 if (::sax::Converter::convertBool(bTmp
, rValue
))
209 bRelativeTabs
= bTmp
;
215 // unknown attribute -> ignore
220 void XMLIndexSourceBaseContext::EndElement()
224 aAny
.setValue(&bRelativeTabs
, cppu::UnoType
<bool>::get());
225 rIndexPropertySet
->setPropertyValue(sIsRelativeTabstops
, aAny
);
227 aAny
.setValue(&bChapterIndex
, cppu::UnoType
<bool>::get());
228 rIndexPropertySet
->setPropertyValue(sCreateFromChapter
, aAny
);
231 SvXMLImportContext
* XMLIndexSourceBaseContext::CreateChildContext(
233 const OUString
& rLocalName
,
234 const Reference
<XAttributeList
> & xAttrList
)
236 SvXMLImportContext
* pContext
= NULL
;
238 if (XML_NAMESPACE_TEXT
== nPrefix
)
240 if ( IsXMLToken( rLocalName
, XML_INDEX_TITLE_TEMPLATE
) )
242 pContext
= new XMLIndexTitleTemplateContext(GetImport(),
244 nPrefix
, rLocalName
);
246 else if ( bUseLevelFormats
&&
247 IsXMLToken( rLocalName
, XML_INDEX_SOURCE_STYLES
) )
249 pContext
= new XMLIndexTOCStylesContext(GetImport(),
251 nPrefix
, rLocalName
);
253 // else: unknown element in text namespace -> ignore
255 // else: unknown namespace -> ignore
257 // use default context
258 if (pContext
== NULL
)
260 pContext
= SvXMLImportContext::CreateChildContext(nPrefix
, rLocalName
,
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */