Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / dtrans / source / cnttype / mcnttype.cxx
blob8b35abb231933efe0e4585244444e84f4a297ecf
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 <sal/config.h>
22 #include <com/sun/star/container/NoSuchElementException.hpp>
23 #include <comphelper/sequence.hxx>
24 #include <rtl/ustring.hxx>
25 #include <tools/inetmime.hxx>
27 #include "mcnttype.hxx"
29 using namespace com::sun::star::uno;
30 using namespace com::sun::star::container;
31 using namespace std;
33 CMimeContentType::CMimeContentType( const OUString& aCntType )
35 init( aCntType );
38 OUString SAL_CALL CMimeContentType::getMediaType( )
40 return m_MediaType;
43 OUString SAL_CALL CMimeContentType::getMediaSubtype( )
45 return m_MediaSubtype;
48 OUString SAL_CALL CMimeContentType::getFullMediaType( )
50 return m_MediaType + "/" + m_MediaSubtype;
53 Sequence< OUString > SAL_CALL CMimeContentType::getParameters( )
55 return comphelper::mapKeysToSequence(m_ParameterMap);
58 sal_Bool SAL_CALL CMimeContentType::hasParameter( const OUString& aName )
60 return ( m_ParameterMap.end( ) != m_ParameterMap.find( aName.toAsciiLowerCase() ) );
63 OUString SAL_CALL CMimeContentType::getParameterValue( const OUString& aName )
65 auto const lower = aName.toAsciiLowerCase();
67 if ( !hasParameter( lower ) )
68 throw NoSuchElementException( );
70 return m_ParameterMap.find( lower )->second;
73 void CMimeContentType::init( const OUString& aCntType )
75 INetContentTypeParameterList params;
76 if (INetMIME::scanContentType(aCntType, &m_MediaType, &m_MediaSubtype, &params)
77 != aCntType.getStr() + aCntType.getLength())
79 throw css::lang::IllegalArgumentException(
80 "illegal media type " + aCntType, css::uno::Reference<css::uno::XInterface>(), -1);
82 for (auto const & i: params) {
83 if (!i.second.m_bConverted) {
84 throw css::lang::IllegalArgumentException(
85 "illegal parameter value in media type " + aCntType,
86 css::uno::Reference<css::uno::XInterface>(), -1);
88 m_ParameterMap[OUString::fromUtf8(i.first)] = i.second.m_sValue;
92 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */