Debian Codegraph @

xmloff/source/transform/FrameOASISTContext.cxx

raw
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 "FrameOASISTContext.hxx"
21 #include "IgnoreTContext.hxx"
22 #include "MutableAttrList.hxx"
23 #include <xmloff/xmlnamespace.hxx>
24 #include "ActionMapTypesOASIS.hxx"
25 #include "ElemTransformerAction.hxx"
26 #include "TransformerActions.hxx"
27 #include "TransformerBase.hxx"
28 #include <osl/diagnose.h>
29
30
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::xml::sax;
33 using namespace ::xmloff::token;
34
35 bool XMLFrameOASISTransformerContext::IsLinkedEmbeddedObject(
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 =
49 GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName,
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
70 XMLFrameOASISTransformerContext::XMLFrameOASISTransformerContext(
71 XMLTransformerBase& rImp,
72 const OUString& rQName ) :
73 XMLTransformerContext( rImp, rQName ),
74 m_bIgnoreElement( false )
75 {
76 }
77
78 XMLFrameOASISTransformerContext::~XMLFrameOASISTransformerContext()
79 {
80 }
81
82 void XMLFrameOASISTransformerContext::StartElement(
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 aAttrName = rAttrList->getNameByIndex( i );
91 OUString aLocalName;
92 sal_uInt16 nPrefix =
93 GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName, &aLocalName );
94
95 if( (nPrefix == XML_NAMESPACE_PRESENTATION) && IsXMLToken( aLocalName, XML_CLASS ) )
96 {
97 const OUString aAttrValue = rAttrList->getValueByIndex( i );
98 if( IsXMLToken( aAttrValue, XML_HEADER ) || IsXMLToken( aAttrValue, XML_FOOTER ) ||
99 IsXMLToken( aAttrValue, XML_PAGE_NUMBER ) || IsXMLToken( aAttrValue, XML_DATE_TIME ) )
100 {
101 m_bIgnoreElement = true;
102 break;
103 }
104 }
105 }
106 }
107
108 rtl::Reference<XMLTransformerContext> XMLFrameOASISTransformerContext::CreateChildContext(
109 sal_uInt16 nPrefix,
110 const OUString& rLocalName,
111 const OUString& rQName,
112 const Reference< XAttributeList >& rAttrList )
113 {
114 rtl::Reference<XMLTransformerContext> pContext;
115
116 if( m_bIgnoreElement )
117 {
118 // do not export the frame element and all of its children
119 pContext.set(new XMLIgnoreTransformerContext( GetTransformer(),
120 rQName,
121 true, true ));
122 }
123 else
124 {
125 XMLTransformerActions *pActions =
126 GetTransformer().GetUserDefinedActions( OASIS_FRAME_ELEM_ACTIONS );
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 {
135 case XML_ETACTION_COPY:
136 if( m_aElemQName.isEmpty() &&
137 !IsLinkedEmbeddedObject( rLocalName, rAttrList ) )
138 {
139 pContext.set(new XMLIgnoreTransformerContext( GetTransformer(),
140 rQName,
141 false, false ));
142 m_aElemQName = rQName;
143 static_cast< XMLMutableAttributeList * >( m_xAttrList.get() )
144 ->AppendAttributeList( rAttrList );
145 GetTransformer().ProcessAttrList( m_xAttrList,
146 OASIS_SHAPE_ACTIONS,
147 false );
148 GetTransformer().GetDocHandler()->startElement( m_aElemQName, m_xAttrList );
149 }
150 else
151 {
152 pContext.set(new XMLIgnoreTransformerContext( GetTransformer(),
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() )
166 pContext = XMLTransformerContext::CreateChildContext( nPrefix,
167 rLocalName,
168 rQName,
169 rAttrList );
170
171 return pContext;
172 }
173
174 void XMLFrameOASISTransformerContext::EndElement()
175 {
176 if( !m_bIgnoreElement )
177 GetTransformer().GetDocHandler()->endElement( m_aElemQName );
178 }
179
180 void XMLFrameOASISTransformerContext::Characters( const OUString& rChars )
181 {
182 // ignore
183 if( !m_aElemQName.isEmpty() && !m_bIgnoreElement )
184 XMLTransformerContext::Characters( rChars );
185 }
186
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */