Line data Source code
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/xmlnmspe.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 0 : TYPEINIT1( XMLFrameOASISTransformerContext, XMLTransformerContext );
36 :
37 0 : bool XMLFrameOASISTransformerContext::IsLinkedEmbeddedObject(
38 : const OUString& rLocalName,
39 : const Reference< XAttributeList >& rAttrList )
40 : {
41 0 : if( !(IsXMLToken( rLocalName, XML_OBJECT ) ||
42 0 : IsXMLToken( rLocalName, XML_OBJECT_OLE) ) )
43 0 : return false;
44 :
45 0 : sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
46 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
47 : {
48 0 : OUString aAttrName( rAttrList->getNameByIndex( i ) );
49 0 : OUString aLocalName;
50 : sal_uInt16 nPrefix =
51 0 : GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName,
52 0 : &aLocalName );
53 0 : if( XML_NAMESPACE_XLINK == nPrefix &&
54 0 : IsXMLToken( aLocalName, XML_HREF ) )
55 : {
56 0 : OUString sHRef( rAttrList->getValueByIndex( i ) );
57 0 : if (sHRef.isEmpty())
58 : {
59 : // When the href is empty then the object is not linked but
60 : // a placeholder.
61 0 : return false;
62 : }
63 0 : GetTransformer().ConvertURIToOOo( sHRef, true );
64 0 : return !(!sHRef.isEmpty() && '#'==sHRef[0]);
65 : }
66 0 : }
67 :
68 0 : return false;
69 : }
70 :
71 :
72 0 : XMLFrameOASISTransformerContext::XMLFrameOASISTransformerContext(
73 : XMLTransformerBase& rImp,
74 : const OUString& rQName ) :
75 : XMLTransformerContext( rImp, rQName ),
76 0 : m_bIgnoreElement( false )
77 : {
78 0 : }
79 :
80 0 : XMLFrameOASISTransformerContext::~XMLFrameOASISTransformerContext()
81 : {
82 0 : }
83 :
84 0 : void XMLFrameOASISTransformerContext::StartElement(
85 : const Reference< XAttributeList >& rAttrList )
86 : {
87 0 : m_xAttrList = new XMLMutableAttributeList( rAttrList, true );
88 :
89 0 : sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
90 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
91 : {
92 0 : const OUString& rAttrName = rAttrList->getNameByIndex( i );
93 0 : OUString aLocalName;
94 : sal_uInt16 nPrefix =
95 0 : GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
96 :
97 0 : if( (nPrefix == XML_NAMESPACE_PRESENTATION) && IsXMLToken( aLocalName, XML_CLASS ) )
98 : {
99 0 : const OUString& rAttrValue = rAttrList->getValueByIndex( i );
100 0 : if( IsXMLToken( rAttrValue, XML_HEADER ) || IsXMLToken( rAttrValue, XML_FOOTER ) ||
101 0 : IsXMLToken( rAttrValue, XML_PAGE_NUMBER ) || IsXMLToken( rAttrValue, XML_DATE_TIME ) )
102 : {
103 0 : m_bIgnoreElement = true;
104 0 : break;
105 0 : }
106 : }
107 0 : }
108 0 : }
109 :
110 0 : XMLTransformerContext *XMLFrameOASISTransformerContext::CreateChildContext(
111 : sal_uInt16 nPrefix,
112 : const OUString& rLocalName,
113 : const OUString& rQName,
114 : const Reference< XAttributeList >& rAttrList )
115 : {
116 0 : XMLTransformerContext *pContext = 0;
117 :
118 0 : if( m_bIgnoreElement )
119 : {
120 : // do not export the frame element and all of its children
121 0 : pContext = new XMLIgnoreTransformerContext( GetTransformer(),
122 : rQName,
123 0 : true, true );
124 : }
125 : else
126 : {
127 : XMLTransformerActions *pActions =
128 0 : GetTransformer().GetUserDefinedActions( OASIS_FRAME_ELEM_ACTIONS );
129 : OSL_ENSURE( pActions, "go no actions" );
130 0 : XMLTransformerActions::key_type aKey( nPrefix, rLocalName );
131 0 : XMLTransformerActions::const_iterator aIter = pActions->find( aKey );
132 :
133 0 : if( !(aIter == pActions->end()) )
134 : {
135 0 : switch( (*aIter).second.m_nActionType )
136 : {
137 : case XML_ETACTION_COPY:
138 0 : if( m_aElemQName.isEmpty() &&
139 0 : !IsLinkedEmbeddedObject( rLocalName, rAttrList ) )
140 : {
141 0 : pContext = new XMLIgnoreTransformerContext( GetTransformer(),
142 : rQName,
143 0 : false, false );
144 0 : m_aElemQName = rQName;
145 0 : static_cast< XMLMutableAttributeList * >( m_xAttrList.get() )
146 0 : ->AppendAttributeList( rAttrList );
147 0 : GetTransformer().ProcessAttrList( m_xAttrList,
148 : OASIS_SHAPE_ACTIONS,
149 0 : false );
150 0 : GetTransformer().GetDocHandler()->startElement( m_aElemQName,
151 0 : m_xAttrList );
152 : }
153 : else
154 : {
155 0 : pContext = new XMLIgnoreTransformerContext( GetTransformer(),
156 : rQName,
157 0 : true, true );
158 : }
159 0 : break;
160 : default:
161 : OSL_ENSURE( false, "unknown action" );
162 0 : break;
163 : }
164 0 : }
165 : }
166 :
167 : // default is copying
168 0 : if( !pContext )
169 : pContext = XMLTransformerContext::CreateChildContext( nPrefix,
170 : rLocalName,
171 : rQName,
172 0 : rAttrList );
173 :
174 0 : return pContext;
175 : }
176 :
177 0 : void XMLFrameOASISTransformerContext::EndElement()
178 : {
179 0 : if( !m_bIgnoreElement )
180 0 : GetTransformer().GetDocHandler()->endElement( m_aElemQName );
181 0 : }
182 :
183 0 : void XMLFrameOASISTransformerContext::Characters( const OUString& rChars )
184 : {
185 : // ignore
186 0 : if( !m_aElemQName.isEmpty() && !m_bIgnoreElement )
187 0 : XMLTransformerContext::Characters( rChars );
188 0 : }
189 :
190 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|