Debian Codegraph @

xmloff/source/transform/FrameOOoTContext.cxx

raw
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 "FrameOOoTContext.hxx"
21 #include "MutableAttrList.hxx"
22 #include <xmloff/xmlnamespace.hxx>
23 #include <xmloff/namespacemap.hxx>
24 #include "ActionMapTypesOOo.hxx"
25 #include "AttrTransformerAction.hxx"
26 #include "ElemTransformerAction.hxx"
27 #include "TransformerActions.hxx"
28 #include "TransformerBase.hxx"
29 #include <osl/diagnose.h>
30
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::xml::sax;
33 using namespace ::xmloff::token;
34
35 XMLFrameOOoTransformerContext::XMLFrameOOoTransformerContext(
36 XMLTransformerBase& rImp,
37 const OUString& rQName ) :
38 XMLPersElemContentTContext( rImp, rQName ),
39 m_aElemQName( rImp.GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_DRAW,
40 ::xmloff::token::GetXMLToken( XML_FRAME ) ) )
41 {
42 }
43
44 void XMLFrameOOoTransformerContext::StartElement(
45 const Reference< XAttributeList >& rAttrList )
46 {
47
48 XMLTransformerActions *pActions =
49 GetTransformer().GetUserDefinedActions( OOO_FRAME_ATTR_ACTIONS );
50 OSL_ENSURE( pActions, "go no actions" );
51
52 Reference< XAttributeList > xAttrList( rAttrList );
53 rtl::Reference<XMLMutableAttributeList> pMutableAttrList =
54 GetTransformer().ProcessAttrList( xAttrList, OOO_SHAPE_ACTIONS,
55 true );
56 if( !pMutableAttrList )
57 pMutableAttrList = new XMLMutableAttributeList( rAttrList );
58 xAttrList = pMutableAttrList;
59
60 rtl::Reference<XMLMutableAttributeList> pFrameMutableAttrList =
61 new XMLMutableAttributeList;
62
63 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
64 for( sal_Int16 i=0; i < nAttrCount; i++ )
65 {
66 const OUString aAttrName = xAttrList->getNameByIndex( i );
67 OUString aLocalName;
68 sal_uInt16 nPrefix =
69 GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName,
70 &aLocalName );
71 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
72 XMLTransformerActions::const_iterator aIter =
73 pActions->find( aKey );
74 if( aIter != pActions->end() )
75 {
76 const OUString aAttrValue = xAttrList->getValueByIndex( i );
77 switch( (*aIter).second.m_nActionType )
78 {
79 case XML_ATACTION_MOVE_TO_ELEM:
80 pFrameMutableAttrList->AddAttribute( aAttrName, aAttrValue );
81 pMutableAttrList->RemoveAttributeByIndex( i );
82 --i;
83 --nAttrCount;
84 break;
85 default:
86 OSL_ENSURE( false, "unknown action" );
87 break;
88 }
89 }
90 }
91
92 GetTransformer().GetDocHandler()->startElement( m_aElemQName,
93 Reference< XAttributeList >( pFrameMutableAttrList ) );
94 XMLTransformerContext::StartElement( xAttrList );
95 }
96
97 rtl::Reference<XMLTransformerContext> XMLFrameOOoTransformerContext::CreateChildContext(
98 sal_uInt16 nPrefix,
99 const OUString& rLocalName,
100 const OUString& rQName,
101 const Reference< XAttributeList >& rAttrList )
102 {
103 rtl::Reference<XMLTransformerContext> pContext;
104
105 XMLTransformerActions *pActions =
106 GetTransformer().GetUserDefinedActions( OOO_FRAME_ELEM_ACTIONS );
107 OSL_ENSURE( pActions, "go no actions" );
108 XMLTransformerActions::key_type aKey( nPrefix, rLocalName );
109 XMLTransformerActions::const_iterator aIter = pActions->find( aKey );
110
111 if( aIter != pActions->end() )
112 {
113 switch( (*aIter).second.m_nActionType )
114 {
115 case XML_ETACTION_COPY:
116 case XML_ETACTION_COPY_TEXT:
117 case XML_ETACTION_RENAME_ELEM:
118 // the ones in the list have to be persistent
119
120 pContext = XMLPersElemContentTContext::CreateChildContext(
121 nPrefix, rLocalName, rQName, rAttrList );
122 break;
123 default:
124 OSL_ENSURE( false, "unknown action" );
125 break;
126 }
127 }
128
129 // default is copying
130 if( !pContext.is() )
131 pContext = XMLTransformerContext::CreateChildContext(
132 nPrefix, rLocalName, rQName, rAttrList );
133
134 return pContext;
135 }
136
137 void XMLFrameOOoTransformerContext::EndElement()
138 {
139 XMLTransformerContext::EndElement();
140 ExportContent();
141 GetTransformer().GetDocHandler()->endElement( m_aElemQName );
142 }
143
144 void XMLFrameOOoTransformerContext::Characters( const OUString& rChars )
145 {
146 XMLTransformerContext::Characters( rChars );
147 }
148
149 bool XMLFrameOOoTransformerContext::IsPersistent() const
150 {
151 // this context stores some of its child elements, but is not persistent
152 // itself.
153 return false;
154 }
155
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */