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