1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
30 #include "XMLIndexTableSourceContext.hxx"
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/container/XIndexReplace.hpp>
34 #include <com/sun/star/text/ReferenceFieldPart.hpp>
36 #include <sax/tools/converter.hxx>
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>
51 using namespace ::com::sun::star::text
;
52 using namespace ::xmloff::token
;
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
;
60 const sal_Char sAPI_CreateFromLabels
[] = "CreateFromLabels";
61 const sal_Char sAPI_LabelCategory
[] = "LabelCategory";
62 const sal_Char sAPI_LabelDisplayType
[] = "LabelDisplayType";
65 TYPEINIT1(XMLIndexTableSourceContext
, XMLIndexSourceBaseContext
);
68 XMLIndexTableSourceContext::XMLIndexTableSourceContext(
71 const OUString
& rLocalName
,
72 Reference
<XPropertySet
> & rPropSet
) :
73 XMLIndexSourceBaseContext(rImport
, nPrfx
, rLocalName
,
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
),
84 XMLIndexTableSourceContext::~XMLIndexTableSourceContext()
88 static SvXMLEnumMapEntry
const lcl_aReferenceTypeTokenMap
[] =
91 { XML_TEXT
, ReferenceFieldPart::TEXT
},
92 { XML_CATEGORY_AND_VALUE
, ReferenceFieldPart::CATEGORY_AND_NUMBER
},
93 { XML_CAPTION
, ReferenceFieldPart::ONLY_CAPTION
},
95 // wrong values that previous versions wrote:
96 { XML_CHAPTER
, ReferenceFieldPart::CATEGORY_AND_NUMBER
},
97 { XML_PAGE
, ReferenceFieldPart::ONLY_CAPTION
},
99 { XML_TOKEN_INVALID
, 0 }
102 void XMLIndexTableSourceContext::ProcessAttribute(
103 enum IndexSourceParamEnum eParam
,
104 const OUString
& rValue
)
110 case XML_TOK_INDEXSOURCE_USE_CAPTION
:
111 if (::sax::Converter::convertBool(bTmp
, rValue
))
117 case XML_TOK_INDEXSOURCE_SEQUENCE_NAME
:
119 bSequenceOK
= sal_True
;
122 case XML_TOK_INDEXSOURCE_SEQUENCE_FORMAT
:
125 if (SvXMLUnitConverter::convertEnum(nTmp
, rValue
,
126 lcl_aReferenceTypeTokenMap
))
128 nDisplayFormat
= nTmp
;
129 bDisplayFormatOK
= sal_True
;
135 XMLIndexSourceBaseContext::ProcessAttribute(eParam
, rValue
);
141 void XMLIndexTableSourceContext::EndElement()
145 aAny
.setValue(&bUseCaption
, ::getBooleanCppuType());
146 rIndexPropertySet
->setPropertyValue(sCreateFromLabels
, aAny
);
151 rIndexPropertySet
->setPropertyValue(sLabelCategory
, aAny
);
154 if (bDisplayFormatOK
)
156 aAny
<<= nDisplayFormat
;
157 rIndexPropertySet
->setPropertyValue(sLabelDisplayType
, aAny
);
160 XMLIndexSourceBaseContext::EndElement();
164 SvXMLImportContext
* XMLIndexTableSourceContext::CreateChildContext(
166 const OUString
& rLocalName
,
167 const Reference
<XAttributeList
> & xAttrList
)
169 if ( ( XML_NAMESPACE_TEXT
== nPrefix
) &&
170 ( IsXMLToken( rLocalName
, XML_TABLE_INDEX_ENTRY_TEMPLATE
) ) )
172 return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet
,
175 XML_TOKEN_INVALID
, // no outline-level attr
176 aLevelStylePropNameTableMap
,
177 aAllowedTokenTypesTable
);
181 return XMLIndexSourceBaseContext::CreateChildContext(nPrefix
,
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */