LibreOffice Module vcl (master) 1
mcnttype.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 <sal/config.h>
21
22#include <com/sun/star/container/NoSuchElementException.hpp>
24#include <rtl/ustring.hxx>
25#include <tools/inetmime.hxx>
26
27#include "mcnttype.hxx"
28
29CMimeContentType::CMimeContentType( const OUString& aCntType )
30{
31 init( aCntType );
32}
33
35{
36 return m_MediaType;
37}
38
40{
41 return m_MediaSubtype;
42}
43
45{
46 return m_MediaType + "/" + m_MediaSubtype;
47}
48
49css::uno::Sequence< OUString > SAL_CALL CMimeContentType::getParameters( )
50{
52}
53
54sal_Bool SAL_CALL CMimeContentType::hasParameter( const OUString& aName )
55{
56 return ( m_ParameterMap.end( ) != m_ParameterMap.find( aName.toAsciiLowerCase() ) );
57}
58
59OUString SAL_CALL CMimeContentType::getParameterValue( const OUString& aName )
60{
61 auto const lower = aName.toAsciiLowerCase();
62
63 if ( !hasParameter( lower ) )
64 throw css::container::NoSuchElementException( );
65
66 return m_ParameterMap.find( lower )->second;
67}
68
69void CMimeContentType::init( const OUString& aCntType )
70{
73 != aCntType.getStr() + aCntType.getLength())
74 {
75 throw css::lang::IllegalArgumentException(
76 "illegal media type " + aCntType, css::uno::Reference<css::uno::XInterface>(), -1);
77 }
78 for (auto const & i: params) {
79 if (!i.second.m_bConverted) {
80 throw css::lang::IllegalArgumentException(
81 "illegal parameter value in media type " + aCntType,
82 css::uno::Reference<css::uno::XInterface>(), -1);
83 }
84 m_ParameterMap[OUString::fromUtf8(i.first)] = i.second.m_sValue;
85 }
86}
87
88/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::map< OUString, OUString > m_ParameterMap
Definition: mcnttype.hxx:55
virtual sal_Bool SAL_CALL hasParameter(const OUString &aName) override
Definition: mcnttype.cxx:54
virtual OUString SAL_CALL getFullMediaType() override
Definition: mcnttype.cxx:44
void init(const OUString &aCntType)
Definition: mcnttype.cxx:69
virtual OUString SAL_CALL getMediaSubtype() override
Definition: mcnttype.cxx:39
OUString m_MediaType
Definition: mcnttype.hxx:53
OUString m_MediaSubtype
Definition: mcnttype.hxx:54
virtual OUString SAL_CALL getParameterValue(const OUString &aName) override
Definition: mcnttype.cxx:59
virtual css::uno::Sequence< OUString > SAL_CALL getParameters() override
Definition: mcnttype.cxx:49
virtual OUString SAL_CALL getMediaType() override
Definition: mcnttype.cxx:34
CMimeContentType(const OUString &rCntType)
Definition: mcnttype.cxx:29
static sal_Unicode const * scanContentType(std::u16string_view rStr, OUString *pType=nullptr, OUString *pSubType=nullptr, INetContentTypeParameterList *pParameters=nullptr)
std::unordered_map< OString, INetContentTypeParameter > INetContentTypeParameterList
OUString aName
css::uno::Sequence< typename M::key_type > mapKeysToSequence(M const &map)
int i
unsigned char sal_Bool