1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DocumentTContext.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <com/sun/star/xml/sax/SAXParseException.hpp>
34 #include <com/sun/star/xml/sax/SAXException.hpp>
35 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
36 #include <com/sun/star/xml/sax/XAttributeList.hpp>
37 #include <com/sun/star/beans/XPropertySetInfo.hpp>
38 #include <xmloff/nmspmap.hxx>
39 #include <xmloff/xmltoken.hxx>
40 #include "xmlnmspe.hxx"
42 #ifndef _XMLOFF_TRANSFOERMERBASE_HXX
43 #include "TransformerBase.hxx"
45 #include "MutableAttrList.hxx"
47 #ifndef _XMLOFF_METATCONTEXT_HXX
48 #include "DocumentTContext.hxx"
51 using ::rtl::OUString
;
53 using namespace ::xmloff::token
;
54 using namespace ::com::sun::star::uno
;
55 using namespace ::com::sun::star::xml::sax
;
56 using namespace ::com::sun::star::beans
;
58 TYPEINIT1( XMLDocumentTransformerContext
, XMLTransformerContext
);
60 XMLDocumentTransformerContext::XMLDocumentTransformerContext( XMLTransformerBase
& rImp
,
61 const OUString
& rQName
) :
62 XMLTransformerContext( rImp
, rQName
)
66 XMLDocumentTransformerContext::~XMLDocumentTransformerContext()
70 void XMLDocumentTransformerContext::StartElement( const Reference
< XAttributeList
>& rAttrList
)
72 Reference
< XAttributeList
> xAttrList( rAttrList
);
74 sal_Bool bMimeFound
= sal_False
;
77 GetTransformer().GetNamespaceMap().GetQNameByKey(
78 XML_NAMESPACE_OFFICE
, GetXMLToken(XML_CLASS
) ) );
80 XMLMutableAttributeList
*pMutableAttrList
= 0;
81 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
82 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
84 const OUString
& rAttrName
= xAttrList
->getNameByIndex( i
);
87 GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
89 if( XML_NAMESPACE_OFFICE
== nPrefix
&&
90 IsXMLToken( aLocalName
, XML_MIMETYPE
) )
92 const OUString
& rValue
= xAttrList
->getValueByIndex( i
);
93 static const char * aTmp
[] =
95 "application/vnd.oasis.openoffice.",
96 "application/x-vnd.oasis.openoffice.",
97 "application/vnd.oasis.opendocument.",
98 "application/x-vnd.oasis.document.",
101 for (int k
=0; aTmp
[k
]; k
++)
103 ::rtl::OUString sTmpString
= ::rtl::OUString::createFromAscii(aTmp
[k
]);
104 if( rValue
.matchAsciiL( aTmp
[k
], sTmpString
.getLength() ) )
106 aClass
= rValue
.copy( sTmpString
.getLength() );
111 if( !pMutableAttrList
)
113 pMutableAttrList
= new XMLMutableAttributeList( xAttrList
);
114 xAttrList
= pMutableAttrList
;
116 pMutableAttrList
->SetValueByIndex( i
, aClass
);
117 pMutableAttrList
->RenameAttributeByIndex(i
, aClassQName
);
118 bMimeFound
= sal_True
;
125 const Reference
< XPropertySet
> rPropSet
=
126 GetTransformer().GetPropertySet();
130 Reference
< XPropertySetInfo
> xPropSetInfo(
131 rPropSet
->getPropertySetInfo() );
132 OUString
aPropName(RTL_CONSTASCII_USTRINGPARAM("Class"));
133 if( xPropSetInfo
.is() && xPropSetInfo
->hasPropertyByName( aPropName
) )
135 Any aAny
= rPropSet
->getPropertyValue( aPropName
);
140 if( aClass
.getLength() )
142 if( !pMutableAttrList
)
144 pMutableAttrList
= new XMLMutableAttributeList( xAttrList
);
145 xAttrList
= pMutableAttrList
;
148 pMutableAttrList
->AddAttribute( aClassQName
, aClass
);
151 XMLTransformerContext::StartElement( xAttrList
);