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