Line data Source code
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"
23 : #include "XMLTableShapeImportHelper.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 :
33 : //------------------------------------------------------------------
34 :
35 2 : ScXMLAnnotationData::ScXMLAnnotationData() :
36 : mbUseShapePos( false ),
37 2 : mbShown( false )
38 : {
39 2 : }
40 :
41 2 : ScXMLAnnotationData::~ScXMLAnnotationData()
42 : {
43 2 : }
44 :
45 : //------------------------------------------------------------------
46 :
47 2 : ScXMLAnnotationContext::ScXMLAnnotationContext( ScXMLImport& rImport,
48 : sal_uInt16 nPrfx,
49 : const ::rtl::OUString& rLName,
50 : const uno::Reference<xml::sax::XAttributeList>& xAttrList,
51 : ScXMLAnnotationData& rAnnotationData,
52 : ScXMLTableRowCellContext* pTempCellContext) :
53 : SvXMLImportContext( rImport, nPrfx, rLName ),
54 : mrAnnotationData( rAnnotationData ),
55 : pCellContext(pTempCellContext),
56 2 : pShapeContext(NULL)
57 : {
58 2 : uno::Reference<drawing::XShapes> xLocalShapes (GetScImport().GetTables().GetCurrentXShapes());
59 2 : if (xLocalShapes.is())
60 : {
61 2 : XMLTableShapeImportHelper* pTableShapeImport = (XMLTableShapeImportHelper*)GetScImport().GetShapeImport().get();
62 2 : pTableShapeImport->SetAnnotation(this);
63 2 : pShapeContext = GetScImport().GetShapeImport()->CreateGroupChildContext(
64 4 : GetScImport(), nPrfx, rLName, xAttrList, xLocalShapes, true);
65 : }
66 :
67 2 : pCellContext = pTempCellContext;
68 2 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
69 2 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetTableAnnotationAttrTokenMap();
70 18 : for( sal_Int16 i=0; i < nAttrCount; ++i )
71 : {
72 16 : const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
73 16 : rtl::OUString aLocalName;
74 16 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
75 16 : sAttrName, &aLocalName );
76 16 : const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
77 :
78 16 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
79 : {
80 : case XML_TOK_TABLE_ANNOTATION_ATTR_AUTHOR:
81 : {
82 0 : maAuthorBuffer = sValue;
83 : }
84 0 : break;
85 : case XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE:
86 : {
87 0 : maCreateDateBuffer = sValue;
88 : }
89 0 : break;
90 : case XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE_STRING:
91 : {
92 0 : maCreateDateStringBuffer = sValue;
93 : }
94 0 : break;
95 : case XML_TOK_TABLE_ANNOTATION_ATTR_DISPLAY:
96 : {
97 0 : mrAnnotationData.mbShown = IsXMLToken(sValue, XML_TRUE);
98 : }
99 0 : break;
100 : case XML_TOK_TABLE_ANNOTATION_ATTR_X:
101 : {
102 2 : mrAnnotationData.mbUseShapePos = true;
103 : }
104 2 : break;
105 : case XML_TOK_TABLE_ANNOTATION_ATTR_Y:
106 : {
107 2 : mrAnnotationData.mbUseShapePos = true;
108 : }
109 2 : break;
110 : }
111 18 : }
112 2 : }
113 :
114 4 : ScXMLAnnotationContext::~ScXMLAnnotationContext()
115 : {
116 4 : }
117 :
118 2 : void ScXMLAnnotationContext::StartElement(const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList)
119 : {
120 2 : if (pShapeContext)
121 2 : pShapeContext->StartElement(xAttrList);
122 2 : }
123 :
124 4 : SvXMLImportContext *ScXMLAnnotationContext::CreateChildContext( sal_uInt16 nPrefix,
125 : const ::rtl::OUString& rLName,
126 : const ::com::sun::star::uno::Reference<
127 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
128 : {
129 4 : SvXMLImportContext *pContext = 0;
130 :
131 4 : if( XML_NAMESPACE_DC == nPrefix )
132 : {
133 2 : if( IsXMLToken( rLName, XML_CREATOR ) )
134 : pContext = new ScXMLContentContext(GetScImport(), nPrefix,
135 0 : rLName, xAttrList, maAuthorBuffer);
136 2 : else if( IsXMLToken( rLName, XML_DATE ) )
137 : pContext = new ScXMLContentContext(GetScImport(), nPrefix,
138 2 : rLName, xAttrList, maCreateDateBuffer);
139 : }
140 2 : else if( XML_NAMESPACE_META == nPrefix )
141 : {
142 0 : if( IsXMLToken( rLName, XML_DATE_STRING ) )
143 : pContext = new ScXMLContentContext(GetScImport(), nPrefix,
144 0 : rLName, xAttrList, maCreateDateStringBuffer);
145 : }
146 :
147 4 : if( !pContext && pShapeContext )
148 2 : pContext = pShapeContext->CreateChildContext(nPrefix, rLName, xAttrList);
149 :
150 4 : if( !pContext )
151 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
152 :
153 4 : return pContext;
154 : }
155 :
156 0 : void ScXMLAnnotationContext::Characters( const ::rtl::OUString& rChars )
157 : {
158 0 : maTextBuffer.append(rChars);
159 0 : }
160 :
161 2 : void ScXMLAnnotationContext::EndElement()
162 : {
163 2 : if (pShapeContext)
164 : {
165 2 : pShapeContext->EndElement();
166 2 : delete pShapeContext;
167 2 : pShapeContext = NULL;
168 : }
169 :
170 2 : mrAnnotationData.maAuthor = maAuthorBuffer.makeStringAndClear();
171 2 : mrAnnotationData.maCreateDate = maCreateDateBuffer.makeStringAndClear();
172 2 : if (mrAnnotationData.maCreateDate.isEmpty())
173 0 : mrAnnotationData.maCreateDate = maCreateDateStringBuffer.makeStringAndClear();
174 2 : mrAnnotationData.maSimpleText = maTextBuffer.makeStringAndClear();
175 :
176 2 : XMLTableShapeImportHelper* pTableShapeImport = (XMLTableShapeImportHelper*)GetScImport().GetShapeImport().get();
177 2 : pTableShapeImport->SetAnnotation(NULL);
178 2 : }
179 :
180 2 : void ScXMLAnnotationContext::SetShape( const uno::Reference< drawing::XShape >& rxShape, const uno::Reference< drawing::XShapes >& rxShapes,
181 : const rtl::OUString& rStyleName, const rtl::OUString& rTextStyle )
182 : {
183 2 : mrAnnotationData.mxShape = rxShape;
184 2 : mrAnnotationData.mxShapes = rxShapes;
185 2 : mrAnnotationData.maStyleName = rStyleName;
186 2 : mrAnnotationData.maTextStyle = rTextStyle;
187 2 : }
188 :
189 2 : void ScXMLAnnotationContext::AddContentStyle( sal_uInt16 nFamily, const rtl::OUString& rName, const ESelection& rSelection )
190 : {
191 2 : mrAnnotationData.maContentStyles.push_back( ScXMLAnnotationStyleEntry( nFamily, rName, rSelection ) );
192 2 : }
193 :
194 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|