| 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 "DeepTContext.hxx" |
| 21 |
#include "TransformerActions.hxx" |
| 22 |
#include "ElemTransformerAction.hxx" |
| 23 |
#include "PersMixedContentTContext.hxx" |
| 24 |
#include "TransformerBase.hxx" |
| 25 |
#include <osl/diagnose.h> |
| 26 |
|
| 27 |
using namespace ::com::sun::star::uno; |
| 28 |
using namespace ::com::sun::star::xml::sax; |
| 29 |
|
| 30 |
void XMLPersElemContentTContext::AddContent( rtl::Reference<XMLTransformerContext> const & pContext ) |
| 31 |
{ |
| 32 |
OSL_ENSURE( pContext.is() && pContext->IsPersistent(), |
| 33 |
"non-persistent context" ); |
| 34 |
m_aChildContexts.push_back(pContext); |
| 35 |
} |
| 36 |
|
| 37 |
XMLPersElemContentTContext::XMLPersElemContentTContext( |
| 38 |
XMLTransformerBase& rImp, |
| 39 |
const OUString& rQName ) : |
| 40 |
XMLPersAttrListTContext( rImp, rQName ) |
| 41 |
{ |
| 42 |
} |
| 43 |
|
| 44 |
XMLPersElemContentTContext::XMLPersElemContentTContext( |
| 45 |
XMLTransformerBase& rImp, |
| 46 |
const OUString& rQName, |
| 47 |
sal_uInt16 nActionMap ) : |
| 48 |
XMLPersAttrListTContext( rImp, rQName, nActionMap ) |
| 49 |
{ |
| 50 |
} |
| 51 |
|
| 52 |
XMLPersElemContentTContext::XMLPersElemContentTContext( |
| 53 |
XMLTransformerBase& rImp, |
| 54 |
const OUString& rQName, |
| 55 |
sal_uInt16 nPrefix, |
| 56 |
::xmloff::token::XMLTokenEnum eToken ) : |
| 57 |
XMLPersAttrListTContext( rImp, rQName, nPrefix, eToken ) |
| 58 |
{ |
| 59 |
} |
| 60 |
|
| 61 |
XMLPersElemContentTContext::XMLPersElemContentTContext( |
| 62 |
XMLTransformerBase& rImp, |
| 63 |
const OUString& rQName, |
| 64 |
sal_uInt16 nPrefix, |
| 65 |
::xmloff::token::XMLTokenEnum eToken, |
| 66 |
sal_uInt16 nActionMap ) : |
| 67 |
XMLPersAttrListTContext( rImp, rQName, nPrefix, eToken, nActionMap ) |
| 68 |
{ |
| 69 |
} |
| 70 |
|
| 71 |
XMLPersElemContentTContext::~XMLPersElemContentTContext() |
| 72 |
{ |
| 73 |
} |
| 74 |
|
| 75 |
rtl::Reference<XMLTransformerContext> XMLPersElemContentTContext::CreateChildContext( |
| 76 |
sal_uInt16 nPrefix, |
| 77 |
const OUString& rLocalName, |
| 78 |
const OUString& rQName, |
| 79 |
const Reference< XAttributeList >& ) |
| 80 |
{ |
| 81 |
rtl::Reference<XMLTransformerContext> pContext; |
| 82 |
|
| 83 |
XMLTransformerActions::key_type aKey( nPrefix, rLocalName ); |
| 84 |
XMLTransformerActions::const_iterator aIter = |
| 85 |
GetTransformer().GetElemActions().find( aKey ); |
| 86 |
|
| 87 |
if( aIter != GetTransformer().GetElemActions().end() ) |
| 88 |
{ |
| 89 |
switch( (*aIter).second.m_nActionType ) |
| 90 |
{ |
| 91 |
case XML_ETACTION_COPY: |
| 92 |
case XML_ETACTION_COPY_TEXT: |
| 93 |
pContext.set(new XMLPersMixedContentTContext( GetTransformer(), |
| 94 |
rQName )); |
| 95 |
break; |
| 96 |
case XML_ETACTION_RENAME_ELEM: |
| 97 |
pContext.set(new XMLPersMixedContentTContext( GetTransformer(), rQName, |
| 98 |
(*aIter).second.GetQNamePrefixFromParam1(), |
| 99 |
(*aIter).second.GetQNameTokenFromParam1() )); |
| 100 |
break; |
| 101 |
case XML_ETACTION_RENAME_ELEM_PROC_ATTRS: |
| 102 |
pContext.set(new XMLPersMixedContentTContext( GetTransformer(), rQName, |
| 103 |
(*aIter).second.GetQNamePrefixFromParam1(), |
| 104 |
(*aIter).second.GetQNameTokenFromParam1(), |
| 105 |
static_cast< sal_uInt16 >( (*aIter).second.m_nParam2 ) )); |
| 106 |
break; |
| 107 |
case XML_ETACTION_RENAME_ELEM_ADD_PROC_ATTR: |
| 108 |
{ |
| 109 |
rtl::Reference<XMLPersMixedContentTContext> pMC( |
| 110 |
new XMLPersMixedContentTContext( GetTransformer(), rQName, |
| 111 |
(*aIter).second.GetQNamePrefixFromParam1(), |
| 112 |
(*aIter).second.GetQNameTokenFromParam1(), |
| 113 |
static_cast< sal_uInt16 >( |
| 114 |
(*aIter).second.m_nParam3 >> 16 ) )); |
| 115 |
pMC->AddAttribute( |
| 116 |
(*aIter).second.GetQNamePrefixFromParam2(), |
| 117 |
(*aIter).second.GetQNameTokenFromParam2(), |
| 118 |
static_cast< ::xmloff::token::XMLTokenEnum >( |
| 119 |
(*aIter).second.m_nParam3 & 0xffff ) ); |
| 120 |
pContext = pMC; |
| 121 |
} |
| 122 |
break; |
| 123 |
case XML_ETACTION_PROC_ATTRS: |
| 124 |
pContext.set(new XMLPersMixedContentTContext( GetTransformer(), rQName, |
| 125 |
static_cast< sal_uInt16 >( (*aIter).second.m_nParam1 ) )); |
| 126 |
break; |
| 127 |
default: |
| 128 |
pContext = GetTransformer().CreateUserDefinedContext( |
| 129 |
(*aIter).second, rQName, true ); |
| 130 |
OSL_ENSURE( pContext.is() && pContext->IsPersistent(), |
| 131 |
"unknown or not persistent action" ); |
| 132 |
if( pContext.is() && !pContext->IsPersistent() ) |
| 133 |
{ |
| 134 |
pContext.clear(); |
| 135 |
} |
| 136 |
break; |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
// default is copying |
| 141 |
if( !pContext.is() ) |
| 142 |
pContext.set(new XMLPersMixedContentTContext( GetTransformer(), rQName )); |
| 143 |
m_aChildContexts.push_back(pContext); |
| 144 |
|
| 145 |
return pContext; |
| 146 |
} |
| 147 |
|
| 148 |
void XMLPersElemContentTContext::ExportContent() |
| 149 |
{ |
| 150 |
for (auto const & i: m_aChildContexts) |
| 151 |
{ |
| 152 |
i->Export(); |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |