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