bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / transform / FrameOOoTContext.cxx
blobdaca17493fca62ba0301b4606dc8290418d04e43
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "FrameOOoTContext.hxx"
21 #include "IgnoreTContext.hxx"
22 #include "MutableAttrList.hxx"
23 #include <xmloff/xmlnmspe.hxx>
24 #include <xmloff/nmspmap.hxx>
25 #include "ActionMapTypesOOo.hxx"
26 #include "AttrTransformerAction.hxx"
27 #include "ElemTransformerAction.hxx"
28 #include "TransformerActions.hxx"
29 #include "TransformerBase.hxx"
30 #include <osl/diagnose.h>
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::xml::sax;
34 using namespace ::xmloff::token;
36 TYPEINIT1( XMLFrameOOoTransformerContext, XMLPersElemContentTContext );
38 XMLFrameOOoTransformerContext::XMLFrameOOoTransformerContext(
39 XMLTransformerBase& rImp,
40 const OUString& rQName ) :
41 XMLPersElemContentTContext( rImp, rQName ),
42 m_aElemQName( rImp.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_DRAW,
43 ::xmloff::token::GetXMLToken( XML_FRAME ) ) )
47 XMLFrameOOoTransformerContext::~XMLFrameOOoTransformerContext()
51 void XMLFrameOOoTransformerContext::StartElement(
52 const Reference< XAttributeList >& rAttrList )
55 XMLTransformerActions *pActions =
56 GetTransformer().GetUserDefinedActions( OOO_FRAME_ATTR_ACTIONS );
57 OSL_ENSURE( pActions, "go no actions" );
59 Reference< XAttributeList > xAttrList( rAttrList );
60 XMLMutableAttributeList *pMutableAttrList =
61 GetTransformer().ProcessAttrList( xAttrList, OOO_SHAPE_ACTIONS,
62 true );
63 if( !pMutableAttrList )
64 pMutableAttrList = new XMLMutableAttributeList( rAttrList );
65 xAttrList = pMutableAttrList;
67 XMLMutableAttributeList *pFrameMutableAttrList =
68 new XMLMutableAttributeList;
69 Reference< XAttributeList > xFrameAttrList( pFrameMutableAttrList );
71 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
72 for( sal_Int16 i=0; i < nAttrCount; i++ )
74 const OUString& rAttrName = xAttrList->getNameByIndex( i );
75 OUString aLocalName;
76 sal_uInt16 nPrefix =
77 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
78 &aLocalName );
79 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
80 XMLTransformerActions::const_iterator aIter =
81 pActions->find( aKey );
82 if( !(aIter == pActions->end() ) )
84 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
85 switch( (*aIter).second.m_nActionType )
87 case XML_ATACTION_MOVE_TO_ELEM:
88 pFrameMutableAttrList->AddAttribute( rAttrName, rAttrValue );
89 pMutableAttrList->RemoveAttributeByIndex( i );
90 --i;
91 --nAttrCount;
92 break;
93 default:
94 OSL_ENSURE( false, "unknown action" );
95 break;
100 GetTransformer().GetDocHandler()->startElement( m_aElemQName,
101 xFrameAttrList );
102 XMLTransformerContext::StartElement( xAttrList );
105 XMLTransformerContext *XMLFrameOOoTransformerContext::CreateChildContext(
106 sal_uInt16 nPrefix,
107 const OUString& rLocalName,
108 const OUString& rQName,
109 const Reference< XAttributeList >& rAttrList )
111 XMLTransformerContext *pContext = 0;
113 XMLTransformerActions *pActions =
114 GetTransformer().GetUserDefinedActions( OOO_FRAME_ELEM_ACTIONS );
115 OSL_ENSURE( pActions, "go no actions" );
116 XMLTransformerActions::key_type aKey( nPrefix, rLocalName );
117 XMLTransformerActions::const_iterator aIter = pActions->find( aKey );
119 if( !(aIter == pActions->end()) )
121 switch( (*aIter).second.m_nActionType )
123 case XML_ETACTION_COPY:
124 case XML_ETACTION_COPY_TEXT:
125 case XML_ETACTION_RENAME_ELEM:
126 // the ones in the list have to be persistent
128 pContext = XMLPersElemContentTContext::CreateChildContext(
129 nPrefix, rLocalName, rQName, rAttrList );
130 break;
131 default:
132 OSL_ENSURE( false, "unknown action" );
133 break;
137 // default is copying
138 if( !pContext )
139 pContext = XMLTransformerContext::CreateChildContext(
140 nPrefix, rLocalName, rQName, rAttrList );
142 return pContext;
145 void XMLFrameOOoTransformerContext::EndElement()
147 XMLTransformerContext::EndElement();
148 ExportContent();
149 GetTransformer().GetDocHandler()->endElement( m_aElemQName );
152 void XMLFrameOOoTransformerContext::Characters( const OUString& rChars )
154 XMLTransformerContext::Characters( rChars );
157 bool XMLFrameOOoTransformerContext::IsPersistent() const
159 // this context stores some of its child elements, but is not persistent
160 // itself.
161 return false;
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */