Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / xmloff / source / transform / FrameOOoTContext.cxx
blob74385d604e0324595c7368c69ce0bf52cb21f581
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 XMLFrameOOoTransformerContext::XMLFrameOOoTransformerContext(
37 XMLTransformerBase& rImp,
38 const OUString& rQName ) :
39 XMLPersElemContentTContext( rImp, rQName ),
40 m_aElemQName( rImp.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_DRAW,
41 ::xmloff::token::GetXMLToken( XML_FRAME ) ) )
45 XMLFrameOOoTransformerContext::~XMLFrameOOoTransformerContext()
49 void XMLFrameOOoTransformerContext::StartElement(
50 const Reference< XAttributeList >& rAttrList )
53 XMLTransformerActions *pActions =
54 GetTransformer().GetUserDefinedActions( OOO_FRAME_ATTR_ACTIONS );
55 OSL_ENSURE( pActions, "go no actions" );
57 Reference< XAttributeList > xAttrList( rAttrList );
58 XMLMutableAttributeList *pMutableAttrList =
59 GetTransformer().ProcessAttrList( xAttrList, OOO_SHAPE_ACTIONS,
60 true );
61 if( !pMutableAttrList )
62 pMutableAttrList = new XMLMutableAttributeList( rAttrList );
63 xAttrList = pMutableAttrList;
65 XMLMutableAttributeList *pFrameMutableAttrList =
66 new XMLMutableAttributeList;
67 Reference< XAttributeList > xFrameAttrList( pFrameMutableAttrList );
69 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
70 for( sal_Int16 i=0; i < nAttrCount; i++ )
72 const OUString& rAttrName = xAttrList->getNameByIndex( i );
73 OUString aLocalName;
74 sal_uInt16 nPrefix =
75 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
76 &aLocalName );
77 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
78 XMLTransformerActions::const_iterator aIter =
79 pActions->find( aKey );
80 if( !(aIter == pActions->end() ) )
82 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
83 switch( (*aIter).second.m_nActionType )
85 case XML_ATACTION_MOVE_TO_ELEM:
86 pFrameMutableAttrList->AddAttribute( rAttrName, rAttrValue );
87 pMutableAttrList->RemoveAttributeByIndex( i );
88 --i;
89 --nAttrCount;
90 break;
91 default:
92 OSL_ENSURE( false, "unknown action" );
93 break;
98 GetTransformer().GetDocHandler()->startElement( m_aElemQName,
99 xFrameAttrList );
100 XMLTransformerContext::StartElement( xAttrList );
103 rtl::Reference<XMLTransformerContext> XMLFrameOOoTransformerContext::CreateChildContext(
104 sal_uInt16 nPrefix,
105 const OUString& rLocalName,
106 const OUString& rQName,
107 const Reference< XAttributeList >& rAttrList )
109 rtl::Reference<XMLTransformerContext> pContext;
111 XMLTransformerActions *pActions =
112 GetTransformer().GetUserDefinedActions( OOO_FRAME_ELEM_ACTIONS );
113 OSL_ENSURE( pActions, "go no actions" );
114 XMLTransformerActions::key_type aKey( nPrefix, rLocalName );
115 XMLTransformerActions::const_iterator aIter = pActions->find( aKey );
117 if( !(aIter == pActions->end()) )
119 switch( (*aIter).second.m_nActionType )
121 case XML_ETACTION_COPY:
122 case XML_ETACTION_COPY_TEXT:
123 case XML_ETACTION_RENAME_ELEM:
124 // the ones in the list have to be persistent
126 pContext = XMLPersElemContentTContext::CreateChildContext(
127 nPrefix, rLocalName, rQName, rAttrList );
128 break;
129 default:
130 OSL_ENSURE( false, "unknown action" );
131 break;
135 // default is copying
136 if( !pContext.is() )
137 pContext = XMLTransformerContext::CreateChildContext(
138 nPrefix, rLocalName, rQName, rAttrList );
140 return pContext;
143 void XMLFrameOOoTransformerContext::EndElement()
145 XMLTransformerContext::EndElement();
146 ExportContent();
147 GetTransformer().GetDocHandler()->endElement( m_aElemQName );
150 void XMLFrameOOoTransformerContext::Characters( const OUString& rChars )
152 XMLTransformerContext::Characters( rChars );
155 bool XMLFrameOOoTransformerContext::IsPersistent() const
157 // this context stores some of its child elements, but is not persistent
158 // itself.
159 return false;
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */