1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLIndexSourceBaseContext.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
35 #include "XMLIndexSourceBaseContext.hxx"
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/container/XIndexReplace.hpp>
38 #include "XMLIndexTemplateContext.hxx"
39 #include "XMLIndexTitleTemplateContext.hxx"
40 #include "XMLIndexTOCStylesContext.hxx"
41 #include <xmloff/xmlictxt.hxx>
42 #include <xmloff/xmlimp.hxx>
43 #include <xmloff/txtimp.hxx>
44 #include "xmlnmspe.hxx"
45 #include <xmloff/nmspmap.hxx>
46 #include <xmloff/xmltoken.hxx>
47 #include <xmloff/xmluconv.hxx>
48 #include <tools/debug.hxx>
49 #include <rtl/ustring.hxx>
53 using namespace ::xmloff::token
;
55 using ::rtl::OUString
;
56 using ::com::sun::star::beans::XPropertySet
;
57 using ::com::sun::star::uno::Reference
;
58 using ::com::sun::star::uno::Any
;
59 using ::com::sun::star::xml::sax::XAttributeList
;
61 const sal_Char sAPI_CreateFromChapter
[] = "CreateFromChapter";
62 const sal_Char sAPI_IsRelativeTabstops
[] = "IsRelativeTabstops";
64 static __FAR_DATA SvXMLTokenMapEntry aIndexSourceTokenMap
[] =
68 XML_TOK_INDEXSOURCE_OUTLINE_LEVEL
},
71 XML_TOK_INDEXSOURCE_USE_INDEX_MARKS
},
74 XML_TOK_INDEXSOURCE_INDEX_SCOPE
},
76 XML_RELATIVE_TAB_STOP_POSITION
,
77 XML_TOK_INDEXSOURCE_RELATIVE_TABS
} ,
79 XML_USE_OTHER_OBJECTS
,
80 XML_TOK_INDEXSOURCE_USE_OTHER_OBJECTS
},
82 XML_USE_SPREADSHEET_OBJECTS
,
83 XML_TOK_INDEXSOURCE_USE_SHEET
},
85 XML_USE_CHART_OBJECTS
,
86 XML_TOK_INDEXSOURCE_USE_CHART
},
89 XML_TOK_INDEXSOURCE_USE_DRAW
},
91 XML_USE_IMAGE_OBJECTS
,
92 XML_TOK_INDEXSOURCE_USE_IMAGE
},
95 XML_TOK_INDEXSOURCE_USE_MATH
},
97 XML_MAIN_ENTRY_STYLE_NAME
,
98 XML_TOK_INDEXSOURCE_MAIN_ENTRY_STYLE
},
101 XML_TOK_INDEXSOURCE_IGNORE_CASE
},
102 { XML_NAMESPACE_TEXT
,
103 XML_ALPHABETICAL_SEPARATORS
,
104 XML_TOK_INDEXSOURCE_SEPARATORS
},
105 { XML_NAMESPACE_TEXT
,
107 XML_TOK_INDEXSOURCE_COMBINE_ENTRIES
},
108 { XML_NAMESPACE_TEXT
,
109 XML_COMBINE_ENTRIES_WITH_DASH
,
110 XML_TOK_INDEXSOURCE_COMBINE_WITH_DASH
},
111 { XML_NAMESPACE_TEXT
,
112 XML_USE_KEYS_AS_ENTRIES
,
113 XML_TOK_INDEXSOURCE_KEYS_AS_ENTRIES
},
114 { XML_NAMESPACE_TEXT
,
115 XML_COMBINE_ENTRIES_WITH_PP
,
116 XML_TOK_INDEXSOURCE_COMBINE_WITH_PP
},
117 { XML_NAMESPACE_TEXT
,
118 XML_CAPITALIZE_ENTRIES
,
119 XML_TOK_INDEXSOURCE_CAPITALIZE
},
120 { XML_NAMESPACE_TEXT
,
122 XML_TOK_INDEXSOURCE_USE_OBJECTS
},
123 { XML_NAMESPACE_TEXT
,
125 XML_TOK_INDEXSOURCE_USE_GRAPHICS
},
126 { XML_NAMESPACE_TEXT
,
128 XML_TOK_INDEXSOURCE_USE_TABLES
},
129 { XML_NAMESPACE_TEXT
,
130 XML_USE_FLOATING_FRAMES
,
131 XML_TOK_INDEXSOURCE_USE_FRAMES
},
132 { XML_NAMESPACE_TEXT
,
133 XML_COPY_OUTLINE_LEVELS
,
134 XML_TOK_INDEXSOURCE_COPY_OUTLINE_LEVELS
},
135 { XML_NAMESPACE_TEXT
,
137 XML_TOK_INDEXSOURCE_USE_CAPTION
},
138 { XML_NAMESPACE_TEXT
,
139 XML_CAPTION_SEQUENCE_NAME
,
140 XML_TOK_INDEXSOURCE_SEQUENCE_NAME
},
141 { XML_NAMESPACE_TEXT
,
142 XML_CAPTION_SEQUENCE_FORMAT
,
143 XML_TOK_INDEXSOURCE_SEQUENCE_FORMAT
},
144 { XML_NAMESPACE_TEXT
,
146 XML_TOK_INDEXSOURCE_COMMA_SEPARATED
},
147 { XML_NAMESPACE_TEXT
,
148 XML_USE_INDEX_SOURCE_STYLES
,
149 XML_TOK_INDEXSOURCE_USE_INDEX_SOURCE_STYLES
},
150 { XML_NAMESPACE_TEXT
, XML_SORT_ALGORITHM
,
151 XML_TOK_INDEXSOURCE_SORT_ALGORITHM
},
152 { XML_NAMESPACE_FO
, XML_LANGUAGE
, XML_TOK_INDEXSOURCE_LANGUAGE
},
153 { XML_NAMESPACE_FO
, XML_COUNTRY
, XML_TOK_INDEXSOURCE_COUNTRY
},
154 { XML_NAMESPACE_TEXT
, XML_INDEX_NAME
, XML_TOK_INDEXSOURCE_USER_INDEX_NAME
},
155 { XML_NAMESPACE_TEXT
,
156 XML_USE_OUTLINE_LEVEL
,
157 XML_TOK_INDEXSOURCE_USE_OUTLINE_LEVEL
},
163 TYPEINIT1( XMLIndexSourceBaseContext
, SvXMLImportContext
);
165 XMLIndexSourceBaseContext::XMLIndexSourceBaseContext(
166 SvXMLImport
& rImport
,
168 const OUString
& rLocalName
,
169 Reference
<XPropertySet
> & rPropSet
,
170 sal_Bool bLevelFormats
)
171 : SvXMLImportContext(rImport
, nPrfx
, rLocalName
)
172 , sCreateFromChapter(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromChapter
))
173 , sIsRelativeTabstops(RTL_CONSTASCII_USTRINGPARAM(sAPI_IsRelativeTabstops
))
174 , bUseLevelFormats(bLevelFormats
)
175 , bChapterIndex(sal_False
)
176 , bRelativeTabs(sal_True
)
177 , rIndexPropertySet(rPropSet
)
181 XMLIndexSourceBaseContext::~XMLIndexSourceBaseContext()
185 void XMLIndexSourceBaseContext::StartElement(
186 const Reference
<XAttributeList
> & xAttrList
)
188 SvXMLTokenMap
aTokenMap(aIndexSourceTokenMap
);
190 // process attributes
191 sal_Int16 nLength
= xAttrList
->getLength();
192 for(sal_Int16 i
=0; i
<nLength
; i
++)
194 // map to IndexSourceParamEnum
196 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
197 GetKeyByAttrName( xAttrList
->getNameByIndex(i
), &sLocalName
);
198 sal_uInt16 nToken
= aTokenMap
.Get(nPrefix
, sLocalName
);
201 ProcessAttribute((enum IndexSourceParamEnum
)nToken
,
202 xAttrList
->getValueByIndex(i
));
206 void XMLIndexSourceBaseContext::ProcessAttribute(
207 enum IndexSourceParamEnum eParam
,
208 const OUString
& rValue
)
212 case XML_TOK_INDEXSOURCE_INDEX_SCOPE
:
213 if ( IsXMLToken( rValue
, XML_CHAPTER
) )
215 bChapterIndex
= sal_True
;
219 case XML_TOK_INDEXSOURCE_RELATIVE_TABS
:
222 if (SvXMLUnitConverter::convertBool(bTmp
, rValue
))
224 bRelativeTabs
= bTmp
;
230 // unknown attribute -> ignore
235 void XMLIndexSourceBaseContext::EndElement()
239 aAny
.setValue(&bRelativeTabs
, ::getBooleanCppuType());
240 rIndexPropertySet
->setPropertyValue(sIsRelativeTabstops
, aAny
);
242 aAny
.setValue(&bChapterIndex
, ::getBooleanCppuType());
243 rIndexPropertySet
->setPropertyValue(sCreateFromChapter
, aAny
);
246 SvXMLImportContext
* XMLIndexSourceBaseContext::CreateChildContext(
248 const OUString
& rLocalName
,
249 const Reference
<XAttributeList
> & xAttrList
)
251 SvXMLImportContext
* pContext
= NULL
;
253 if (XML_NAMESPACE_TEXT
== nPrefix
)
255 if ( IsXMLToken( rLocalName
, XML_INDEX_TITLE_TEMPLATE
) )
257 pContext
= new XMLIndexTitleTemplateContext(GetImport(),
259 nPrefix
, rLocalName
);
261 else if ( bUseLevelFormats
&&
262 IsXMLToken( rLocalName
, XML_INDEX_SOURCE_STYLES
) )
264 pContext
= new XMLIndexTOCStylesContext(GetImport(),
266 nPrefix
, rLocalName
);
268 // else: unknown element in text namespace -> ignore
270 // else: unknown namespace -> ignore
272 // use default context
273 if (pContext
== NULL
)
275 pContext
= SvXMLImportContext::CreateChildContext(nPrefix
, rLocalName
,