bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / transform / DocumentTContext.cxx
blobea465424528109e31c4e4f9c70b1a07fbb9bd5ba
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/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 TYPEINIT1( XMLDocumentTransformerContext, XMLTransformerContext );
42 XMLDocumentTransformerContext::XMLDocumentTransformerContext( XMLTransformerBase& rImp,
43 const OUString& rQName ) :
44 XMLTransformerContext( rImp, rQName )
48 XMLDocumentTransformerContext::~XMLDocumentTransformerContext()
52 void XMLDocumentTransformerContext::StartElement( const Reference< XAttributeList >& rAttrList )
54 Reference< XAttributeList > xAttrList( rAttrList );
56 bool bMimeFound = false;
57 OUString aClass;
58 OUString aClassQName(
59 GetTransformer().GetNamespaceMap().GetQNameByKey(
60 XML_NAMESPACE_OFFICE, GetXMLToken(XML_CLASS ) ) );
62 XMLMutableAttributeList *pMutableAttrList = 0;
63 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
64 for( sal_Int16 i=0; i < nAttrCount; i++ )
66 const OUString& rAttrName = xAttrList->getNameByIndex( i );
67 OUString aLocalName;
68 sal_uInt16 nPrefix =
69 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
70 &aLocalName );
71 if( XML_NAMESPACE_OFFICE == nPrefix &&
72 IsXMLToken( aLocalName, XML_MIMETYPE ) )
74 const OUString& rValue = xAttrList->getValueByIndex( i );
75 static const char * aTmp[] =
77 "application/vnd.oasis.openoffice.",
78 "application/x-vnd.oasis.openoffice.",
79 "application/vnd.oasis.opendocument.",
80 "application/x-vnd.oasis.document.",
81 NULL
83 for (int k=0; aTmp[k]; k++)
85 OUString sTmpString = OUString::createFromAscii(aTmp[k]);
86 if( rValue.matchAsciiL( aTmp[k], sTmpString.getLength() ) )
88 aClass = rValue.copy( sTmpString.getLength() );
89 break;
93 if( !pMutableAttrList )
95 pMutableAttrList = new XMLMutableAttributeList( xAttrList );
96 xAttrList = pMutableAttrList;
98 pMutableAttrList->SetValueByIndex( i, aClass );
99 pMutableAttrList->RenameAttributeByIndex(i, aClassQName );
100 bMimeFound = true;
101 break;
105 if( !bMimeFound )
107 const Reference< XPropertySet > rPropSet =
108 GetTransformer().GetPropertySet();
110 if( rPropSet.is() )
112 Reference< XPropertySetInfo > xPropSetInfo(
113 rPropSet->getPropertySetInfo() );
114 OUString aPropName("Class");
115 if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName( aPropName ) )
117 Any aAny = rPropSet->getPropertyValue( aPropName );
118 aAny >>= aClass;
122 if( !aClass.isEmpty() )
124 if( !pMutableAttrList )
126 pMutableAttrList = new XMLMutableAttributeList( xAttrList );
127 xAttrList = pMutableAttrList;
130 pMutableAttrList->AddAttribute( aClassQName, aClass );
133 XMLTransformerContext::StartElement( xAttrList );
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */