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