LibreOffice Module xmloff (master) 1
DocumentTContext.cxx
Go to the documentation of this file.
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/SAXException.hpp>
21#include <com/sun/star/xml/sax/XAttributeList.hpp>
22#include <com/sun/star/beans/XPropertySetInfo.hpp>
24#include <xmloff/xmltoken.hxx>
26
27#include "TransformerBase.hxx"
28#include "MutableAttrList.hxx"
29
30#include "DocumentTContext.hxx"
31
32
33using namespace ::xmloff::token;
34using namespace ::com::sun::star::uno;
35using namespace ::com::sun::star::xml::sax;
36using namespace ::com::sun::star::beans;
37
39 const OUString& rQName ) :
40 XMLTransformerContext( rImp, rQName )
41{
42}
43
44void XMLDocumentTransformerContext::StartElement( const Reference< XAttributeList >& rAttrList )
45{
46 Reference< XAttributeList > xAttrList( rAttrList );
47
48 bool bMimeFound = false;
49 OUString aClass;
50 OUString aClassQName(
51 GetTransformer().GetNamespaceMap().GetQNameByKey(
53
55 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
56 for( sal_Int16 i=0; i < nAttrCount; i++ )
57 {
58 const OUString& rAttrName = xAttrList->getNameByIndex( i );
59 OUString aLocalName;
60 sal_uInt16 nPrefix =
62 &aLocalName );
63 if( XML_NAMESPACE_OFFICE == nPrefix &&
64 IsXMLToken( aLocalName, XML_MIMETYPE ) )
65 {
66 const OUString& rValue = xAttrList->getValueByIndex( i );
67 static constexpr std::string_view aTmp[]
68 {
69 "application/vnd.oasis.openoffice.",
70 "application/x-vnd.oasis.openoffice.",
71 "application/vnd.oasis.opendocument.",
72 "application/x-vnd.oasis.document."
73 };
74 for (const auto & rPrefix : aTmp)
75 {
76 if( rValue.matchAsciiL( rPrefix.data(), rPrefix.size() ) )
77 {
78 aClass = rValue.copy( rPrefix.size() );
79 break;
80 }
81 }
82
83 if( !pMutableAttrList )
84 {
85 pMutableAttrList = new XMLMutableAttributeList( xAttrList );
86 xAttrList = pMutableAttrList;
87 }
88 pMutableAttrList->SetValueByIndex( i, aClass );
89 pMutableAttrList->RenameAttributeByIndex(i, aClassQName );
90 bMimeFound = true;
91 break;
92 }
93 }
94
95 if( !bMimeFound )
96 {
97 const Reference< XPropertySet > rPropSet =
99
100 if( rPropSet.is() )
101 {
102 Reference< XPropertySetInfo > xPropSetInfo(
103 rPropSet->getPropertySetInfo() );
104 OUString aPropName("Class");
105 if( xPropSetInfo.is() && xPropSetInfo->hasPropertyByName( aPropName ) )
106 {
107 Any aAny = rPropSet->getPropertyValue( aPropName );
108 aAny >>= aClass;
109 }
110 }
111
112 if( !aClass.isEmpty() )
113 {
114 if( !pMutableAttrList )
115 {
116 pMutableAttrList = new XMLMutableAttributeList( xAttrList );
117 xAttrList = pMutableAttrList;
118 }
119
120 pMutableAttrList->AddAttribute( aClassQName, aClass );
121 }
122 }
124}
125
126/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
XMLDocumentTransformerContext(XMLTransformerBase &rTransformer, const OUString &rQName)
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
const css::uno::Reference< css::beans::XPropertySet > & GetPropertySet() const
SvXMLNamespaceMap & GetNamespaceMap()
XMLTransformerBase & GetTransformer()
virtual void StartElement(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList)
int i
OUString aPropName
Handling of tokens in XML:
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3597
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3541
constexpr sal_uInt16 XML_NAMESPACE_OFFICE