diff --git a/Repository.mk b/Repository.mk index 46d2783786e4..a02d3d65981e 100644 --- a/Repository.mk +++ b/Repository.mk @@ -327,6 +327,7 @@ $(eval $(call gb_Helper_register_libraries_for_install,OOOLIBS,ooo, \ sot \ spell \ $(if $(ENABLE_HEADLESS),,spl) \ + storagefd \ $(if $(DISABLE_SCRIPTING),,stringresource) \ svgio \ svl \ diff --git a/filter/Library_storagefd.mk b/filter/Library_storagefd.mk new file mode 100644 index 000000000000..5b05e7e5c4ee --- /dev/null +++ b/filter/Library_storagefd.mk @@ -0,0 +1,36 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +#************************************************************************* +# +# 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/. +# +#************************************************************************* + +$(eval $(call gb_Library_Library,storagefd)) + +$(eval $(call gb_Library_set_componentfile,storagefd,filter/source/storagefilterdetect/storagefd)) + +$(eval $(call gb_Library_use_external,storagefd,boost_headers)) + +$(eval $(call gb_Library_use_sdk_api,storagefd)) + +$(eval $(call gb_Library_use_libraries,storagefd,\ + comphelper \ + cppuhelper \ + cppu \ + sal \ + sfx \ + tl \ + utl \ + $(gb_UWINAPI) \ +)) + +$(eval $(call gb_Library_add_exception_objects,storagefd,\ + filter/source/storagefilterdetect/fdcomp \ + filter/source/storagefilterdetect/filterdetect \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/filter/Module_filter.mk b/filter/Module_filter.mk index 1cb203f8bd30..3558f449e62d 100644 --- a/filter/Module_filter.mk +++ b/filter/Module_filter.mk @@ -50,6 +50,7 @@ $(eval $(call gb_Module_add_targets,filter,\ Library_odfflatxml \ Library_pdffilter \ Library_placeware \ + Library_storagefd \ Library_svgfilter \ Library_graphicfilter \ Library_t602filter \ diff --git a/filter/source/config/fragments/types/calc8.xcu b/filter/source/config/fragments/types/calc8.xcu index 40d87cdfd5cf..1abd38ef7f0f 100644 --- a/filter/source/config/fragments/types/calc8.xcu +++ b/filter/source/config/fragments/types/calc8.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - com.sun.star.comp.calc.FormatDetector + com.sun.star.comp.filters.StorageFilterDetect private:factory/scalc* ods application/vnd.oasis.opendocument.spreadsheet diff --git a/filter/source/config/fragments/types/calc8_template.xcu b/filter/source/config/fragments/types/calc8_template.xcu index d99d45b53ce1..293283bb400d 100644 --- a/filter/source/config/fragments/types/calc8_template.xcu +++ b/filter/source/config/fragments/types/calc8_template.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - com.sun.star.comp.calc.FormatDetector + com.sun.star.comp.filters.StorageFilterDetect ots application/vnd.oasis.opendocument.spreadsheet-template diff --git a/filter/source/config/fragments/types/calc_StarOffice_XML_Calc.xcu b/filter/source/config/fragments/types/calc_StarOffice_XML_Calc.xcu index 4b998c4402b6..79e57ae8179c 100644 --- a/filter/source/config/fragments/types/calc_StarOffice_XML_Calc.xcu +++ b/filter/source/config/fragments/types/calc_StarOffice_XML_Calc.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - com.sun.star.comp.calc.FormatDetector + com.sun.star.comp.filters.StorageFilterDetect sxc application/vnd.sun.xml.calc diff --git a/filter/source/config/fragments/types/calc_StarOffice_XML_Calc_Template.xcu b/filter/source/config/fragments/types/calc_StarOffice_XML_Calc_Template.xcu index 0de78f4fd03f..df5f7374122a 100644 --- a/filter/source/config/fragments/types/calc_StarOffice_XML_Calc_Template.xcu +++ b/filter/source/config/fragments/types/calc_StarOffice_XML_Calc_Template.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - com.sun.star.comp.calc.FormatDetector + com.sun.star.comp.filters.StorageFilterDetect stc application/vnd.sun.xml.calc.template diff --git a/filter/source/config/fragments/types/chart8.xcu b/filter/source/config/fragments/types/chart8.xcu index 59f0d0c38504..fb4a1f615fb8 100644 --- a/filter/source/config/fragments/types/chart8.xcu +++ b/filter/source/config/fragments/types/chart8.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - + com.sun.star.comp.filters.StorageFilterDetect private:factory/schart* odc application/vnd.oasis.opendocument.chart diff --git a/filter/source/config/fragments/types/chart_StarOffice_XML_Chart.xcu b/filter/source/config/fragments/types/chart_StarOffice_XML_Chart.xcu index bacd5d3da5f7..1292786f81e8 100644 --- a/filter/source/config/fragments/types/chart_StarOffice_XML_Chart.xcu +++ b/filter/source/config/fragments/types/chart_StarOffice_XML_Chart.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - + com.sun.star.comp.filters.StorageFilterDetect sxs application/vnd.sun.xml.chart diff --git a/filter/source/config/fragments/types/draw8.xcu b/filter/source/config/fragments/types/draw8.xcu index 3637cc95c0ea..d06dc3a66c93 100644 --- a/filter/source/config/fragments/types/draw8.xcu +++ b/filter/source/config/fragments/types/draw8.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - com.sun.star.comp.draw.FormatDetector + com.sun.star.comp.filters.StorageFilterDetect private:factory/sdraw* odg application/vnd.oasis.opendocument.graphics diff --git a/filter/source/config/fragments/types/draw8_template.xcu b/filter/source/config/fragments/types/draw8_template.xcu index bf8f58f6aee2..b20422ad49d6 100644 --- a/filter/source/config/fragments/types/draw8_template.xcu +++ b/filter/source/config/fragments/types/draw8_template.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - com.sun.star.comp.draw.FormatDetector + com.sun.star.comp.filters.StorageFilterDetect otg application/vnd.oasis.opendocument.graphics-template diff --git a/filter/source/config/fragments/types/draw_StarOffice_XML_Draw.xcu b/filter/source/config/fragments/types/draw_StarOffice_XML_Draw.xcu index 1a34933e573a..d2a4f1f6af5e 100644 --- a/filter/source/config/fragments/types/draw_StarOffice_XML_Draw.xcu +++ b/filter/source/config/fragments/types/draw_StarOffice_XML_Draw.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - com.sun.star.comp.draw.FormatDetector + com.sun.star.comp.filters.StorageFilterDetect sxd application/vnd.sun.xml.draw diff --git a/filter/source/config/fragments/types/draw_StarOffice_XML_Draw_Template.xcu b/filter/source/config/fragments/types/draw_StarOffice_XML_Draw_Template.xcu index 2e1b9e72ab38..fcbb470d7c75 100644 --- a/filter/source/config/fragments/types/draw_StarOffice_XML_Draw_Template.xcu +++ b/filter/source/config/fragments/types/draw_StarOffice_XML_Draw_Template.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - com.sun.star.comp.draw.FormatDetector + com.sun.star.comp.filters.StorageFilterDetect std application/vnd.sun.xml.draw.template diff --git a/filter/source/config/fragments/types/impress8.xcu b/filter/source/config/fragments/types/impress8.xcu index cd3fb6752b9e..693535503899 100644 --- a/filter/source/config/fragments/types/impress8.xcu +++ b/filter/source/config/fragments/types/impress8.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - com.sun.star.comp.draw.FormatDetector + com.sun.star.comp.filters.StorageFilterDetect private:factory/simpress* odp application/vnd.oasis.opendocument.presentation diff --git a/filter/source/config/fragments/types/impress8_template.xcu b/filter/source/config/fragments/types/impress8_template.xcu index 02e7e592823a..5c3170a97fd4 100644 --- a/filter/source/config/fragments/types/impress8_template.xcu +++ b/filter/source/config/fragments/types/impress8_template.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - com.sun.star.comp.draw.FormatDetector + com.sun.star.comp.filters.StorageFilterDetect otp application/vnd.oasis.opendocument.presentation-template diff --git a/filter/source/config/fragments/types/impress_StarOffice_XML_Impress.xcu b/filter/source/config/fragments/types/impress_StarOffice_XML_Impress.xcu index 4e39cd8d2e72..311c43b66888 100644 --- a/filter/source/config/fragments/types/impress_StarOffice_XML_Impress.xcu +++ b/filter/source/config/fragments/types/impress_StarOffice_XML_Impress.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - com.sun.star.comp.draw.FormatDetector + com.sun.star.comp.filters.StorageFilterDetect sxi application/vnd.sun.xml.impress diff --git a/filter/source/config/fragments/types/impress_StarOffice_XML_Impress_Template.xcu b/filter/source/config/fragments/types/impress_StarOffice_XML_Impress_Template.xcu index 4a2f7065949a..2df7deae8936 100644 --- a/filter/source/config/fragments/types/impress_StarOffice_XML_Impress_Template.xcu +++ b/filter/source/config/fragments/types/impress_StarOffice_XML_Impress_Template.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - com.sun.star.comp.draw.FormatDetector + com.sun.star.comp.filters.StorageFilterDetect sti application/vnd.sun.xml.impress.template diff --git a/filter/source/config/fragments/types/math8.xcu b/filter/source/config/fragments/types/math8.xcu index 159d49efe80d..8c90554d39f1 100644 --- a/filter/source/config/fragments/types/math8.xcu +++ b/filter/source/config/fragments/types/math8.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - com.sun.star.comp.math.FormatDetector + com.sun.star.comp.filters.StorageFilterDetect private:factory/smath* odf application/vnd.oasis.opendocument.formula diff --git a/filter/source/config/fragments/types/math_StarOffice_XML_Math.xcu b/filter/source/config/fragments/types/math_StarOffice_XML_Math.xcu index 051c381aa92f..c1d31ac8d3c1 100644 --- a/filter/source/config/fragments/types/math_StarOffice_XML_Math.xcu +++ b/filter/source/config/fragments/types/math_StarOffice_XML_Math.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - com.sun.star.comp.math.FormatDetector + com.sun.star.comp.filters.StorageFilterDetect sxm application/vnd.sun.xml.math diff --git a/filter/source/config/fragments/types/writer8.xcu b/filter/source/config/fragments/types/writer8.xcu index 7ba69bb20b17..c5cf5dd4e5b3 100644 --- a/filter/source/config/fragments/types/writer8.xcu +++ b/filter/source/config/fragments/types/writer8.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - com.sun.star.text.FormatDetector + com.sun.star.comp.filters.StorageFilterDetect private:factory/swriter odt application/vnd.oasis.opendocument.text diff --git a/filter/source/config/fragments/types/writer8_template.xcu b/filter/source/config/fragments/types/writer8_template.xcu index 055b351eba13..eeb4b3512629 100644 --- a/filter/source/config/fragments/types/writer8_template.xcu +++ b/filter/source/config/fragments/types/writer8_template.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - com.sun.star.text.FormatDetector + com.sun.star.comp.filters.StorageFilterDetect ott application/vnd.oasis.opendocument.text-template diff --git a/filter/source/config/fragments/types/writer_StarOffice_XML_Writer.xcu b/filter/source/config/fragments/types/writer_StarOffice_XML_Writer.xcu index 34db4e33e7b8..e8dd8c275922 100644 --- a/filter/source/config/fragments/types/writer_StarOffice_XML_Writer.xcu +++ b/filter/source/config/fragments/types/writer_StarOffice_XML_Writer.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - com.sun.star.text.FormatDetector + com.sun.star.comp.filters.StorageFilterDetect sxw application/vnd.sun.xml.writer diff --git a/filter/source/config/fragments/types/writer_StarOffice_XML_Writer_Template.xcu b/filter/source/config/fragments/types/writer_StarOffice_XML_Writer_Template.xcu index 201d00bdb245..b5b19b58eeb8 100644 --- a/filter/source/config/fragments/types/writer_StarOffice_XML_Writer_Template.xcu +++ b/filter/source/config/fragments/types/writer_StarOffice_XML_Writer_Template.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - com.sun.star.text.FormatDetector + com.sun.star.comp.filters.StorageFilterDetect stw application/vnd.sun.xml.writer.template diff --git a/filter/source/config/fragments/types/writer_globaldocument_StarOffice_XML_Writer_GlobalDocument.xcu b/filter/source/config/fragments/types/writer_globaldocument_StarOffice_XML_Writer_GlobalDocument.xcu index f84fb074abbe..e920809e6622 100644 --- a/filter/source/config/fragments/types/writer_globaldocument_StarOffice_XML_Writer_GlobalDocument.xcu +++ b/filter/source/config/fragments/types/writer_globaldocument_StarOffice_XML_Writer_GlobalDocument.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - com.sun.star.text.FormatDetector + com.sun.star.comp.filters.StorageFilterDetect sxg application/vnd.sun.xml.writer.global diff --git a/filter/source/config/fragments/types/writer_web_StarOffice_XML_Writer_Web_Template.xcu b/filter/source/config/fragments/types/writer_web_StarOffice_XML_Writer_Web_Template.xcu index f7bd56357cc2..e81eebb289a5 100644 --- a/filter/source/config/fragments/types/writer_web_StarOffice_XML_Writer_Web_Template.xcu +++ b/filter/source/config/fragments/types/writer_web_StarOffice_XML_Writer_Web_Template.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - com.sun.star.text.FormatDetector + com.sun.star.comp.filters.StorageFilterDetect stw application/vnd.sun.xml.writer.web diff --git a/filter/source/config/fragments/types/writerglobal8.xcu b/filter/source/config/fragments/types/writerglobal8.xcu index 6248bc7b3f50..089e31661f5c 100644 --- a/filter/source/config/fragments/types/writerglobal8.xcu +++ b/filter/source/config/fragments/types/writerglobal8.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - com.sun.star.text.FormatDetector + com.sun.star.comp.filters.StorageFilterDetect private:factory/swriter/GlobalDocument* odm application/vnd.oasis.opendocument.text-master diff --git a/filter/source/config/fragments/types/writerweb8_writer_template.xcu b/filter/source/config/fragments/types/writerweb8_writer_template.xcu index 30aef7350b0e..9d1ace8ed9bd 100644 --- a/filter/source/config/fragments/types/writerweb8_writer_template.xcu +++ b/filter/source/config/fragments/types/writerweb8_writer_template.xcu @@ -16,7 +16,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - com.sun.star.text.FormatDetector + com.sun.star.comp.filters.StorageFilterDetect oth application/vnd.oasis.opendocument.text-web diff --git a/filter/source/storagefilterdetect/fdcomp.cxx b/filter/source/storagefilterdetect/fdcomp.cxx new file mode 100644 index 000000000000..ec2d9052e04d --- /dev/null +++ b/filter/source/storagefilterdetect/fdcomp.cxx @@ -0,0 +1,36 @@ +/* -*- 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/. + */ + +#include + +#include +#include +#include + +#include "filterdetect.hxx" + +namespace { + +static cppu::ImplementationEntry const services[] = { + { &StorageFilterDetect_createInstance, &StorageFilterDetect_getImplementationName, + &StorageFilterDetect_getSupportedServiceNames, + &cppu::createSingleComponentFactory, 0, 0 }, + { 0, 0, 0, 0, 0, 0 } +}; + +} + +extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL storagefd_component_getFactory( + char const * pImplName, void * pServiceManager, void * pRegistryKey) +{ + return cppu::component_getFactoryHelper( + pImplName, pServiceManager, pRegistryKey, services); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/filter/source/storagefilterdetect/filterdetect.cxx b/filter/source/storagefilterdetect/filterdetect.cxx new file mode 100644 index 000000000000..591726119bb0 --- /dev/null +++ b/filter/source/storagefilterdetect/filterdetect.cxx @@ -0,0 +1,208 @@ +/* -*- 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 "filterdetect.hxx" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +using namespace ::com::sun::star; +using utl::MediaDescriptor; + +namespace { + +OUString getInternalFromMediaType(const OUString& aMediaType) +{ + // OpenDocument types + if ( aMediaType == MIMETYPE_OASIS_OPENDOCUMENT_TEXT_ASCII ) return OUString("writer8"); + else if ( aMediaType == MIMETYPE_OASIS_OPENDOCUMENT_TEXT_TEMPLATE_ASCII ) return OUString("writer8_template"); + else if ( aMediaType == MIMETYPE_OASIS_OPENDOCUMENT_TEXT_WEB_ASCII ) return OUString("writerweb8_writer_template"); + else if ( aMediaType == MIMETYPE_OASIS_OPENDOCUMENT_TEXT_GLOBAL_ASCII ) return OUString("writerglobal8"); + else if ( aMediaType == MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_ASCII ) return OUString("draw8"); + else if ( aMediaType == MIMETYPE_OASIS_OPENDOCUMENT_DRAWING_TEMPLATE_ASCII ) return OUString("draw8_template"); + else if ( aMediaType == MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_ASCII ) return OUString("impress8"); + else if ( aMediaType == MIMETYPE_OASIS_OPENDOCUMENT_PRESENTATION_TEMPLATE_ASCII ) return OUString("impress8_template"); + else if ( aMediaType == MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_ASCII ) return OUString("calc8"); + else if ( aMediaType == MIMETYPE_OASIS_OPENDOCUMENT_SPREADSHEET_TEMPLATE_ASCII ) return OUString("calc8_template"); + else if ( aMediaType == MIMETYPE_OASIS_OPENDOCUMENT_CHART_ASCII ) return OUString("chart8"); + else if ( aMediaType == MIMETYPE_OASIS_OPENDOCUMENT_FORMULA_ASCII ) return OUString("math8"); + else if ( aMediaType == MIMETYPE_OASIS_OPENDOCUMENT_REPORT_CHART_ASCII ) return OUString("StarBaseReportChart"); + + // OOo legacy types + else if ( aMediaType == MIMETYPE_VND_SUN_XML_WRITER_ASCII ) return OUString("writer_StarOffice_XML_Writer"); + else if ( aMediaType == MIMETYPE_VND_SUN_XML_WRITER_TEMPLATE_ASCII ) return OUString("writer_StarOffice_XML_Writer_Template"); + else if ( aMediaType == MIMETYPE_VND_SUN_XML_WRITER_WEB_ASCII ) return OUString("writer_web_StarOffice_XML_Writer_Web_Template"); + else if ( aMediaType == MIMETYPE_VND_SUN_XML_WRITER_GLOBAL_ASCII ) return OUString("writer_globaldocument_StarOffice_XML_Writer_GlobalDocument"); + else if ( aMediaType == MIMETYPE_VND_SUN_XML_DRAW_ASCII ) return OUString("draw_StarOffice_XML_Draw"); + else if ( aMediaType == MIMETYPE_VND_SUN_XML_DRAW_TEMPLATE_ASCII ) return OUString("draw_StarOffice_XML_Draw_Template"); + else if ( aMediaType == MIMETYPE_VND_SUN_XML_IMPRESS_ASCII ) return OUString("impress_StarOffice_XML_Impress"); + else if ( aMediaType == MIMETYPE_VND_SUN_XML_IMPRESS_TEMPLATE_ASCII ) return OUString("impress_StarOffice_XML_Impress_Template"); + else if ( aMediaType == MIMETYPE_VND_SUN_XML_CALC_ASCII ) return OUString("calc_StarOffice_XML_Calc"); + else if ( aMediaType == MIMETYPE_VND_SUN_XML_CALC_TEMPLATE_ASCII ) return OUString("calc_StarOffice_XML_Calc_Template"); + else if ( aMediaType == MIMETYPE_VND_SUN_XML_CHART_ASCII ) return OUString("chart_StarOffice_XML_Chart"); + else if ( aMediaType == MIMETYPE_VND_SUN_XML_MATH_ASCII ) return OUString("math_StarOffice_XML_Math"); + + // Unknown type + return OUString(); +} + +} + +StorageFilterDetect::StorageFilterDetect(const uno::Reference& xCxt) : + mxCxt(xCxt) {} + +StorageFilterDetect::~StorageFilterDetect() {} + +OUString SAL_CALL StorageFilterDetect::detect(uno::Sequence& rDescriptor) + throw (uno::RuntimeException, std::exception) +{ + MediaDescriptor aMediaDesc( rDescriptor ); + OUString aTypeName; + + try + { + uno::Reference< io::XInputStream > xInStream( aMediaDesc[MediaDescriptor::PROP_INPUTSTREAM()], uno::UNO_QUERY ); + if ( !xInStream.is() ) + return OUString(); + + uno::Reference< embed::XStorage > xStorage( ::comphelper::OStorageHelper::GetStorageFromInputStream( xInStream, mxCxt ), uno::UNO_QUERY ); + if ( !xStorage.is() ) + return OUString(); + + uno::Reference< beans::XPropertySet > xStorageProperties( xStorage, uno::UNO_QUERY ); + if ( !xStorageProperties.is() ) + return OUString(); + + OUString aMediaType; + xStorageProperties->getPropertyValue( "MediaType" ) >>= aMediaType; + aTypeName = getInternalFromMediaType( aMediaType ); + } + + catch( const lang::WrappedTargetException& aWrap ) + { + packages::zip::ZipIOException aZipException; + // We don't do any type detection on broken packages (f.e. because it might be impossible), + // so for repairing we'll use the requested type, which was detected by the flat detection. + OUString aRequestedTypeName = aMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_TYPENAME(), OUString() ); + if ( ( aWrap.TargetException >>= aZipException ) && !aRequestedTypeName.isEmpty() ) + { + // The package is a broken one. + uno::Reference< task::XInteractionHandler > xInteraction = + aMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_INTERACTIONHANDLER(), uno::Reference< task::XInteractionHandler >() ); + + if ( xInteraction.is() ) + { + INetURLObject aParser( aMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_URL(), OUString() ) ); + OUString aDocumentTitle = aParser.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ); + bool bRepairPackage = aMediaDesc.getUnpackedValueOrDefault( "RepairPackage", false ); + // fdo#46310 Don't try to repair if the user rejected it once. + bool bRepairAllowed = aMediaDesc.getUnpackedValueOrDefault( "RepairAllowed", true ); + + if ( !bRepairPackage && bRepairAllowed ) + { + // Ask the user whether he wants to try to repair. + RequestPackageReparation aRequest( aDocumentTitle ); + xInteraction->handle( aRequest.GetRequest() ); + + if ( aRequest.isApproved() ) + { + aTypeName = aRequestedTypeName; + aMediaDesc[MediaDescriptor::PROP_DOCUMENTTITLE()] <<= aDocumentTitle; + aMediaDesc[MediaDescriptor::PROP_ASTEMPLATE()] <<= true; + aMediaDesc["RepairPackage"] <<= true; + } + else + { + // Repair either not allowed or not successful. + NotifyBrokenPackage aNotifyRequest( aDocumentTitle ); + xInteraction->handle( aNotifyRequest.GetRequest() ); + aMediaDesc["RepairAllowed"] <<= false; + } + + // Write the changes back. + aMediaDesc >> rDescriptor; + } + } + } + } + catch( uno::RuntimeException& ) + { + throw; + } + catch( uno::Exception& ) + {} + + return aTypeName; +} + +// XInitialization +void SAL_CALL StorageFilterDetect::initialize(const uno::Sequence& /*aArguments*/) + throw (uno::Exception, uno::RuntimeException, std::exception) {} + +OUString StorageFilterDetect_getImplementationName() +{ + return OUString("com.sun.star.comp.filters.StorageFilterDetect"); +} + +uno::Sequence StorageFilterDetect_getSupportedServiceNames() +{ + uno::Sequence aRet(2); + OUString* pArray = aRet.getArray(); + pArray[0] = "com.sun.star.document.ExtendedTypeDetection"; + pArray[1] = "com.sun.star.comp.filters.StorageFilterDetect"; + return aRet; +} + +uno::Reference StorageFilterDetect_createInstance( + const uno::Reference & rCxt) +{ + return static_cast(new StorageFilterDetect(rCxt)); +} + +// XServiceInfo +OUString SAL_CALL StorageFilterDetect::getImplementationName() + throw (uno::RuntimeException, std::exception) +{ + return StorageFilterDetect_getImplementationName(); +} + +sal_Bool SAL_CALL StorageFilterDetect::supportsService(const OUString& rServiceName) + throw (uno::RuntimeException, std::exception) +{ + return cppu::supportsService(this, rServiceName); +} + +uno::Sequence SAL_CALL StorageFilterDetect::getSupportedServiceNames() + throw (uno::RuntimeException, std::exception) +{ + return StorageFilterDetect_getSupportedServiceNames(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/filter/source/storagefilterdetect/filterdetect.hxx b/filter/source/storagefilterdetect/filterdetect.hxx new file mode 100644 index 000000000000..385d3c011478 --- /dev/null +++ b/filter/source/storagefilterdetect/filterdetect.hxx @@ -0,0 +1,72 @@ +/* -*- 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 . + */ + +#ifndef INCLUDED_FILTER_SOURCE_STORAGEFILTERDETECT_FILTERDETECT_HXX +#define INCLUDED_FILTER_SOURCE_STORAGEFILTERDETECT_FILTERDETECT_HXX + +#include +#include +#include +#include + +#include + +class StorageFilterDetect : public cppu::WeakImplHelper3< + com::sun::star::document::XExtendedFilterDetection, + com::sun::star::lang::XInitialization, + com::sun::star::lang::XServiceInfo> +{ + com::sun::star::uno::Reference mxCxt; + +public: + + StorageFilterDetect (const com::sun::star::uno::Reference& xCxt); + virtual ~StorageFilterDetect(); + + // XExtendedFilterDetection + virtual OUString SAL_CALL detect(com::sun::star::uno::Sequence& rDescriptor) + throw( com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE; + + // XInitialization + virtual void SAL_CALL initialize(const ::com::sun::star::uno::Sequence& aArguments) + throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() + throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) + throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; + + virtual com::sun::star::uno::Sequence SAL_CALL getSupportedServiceNames() + throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE; +}; + +OUString StorageFilterDetect_getImplementationName(); + +sal_Bool StorageFilterDetect_supportsService(const OUString& ServiceName); + +com::sun::star::uno::Sequence StorageFilterDetect_getSupportedServiceNames(); + +com::sun::star::uno::Reference +StorageFilterDetect_createInstance(const com::sun::star::uno::Reference& rCxt); + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/filter/source/storagefilterdetect/storagefd.component b/filter/source/storagefilterdetect/storagefd.component new file mode 100644 index 000000000000..9f85bfa1efa2 --- /dev/null +++ b/filter/source/storagefilterdetect/storagefd.component @@ -0,0 +1,15 @@ + + + + + + + + diff --git a/postprocess/Rdb_services.mk b/postprocess/Rdb_services.mk index 5a4b104a3b19..15ca77633f94 100644 --- a/postprocess/Rdb_services.mk +++ b/postprocess/Rdb_services.mk @@ -33,6 +33,7 @@ $(eval $(call gb_Rdb_add_components,services,\ filter/source/odfflatxml/odfflatxml \ filter/source/pdf/pdffilter \ filter/source/placeware/placeware \ + filter/source/storagefilterdetect/storagefd \ filter/source/svg/svgfilter \ filter/source/t602/t602filter \ filter/source/textfilterdetect/textfd \ diff --git a/solenv/gbuild/extensions/pre_MergedLibsList.mk b/solenv/gbuild/extensions/pre_MergedLibsList.mk index 18acb8224986..88e7e553edba 100644 --- a/solenv/gbuild/extensions/pre_MergedLibsList.mk +++ b/solenv/gbuild/extensions/pre_MergedLibsList.mk @@ -82,6 +82,7 @@ gb_EXTRAMERGEDLIBS := \ $(if $(filter-out ANDROID IOS,$(OS)),scn) \ sd \ $(call gb_Helper_optional,DBCONNECTIVITY,sdbc2) \ + storagefd \ spell \ svgfilter \ swd \