LibreOffice Module sc (master)  1
xmlannoi.cxx
Go to the documentation of this file.
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 #include "xmlannoi.hxx"
21 #include "xmlimprt.hxx"
22 #include "xmlconti.hxx"
24 
25 #include <xmloff/xmltkmap.hxx>
26 #include <xmloff/nmspmap.hxx>
27 #include <xmloff/xmlnmspe.hxx>
28 #include <xmloff/xmltoken.hxx>
29 
30 using namespace com::sun::star;
31 using namespace xmloff::token;
32 
34  mbUseShapePos( false ),
35  mbShown( false )
36 {
37 }
38 
40 {
41 }
42 
44  sal_uInt16 nPrfx,
45  const OUString& rLName,
46  const uno::Reference<xml::sax::XAttributeList>& xAttrList,
47  ScXMLAnnotationData& rAnnotationData) :
48  ScXMLImportContext( rImport, nPrfx, rLName ),
49  mrAnnotationData( rAnnotationData )
50 {
51  uno::Reference<drawing::XShapes> xLocalShapes (GetScImport().GetTables().GetCurrentXShapes());
52  if (xLocalShapes.is())
53  {
54  XMLTableShapeImportHelper* pTableShapeImport = static_cast<XMLTableShapeImportHelper*>(GetScImport().GetShapeImport().get());
55  pTableShapeImport->SetAnnotation(this);
56  pShapeContext.reset( GetScImport().GetShapeImport()->CreateGroupChildContext(
57  GetScImport(), nPrfx, rLName, xAttrList, xLocalShapes, true) );
58  }
59 
60  sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
61  const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetTableAnnotationAttrTokenMap();
62  for( sal_Int16 i=0; i < nAttrCount; ++i )
63  {
64  const OUString& sAttrName(xAttrList->getNameByIndex( i ));
65  OUString aLocalName;
66  sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
67  sAttrName, &aLocalName );
68  const OUString& sValue(xAttrList->getValueByIndex( i ));
69 
70  switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
71  {
73  {
74  maAuthorBuffer = sValue;
75  }
76  break;
78  {
79  maCreateDateBuffer = sValue;
80  }
81  break;
83  {
84  maCreateDateStringBuffer = sValue;
85  }
86  break;
88  {
90  }
91  break;
93  {
95  }
96  break;
98  {
100  }
101  break;
102  }
103  }
104 }
105 
107 {
108 }
109 
110 void ScXMLAnnotationContext::StartElement(const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList)
111 {
112  if (pShapeContext)
113  pShapeContext->StartElement(xAttrList);
114 }
115 
117  const OUString& rLName,
118  const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList )
119 {
120  SvXMLImportContextRef xContext;
121 
122  if( XML_NAMESPACE_DC == nPrefix )
123  {
124  if( IsXMLToken( rLName, XML_CREATOR ) )
125  xContext = new ScXMLContentContext(GetScImport(), nPrefix,
126  rLName, maAuthorBuffer);
127  else if( IsXMLToken( rLName, XML_DATE ) )
128  xContext = new ScXMLContentContext(GetScImport(), nPrefix,
129  rLName, maCreateDateBuffer);
130  }
131  else if( XML_NAMESPACE_META == nPrefix )
132  {
133  if( IsXMLToken( rLName, XML_DATE_STRING ) )
134  xContext = new ScXMLContentContext(GetScImport(), nPrefix,
135  rLName, maCreateDateStringBuffer);
136  }
137 
138  if( !xContext && pShapeContext )
139  xContext = pShapeContext->CreateChildContext(nPrefix, rLName, xAttrList);
140 
141  return xContext;
142 }
143 
144 void ScXMLAnnotationContext::Characters( const OUString& rChars )
145 {
146  maTextBuffer.append(rChars);
147 }
148 
150 {
151  if (pShapeContext)
152  {
153  pShapeContext->EndElement();
154  pShapeContext.reset();
155  }
156 
157  mrAnnotationData.maAuthor = maAuthorBuffer.makeStringAndClear();
158  mrAnnotationData.maCreateDate = maCreateDateBuffer.makeStringAndClear();
159  if (mrAnnotationData.maCreateDate.isEmpty())
161  mrAnnotationData.maSimpleText = maTextBuffer.makeStringAndClear();
162 
163  XMLTableShapeImportHelper* pTableShapeImport = static_cast<XMLTableShapeImportHelper*>(GetScImport().GetShapeImport().get());
164  pTableShapeImport->SetAnnotation(nullptr);
165 }
166 
167 void ScXMLAnnotationContext::SetShape( const uno::Reference< drawing::XShape >& rxShape, const uno::Reference< drawing::XShapes >& rxShapes,
168  const OUString& rStyleName, const OUString& rTextStyle )
169 {
170  mrAnnotationData.mxShape = rxShape;
171  mrAnnotationData.mxShapes = rxShapes;
172  mrAnnotationData.maStyleName = rStyleName;
173  mrAnnotationData.maTextStyle = rTextStyle;
174 }
175 
176 void ScXMLAnnotationContext::AddContentStyle( XmlStyleFamily nFamily, const OUString& rName, const ESelection& rSelection )
177 {
178  mrAnnotationData.maContentStyles.emplace_back( nFamily, rName, rSelection );
179 }
180 
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SvXMLTokenMap & GetTableAnnotationAttrTokenMap()
Definition: xmlimprt.cxx:486
bool IsXMLToken(const OUString &rString, enum XMLTokenEnum eToken)
OUString maStyleName
Definition: xmlannoi.hxx:57
OUString maCreateDate
Definition: xmlannoi.hxx:55
virtual void Characters(const OUString &rChars) override
Definition: xmlannoi.cxx:144
OUStringBuffer maCreateDateBuffer
Definition: xmlannoi.hxx:99
SvXMLNamespaceMap & GetNamespaceMap()
constexpr sal_uInt16 XML_NAMESPACE_DC
OUString maSimpleText
Definition: xmlannoi.hxx:56
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
XmlStyleFamily
OUStringBuffer maCreateDateStringBuffer
Definition: xmlannoi.hxx:100
XML_CREATOR
css::uno::Reference< css::drawing::XShapes > mxShapes
Definition: xmlannoi.hxx:53
ScXMLAnnotationData & mrAnnotationData
Definition: xmlannoi.hxx:96
virtual void EndElement() override
Definition: xmlannoi.cxx:149
This class exists only to provide GetScImport() to its derived classes.
void SetShape(const css::uno::Reference< css::drawing::XShape > &rxShape, const css::uno::Reference< css::drawing::XShapes > &rxShapes, const OUString &rStyleName, const OUString &rTextStyle)
Definition: xmlannoi.cxx:167
int i
XML_DATE
virtual ~ScXMLAnnotationContext() override
Definition: xmlannoi.cxx:106
css::uno::Reference< css::drawing::XShape > mxShape
Definition: xmlannoi.hxx:51
sal_uInt16 Get(sal_uInt16 nPrefix, const OUString &rLName) const
OUStringBuffer maAuthorBuffer
Definition: xmlannoi.hxx:98
ScXMLImport & GetScImport()
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
Definition: xmlannoi.cxx:116
ScXMLAnnotationContext(ScXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList, ScXMLAnnotationData &rAnnotationData)
Definition: xmlannoi.cxx:43
OUStringBuffer maTextBuffer
Definition: xmlannoi.hxx:97
std::vector< ScXMLAnnotationStyleEntry > maContentStyles
Definition: xmlannoi.hxx:61
XML_DATE_STRING
constexpr sal_uInt16 XML_NAMESPACE_META
XML_TRUE
std::unique_ptr< SvXMLImportContext > pShapeContext
Definition: xmlannoi.hxx:101
OUString maTextStyle
Definition: xmlannoi.hxx:58
void SetAnnotation(ScXMLAnnotationContext *pAnnotation)
rtl::Reference< XMLShapeImportHelper > const & GetShapeImport()
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
Definition: xmlannoi.cxx:110
void AddContentStyle(XmlStyleFamily nFamily, const OUString &rName, const ESelection &rSelection)
Definition: xmlannoi.cxx:176