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