LibreOffice Module xmloff (master) 1
FrameOASISTContext.cxx
Go to the documentation of this file.
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
21#include "IgnoreTContext.hxx"
22#include "MutableAttrList.hxx"
27#include "TransformerBase.hxx"
28#include <osl/diagnose.h>
29
30
31using namespace ::com::sun::star::uno;
32using namespace ::com::sun::star::xml::sax;
33using namespace ::xmloff::token;
34
36 std::u16string_view rLocalName,
37 const Reference< XAttributeList >& rAttrList )
38{
39 if( !(IsXMLToken( rLocalName, XML_OBJECT ) ||
40 IsXMLToken( rLocalName, XML_OBJECT_OLE) ) )
41 return false;
42
43 sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
44 for( sal_Int16 i=0; i < nAttrCount; i++ )
45 {
46 OUString aAttrName( rAttrList->getNameByIndex( i ) );
47 OUString aLocalName;
48 sal_uInt16 nPrefix =
50 &aLocalName );
51 if( XML_NAMESPACE_XLINK == nPrefix &&
52 IsXMLToken( aLocalName, XML_HREF ) )
53 {
54 OUString sHRef( rAttrList->getValueByIndex( i ) );
55 if (sHRef.isEmpty())
56 {
57 // When the href is empty then the object is not linked but
58 // a placeholder.
59 return false;
60 }
61 GetTransformer().ConvertURIToOOo( sHRef, true );
62 return sHRef.isEmpty() || '#' != sHRef[0];
63 }
64 }
65
66 return false;
67}
68
69
72 const OUString& rQName ) :
73 XMLTransformerContext( rImp, rQName ),
74 m_bIgnoreElement( false )
75{
76}
77
79{
80}
81
83 const Reference< XAttributeList >& rAttrList )
84{
85 m_xAttrList = new XMLMutableAttributeList( rAttrList, true );
86
87 sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
88 for( sal_Int16 i=0; i < nAttrCount; i++ )
89 {
90 const OUString& rAttrName = rAttrList->getNameByIndex( i );
91 OUString aLocalName;
92 sal_uInt16 nPrefix =
93 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
94
95 if( (nPrefix == XML_NAMESPACE_PRESENTATION) && IsXMLToken( aLocalName, XML_CLASS ) )
96 {
97 const OUString& rAttrValue = rAttrList->getValueByIndex( i );
98 if( IsXMLToken( rAttrValue, XML_HEADER ) || IsXMLToken( rAttrValue, XML_FOOTER ) ||
99 IsXMLToken( rAttrValue, XML_PAGE_NUMBER ) || IsXMLToken( rAttrValue, XML_DATE_TIME ) )
100 {
101 m_bIgnoreElement = true;
102 break;
103 }
104 }
105 }
106}
107
109 sal_uInt16 nPrefix,
110 const OUString& rLocalName,
111 const OUString& rQName,
112 const Reference< XAttributeList >& rAttrList )
113{
115
116 if( m_bIgnoreElement )
117 {
118 // do not export the frame element and all of its children
120 rQName,
121 true, true ));
122 }
123 else
124 {
125 XMLTransformerActions *pActions =
127 OSL_ENSURE( pActions, "go no actions" );
128 XMLTransformerActions::key_type aKey( nPrefix, rLocalName );
129 XMLTransformerActions::const_iterator aIter = pActions->find( aKey );
130
131 if( aIter != pActions->end() )
132 {
133 switch( (*aIter).second.m_nActionType )
134 {
136 if( m_aElemQName.isEmpty() &&
137 !IsLinkedEmbeddedObject( rLocalName, rAttrList ) )
138 {
140 rQName,
141 false, false ));
142 m_aElemQName = rQName;
143 static_cast< XMLMutableAttributeList * >( m_xAttrList.get() )
144 ->AppendAttributeList( rAttrList );
147 false );
149 }
150 else
151 {
153 rQName,
154 true, true ));
155 }
156 break;
157 default:
158 OSL_ENSURE( false, "unknown action" );
159 break;
160 }
161 }
162 }
163
164 // default is copying
165 if( !pContext.is() )
167 rLocalName,
168 rQName,
169 rAttrList );
170
171 return pContext;
172}
173
175{
176 if( !m_bIgnoreElement )
177 GetTransformer().GetDocHandler()->endElement( m_aElemQName );
178}
179
181{
182 // ignore
183 if( !m_aElemQName.isEmpty() && !m_bIgnoreElement )
185}
186
187/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@ OASIS_SHAPE_ACTIONS
@ OASIS_FRAME_ELEM_ACTIONS
@ XML_ETACTION_COPY
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
virtual void Characters(const OUString &rChars) override
virtual rtl::Reference< XMLTransformerContext > CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const OUString &rQName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
bool IsLinkedEmbeddedObject(std::u16string_view rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &rAttrList)
virtual ~XMLFrameOASISTransformerContext() override
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
XMLFrameOASISTransformerContext(XMLTransformerBase &rTransformer, const OUString &rQName)
css::uno::Reference< css::xml::sax::XAttributeList > m_xAttrList
virtual void EndElement() override
virtual XMLTransformerActions * GetUserDefinedActions(sal_uInt16 n)
SvXMLNamespaceMap & GetNamespaceMap()
const css::uno::Reference< css::xml::sax::XDocumentHandler > & GetDocHandler() const
XMLMutableAttributeList * ProcessAttrList(css::uno::Reference< css::xml::sax::XAttributeList > &rAttrList, sal_uInt16 nActionMap, bool bClone)
bool ConvertURIToOOo(OUString &rURI, bool bSupportPackage) const
virtual rtl::Reference< XMLTransformerContext > CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const OUString &rQName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList)
virtual void Characters(const OUString &rChars)
XMLTransformerBase & GetTransformer()
int i
Handling of tokens in XML:
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3583
constexpr sal_uInt16 XML_NAMESPACE_XLINK
constexpr sal_uInt16 XML_NAMESPACE_PRESENTATION