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