summaryrefslogtreecommitdiffstats
path: root/vcl/source/cnttype
diff options
context:
space:
mode:
Diffstat (limited to 'vcl/source/cnttype')
-rw-r--r--vcl/source/cnttype/mcnttfactory.cxx67
-rw-r--r--vcl/source/cnttype/mcnttfactory.hxx49
-rw-r--r--vcl/source/cnttype/mcnttype.cxx88
-rw-r--r--vcl/source/cnttype/mcnttype.hxx58
4 files changed, 262 insertions, 0 deletions
diff --git a/vcl/source/cnttype/mcnttfactory.cxx b/vcl/source/cnttype/mcnttfactory.cxx
new file mode 100644
index 000000000..4a3e6fbb4
--- /dev/null
+++ b/vcl/source/cnttype/mcnttfactory.cxx
@@ -0,0 +1,67 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <cppuhelper/supportsservice.hxx>
+#include <com/sun/star/uno/XComponentContext.hpp>
+#include "mcnttfactory.hxx"
+#include "mcnttype.hxx"
+
+using namespace ::osl;
+using namespace ::cppu;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::lang;
+using namespace com::sun::star::datatransfer;
+
+CMimeContentTypeFactory::CMimeContentTypeFactory()
+{
+}
+
+Reference< XMimeContentType > CMimeContentTypeFactory::createMimeContentType( const OUString& aContentType )
+{
+ return Reference< XMimeContentType >( new CMimeContentType( aContentType ) );
+}
+
+// XServiceInfo
+
+OUString SAL_CALL CMimeContentTypeFactory::getImplementationName( )
+{
+ return "com.sun.star.datatransfer.MimeCntTypeFactory";
+}
+
+sal_Bool SAL_CALL CMimeContentTypeFactory::supportsService( const OUString& ServiceName )
+{
+ return cppu::supportsService(this, ServiceName);
+}
+
+Sequence< OUString > SAL_CALL CMimeContentTypeFactory::getSupportedServiceNames( )
+{
+ return { "com.sun.star.datatransfer.MimeContentTypeFactory" };
+}
+
+
+// returns a factory to create XFilePicker-Services
+
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+dtrans_CMimeContentTypeFactory_get_implementation(
+ css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
+{
+ return cppu::acquire( new CMimeContentTypeFactory() );
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/cnttype/mcnttfactory.hxx b/vcl/source/cnttype/mcnttfactory.hxx
new file mode 100644
index 000000000..c9bd3518c
--- /dev/null
+++ b/vcl/source/cnttype/mcnttfactory.hxx
@@ -0,0 +1,49 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <rtl/ustring.hxx>
+#include <sal/types.h>
+#include <cppuhelper/implbase.hxx>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/datatransfer/XMimeContentTypeFactory.hpp>
+
+class CMimeContentTypeFactory : public
+ cppu::WeakImplHelper< css::datatransfer::XMimeContentTypeFactory,
+ css::lang::XServiceInfo >
+{
+
+public:
+ CMimeContentTypeFactory();
+
+ // XMimeContentTypeFactory
+
+ virtual css::uno::Reference< css::datatransfer::XMimeContentType > SAL_CALL createMimeContentType( const OUString& aContentType ) override;
+
+ // XServiceInfo
+
+ virtual OUString SAL_CALL getImplementationName( ) override;
+
+ virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
+
+ virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/cnttype/mcnttype.cxx b/vcl/source/cnttype/mcnttype.cxx
new file mode 100644
index 000000000..f41f5d25e
--- /dev/null
+++ b/vcl/source/cnttype/mcnttype.cxx
@@ -0,0 +1,88 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <sal/config.h>
+
+#include <com/sun/star/container/NoSuchElementException.hpp>
+#include <comphelper/sequence.hxx>
+#include <rtl/ustring.hxx>
+#include <tools/inetmime.hxx>
+
+#include "mcnttype.hxx"
+
+CMimeContentType::CMimeContentType( const OUString& aCntType )
+{
+ init( aCntType );
+}
+
+OUString SAL_CALL CMimeContentType::getMediaType( )
+{
+ return m_MediaType;
+}
+
+OUString SAL_CALL CMimeContentType::getMediaSubtype( )
+{
+ return m_MediaSubtype;
+}
+
+OUString SAL_CALL CMimeContentType::getFullMediaType( )
+{
+ return m_MediaType + "/" + m_MediaSubtype;
+}
+
+css::uno::Sequence< OUString > SAL_CALL CMimeContentType::getParameters( )
+{
+ return comphelper::mapKeysToSequence(m_ParameterMap);
+}
+
+sal_Bool SAL_CALL CMimeContentType::hasParameter( const OUString& aName )
+{
+ return ( m_ParameterMap.end( ) != m_ParameterMap.find( aName.toAsciiLowerCase() ) );
+}
+
+OUString SAL_CALL CMimeContentType::getParameterValue( const OUString& aName )
+{
+ auto const lower = aName.toAsciiLowerCase();
+
+ if ( !hasParameter( lower ) )
+ throw css::container::NoSuchElementException( );
+
+ return m_ParameterMap.find( lower )->second;
+}
+
+void CMimeContentType::init( const OUString& aCntType )
+{
+ INetContentTypeParameterList params;
+ if (INetMIME::scanContentType(aCntType, &m_MediaType, &m_MediaSubtype, &params)
+ != aCntType.getStr() + aCntType.getLength())
+ {
+ throw css::lang::IllegalArgumentException(
+ "illegal media type " + aCntType, css::uno::Reference<css::uno::XInterface>(), -1);
+ }
+ for (auto const & i: params) {
+ if (!i.second.m_bConverted) {
+ throw css::lang::IllegalArgumentException(
+ "illegal parameter value in media type " + aCntType,
+ css::uno::Reference<css::uno::XInterface>(), -1);
+ }
+ m_ParameterMap[OUString::fromUtf8(i.first)] = i.second.m_sValue;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/cnttype/mcnttype.hxx b/vcl/source/cnttype/mcnttype.hxx
new file mode 100644
index 000000000..c4053066b
--- /dev/null
+++ b/vcl/source/cnttype/mcnttype.hxx
@@ -0,0 +1,58 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <cppuhelper/implbase.hxx>
+#include <rtl/ustring.hxx>
+#include <sal/types.h>
+#include <com/sun/star/lang/IllegalArgumentException.hpp>
+#include <com/sun/star/datatransfer/XMimeContentType.hpp>
+
+#include <map>
+
+class CMimeContentType : public
+ cppu::WeakImplHelper< css::datatransfer::XMimeContentType >
+{
+public:
+ explicit CMimeContentType(const OUString& rCntType);
+
+ // XMimeContentType
+
+ virtual OUString SAL_CALL getMediaType( ) override;
+ virtual OUString SAL_CALL getMediaSubtype( ) override;
+ virtual OUString SAL_CALL getFullMediaType( ) override;
+
+ virtual css::uno::Sequence< OUString > SAL_CALL getParameters( ) override;
+
+ virtual sal_Bool SAL_CALL hasParameter( const OUString& aName ) override;
+
+ virtual OUString SAL_CALL getParameterValue( const OUString& aName ) override;
+
+private:
+ /// @throws css::lang::IllegalArgumentException
+ void init( const OUString& aCntType );
+
+private:
+ OUString m_MediaType;
+ OUString m_MediaSubtype;
+ std::map< OUString, OUString > m_ParameterMap;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */