Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
28 :
29 : #include "TransformerBase.hxx"
30 : #include "MutableAttrList.hxx"
31 :
32 : #include "DocumentTContext.hxx"
33 :
34 :
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;
39 :
40 0 : TYPEINIT1( XMLDocumentTransformerContext, XMLTransformerContext );
41 :
42 2 : XMLDocumentTransformerContext::XMLDocumentTransformerContext( XMLTransformerBase& rImp,
43 : const OUString& rQName ) :
44 2 : XMLTransformerContext( rImp, rQName )
45 : {
46 2 : }
47 :
48 4 : XMLDocumentTransformerContext::~XMLDocumentTransformerContext()
49 : {
50 4 : }
51 :
52 2 : void XMLDocumentTransformerContext::StartElement( const Reference< XAttributeList >& rAttrList )
53 : {
54 2 : Reference< XAttributeList > xAttrList( rAttrList );
55 :
56 2 : bool bMimeFound = false;
57 4 : OUString aClass;
58 : OUString aClassQName(
59 2 : GetTransformer().GetNamespaceMap().GetQNameByKey(
60 6 : XML_NAMESPACE_OFFICE, GetXMLToken(XML_CLASS ) ) );
61 :
62 2 : XMLMutableAttributeList *pMutableAttrList = 0;
63 2 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
64 82 : for( sal_Int16 i=0; i < nAttrCount; i++ )
65 : {
66 82 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
67 162 : OUString aLocalName;
68 : sal_uInt16 nPrefix =
69 82 : GetTransformer().GetNamespaceMap().GetKeyByAttrName( rAttrName,
70 82 : &aLocalName );
71 86 : if( XML_NAMESPACE_OFFICE == nPrefix &&
72 4 : IsXMLToken( aLocalName, XML_MIMETYPE ) )
73 : {
74 2 : const OUString& rValue = xAttrList->getValueByIndex( i );
75 : static const char * aTmp[] =
76 : {
77 : "application/vnd.oasis.openoffice.",
78 : "application/x-vnd.oasis.openoffice.",
79 : "application/vnd.oasis.opendocument.",
80 : "application/x-vnd.oasis.document.",
81 : NULL
82 : };
83 6 : for (int k=0; aTmp[k]; k++)
84 : {
85 6 : OUString sTmpString = OUString::createFromAscii(aTmp[k]);
86 6 : if( rValue.matchAsciiL( aTmp[k], sTmpString.getLength() ) )
87 : {
88 2 : aClass = rValue.copy( sTmpString.getLength() );
89 2 : break;
90 : }
91 4 : }
92 :
93 2 : if( !pMutableAttrList )
94 : {
95 2 : pMutableAttrList = new XMLMutableAttributeList( xAttrList );
96 2 : xAttrList = pMutableAttrList;
97 : }
98 2 : pMutableAttrList->SetValueByIndex( i, aClass );
99 2 : pMutableAttrList->RenameAttributeByIndex(i, aClassQName );
100 2 : bMimeFound = true;
101 2 : break;
102 : }
103 80 : }
104 :
105 2 : if( !bMimeFound )
106 : {
107 : const Reference< XPropertySet > rPropSet =
108 0 : GetTransformer().GetPropertySet();
109 :
110 0 : if( rPropSet.is() )
111 : {
112 : Reference< XPropertySetInfo > xPropSetInfo(
113 0 : rPropSet->getPropertySetInfo() );
114 0 : OUString aPropName("Class");
115 0 : if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName( aPropName ) )
116 : {
117 0 : Any aAny = rPropSet->getPropertyValue( aPropName );
118 0 : aAny >>= aClass;
119 0 : }
120 : }
121 :
122 0 : if( !aClass.isEmpty() )
123 : {
124 0 : if( !pMutableAttrList )
125 : {
126 0 : pMutableAttrList = new XMLMutableAttributeList( xAttrList );
127 0 : xAttrList = pMutableAttrList;
128 : }
129 :
130 0 : pMutableAttrList->AddAttribute( aClassQName, aClass );
131 0 : }
132 : }
133 4 : XMLTransformerContext::StartElement( xAttrList );
134 2 : }
135 :
136 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|