20#include <com/sun/star/io/XActiveDataControl.hpp>
21#include <com/sun/star/io/XInputStream.hpp>
22#include <com/sun/star/io/XActiveDataSink.hpp>
23#include <com/sun/star/beans/NamedValue.hpp>
24#include <com/sun/star/container/XNameContainer.hpp>
25#include <com/sun/star/container/XNamed.hpp>
26#include <com/sun/star/container/XChild.hpp>
27#include <com/sun/star/lang/IllegalArgumentException.hpp>
28#include <com/sun/star/lang/XUnoTunnel.hpp>
29#include <com/sun/star/util/XChangesBatch.hpp>
30#include <com/sun/star/uno/XComponentContext.hpp>
35#include <osl/file.hxx>
67 sXSLTPath(
"$(user)/xslt/" ),
68 sTemplatePath(
"$(user)/template/" ),
69 sProgPath(
"$(prog)/" )
79 return Uri::encode( rURI, rtl_UriCharClassUric, rtl_UriEncodeCheckEscapes, RTL_TEXTENCODING_UTF8 );
85 if ( rName ==
".." || rName ==
"." )
86 throw lang::IllegalArgumentException();
94 if( xNamed.is() && xChild.is() )
97 xNamed->setName(
aName );
98 xChild->setParent( xRootFolder );
109 if(
xSink.is() && xTunnel.is())
113 xSink->setInputStream( xInput );
119 if( rSourceFile.isEmpty() ||
120 rSourceFile.startsWith(
"http:") ||
121 rSourceFile.startsWith(
"https:") ||
122 rSourceFile.startsWith(
"jar:") ||
123 rSourceFile.startsWith(
"ftp:") )
126 OUString aFileURL( rSourceFile );
128 if( !aFileURL.matchIgnoreAsciiCase(
"file://") )
145 osl::File::remove( rPackageURL );
151 Any(beans::NamedValue(
155 mxContext->getServiceManager()->createInstanceWithArgumentsAndContext(
156 "com.sun.star.packages.comp.ZipPackage",
165 xIfc->getByHierarchicalName(
"/" ) >>= xRootFolder;
168 for (
auto const&
filter : rFilters)
172 if( xFilterRoot.is() )
174 if( !
filter->maExportXSLT.isEmpty() )
178 if( !
filter->maImportXSLT.isEmpty() )
181 catch(
const css::container::ElementExistException&)
188 if( !
filter->maImportTemplate.isEmpty() )
210 xBatch->commitChanges();
220 osl::File::remove( rPackageURL );
227 std::vector< std::unique_ptr<filter_info_impl> >& rFilters )
234 beans::NamedValue aArg;
235 aArg.Name =
"StorageFormat";
240 mxContext->getServiceManager()->createInstanceWithArgumentsAndContext(
241 "com.sun.star.packages.comp.ZipPackage",
248 xIfc->getByHierarchicalName(
"/" ) >>= xRootFolder;
250 OUString szTypeDetection(
"TypeDetection.xcu");
251 if( xIfc->hasByHierarchicalName( szTypeDetection ) )
254 xIfc->getByHierarchicalName( szTypeDetection ) >>= xTypeDetection;
256 if( xTypeDetection.is() )
260 std::vector< std::unique_ptr<filter_info_impl> > aFilters;
265 for (
auto&
filter : aFilters)
269 rFilters.push_back(std::move(
filter));
311 throw lang::IllegalArgumentException();
313 if( xIfc->hasByHierarchicalName( szPackagePath ) )
316 xIfc->getByHierarchicalName( szPackagePath ) >>= xFileEntry;
318 if( xFileEntry.is() )
326 if( !rURL.isEmpty() )
332 ::osl::File file(rURL);
333 ::osl::FileBase::RC rc =
334 file.open(osl_File_OpenFlag_Write|osl_File_OpenFlag_Create);
335 if (::osl::FileBase::E_EXIST == rc) {
336 rc = file.open(osl_File_OpenFlag_Write);
337 if (::osl::FileBase::E_None == rc) {
341 if (::osl::FileBase::E_None != rc) {
sal_uInt64 Seek(sal_uInt64 nPos)
OUString SubstituteVariable(const OUString &rVar) const
void doExport(const css::uno::Reference< css::io::XOutputStream > &xOS, const std::vector< filter_info_impl * > &rFilters)
static void doImport(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Reference< css::io::XInputStream > &xOS, std::vector< std::unique_ptr< filter_info_impl > > &rFilters)
XMLFilterJarHelper(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
css::uno::Reference< css::uno::XComponentContext > mxContext
void openPackage(const OUString &rPackageURL, std::vector< std::unique_ptr< filter_info_impl > > &rFilters)
void addFile(css::uno::Reference< css::uno::XInterface > const &xRootFolder, css::uno::Reference< css::lang::XSingleServiceFactory > const &xFactory, const OUString &rSourceFile)
bool savePackage(const OUString &rPackageURL, const std::vector< filter_info_impl * > &rFilters)
bool copyFiles(const css::uno::Reference< css::container::XHierarchicalNameAccess > &xIfc, filter_info_impl *pFilter)
static bool copyFile(const css::uno::Reference< css::container::XHierarchicalNameAccess > &xIfc, OUString &rURL, std::u16string_view rTargetURL)
static bool PathHasSegment(std::u16string_view aPath, std::u16string_view aSegment)
OUString maImportTemplate
SvStream * GetStream(StreamMode eMode)
#define TOOLS_WARN_EXCEPTION(area, stream)
Reference< XSingleServiceFactory > xFactory
Sequence< PropertyValue > aArguments
tools::SvRef< SvBaseLink > xSink
SVL_DLLPUBLIC OUString SmartRel2Abs(INetURLObject const &rTheBaseURIRef, OUString const &rTheRelURIRef, Link< OUString *, bool > const &rMaybeFileHdl=Link< OUString *, bool >(), bool bCheckFileExists=true, bool bIgnoreFragment=false, INetURLObject::EncodeMechanism eEncodeMechanism=INetURLObject::EncodeMechanism::WasEncoded, INetURLObject::DecodeMechanism eDecodeMechanism=INetURLObject::DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
Shape IDs per cluster in DGG atom.
constexpr OUStringLiteral ZIP_STORAGE_FORMAT_STRING
bool createDirectory(std::u16string_view rURL)
bool copyStreams(const css::uno::Reference< css::io::XInputStream > &xIS, const css::uno::Reference< css::io::XOutputStream > &xOS)
static Reference< XInterface > addFolder(Reference< XInterface > const &xRootFolder, Reference< XSingleServiceFactory > const &xFactory, const OUString &rName)
static void addFile_(Reference< XInterface > const &xRootFolder, Reference< XSingleServiceFactory > const &xFactory, Reference< XInputStream > const &xInput, const OUString &aName)
constexpr OUStringLiteral sVndSunStarPackage(u"vnd.sun.star.Package:")
static OUString encodeZipUri(const OUString &rURI)