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