| 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 <com/sun/star/xml/sax/XDocumentHandler.hpp> |
| 21 |
#include <osl/diagnose.h> |
| 22 |
#include <xmloff/namespacemap.hxx> |
| 23 |
#include <xmloff/xmltoken.hxx> |
| 24 |
#include <xmloff/xmlnamespace.hxx> |
| 25 |
|
| 26 |
#include "TransformerBase.hxx" |
| 27 |
#include "TransformerActions.hxx" |
| 28 |
#include "AttrTransformerAction.hxx" |
| 29 |
#include "ActionMapTypesOASIS.hxx" |
| 30 |
#include "MutableAttrList.hxx" |
| 31 |
#include "RenameElemTContext.hxx" |
| 32 |
#include "FlatTContext.hxx" |
| 33 |
|
| 34 |
#include "NotesTContext.hxx" |
| 35 |
|
| 36 |
using namespace ::xmloff::token; |
| 37 |
using namespace ::com::sun::star::uno; |
| 38 |
using namespace ::com::sun::star::xml::sax; |
| 39 |
|
| 40 |
XMLNotesTransformerContext::XMLNotesTransformerContext( |
| 41 |
XMLTransformerBase& rImp, |
| 42 |
const OUString& rQName, |
| 43 |
XMLTokenEnum eToken, bool bPersistent ) : |
| 44 |
XMLPersElemContentTContext( rImp, rQName ), |
| 45 |
m_bEndNote( false ), |
| 46 |
m_bPersistent( bPersistent ), |
| 47 |
m_eTypeToken( eToken ) |
| 48 |
{ |
| 49 |
} |
| 50 |
|
| 51 |
XMLNotesTransformerContext::~XMLNotesTransformerContext() |
| 52 |
{ |
| 53 |
} |
| 54 |
|
| 55 |
void XMLNotesTransformerContext::StartElement( |
| 56 |
const Reference< XAttributeList >& rAttrList ) |
| 57 |
{ |
| 58 |
XMLTransformerActions *pActions = |
| 59 |
GetTransformer().GetUserDefinedActions( OASIS_NOTES_ACTIONS ); |
| 60 |
OSL_ENSURE( pActions, "go no actions" ); |
| 61 |
|
| 62 |
Reference< XAttributeList > xAttrList( rAttrList ); |
| 63 |
rtl::Reference<XMLMutableAttributeList> pMutableAttrList; |
| 64 |
sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; |
| 65 |
for( sal_Int16 i=0; i < nAttrCount; i++ ) |
| 66 |
{ |
| 67 |
const OUString aAttrName = xAttrList->getNameByIndex( i ); |
| 68 |
OUString aLocalName; |
| 69 |
sal_uInt16 nPrefix = |
| 70 |
GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName, |
| 71 |
&aLocalName ); |
| 72 |
XMLTransformerActions::key_type aKey( nPrefix, aLocalName ); |
| 73 |
XMLTransformerActions::const_iterator aIter = |
| 74 |
pActions->find( aKey ); |
| 75 |
if( aIter != pActions->end() ) |
| 76 |
{ |
| 77 |
const OUString aAttrValue = xAttrList->getValueByIndex( i ); |
| 78 |
|
| 79 |
if( !pMutableAttrList ) |
| 80 |
{ |
| 81 |
pMutableAttrList = |
| 82 |
new XMLMutableAttributeList( xAttrList ); |
| 83 |
xAttrList = pMutableAttrList; |
| 84 |
} |
| 85 |
switch( (*aIter).second.m_nActionType ) |
| 86 |
{ |
| 87 |
case XML_ATACTION_STYLE_FAMILY: |
| 88 |
{ |
| 89 |
if( IsXMLToken( aAttrValue, XML_FOOTNOTE ) ) |
| 90 |
{ |
| 91 |
} |
| 92 |
else if( IsXMLToken( aAttrValue, XML_ENDNOTE ) ) |
| 93 |
{ |
| 94 |
m_bEndNote = true; |
| 95 |
} |
| 96 |
pMutableAttrList->RemoveAttributeByIndex( i ); |
| 97 |
--i; |
| 98 |
--nAttrCount; |
| 99 |
} |
| 100 |
break; |
| 101 |
case XML_ATACTION_DECODE_STYLE_NAME: |
| 102 |
case XML_ATACTION_DECODE_STYLE_NAME_REF: |
| 103 |
{ |
| 104 |
OUString aAttrValue2( aAttrValue ); |
| 105 |
if( XMLTransformerBase::DecodeStyleName(aAttrValue2) ) |
| 106 |
pMutableAttrList->SetValueByIndex( i, aAttrValue2 ); |
| 107 |
} |
| 108 |
break; |
| 109 |
} |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
XMLTokenEnum eToken = XML_FOOTNOTE; |
| 114 |
switch( m_eTypeToken ) |
| 115 |
{ |
| 116 |
case XML_NOTE: |
| 117 |
eToken = (m_bEndNote ? XML_ENDNOTE : XML_FOOTNOTE); |
| 118 |
break; |
| 119 |
case XML_NOTES_CONFIGURATION: |
| 120 |
eToken = (m_bEndNote ? XML_ENDNOTES_CONFIGURATION |
| 121 |
: XML_FOOTNOTES_CONFIGURATION); |
| 122 |
break; |
| 123 |
case XML_NOTE_REF: |
| 124 |
eToken = (m_bEndNote ? XML_ENDNOTE_REF : XML_FOOTNOTE_REF); |
| 125 |
break; |
| 126 |
default: |
| 127 |
OSL_ENSURE( XML_NOTE==m_eTypeToken, "invalid note type" ); |
| 128 |
break; |
| 129 |
} |
| 130 |
|
| 131 |
SetExportQName( GetTransformer().GetNamespaceMap().GetQNameByKey( |
| 132 |
XML_NAMESPACE_TEXT, |
| 133 |
::xmloff::token::GetXMLToken( eToken ) ) ); |
| 134 |
if( m_bPersistent ) |
| 135 |
XMLPersElemContentTContext::StartElement( xAttrList ); |
| 136 |
else |
| 137 |
GetTransformer().GetDocHandler()->startElement( GetExportQName(), |
| 138 |
xAttrList ); |
| 139 |
} |
| 140 |
|
| 141 |
void XMLNotesTransformerContext::EndElement() |
| 142 |
{ |
| 143 |
if( m_bPersistent ) |
| 144 |
{ |
| 145 |
XMLPersElemContentTContext::EndElement(); |
| 146 |
} |
| 147 |
else |
| 148 |
{ |
| 149 |
GetTransformer().GetDocHandler()->endElement( GetExportQName() ); |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
rtl::Reference<XMLTransformerContext> XMLNotesTransformerContext::CreateChildContext( |
| 154 |
sal_uInt16 nPrefix, |
| 155 |
const OUString& rLocalName, |
| 156 |
const OUString& rQName, |
| 157 |
const Reference< XAttributeList >& rAttrList ) |
| 158 |
{ |
| 159 |
rtl::Reference<XMLTransformerContext> pContext; |
| 160 |
if( XML_NOTE == m_eTypeToken ) |
| 161 |
{ |
| 162 |
if( XML_NAMESPACE_TEXT == nPrefix ) |
| 163 |
{ |
| 164 |
XMLTokenEnum eToken ( XML_TOKEN_INVALID ); |
| 165 |
if( IsXMLToken( rLocalName, XML_NOTE_CITATION ) ) |
| 166 |
{ |
| 167 |
eToken = m_bEndNote ? XML_ENDNOTE_CITATION |
| 168 |
: XML_FOOTNOTE_CITATION; |
| 169 |
} |
| 170 |
else if( IsXMLToken( rLocalName, XML_NOTE_BODY ) ) |
| 171 |
{ |
| 172 |
eToken = m_bEndNote ? XML_ENDNOTE_BODY |
| 173 |
: XML_FOOTNOTE_BODY; |
| 174 |
} |
| 175 |
|
| 176 |
if( XML_TOKEN_INVALID != eToken ) |
| 177 |
{ |
| 178 |
if( m_bPersistent ) |
| 179 |
{ |
| 180 |
pContext.set(new XMLPersTextContentTContext( |
| 181 |
GetTransformer(), rQName, |
| 182 |
XML_NAMESPACE_TEXT, |
| 183 |
eToken )); |
| 184 |
AddContent( pContext ); |
| 185 |
|
| 186 |
} |
| 187 |
else |
| 188 |
{ |
| 189 |
pContext.set(new XMLRenameElemTransformerContext( |
| 190 |
GetTransformer(), rQName, |
| 191 |
XML_NAMESPACE_TEXT, |
| 192 |
eToken )); |
| 193 |
} |
| 194 |
} |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
if( !pContext.is() ) |
| 199 |
{ |
| 200 |
pContext = m_bPersistent |
| 201 |
? XMLPersElemContentTContext::CreateChildContext( |
| 202 |
nPrefix, rLocalName, rQName, rAttrList ) |
| 203 |
: XMLTransformerContext::CreateChildContext( |
| 204 |
nPrefix, rLocalName, rQName, rAttrList ); |
| 205 |
} |
| 206 |
|
| 207 |
return pContext; |
| 208 |
} |
| 209 |
|
| 210 |
bool XMLNotesTransformerContext::IsPersistent() const |
| 211 |
{ |
| 212 |
return m_bPersistent; |
| 213 |
} |
| 214 |
|
| 215 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |