1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_xmloff.hxx" 26 #include <com/sun/star/xml/sax/SAXParseException.hpp> 27 #include <com/sun/star/xml/sax/SAXException.hpp> 28 #include <com/sun/star/xml/sax/XDocumentHandler.hpp> 29 #include <com/sun/star/xml/sax/XAttributeList.hpp> 30 #include <xmloff/nmspmap.hxx> 31 #include <xmloff/xmltoken.hxx> 32 #include "xmloff/xmlnmspe.hxx" 33 34 #ifndef _XMLOFF_TRANSFOERMERBASE_HXX 35 #include "TransformerBase.hxx" 36 #endif 37 #include "TransformerActions.hxx" 38 #include "AttrTransformerAction.hxx" 39 #include "ActionMapTypesOASIS.hxx" 40 #include "MutableAttrList.hxx" 41 #include "RenameElemTContext.hxx" 42 #include "FlatTContext.hxx" 43 44 #ifndef _XMLOFF_NOTESCONTEXT_HXX 45 #include "NotesTContext.hxx" 46 #endif 47 48 using ::rtl::OUString; 49 using namespace ::xmloff::token; 50 using namespace ::com::sun::star::uno; 51 using namespace ::com::sun::star::xml::sax; 52 53 TYPEINIT1( XMLNotesTransformerContext, XMLPersElemContentTContext ); 54 55 XMLNotesTransformerContext::XMLNotesTransformerContext( 56 XMLTransformerBase& rImp, 57 const OUString& rQName, 58 XMLTokenEnum eToken, sal_Bool bPersistent ) : 59 XMLPersElemContentTContext( rImp, rQName ), 60 m_bEndNote( sal_False ), 61 m_bPersistent( bPersistent ), 62 m_eTypeToken( eToken ) 63 { 64 } 65 66 XMLNotesTransformerContext::~XMLNotesTransformerContext() 67 { 68 } 69 70 void XMLNotesTransformerContext::StartElement( 71 const Reference< XAttributeList >& rAttrList ) 72 { 73 XMLTransformerActions *pActions = 74 GetTransformer().GetUserDefinedActions( OASIS_NOTES_ACTIONS ); 75 OSL_ENSURE( pActions, "go no actions" ); 76 77 Reference< XAttributeList > xAttrList( rAttrList ); 78 XMLMutableAttributeList *pMutableAttrList = 0; 79 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 80 for( sal_Int16 i=0; i < nAttrCount; i++ ) 81 { 82 const OUString& rAttrName = xAttrList->getNameByIndex( i ); 83 OUString aLocalName; 84 sal_uInt16 nPrefix = 85 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName, 86 &aLocalName ); 87 XMLTransformerActions::key_type aKey( nPrefix, aLocalName ); 88 XMLTransformerActions::const_iterator aIter = 89 pActions->find( aKey ); 90 if( !(aIter == pActions->end() ) ) 91 { 92 const OUString& rAttrValue = xAttrList->getValueByIndex( i ); 93 94 if( !pMutableAttrList ) 95 { 96 pMutableAttrList = 97 new XMLMutableAttributeList( xAttrList ); 98 xAttrList = pMutableAttrList; 99 } 100 switch( (*aIter).second.m_nActionType ) 101 { 102 case XML_ATACTION_STYLE_FAMILY: 103 { 104 if( IsXMLToken( rAttrValue, XML_FOOTNOTE ) ) 105 { 106 } 107 else if( IsXMLToken( rAttrValue, XML_ENDNOTE ) ) 108 { 109 m_bEndNote = sal_True; 110 } 111 pMutableAttrList->RemoveAttributeByIndex( i ); 112 --i; 113 --nAttrCount; 114 } 115 break; 116 case XML_ATACTION_DECODE_STYLE_NAME: 117 case XML_ATACTION_DECODE_STYLE_NAME_REF: 118 { 119 OUString aAttrValue( rAttrValue ); 120 if( GetTransformer().DecodeStyleName(aAttrValue) ) 121 pMutableAttrList->SetValueByIndex( i, aAttrValue ); 122 } 123 break; 124 } 125 } 126 } 127 128 XMLTokenEnum eToken = XML_FOOTNOTE; 129 switch( m_eTypeToken ) 130 { 131 case XML_NOTE: 132 eToken = (m_bEndNote ? XML_ENDNOTE : XML_FOOTNOTE); 133 break; 134 case XML_NOTES_CONFIGURATION: 135 eToken = (m_bEndNote ? XML_ENDNOTES_CONFIGURATION 136 : XML_FOOTNOTES_CONFIGURATION); 137 break; 138 case XML_NOTE_REF: 139 eToken = (m_bEndNote ? XML_ENDNOTE_REF : XML_FOOTNOTE_REF); 140 break; 141 default: 142 OSL_ENSURE( XML_NOTE==m_eTypeToken, "invalid note type" ); 143 break; 144 } 145 146 SetExportQName( GetTransformer().GetNamespaceMap().GetQNameByKey( 147 XML_NAMESPACE_TEXT, 148 ::xmloff::token::GetXMLToken( eToken ) ) ); 149 if( m_bPersistent ) 150 XMLPersElemContentTContext::StartElement( xAttrList ); 151 else 152 GetTransformer().GetDocHandler()->startElement( GetExportQName(), 153 xAttrList ); 154 } 155 156 void XMLNotesTransformerContext::EndElement() 157 { 158 if( m_bPersistent ) 159 { 160 XMLPersElemContentTContext::EndElement(); 161 } 162 else 163 { 164 GetTransformer().GetDocHandler()->endElement( GetExportQName() ); 165 } 166 } 167 168 XMLTransformerContext *XMLNotesTransformerContext::CreateChildContext( 169 sal_uInt16 nPrefix, 170 const OUString& rLocalName, 171 const OUString& rQName, 172 const Reference< XAttributeList >& rAttrList ) 173 { 174 XMLTransformerContext *pContext = 0; 175 if( XML_NOTE == m_eTypeToken ) 176 { 177 if( XML_NAMESPACE_TEXT == nPrefix ) 178 { 179 XMLTokenEnum eToken ( XML_TOKEN_INVALID ); 180 if( IsXMLToken( rLocalName, XML_NOTE_CITATION ) ) 181 { 182 eToken = m_bEndNote ? XML_ENDNOTE_CITATION 183 : XML_FOOTNOTE_CITATION; 184 } 185 else if( IsXMLToken( rLocalName, XML_NOTE_BODY ) ) 186 { 187 eToken = m_bEndNote ? XML_ENDNOTE_BODY 188 : XML_FOOTNOTE_BODY; 189 } 190 191 if( XML_TOKEN_INVALID != eToken ) 192 { 193 if( m_bPersistent ) 194 { 195 pContext = new XMLPersTextContentTContext( 196 GetTransformer(), rQName, 197 XML_NAMESPACE_TEXT, 198 eToken ); 199 AddContent( pContext ); 200 201 } 202 else 203 { 204 pContext = new XMLRenameElemTransformerContext( 205 GetTransformer(), rQName, 206 XML_NAMESPACE_TEXT, 207 eToken ); 208 } 209 } 210 } 211 } 212 213 if( !pContext ) 214 { 215 pContext = m_bPersistent 216 ? XMLPersElemContentTContext::CreateChildContext( 217 nPrefix, rLocalName, rQName, rAttrList ) 218 : XMLTransformerContext::CreateChildContext( 219 nPrefix, rLocalName, rQName, rAttrList ); 220 } 221 222 return pContext; 223 } 224 225 sal_Bool XMLNotesTransformerContext::IsPersistent() const 226 { 227 return m_bPersistent; 228 } 229