Line data Source code
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 :
21 : #include "XMLIndexTableSourceContext.hxx"
22 :
23 : #include <com/sun/star/beans/XPropertySet.hpp>
24 : #include <com/sun/star/container/XIndexReplace.hpp>
25 : #include <com/sun/star/text/ReferenceFieldPart.hpp>
26 :
27 : #include <sax/tools/converter.hxx>
28 :
29 : #include "XMLIndexTemplateContext.hxx"
30 : #include "XMLIndexTitleTemplateContext.hxx"
31 : #include "XMLIndexTOCStylesContext.hxx"
32 : #include <xmloff/xmlictxt.hxx>
33 : #include <xmloff/xmlimp.hxx>
34 : #include <xmloff/txtimp.hxx>
35 : #include "xmloff/xmlnmspe.hxx"
36 : #include <xmloff/nmspmap.hxx>
37 : #include <xmloff/xmltoken.hxx>
38 : #include <xmloff/xmluconv.hxx>
39 : #include <rtl/ustring.hxx>
40 :
41 :
42 : using namespace ::com::sun::star::text;
43 : using namespace ::xmloff::token;
44 :
45 : using ::com::sun::star::beans::XPropertySet;
46 : using ::com::sun::star::uno::Reference;
47 : using ::com::sun::star::uno::Any;
48 : using ::com::sun::star::xml::sax::XAttributeList;
49 :
50 : const sal_Char sAPI_CreateFromLabels[] = "CreateFromLabels";
51 : const sal_Char sAPI_LabelCategory[] = "LabelCategory";
52 : const sal_Char sAPI_LabelDisplayType[] = "LabelDisplayType";
53 :
54 :
55 0 : TYPEINIT1(XMLIndexTableSourceContext, XMLIndexSourceBaseContext);
56 :
57 :
58 4 : XMLIndexTableSourceContext::XMLIndexTableSourceContext(
59 : SvXMLImport& rImport,
60 : sal_uInt16 nPrfx,
61 : const OUString& rLocalName,
62 : Reference<XPropertySet> & rPropSet) :
63 : XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName,
64 : rPropSet, sal_False),
65 : sCreateFromLabels(sAPI_CreateFromLabels),
66 : sLabelCategory(sAPI_LabelCategory),
67 : sLabelDisplayType(sAPI_LabelDisplayType),
68 : bSequenceOK(sal_False),
69 : bDisplayFormatOK(sal_False),
70 4 : bUseCaption(sal_True)
71 : {
72 4 : }
73 :
74 6 : XMLIndexTableSourceContext::~XMLIndexTableSourceContext()
75 : {
76 6 : }
77 :
78 : static SvXMLEnumMapEntry const lcl_aReferenceTypeTokenMap[] =
79 : {
80 :
81 : { XML_TEXT, ReferenceFieldPart::TEXT },
82 : { XML_CATEGORY_AND_VALUE, ReferenceFieldPart::CATEGORY_AND_NUMBER },
83 : { XML_CAPTION, ReferenceFieldPart::ONLY_CAPTION },
84 :
85 : // wrong values that previous versions wrote:
86 : { XML_CHAPTER, ReferenceFieldPart::CATEGORY_AND_NUMBER },
87 : { XML_PAGE, ReferenceFieldPart::ONLY_CAPTION },
88 :
89 : { XML_TOKEN_INVALID, 0 }
90 : };
91 :
92 8 : void XMLIndexTableSourceContext::ProcessAttribute(
93 : enum IndexSourceParamEnum eParam,
94 : const OUString& rValue)
95 : {
96 8 : bool bTmp(false);
97 :
98 8 : switch (eParam)
99 : {
100 : case XML_TOK_INDEXSOURCE_USE_CAPTION:
101 0 : if (::sax::Converter::convertBool(bTmp, rValue))
102 : {
103 0 : bUseCaption = bTmp;
104 : }
105 0 : break;
106 :
107 : case XML_TOK_INDEXSOURCE_SEQUENCE_NAME:
108 4 : sSequence = rValue;
109 4 : bSequenceOK = sal_True;
110 4 : break;
111 :
112 : case XML_TOK_INDEXSOURCE_SEQUENCE_FORMAT:
113 : {
114 : sal_uInt16 nTmp;
115 4 : if (SvXMLUnitConverter::convertEnum(nTmp, rValue,
116 4 : lcl_aReferenceTypeTokenMap))
117 : {
118 4 : nDisplayFormat = nTmp;
119 4 : bDisplayFormatOK = sal_True;
120 : }
121 4 : break;
122 : }
123 :
124 : default:
125 0 : XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue);
126 0 : break;
127 : }
128 8 : }
129 :
130 :
131 4 : void XMLIndexTableSourceContext::EndElement()
132 : {
133 4 : Any aAny;
134 :
135 4 : aAny.setValue(&bUseCaption, ::getBooleanCppuType());
136 4 : rIndexPropertySet->setPropertyValue(sCreateFromLabels, aAny);
137 :
138 4 : if (bSequenceOK)
139 : {
140 4 : aAny <<= sSequence;
141 4 : rIndexPropertySet->setPropertyValue(sLabelCategory, aAny);
142 : }
143 :
144 4 : if (bDisplayFormatOK)
145 : {
146 4 : aAny <<= nDisplayFormat;
147 4 : rIndexPropertySet->setPropertyValue(sLabelDisplayType, aAny);
148 : }
149 :
150 4 : XMLIndexSourceBaseContext::EndElement();
151 4 : }
152 :
153 :
154 4 : SvXMLImportContext* XMLIndexTableSourceContext::CreateChildContext(
155 : sal_uInt16 nPrefix,
156 : const OUString& rLocalName,
157 : const Reference<XAttributeList> & xAttrList )
158 : {
159 8 : if ( ( XML_NAMESPACE_TEXT == nPrefix ) &&
160 4 : ( IsXMLToken( rLocalName, XML_TABLE_INDEX_ENTRY_TEMPLATE ) ) )
161 : {
162 2 : return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet,
163 : nPrefix, rLocalName,
164 : aLevelNameTableMap,
165 : XML_TOKEN_INVALID, // no outline-level attr
166 : aLevelStylePropNameTableMap,
167 2 : aAllowedTokenTypesTable);
168 : }
169 : else
170 : {
171 : return XMLIndexSourceBaseContext::CreateChildContext(nPrefix,
172 : rLocalName,
173 2 : xAttrList);
174 : }
175 :
176 : }
177 :
178 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|