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 5 : XMLIndexTableSourceContext::XMLIndexTableSourceContext(
59 : SvXMLImport& rImport, sal_uInt16 nPrfx,
60 : const OUString& rLocalName, Reference<XPropertySet> & rPropSet)
61 : : XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName,
62 : rPropSet, false)
63 : , sCreateFromLabels(sAPI_CreateFromLabels)
64 : , sLabelCategory(sAPI_LabelCategory)
65 : , sLabelDisplayType(sAPI_LabelDisplayType)
66 : , nDisplayFormat(0)
67 : , bSequenceOK(false)
68 : , bDisplayFormatOK(false)
69 5 : , bUseCaption(true)
70 : {
71 5 : }
72 :
73 7 : XMLIndexTableSourceContext::~XMLIndexTableSourceContext()
74 : {
75 7 : }
76 :
77 : static SvXMLEnumMapEntry const lcl_aReferenceTypeTokenMap[] =
78 : {
79 :
80 : { XML_TEXT, ReferenceFieldPart::TEXT },
81 : { XML_CATEGORY_AND_VALUE, ReferenceFieldPart::CATEGORY_AND_NUMBER },
82 : { XML_CAPTION, ReferenceFieldPart::ONLY_CAPTION },
83 :
84 : // wrong values that previous versions wrote:
85 : { XML_CHAPTER, ReferenceFieldPart::CATEGORY_AND_NUMBER },
86 : { XML_PAGE, ReferenceFieldPart::ONLY_CAPTION },
87 :
88 : { XML_TOKEN_INVALID, 0 }
89 : };
90 :
91 10 : void XMLIndexTableSourceContext::ProcessAttribute(
92 : enum IndexSourceParamEnum eParam,
93 : const OUString& rValue)
94 : {
95 10 : bool bTmp(false);
96 :
97 10 : switch (eParam)
98 : {
99 : case XML_TOK_INDEXSOURCE_USE_CAPTION:
100 0 : if (::sax::Converter::convertBool(bTmp, rValue))
101 : {
102 0 : bUseCaption = bTmp;
103 : }
104 0 : break;
105 :
106 : case XML_TOK_INDEXSOURCE_SEQUENCE_NAME:
107 5 : sSequence = rValue;
108 5 : bSequenceOK = true;
109 5 : break;
110 :
111 : case XML_TOK_INDEXSOURCE_SEQUENCE_FORMAT:
112 : {
113 : sal_uInt16 nTmp;
114 5 : if (SvXMLUnitConverter::convertEnum(nTmp, rValue,
115 : lcl_aReferenceTypeTokenMap))
116 : {
117 5 : nDisplayFormat = nTmp;
118 5 : bDisplayFormatOK = true;
119 : }
120 5 : break;
121 : }
122 :
123 : default:
124 0 : XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue);
125 0 : break;
126 : }
127 10 : }
128 :
129 :
130 5 : void XMLIndexTableSourceContext::EndElement()
131 : {
132 5 : Any aAny;
133 :
134 5 : aAny.setValue(&bUseCaption, cppu::UnoType<bool>::get());
135 5 : rIndexPropertySet->setPropertyValue(sCreateFromLabels, aAny);
136 :
137 5 : if (bSequenceOK)
138 : {
139 5 : aAny <<= sSequence;
140 5 : rIndexPropertySet->setPropertyValue(sLabelCategory, aAny);
141 : }
142 :
143 5 : if (bDisplayFormatOK)
144 : {
145 5 : aAny <<= nDisplayFormat;
146 5 : rIndexPropertySet->setPropertyValue(sLabelDisplayType, aAny);
147 : }
148 :
149 5 : XMLIndexSourceBaseContext::EndElement();
150 5 : }
151 :
152 :
153 4 : SvXMLImportContext* XMLIndexTableSourceContext::CreateChildContext(
154 : sal_uInt16 nPrefix,
155 : const OUString& rLocalName,
156 : const Reference<XAttributeList> & xAttrList )
157 : {
158 8 : if ( ( XML_NAMESPACE_TEXT == nPrefix ) &&
159 4 : ( IsXMLToken( rLocalName, XML_TABLE_INDEX_ENTRY_TEMPLATE ) ) )
160 : {
161 2 : return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet,
162 : nPrefix, rLocalName,
163 : aLevelNameTableMap,
164 : XML_TOKEN_INVALID, // no outline-level attr
165 : aLevelStylePropNameTableMap,
166 2 : aAllowedTokenTypesTable);
167 : }
168 : else
169 : {
170 : return XMLIndexSourceBaseContext::CreateChildContext(nPrefix,
171 : rLocalName,
172 2 : xAttrList);
173 : }
174 :
175 : }
176 :
177 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|