Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "FrameOASISTContext.hxx"
30 : : #include "IgnoreTContext.hxx"
31 : : #include "MutableAttrList.hxx"
32 : : #include "xmloff/xmlnmspe.hxx"
33 : : #include "ActionMapTypesOASIS.hxx"
34 : : #include "ElemTransformerAction.hxx"
35 : : #include "TransformerActions.hxx"
36 : : #include "TransformerBase.hxx"
37 : :
38 : : using ::rtl::OUString;
39 : :
40 : : using namespace ::com::sun::star::uno;
41 : : using namespace ::com::sun::star::xml::sax;
42 : : using namespace ::xmloff::token;
43 : :
44 [ # # ][ # # ]: 0 : TYPEINIT1( XMLFrameOASISTransformerContext, XMLTransformerContext );
45 : :
46 : 12 : sal_Bool XMLFrameOASISTransformerContext::IsLinkedEmbeddedObject(
47 : : const OUString& rLocalName,
48 : : const Reference< XAttributeList >& rAttrList )
49 : : {
50 [ + - ]: 24 : if( !(IsXMLToken( rLocalName, XML_OBJECT ) ||
51 [ + - ][ + - ]: 12 : IsXMLToken( rLocalName, XML_OBJECT_OLE) ) )
52 : 12 : return sal_False;
53 : :
54 [ # # ]: 0 : sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
55 [ # # ]: 0 : for( sal_Int16 i=0; i < nAttrCount; i++ )
56 : : {
57 [ # # ][ # # ]: 0 : OUString aAttrName( rAttrList->getNameByIndex( i ) );
58 : 0 : OUString aLocalName;
59 : : sal_uInt16 nPrefix =
60 : 0 : GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName,
61 [ # # ]: 0 : &aLocalName );
62 [ # # ][ # # ]: 0 : if( XML_NAMESPACE_XLINK == nPrefix &&
[ # # ]
63 [ # # ]: 0 : IsXMLToken( aLocalName, XML_HREF ) )
64 : : {
65 [ # # ][ # # ]: 0 : OUString sHRef( rAttrList->getValueByIndex( i ) );
66 [ # # ]: 0 : if (sHRef.isEmpty())
67 : : {
68 : : // When the href is empty then the object is not linked but
69 : : // a placeholder.
70 : 0 : return sal_False;
71 : : }
72 [ # # ]: 0 : GetTransformer().ConvertURIToOOo( sHRef, sal_True );
73 [ # # ][ # # ]: 0 : return !(!sHRef.isEmpty() && '#'==sHRef[0]);
74 : : }
75 [ # # ][ # # ]: 0 : }
76 : :
77 : 12 : return sal_False;
78 : : }
79 : :
80 : :
81 : 34 : XMLFrameOASISTransformerContext::XMLFrameOASISTransformerContext(
82 : : XMLTransformerBase& rImp,
83 : : const OUString& rQName ) :
84 : : XMLTransformerContext( rImp, rQName ),
85 : 34 : m_bIgnoreElement( false )
86 : : {
87 : 34 : }
88 : :
89 : 34 : XMLFrameOASISTransformerContext::~XMLFrameOASISTransformerContext()
90 : : {
91 [ - + ]: 68 : }
92 : :
93 : 34 : void XMLFrameOASISTransformerContext::StartElement(
94 : : const Reference< XAttributeList >& rAttrList )
95 : : {
96 [ + - ][ + - ]: 34 : m_xAttrList = new XMLMutableAttributeList( rAttrList, sal_True );
97 : :
98 [ + - ]: 34 : sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
99 [ + + ]: 306 : for( sal_Int16 i=0; i < nAttrCount; i++ )
100 : : {
101 [ + - ][ + - ]: 272 : const OUString& rAttrName = rAttrList->getNameByIndex( i );
102 : 272 : OUString aLocalName;
103 : : sal_uInt16 nPrefix =
104 [ + - ]: 272 : GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
105 : :
106 [ + + ][ + - ]: 272 : if( (nPrefix == XML_NAMESPACE_PRESENTATION) && IsXMLToken( aLocalName, XML_CLASS ) )
[ + + ][ + + ]
107 : : {
108 [ + - ][ + - ]: 34 : const OUString& rAttrValue = rAttrList->getValueByIndex( i );
109 [ + - ][ + + ]: 76 : if( IsXMLToken( rAttrValue, XML_HEADER ) || IsXMLToken( rAttrValue, XML_FOOTER ) ||
[ + - ][ + + ]
[ + + ][ + + ]
[ + + ]
110 [ + - ][ + - ]: 42 : IsXMLToken( rAttrValue, XML_PAGE_NUMBER ) || IsXMLToken( rAttrValue, XML_DATE_TIME ) )
111 : : {
112 : 34 : m_bIgnoreElement = true;
113 : : break;
114 [ + + ]: 272 : }
115 : : }
116 [ + + ][ + + ]: 272 : }
117 : 34 : }
118 : :
119 : 34 : XMLTransformerContext *XMLFrameOASISTransformerContext::CreateChildContext(
120 : : sal_uInt16 nPrefix,
121 : : const OUString& rLocalName,
122 : : const OUString& rQName,
123 : : const Reference< XAttributeList >& rAttrList )
124 : : {
125 : 34 : XMLTransformerContext *pContext = 0;
126 : :
127 [ + + ]: 34 : if( m_bIgnoreElement )
128 : : {
129 : : // do not export the frame element and all of its children
130 : 22 : pContext = new XMLIgnoreTransformerContext( GetTransformer(),
131 : : rQName,
132 [ + - ]: 22 : sal_True, sal_True );
133 : : }
134 : : else
135 : : {
136 : : XMLTransformerActions *pActions =
137 [ + - ]: 12 : GetTransformer().GetUserDefinedActions( OASIS_FRAME_ELEM_ACTIONS );
138 : : OSL_ENSURE( pActions, "go no actions" );
139 : 12 : XMLTransformerActions::key_type aKey( nPrefix, rLocalName );
140 [ + - ]: 12 : XMLTransformerActions::const_iterator aIter = pActions->find( aKey );
141 : :
142 [ + - ][ + - ]: 12 : if( !(aIter == pActions->end()) )
143 : : {
144 [ + - ][ + - ]: 12 : switch( (*aIter).second.m_nActionType )
145 : : {
146 : : case XML_ETACTION_COPY:
147 [ + - ][ + - ]: 24 : if( m_aElemQName.isEmpty() &&
[ + - ]
148 [ + - ]: 12 : !IsLinkedEmbeddedObject( rLocalName, rAttrList ) )
149 : : {
150 : 12 : pContext = new XMLIgnoreTransformerContext( GetTransformer(),
151 : : rQName,
152 [ + - ][ + - ]: 12 : sal_False, sal_False );
153 : 12 : m_aElemQName = rQName;
154 [ + - ]: 12 : static_cast< XMLMutableAttributeList * >( m_xAttrList.get() )
155 [ + - ][ + - ]: 12 : ->AppendAttributeList( rAttrList );
156 : 12 : GetTransformer().ProcessAttrList( m_xAttrList,
157 : : OASIS_SHAPE_ACTIONS,
158 [ + - ]: 12 : sal_False );
159 [ + - ]: 12 : GetTransformer().GetDocHandler()->startElement( m_aElemQName,
160 [ + - ]: 12 : m_xAttrList );
161 : : }
162 : : else
163 : : {
164 : 0 : pContext = new XMLIgnoreTransformerContext( GetTransformer(),
165 : : rQName,
166 [ # # ][ # # ]: 0 : sal_True, sal_True );
167 : : }
168 : 12 : break;
169 : : default:
170 : : OSL_ENSURE( !this, "unknown action" );
171 : 12 : break;
172 : : }
173 : 12 : }
174 : : }
175 : :
176 : : // default is copying
177 [ - + ]: 34 : if( !pContext )
178 : : pContext = XMLTransformerContext::CreateChildContext( nPrefix,
179 : : rLocalName,
180 : : rQName,
181 : 0 : rAttrList );
182 : :
183 : 34 : return pContext;
184 : : }
185 : :
186 : 34 : void XMLFrameOASISTransformerContext::EndElement()
187 : : {
188 [ + + ]: 34 : if( !m_bIgnoreElement )
189 : 12 : GetTransformer().GetDocHandler()->endElement( m_aElemQName );
190 : 34 : }
191 : :
192 : 0 : void XMLFrameOASISTransformerContext::Characters( const OUString& rChars )
193 : : {
194 : : // ignore
195 [ # # ][ # # ]: 0 : if( !m_aElemQName.isEmpty() && !m_bIgnoreElement )
[ # # ]
196 : 0 : XMLTransformerContext::Characters( rChars );
197 : 0 : }
198 : :
199 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|