Bump for 3.6-28
[LibreOffice.git] / xmloff / source / transform / DocumentTContext.cxx
blob4c38e843de34068c11039fa98133835a0aecfd1b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
29 #include <com/sun/star/xml/sax/SAXParseException.hpp>
30 #include <com/sun/star/xml/sax/SAXException.hpp>
31 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
32 #include <com/sun/star/xml/sax/XAttributeList.hpp>
33 #include <com/sun/star/beans/XPropertySetInfo.hpp>
34 #include <xmloff/nmspmap.hxx>
35 #include <xmloff/xmltoken.hxx>
36 #include "xmloff/xmlnmspe.hxx"
38 #include "TransformerBase.hxx"
39 #include "MutableAttrList.hxx"
41 #include "DocumentTContext.hxx"
43 using ::rtl::OUString;
45 using namespace ::xmloff::token;
46 using namespace ::com::sun::star::uno;
47 using namespace ::com::sun::star::xml::sax;
48 using namespace ::com::sun::star::beans;
50 TYPEINIT1( XMLDocumentTransformerContext, XMLTransformerContext );
52 XMLDocumentTransformerContext::XMLDocumentTransformerContext( XMLTransformerBase& rImp,
53 const OUString& rQName ) :
54 XMLTransformerContext( rImp, rQName )
58 XMLDocumentTransformerContext::~XMLDocumentTransformerContext()
62 void XMLDocumentTransformerContext::StartElement( const Reference< XAttributeList >& rAttrList )
64 Reference< XAttributeList > xAttrList( rAttrList );
66 sal_Bool bMimeFound = sal_False;
67 OUString aClass;
68 OUString aClassQName(
69 GetTransformer().GetNamespaceMap().GetQNameByKey(
70 XML_NAMESPACE_OFFICE, GetXMLToken(XML_CLASS ) ) );
72 XMLMutableAttributeList *pMutableAttrList = 0;
73 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
74 for( sal_Int16 i=0; i < nAttrCount; i++ )
76 const OUString& rAttrName = xAttrList->getNameByIndex( i );
77 OUString aLocalName;
78 sal_uInt16 nPrefix =
79 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
80 &aLocalName );
81 if( XML_NAMESPACE_OFFICE == nPrefix &&
82 IsXMLToken( aLocalName, XML_MIMETYPE ) )
84 const OUString& rValue = xAttrList->getValueByIndex( i );
85 static const char * aTmp[] =
87 "application/vnd.oasis.openoffice.",
88 "application/x-vnd.oasis.openoffice.",
89 "application/vnd.oasis.opendocument.",
90 "application/x-vnd.oasis.document.",
91 NULL
93 for (int k=0; aTmp[k]; k++)
95 ::rtl::OUString sTmpString = ::rtl::OUString::createFromAscii(aTmp[k]);
96 if( rValue.matchAsciiL( aTmp[k], sTmpString.getLength() ) )
98 aClass = rValue.copy( sTmpString.getLength() );
99 break;
103 if( !pMutableAttrList )
105 pMutableAttrList = new XMLMutableAttributeList( xAttrList );
106 xAttrList = pMutableAttrList;
108 pMutableAttrList->SetValueByIndex( i, aClass );
109 pMutableAttrList->RenameAttributeByIndex(i, aClassQName );
110 bMimeFound = sal_True;
111 break;
115 if( !bMimeFound )
117 const Reference< XPropertySet > rPropSet =
118 GetTransformer().GetPropertySet();
120 if( rPropSet.is() )
122 Reference< XPropertySetInfo > xPropSetInfo(
123 rPropSet->getPropertySetInfo() );
124 OUString aPropName(RTL_CONSTASCII_USTRINGPARAM("Class"));
125 if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName( aPropName ) )
127 Any aAny = rPropSet->getPropertyValue( aPropName );
128 aAny >>= aClass;
132 if( !aClass.isEmpty() )
134 if( !pMutableAttrList )
136 pMutableAttrList = new XMLMutableAttributeList( xAttrList );
137 xAttrList = pMutableAttrList;
140 pMutableAttrList->AddAttribute( aClassQName, aClass );
143 XMLTransformerContext::StartElement( xAttrList );
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */