| 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 "IgnoreTContext.hxx" |
| 21 |
#include "TransformerBase.hxx" |
| 22 |
#include "MutableAttrList.hxx" |
| 23 |
#include <xmloff/namespacemap.hxx> |
| 24 |
#include "PersAttrListTContext.hxx" |
| 25 |
|
| 26 |
|
| 27 |
using namespace ::com::sun::star::uno; |
| 28 |
using namespace ::com::sun::star::xml::sax; |
| 29 |
|
| 30 |
void XMLPersAttrListTContext::AddAttribute( |
| 31 |
sal_uInt16 nAPrefix, |
| 32 |
::xmloff::token::XMLTokenEnum eAToken, |
| 33 |
::xmloff::token::XMLTokenEnum eVToken ) |
| 34 |
{ |
| 35 |
const OUString& aAttrValue( ::xmloff::token::GetXMLToken( eVToken ) ); |
| 36 |
AddAttribute( nAPrefix, eAToken, aAttrValue ); |
| 37 |
} |
| 38 |
|
| 39 |
void XMLPersAttrListTContext::AddAttribute( |
| 40 |
sal_uInt16 nAPrefix, |
| 41 |
::xmloff::token::XMLTokenEnum eAToken, |
| 42 |
const OUString & rValue ) |
| 43 |
{ |
| 44 |
OUString aAttrQName( GetTransformer().GetNamespaceMap().GetQNameByKey( |
| 45 |
nAPrefix, ::xmloff::token::GetXMLToken( eAToken ) ) ); |
| 46 |
const OUString& aAttrValue( rValue ); |
| 47 |
|
| 48 |
rtl::Reference<XMLMutableAttributeList> pMutableAttrList; |
| 49 |
if( m_xAttrList.is() ) |
| 50 |
{ |
| 51 |
pMutableAttrList = |
| 52 |
static_cast< XMLMutableAttributeList * >( m_xAttrList.get() ); |
| 53 |
} |
| 54 |
else |
| 55 |
{ |
| 56 |
pMutableAttrList = new XMLMutableAttributeList ; |
| 57 |
m_xAttrList = pMutableAttrList; |
| 58 |
} |
| 59 |
|
| 60 |
pMutableAttrList->AddAttribute( aAttrQName, aAttrValue ); |
| 61 |
} |
| 62 |
|
| 63 |
XMLPersAttrListTContext::XMLPersAttrListTContext( |
| 64 |
XMLTransformerBase& rImp, |
| 65 |
const OUString& rQName ) : |
| 66 |
XMLTransformerContext( rImp, rQName ), |
| 67 |
m_aElemQName( rQName ), |
| 68 |
m_nActionMap( INVALID_ACTIONS ) |
| 69 |
{ |
| 70 |
} |
| 71 |
|
| 72 |
XMLPersAttrListTContext::XMLPersAttrListTContext( |
| 73 |
XMLTransformerBase& rImp, |
| 74 |
const OUString& rQName, |
| 75 |
sal_uInt16 nActionMap ) : |
| 76 |
XMLTransformerContext( rImp, rQName ), |
| 77 |
m_aElemQName( rQName ), |
| 78 |
m_nActionMap( nActionMap ) |
| 79 |
{ |
| 80 |
} |
| 81 |
|
| 82 |
XMLPersAttrListTContext::XMLPersAttrListTContext( |
| 83 |
XMLTransformerBase& rImp, |
| 84 |
const OUString& rQName, |
| 85 |
sal_uInt16 nPrefix, |
| 86 |
::xmloff::token::XMLTokenEnum eToken ) : |
| 87 |
XMLTransformerContext( rImp, rQName ), |
| 88 |
m_aElemQName( rImp.GetNamespaceMap().GetQNameByKey( nPrefix, |
| 89 |
::xmloff::token::GetXMLToken( eToken ) ) ), |
| 90 |
m_nActionMap( INVALID_ACTIONS ) |
| 91 |
{ |
| 92 |
} |
| 93 |
|
| 94 |
XMLPersAttrListTContext::XMLPersAttrListTContext( |
| 95 |
XMLTransformerBase& rImp, |
| 96 |
const OUString& rQName, |
| 97 |
sal_uInt16 nPrefix, |
| 98 |
::xmloff::token::XMLTokenEnum eToken, |
| 99 |
sal_uInt16 nActionMap ) : |
| 100 |
XMLTransformerContext( rImp, rQName ), |
| 101 |
m_aElemQName( rImp.GetNamespaceMap().GetQNameByKey( nPrefix, |
| 102 |
::xmloff::token::GetXMLToken( eToken ) ) ), |
| 103 |
m_nActionMap( nActionMap ) |
| 104 |
{ |
| 105 |
} |
| 106 |
|
| 107 |
rtl::Reference<XMLTransformerContext> XMLPersAttrListTContext::CreateChildContext( |
| 108 |
sal_uInt16 /*nPrefix*/, |
| 109 |
const OUString& /*rLocalName*/, |
| 110 |
const OUString& rQName, |
| 111 |
const Reference< XAttributeList >& ) |
| 112 |
{ |
| 113 |
// ignore all child elements |
| 114 |
return new XMLIgnoreTransformerContext( GetTransformer(), |
| 115 |
rQName, true, true ); |
| 116 |
} |
| 117 |
|
| 118 |
void XMLPersAttrListTContext::StartElement( |
| 119 |
const Reference< XAttributeList >& rAttrList ) |
| 120 |
{ |
| 121 |
XMLMutableAttributeList *pMutableAttrList = nullptr; |
| 122 |
|
| 123 |
Reference< XAttributeList > xAttrList( rAttrList ); |
| 124 |
if( m_nActionMap != INVALID_ACTIONS ) |
| 125 |
{ |
| 126 |
pMutableAttrList = |
| 127 |
GetTransformer().ProcessAttrList( xAttrList, m_nActionMap, |
| 128 |
true ); |
| 129 |
} |
| 130 |
|
| 131 |
if( m_xAttrList.is() ) |
| 132 |
{ |
| 133 |
static_cast< XMLMutableAttributeList * >( m_xAttrList.get() ) |
| 134 |
->AppendAttributeList( xAttrList ); |
| 135 |
} |
| 136 |
else if( pMutableAttrList ) |
| 137 |
{ |
| 138 |
m_xAttrList = std::move(xAttrList); |
| 139 |
} |
| 140 |
else |
| 141 |
{ |
| 142 |
m_xAttrList = new XMLMutableAttributeList( rAttrList, true ); |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
void XMLPersAttrListTContext::EndElement() |
| 147 |
{ |
| 148 |
// ignore for now |
| 149 |
} |
| 150 |
|
| 151 |
void XMLPersAttrListTContext::Characters( const OUString& ) |
| 152 |
{ |
| 153 |
} |
| 154 |
|
| 155 |
bool XMLPersAttrListTContext::IsPersistent() const |
| 156 |
{ |
| 157 |
return true; |
| 158 |
} |
| 159 |
|
| 160 |
void XMLPersAttrListTContext::Export() |
| 161 |
{ |
| 162 |
GetTransformer().GetDocHandler()->startElement( m_aElemQName, m_xAttrList ); |
| 163 |
ExportContent(); |
| 164 |
GetTransformer().GetDocHandler()->endElement( m_aElemQName ); |
| 165 |
} |
| 166 |
|
| 167 |
void XMLPersAttrListTContext::ExportContent() |
| 168 |
{ |
| 169 |
// nothing to export |
| 170 |
} |
| 171 |
|
| 172 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |