1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/xml/sax/SAXParseException.hpp>
21 #include <com/sun/star/xml/sax/SAXException.hpp>
22 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
23 #include <com/sun/star/xml/sax/XAttributeList.hpp>
24 #include <com/sun/star/beans/XPropertySetInfo.hpp>
25 #include <xmloff/nmspmap.hxx>
26 #include <xmloff/xmltoken.hxx>
27 #include <xmloff/xmlnmspe.hxx>
29 #include "TransformerBase.hxx"
30 #include "MutableAttrList.hxx"
32 #include "DocumentTContext.hxx"
35 using namespace ::xmloff::token
;
36 using namespace ::com::sun::star::uno
;
37 using namespace ::com::sun::star::xml::sax
;
38 using namespace ::com::sun::star::beans
;
40 XMLDocumentTransformerContext::XMLDocumentTransformerContext( XMLTransformerBase
& rImp
,
41 const OUString
& rQName
) :
42 XMLTransformerContext( rImp
, rQName
)
46 XMLDocumentTransformerContext::~XMLDocumentTransformerContext()
50 void XMLDocumentTransformerContext::StartElement( const Reference
< XAttributeList
>& rAttrList
)
52 Reference
< XAttributeList
> xAttrList( rAttrList
);
54 bool bMimeFound
= false;
57 GetTransformer().GetNamespaceMap().GetQNameByKey(
58 XML_NAMESPACE_OFFICE
, GetXMLToken(XML_CLASS
) ) );
60 XMLMutableAttributeList
*pMutableAttrList
= nullptr;
61 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
62 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
64 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
67 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
69 if( XML_NAMESPACE_OFFICE
== nPrefix
&&
70 IsXMLToken( aLocalName
, XML_MIMETYPE
) )
72 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
73 static const char * aTmp
[] =
75 "application/vnd.oasis.openoffice.",
76 "application/x-vnd.oasis.openoffice.",
77 "application/vnd.oasis.opendocument.",
78 "application/x-vnd.oasis.document.",
81 for (int k
=0; aTmp
[k
]; k
++)
83 OUString sTmpString
= OUString::createFromAscii(aTmp
[k
]);
84 if( rValue
.matchAsciiL( aTmp
[k
], sTmpString
.getLength() ) )
86 aClass
= rValue
.copy( sTmpString
.getLength() );
91 if( !pMutableAttrList
)
93 pMutableAttrList
= new XMLMutableAttributeList( xAttrList
);
94 xAttrList
= pMutableAttrList
;
96 pMutableAttrList
->SetValueByIndex( i
, aClass
);
97 pMutableAttrList
->RenameAttributeByIndex(i
, aClassQName
);
105 const Reference
< XPropertySet
> rPropSet
=
106 GetTransformer().GetPropertySet();
110 Reference
< XPropertySetInfo
> xPropSetInfo(
111 rPropSet
->getPropertySetInfo() );
112 OUString
aPropName("Class");
113 if( xPropSetInfo
.is() && xPropSetInfo
->hasPropertyByName( aPropName
) )
115 Any aAny
= rPropSet
->getPropertyValue( aPropName
);
120 if( !aClass
.isEmpty() )
122 if( !pMutableAttrList
)
124 pMutableAttrList
= new XMLMutableAttributeList( xAttrList
);
125 xAttrList
= pMutableAttrList
;
128 pMutableAttrList
->AddAttribute( aClassQName
, aClass
);
131 XMLTransformerContext::StartElement( xAttrList
);
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */