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