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