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 "CreateElemTContext.hxx"
21 : #include "MutableAttrList.hxx"
22 : #include "TransformerBase.hxx"
23 : #include "TransformerActions.hxx"
24 : #include "TContextVector.hxx"
25 : #include "FlatTContext.hxx"
26 : #include "AttrTransformerAction.hxx"
27 : #include <xmloff/nmspmap.hxx>
28 :
29 : using namespace ::com::sun::star::uno;
30 : using namespace ::com::sun::star::xml::sax;
31 : using namespace ::xmloff::token;
32 :
33 0 : TYPEINIT1( XMLCreateElemTransformerContext, XMLTransformerContext );
34 :
35 0 : XMLCreateElemTransformerContext::XMLCreateElemTransformerContext(
36 : XMLTransformerBase& rImp,
37 : const OUString& rQName,
38 : sal_uInt16 nActionMap ) :
39 : XMLTransformerContext( rImp, rQName ),
40 0 : m_nActionMap( nActionMap )
41 : {
42 0 : }
43 :
44 0 : XMLCreateElemTransformerContext::~XMLCreateElemTransformerContext()
45 : {
46 0 : }
47 :
48 0 : void XMLCreateElemTransformerContext::StartElement(
49 : const Reference< XAttributeList >& rAttrList )
50 : {
51 0 : Reference< XAttributeList > xAttrList( rAttrList );
52 :
53 0 : XMLTransformerContextVector aChildContexts;
54 :
55 0 : XMLMutableAttributeList *pMutableAttrList = 0;
56 : XMLTransformerActions *pActions =
57 0 : GetTransformer().GetUserDefinedActions( m_nActionMap );
58 : OSL_ENSURE( pActions, "go no actions" );
59 0 : if( pActions )
60 : {
61 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
62 0 : for( sal_Int16 i=0; i < nAttrCount; ++i )
63 : {
64 0 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
65 0 : const OUString& rAttrValue = xAttrList->getValueByIndex( i );
66 0 : OUString aLocalName;
67 : sal_uInt16 nPrefix =
68 0 : GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
69 0 : &aLocalName );
70 :
71 0 : XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
72 : XMLTransformerActions::const_iterator aIter =
73 0 : pActions->find( aKey );
74 0 : if( !(aIter == pActions->end() ) )
75 : {
76 0 : if( !pMutableAttrList )
77 : {
78 0 : pMutableAttrList = new XMLMutableAttributeList( xAttrList );
79 0 : xAttrList = pMutableAttrList;
80 : }
81 0 : sal_uInt32 nAction = (*aIter).second.m_nActionType;
82 0 : switch( nAction )
83 : {
84 : case XML_ATACTION_MOVE_TO_ELEM:
85 : {
86 : OUString aElemQName(
87 0 : GetTransformer().GetNamespaceMap().GetQNameByKey(
88 0 : (*aIter).second.GetQNamePrefixFromParam1(),
89 : ::xmloff::token::GetXMLToken(
90 0 : (*aIter).second.GetQNameTokenFromParam1()) ) );
91 : XMLTransformerContext *pContext =
92 0 : new XMLPersTextContentTContext( GetTransformer(),
93 0 : aElemQName );
94 0 : pContext->Characters( rAttrValue );
95 : XMLTransformerContextVector::value_type aVal(
96 0 : pContext );
97 0 : aChildContexts.push_back( aVal );
98 0 : pMutableAttrList->RemoveAttributeByIndex( i );
99 0 : --i;
100 0 : --nAttrCount;
101 : }
102 0 : break;
103 : default:
104 : OSL_ENSURE( !this, "unknown action" );
105 0 : break;
106 : }
107 : }
108 0 : }
109 : }
110 0 : XMLTransformerContext::StartElement( xAttrList );
111 :
112 0 : XMLTransformerContextVector::iterator aIter = aChildContexts.begin();
113 :
114 0 : for( ; aIter != aChildContexts.end(); ++aIter )
115 : {
116 0 : (*aIter)->Export();
117 0 : }
118 0 : }
119 :
120 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|