Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "XMLIndexTableSourceContext.hxx"
31 : :
32 : : #include <com/sun/star/beans/XPropertySet.hpp>
33 : : #include <com/sun/star/container/XIndexReplace.hpp>
34 : : #include <com/sun/star/text/ReferenceFieldPart.hpp>
35 : :
36 : : #include <sax/tools/converter.hxx>
37 : :
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 "xmloff/xmlnmspe.hxx"
45 : : #include <xmloff/nmspmap.hxx>
46 : : #include <xmloff/xmltoken.hxx>
47 : : #include <xmloff/xmluconv.hxx>
48 : : #include <rtl/ustring.hxx>
49 : :
50 : :
51 : : using namespace ::com::sun::star::text;
52 : : using namespace ::xmloff::token;
53 : :
54 : : using ::rtl::OUString;
55 : : using ::com::sun::star::beans::XPropertySet;
56 : : using ::com::sun::star::uno::Reference;
57 : : using ::com::sun::star::uno::Any;
58 : : using ::com::sun::star::xml::sax::XAttributeList;
59 : :
60 : : const sal_Char sAPI_CreateFromLabels[] = "CreateFromLabels";
61 : : const sal_Char sAPI_LabelCategory[] = "LabelCategory";
62 : : const sal_Char sAPI_LabelDisplayType[] = "LabelDisplayType";
63 : :
64 : :
65 [ # # ][ # # ]: 0 : TYPEINIT1(XMLIndexTableSourceContext, XMLIndexSourceBaseContext);
66 : :
67 : :
68 : 8 : XMLIndexTableSourceContext::XMLIndexTableSourceContext(
69 : : SvXMLImport& rImport,
70 : : sal_uInt16 nPrfx,
71 : : const OUString& rLocalName,
72 : : Reference<XPropertySet> & rPropSet) :
73 : : XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName,
74 : : rPropSet, sal_False),
75 : : sCreateFromLabels(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromLabels)),
76 : : sLabelCategory(RTL_CONSTASCII_USTRINGPARAM(sAPI_LabelCategory)),
77 : : sLabelDisplayType(RTL_CONSTASCII_USTRINGPARAM(sAPI_LabelDisplayType)),
78 : : bSequenceOK(sal_False),
79 : : bDisplayFormatOK(sal_False),
80 [ + - ][ + - ]: 8 : bUseCaption(sal_True)
[ + - ]
81 : : {
82 : 8 : }
83 : :
84 : 8 : XMLIndexTableSourceContext::~XMLIndexTableSourceContext()
85 : : {
86 [ - + ]: 12 : }
87 : :
88 : : static SvXMLEnumMapEntry const lcl_aReferenceTypeTokenMap[] =
89 : : {
90 : :
91 : : { XML_TEXT, ReferenceFieldPart::TEXT },
92 : : { XML_CATEGORY_AND_VALUE, ReferenceFieldPart::CATEGORY_AND_NUMBER },
93 : : { XML_CAPTION, ReferenceFieldPart::ONLY_CAPTION },
94 : :
95 : : // wrong values that previous versions wrote:
96 : : { XML_CHAPTER, ReferenceFieldPart::CATEGORY_AND_NUMBER },
97 : : { XML_PAGE, ReferenceFieldPart::ONLY_CAPTION },
98 : :
99 : : { XML_TOKEN_INVALID, 0 }
100 : : };
101 : :
102 : 16 : void XMLIndexTableSourceContext::ProcessAttribute(
103 : : enum IndexSourceParamEnum eParam,
104 : : const OUString& rValue)
105 : : {
106 : 16 : bool bTmp(false);
107 : :
108 [ - + + - ]: 16 : switch (eParam)
109 : : {
110 : : case XML_TOK_INDEXSOURCE_USE_CAPTION:
111 [ # # ][ # # ]: 0 : if (::sax::Converter::convertBool(bTmp, rValue))
112 : : {
113 : 0 : bUseCaption = bTmp;
114 : : }
115 : 0 : break;
116 : :
117 : : case XML_TOK_INDEXSOURCE_SEQUENCE_NAME:
118 : 8 : sSequence = rValue;
119 : 8 : bSequenceOK = sal_True;
120 : 8 : break;
121 : :
122 : : case XML_TOK_INDEXSOURCE_SEQUENCE_FORMAT:
123 : : {
124 : : sal_uInt16 nTmp;
125 [ + - ]: 8 : if (SvXMLUnitConverter::convertEnum(nTmp, rValue,
126 [ + - ]: 8 : lcl_aReferenceTypeTokenMap))
127 : : {
128 : 8 : nDisplayFormat = nTmp;
129 : 8 : bDisplayFormatOK = sal_True;
130 : : }
131 : : break;
132 : : }
133 : :
134 : : default:
135 [ # # ]: 0 : XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue);
136 : 0 : break;
137 : : }
138 : 16 : }
139 : :
140 : :
141 : 8 : void XMLIndexTableSourceContext::EndElement()
142 : : {
143 : 8 : Any aAny;
144 : :
145 [ + - ]: 8 : aAny.setValue(&bUseCaption, ::getBooleanCppuType());
146 [ + - ][ + - ]: 8 : rIndexPropertySet->setPropertyValue(sCreateFromLabels, aAny);
147 : :
148 [ + - ]: 8 : if (bSequenceOK)
149 : : {
150 [ + - ]: 8 : aAny <<= sSequence;
151 [ + - ][ + - ]: 8 : rIndexPropertySet->setPropertyValue(sLabelCategory, aAny);
152 : : }
153 : :
154 [ + - ]: 8 : if (bDisplayFormatOK)
155 : : {
156 [ + - ]: 8 : aAny <<= nDisplayFormat;
157 [ + - ][ + - ]: 8 : rIndexPropertySet->setPropertyValue(sLabelDisplayType, aAny);
158 : : }
159 : :
160 [ + - ]: 8 : XMLIndexSourceBaseContext::EndElement();
161 : 8 : }
162 : :
163 : :
164 : 8 : SvXMLImportContext* XMLIndexTableSourceContext::CreateChildContext(
165 : : sal_uInt16 nPrefix,
166 : : const OUString& rLocalName,
167 : : const Reference<XAttributeList> & xAttrList )
168 : : {
169 [ + - + + ]: 16 : if ( ( XML_NAMESPACE_TEXT == nPrefix ) &&
[ + + ]
170 : 8 : ( IsXMLToken( rLocalName, XML_TABLE_INDEX_ENTRY_TEMPLATE ) ) )
171 : : {
172 : 4 : return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet,
173 : : nPrefix, rLocalName,
174 : : aLevelNameTableMap,
175 : : XML_TOKEN_INVALID, // no outline-level attr
176 : : aLevelStylePropNameTableMap,
177 [ + - ]: 4 : aAllowedTokenTypesTable);
178 : : }
179 : : else
180 : : {
181 : : return XMLIndexSourceBaseContext::CreateChildContext(nPrefix,
182 : : rLocalName,
183 : 8 : xAttrList);
184 : : }
185 : :
186 : : }
187 : :
188 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|