1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "xmlannoi.hxx"
21 #include "xmlimprt.hxx"
22 #include "xmlconti.hxx"
23 #include "XMLTableShapeImportHelper.hxx"
25 #include <xmloff/xmltkmap.hxx>
26 #include <xmloff/nmspmap.hxx>
27 #include <xmloff/xmlnmspe.hxx>
28 #include <xmloff/xmltoken.hxx>
30 using namespace com::sun::star
;
31 using namespace xmloff::token
;
33 ScXMLAnnotationData::ScXMLAnnotationData() :
34 mbUseShapePos( false ),
39 ScXMLAnnotationData::~ScXMLAnnotationData()
43 ScXMLAnnotationContext::ScXMLAnnotationContext( ScXMLImport
& rImport
,
45 const OUString
& rLName
,
46 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
,
47 ScXMLAnnotationData
& rAnnotationData
,
48 ScXMLTableRowCellContext
* pTempCellContext
) :
49 SvXMLImportContext( rImport
, nPrfx
, rLName
),
50 mrAnnotationData( rAnnotationData
),
51 pCellContext(pTempCellContext
),
54 uno::Reference
<drawing::XShapes
> xLocalShapes (GetScImport().GetTables().GetCurrentXShapes());
55 if (xLocalShapes
.is())
57 XMLTableShapeImportHelper
* pTableShapeImport
= static_cast<XMLTableShapeImportHelper
*>(GetScImport().GetShapeImport().get());
58 pTableShapeImport
->SetAnnotation(this);
59 pShapeContext
= GetScImport().GetShapeImport()->CreateGroupChildContext(
60 GetScImport(), nPrfx
, rLName
, xAttrList
, xLocalShapes
, true);
63 pCellContext
= pTempCellContext
;
64 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
65 const SvXMLTokenMap
& rAttrTokenMap
= GetScImport().GetTableAnnotationAttrTokenMap();
66 for( sal_Int16 i
=0; i
< nAttrCount
; ++i
)
68 const OUString
& sAttrName(xAttrList
->getNameByIndex( i
));
70 sal_uInt16 nPrefix
= GetScImport().GetNamespaceMap().GetKeyByAttrName(
71 sAttrName
, &aLocalName
);
72 const OUString
& sValue(xAttrList
->getValueByIndex( i
));
74 switch( rAttrTokenMap
.Get( nPrefix
, aLocalName
) )
76 case XML_TOK_TABLE_ANNOTATION_ATTR_AUTHOR
:
78 maAuthorBuffer
= sValue
;
81 case XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE
:
83 maCreateDateBuffer
= sValue
;
86 case XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE_STRING
:
88 maCreateDateStringBuffer
= sValue
;
91 case XML_TOK_TABLE_ANNOTATION_ATTR_DISPLAY
:
93 mrAnnotationData
.mbShown
= IsXMLToken(sValue
, XML_TRUE
);
96 case XML_TOK_TABLE_ANNOTATION_ATTR_X
:
98 mrAnnotationData
.mbUseShapePos
= true;
101 case XML_TOK_TABLE_ANNOTATION_ATTR_Y
:
103 mrAnnotationData
.mbUseShapePos
= true;
110 ScXMLAnnotationContext::~ScXMLAnnotationContext()
114 void ScXMLAnnotationContext::StartElement(const com::sun::star::uno::Reference
< com::sun::star::xml::sax::XAttributeList
>& xAttrList
)
117 pShapeContext
->StartElement(xAttrList
);
120 SvXMLImportContext
*ScXMLAnnotationContext::CreateChildContext( sal_uInt16 nPrefix
,
121 const OUString
& rLName
,
122 const ::com::sun::star::uno::Reference
<
123 ::com::sun::star::xml::sax::XAttributeList
>& xAttrList
)
125 SvXMLImportContext
*pContext
= 0;
127 if( XML_NAMESPACE_DC
== nPrefix
)
129 if( IsXMLToken( rLName
, XML_CREATOR
) )
130 pContext
= new ScXMLContentContext(GetScImport(), nPrefix
,
131 rLName
, xAttrList
, maAuthorBuffer
);
132 else if( IsXMLToken( rLName
, XML_DATE
) )
133 pContext
= new ScXMLContentContext(GetScImport(), nPrefix
,
134 rLName
, xAttrList
, maCreateDateBuffer
);
136 else if( XML_NAMESPACE_META
== nPrefix
)
138 if( IsXMLToken( rLName
, XML_DATE_STRING
) )
139 pContext
= new ScXMLContentContext(GetScImport(), nPrefix
,
140 rLName
, xAttrList
, maCreateDateStringBuffer
);
143 if( !pContext
&& pShapeContext
)
144 pContext
= pShapeContext
->CreateChildContext(nPrefix
, rLName
, xAttrList
);
147 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLName
);
152 void ScXMLAnnotationContext::Characters( const OUString
& rChars
)
154 maTextBuffer
.append(rChars
);
157 void ScXMLAnnotationContext::EndElement()
161 pShapeContext
->EndElement();
162 delete pShapeContext
;
163 pShapeContext
= NULL
;
166 mrAnnotationData
.maAuthor
= maAuthorBuffer
.makeStringAndClear();
167 mrAnnotationData
.maCreateDate
= maCreateDateBuffer
.makeStringAndClear();
168 if (mrAnnotationData
.maCreateDate
.isEmpty())
169 mrAnnotationData
.maCreateDate
= maCreateDateStringBuffer
.makeStringAndClear();
170 mrAnnotationData
.maSimpleText
= maTextBuffer
.makeStringAndClear();
172 XMLTableShapeImportHelper
* pTableShapeImport
= static_cast<XMLTableShapeImportHelper
*>(GetScImport().GetShapeImport().get());
173 pTableShapeImport
->SetAnnotation(NULL
);
176 void ScXMLAnnotationContext::SetShape( const uno::Reference
< drawing::XShape
>& rxShape
, const uno::Reference
< drawing::XShapes
>& rxShapes
,
177 const OUString
& rStyleName
, const OUString
& rTextStyle
)
179 mrAnnotationData
.mxShape
= rxShape
;
180 mrAnnotationData
.mxShapes
= rxShapes
;
181 mrAnnotationData
.maStyleName
= rStyleName
;
182 mrAnnotationData
.maTextStyle
= rTextStyle
;
185 void ScXMLAnnotationContext::AddContentStyle( sal_uInt16 nFamily
, const OUString
& rName
, const ESelection
& rSelection
)
187 mrAnnotationData
.maContentStyles
.push_back( ScXMLAnnotationStyleEntry( nFamily
, rName
, rSelection
) );
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */