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/beans/XPropertySetInfo.hpp>
21 #include <xmloff/namespacemap.hxx>
22 #include <xmloff/xmltoken.hxx>
23 #include <xmloff/xmlnamespace.hxx>
25 #include "TransformerBase.hxx"
26 #include "MutableAttrList.hxx"
28 #include "DocumentTContext.hxx"
31 using namespace ::xmloff::token
;
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::xml::sax
;
34 using namespace ::com::sun::star::beans
;
36 XMLDocumentTransformerContext::XMLDocumentTransformerContext( XMLTransformerBase
& rImp
,
37 const OUString
& rQName
) :
38 XMLTransformerContext( rImp
, rQName
)
42 void XMLDocumentTransformerContext::StartElement( const Reference
< XAttributeList
>& rAttrList
)
44 Reference
< XAttributeList
> xAttrList( rAttrList
);
46 bool bMimeFound
= false;
49 GetTransformer().GetNamespaceMap().GetQNameByKey(
50 XML_NAMESPACE_OFFICE
, GetXMLToken(XML_CLASS
) ) );
52 rtl::Reference
<XMLMutableAttributeList
> pMutableAttrList
;
53 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
54 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
56 const OUString aAttrName
= xAttrList
->getNameByIndex( i
);
59 GetTransformer().GetNamespaceMap().GetKeyByAttrName( aAttrName
,
61 if( XML_NAMESPACE_OFFICE
== nPrefix
&&
62 IsXMLToken( aLocalName
, XML_MIMETYPE
) )
64 const OUString aValue
= xAttrList
->getValueByIndex( i
);
65 static constexpr std::string_view aTmp
[]
67 "application/vnd.oasis.openoffice.",
68 "application/x-vnd.oasis.openoffice.",
69 "application/vnd.oasis.opendocument.",
70 "application/x-vnd.oasis.document."
72 for (const auto & rPrefix
: aTmp
)
74 if( aValue
.matchAsciiL( rPrefix
.data(), rPrefix
.size() ) )
76 aClass
= aValue
.copy( rPrefix
.size() );
81 if( !pMutableAttrList
)
83 pMutableAttrList
= new XMLMutableAttributeList( xAttrList
);
84 xAttrList
= pMutableAttrList
;
86 pMutableAttrList
->SetValueByIndex( i
, aClass
);
87 pMutableAttrList
->RenameAttributeByIndex(i
, aClassQName
);
95 const Reference
< XPropertySet
> rPropSet
=
96 GetTransformer().GetPropertySet();
100 Reference
< XPropertySetInfo
> xPropSetInfo(
101 rPropSet
->getPropertySetInfo() );
102 OUString
aPropName(u
"Class"_ustr
);
103 if( xPropSetInfo
.is() && xPropSetInfo
->hasPropertyByName( aPropName
) )
105 Any aAny
= rPropSet
->getPropertyValue( aPropName
);
110 if( !aClass
.isEmpty() )
112 if( !pMutableAttrList
)
114 pMutableAttrList
= new XMLMutableAttributeList( xAttrList
);
115 xAttrList
= pMutableAttrList
;
118 pMutableAttrList
->AddAttribute( aClassQName
, aClass
);
121 XMLTransformerContext::StartElement( xAttrList
);
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */