1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <rtl/ustring.hxx>
23 #include <osl/diagnose.h>
25 #include <ucbhelper/content.hxx>
26 #include <com/sun/star/uno/XComponentContext.hpp>
27 #include <com/sun/star/frame/XModel.hpp>
28 #include <com/sun/star/frame/XTransientDocumentsDocumentContentFactory.hpp>
29 #include <com/sun/star/ucb/ContentCreationException.hpp>
30 #include <com/sun/star/ucb/SimpleFileAccess.hpp>
31 #include <com/sun/star/lang/IllegalArgumentException.hpp>
32 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
33 #include <comphelper/processfactory.hxx>
42 static css::uno::Sequence
< OUString
> allOpenTDocUrls( const css::uno::Reference
< css::uno::XComponentContext
>& xCtx
)
44 css::uno::Sequence
< OUString
> result
;
51 css::uno::Reference
< css::ucb::XSimpleFileAccess3
> xSFA( css::ucb::SimpleFileAccess::create(xCtx
) );
52 result
= xSFA
->getFolderContents( "vnd.sun.star.tdoc:/", true );
54 catch ( css::uno::Exception
& )
60 static OUString
xModelToTdocUrl( const css::uno::Reference
< css::frame::XModel
>& xModel
,
61 const css::uno::Reference
< css::uno::XComponentContext
>& xContext
)
63 css::uno::Reference
< css::lang::XMultiComponentFactory
> xMCF(
64 xContext
->getServiceManager() );
66 css::frame::XTransientDocumentsDocumentContentFactory
> xDocFac
;
69 xDocFac
.set(xMCF
->createInstanceWithContext(
70 "com.sun.star.frame.TransientDocumentsDocumentContentFactory",
72 css::uno::UNO_QUERY
);
74 catch ( css::uno::Exception
const & )
83 css::uno::Reference
< css::ucb::XContent
> xContent(
84 xDocFac
->createDocumentContent( xModel
) );
85 return xContent
->getIdentifier()->getContentIdentifier();
87 catch ( css::lang::IllegalArgumentException
const & )
89 OSL_FAIL( "Invalid document model!" );
93 OSL_FAIL( "Unable to obtain URL for document model!" );
97 static css::uno::Reference
< css::frame::XModel
> tDocUrlToModel( const OUString
& url
)
103 ::ucbhelper::Content
root( url
, nullptr, comphelper::getProcessComponentContext() );
104 result
= getUCBProperty( root
, "DocumentModel" );
106 catch ( css::ucb::ContentCreationException
& )
108 // carry on, empty value will be returned
110 catch ( css::uno::RuntimeException
& )
112 // carry on, empty value will be returned
115 css::uno::Reference
< css::frame::XModel
> xModel(
116 result
, css::uno::UNO_QUERY
);
122 static css::uno::Any
getUCBProperty( ::ucbhelper::Content
& content
, OUString
const & prop
)
124 css::uno::Any result
;
127 result
= content
.getPropertyValue( prop
);
129 catch ( css::uno::Exception
& )
136 } // namespace sf_misc
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */