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