Teach symstore more duplicated DLLs
[LibreOffice.git] / xmloff / source / transform / DocumentTContext.cxx
blob3edbc250eeda045fe8d3675a409caa2e4889679c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/SAXException.hpp>
21 #include <com/sun/star/xml/sax/XAttributeList.hpp>
22 #include <com/sun/star/beans/XPropertySetInfo.hpp>
23 #include <xmloff/nmspmap.hxx>
24 #include <xmloff/xmltoken.hxx>
25 #include <xmloff/xmlnmspe.hxx>
27 #include "TransformerBase.hxx"
28 #include "MutableAttrList.hxx"
30 #include "DocumentTContext.hxx"
33 using namespace ::xmloff::token;
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::xml::sax;
36 using namespace ::com::sun::star::beans;
38 XMLDocumentTransformerContext::XMLDocumentTransformerContext( XMLTransformerBase& rImp,
39 const OUString& rQName ) :
40 XMLTransformerContext( rImp, rQName )
44 void XMLDocumentTransformerContext::StartElement( const Reference< XAttributeList >& rAttrList )
46 Reference< XAttributeList > xAttrList( rAttrList );
48 bool bMimeFound = false;
49 OUString aClass;
50 OUString aClassQName(
51 GetTransformer().GetNamespaceMap().GetQNameByKey(
52 XML_NAMESPACE_OFFICE, GetXMLToken(XML_CLASS ) ) );
54 XMLMutableAttributeList *pMutableAttrList = nullptr;
55 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
56 for( sal_Int16 i=0; i < nAttrCount; i++ )
58 const OUString& rAttrName = xAttrList->getNameByIndex( i );
59 OUString aLocalName;
60 sal_uInt16 nPrefix =
61 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
62 &aLocalName );
63 if( XML_NAMESPACE_OFFICE == nPrefix &&
64 IsXMLToken( aLocalName, XML_MIMETYPE ) )
66 const OUString& rValue = xAttrList->getValueByIndex( i );
67 static const char * aTmp[] =
69 "application/vnd.oasis.openoffice.",
70 "application/x-vnd.oasis.openoffice.",
71 "application/vnd.oasis.opendocument.",
72 "application/x-vnd.oasis.document.",
73 nullptr
75 for (int k=0; aTmp[k]; k++)
77 OUString sTmpString = OUString::createFromAscii(aTmp[k]);
78 if( rValue.matchAsciiL( aTmp[k], sTmpString.getLength() ) )
80 aClass = rValue.copy( sTmpString.getLength() );
81 break;
85 if( !pMutableAttrList )
87 pMutableAttrList = new XMLMutableAttributeList( xAttrList );
88 xAttrList = pMutableAttrList;
90 pMutableAttrList->SetValueByIndex( i, aClass );
91 pMutableAttrList->RenameAttributeByIndex(i, aClassQName );
92 bMimeFound = true;
93 break;
97 if( !bMimeFound )
99 const Reference< XPropertySet > rPropSet =
100 GetTransformer().GetPropertySet();
102 if( rPropSet.is() )
104 Reference< XPropertySetInfo > xPropSetInfo(
105 rPropSet->getPropertySetInfo() );
106 OUString aPropName("Class");
107 if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName( aPropName ) )
109 Any aAny = rPropSet->getPropertyValue( aPropName );
110 aAny >>= aClass;
114 if( !aClass.isEmpty() )
116 if( !pMutableAttrList )
118 pMutableAttrList = new XMLMutableAttributeList( xAttrList );
119 xAttrList = pMutableAttrList;
122 pMutableAttrList->AddAttribute( aClassQName, aClass );
125 XMLTransformerContext::StartElement( xAttrList );
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */