fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / scripting / source / inc / util / MiscUtils.hxx
blob80d8d6860cd0ebd53089ec47ab7a7a53c7936527
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #ifndef INCLUDED_SCRIPTING_SOURCE_INC_UTIL_MISCUTILS_HXX
21 #define INCLUDED_SCRIPTING_SOURCE_INC_UTIL_MISCUTILS_HXX
23 #include <rtl/ustring.hxx>
24 #include <osl/diagnose.h>
25 #include <tools/urlobj.hxx>
27 #include <ucbhelper/content.hxx>
28 #include <com/sun/star/uno/XComponentContext.hpp>
29 #include <com/sun/star/frame/XModel.hpp>
30 #include <com/sun/star/frame/XTransientDocumentsDocumentContentFactory.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
33 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
34 #include <com/sun/star/ucb/SimpleFileAccess.hpp>
35 #include <com/sun/star/ucb/XContentAccess.hpp>
36 #include <com/sun/star/sdbc/XResultSet.hpp>
37 #include <com/sun/star/sdbc/XRow.hpp>
38 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
39 #include <comphelper/processfactory.hxx>
41 namespace sf_misc
44 class MiscUtils
46 public:
47 static css::uno::Sequence< OUString > allOpenTDocUrls( const css::uno::Reference< css::uno::XComponentContext >& xCtx)
49 css::uno::Sequence< OUString > result;
50 try
52 if ( !xCtx.is() )
54 return result;
56 css::uno::Reference < css::ucb::XSimpleFileAccess3 > xSFA( css::ucb::SimpleFileAccess::create(xCtx) );
57 result = xSFA->getFolderContents( "vnd.sun.star.tdoc:/", true );
59 catch ( css::uno::Exception& )
62 return result;
65 static OUString xModelToTdocUrl( const css::uno::Reference< css::frame::XModel >& xModel,
66 const css::uno::Reference< css::uno::XComponentContext >& xContext )
68 css::uno::Reference< css::lang::XMultiComponentFactory > xMCF(
69 xContext->getServiceManager() );
70 css::uno::Reference<
71 css::frame::XTransientDocumentsDocumentContentFactory > xDocFac;
72 try
74 xDocFac =
75 css::uno::Reference<
76 css::frame::XTransientDocumentsDocumentContentFactory >(
77 xMCF->createInstanceWithContext(
78 OUString(
79 "com.sun.star.frame.TransientDocumentsDocumentContentFactory" ),
80 xContext ),
81 css::uno::UNO_QUERY );
83 catch ( css::uno::Exception const & )
85 // handled below
88 if ( xDocFac.is() )
90 try
92 css::uno::Reference< css::ucb::XContent > xContent(
93 xDocFac->createDocumentContent( xModel ) );
94 return xContent->getIdentifier()->getContentIdentifier();
96 catch ( css::lang::IllegalArgumentException const & )
98 OSL_FAIL( "Invalid document model!" );
102 OSL_FAIL( "Unable to obtain URL for document model!" );
103 return OUString();
105 static css::uno::Reference< css::frame::XModel > tDocUrlToModel( const OUString& url )
107 css::uno::Any result;
111 ::ucbhelper::Content root( url, NULL, comphelper::getProcessComponentContext() );
112 OUString propName = "DocumentModel";
113 result = getUCBProperty( root, propName );
115 catch ( css::ucb::ContentCreationException& )
117 // carry on, empty value will be returned
119 catch ( css::uno::RuntimeException& )
121 // carry on, empty value will be returned
124 css::uno::Reference< css::frame::XModel > xModel(
125 result, css::uno::UNO_QUERY );
127 return xModel;
131 static css::uno::Any getUCBProperty( ::ucbhelper::Content& content, OUString& prop )
133 css::uno::Any result;
136 result = content.getPropertyValue( prop );
138 catch ( css::uno::Exception& )
141 return result;
144 private:
145 static OUString parseLocationName( const OUString& location )
147 // strip out the last leaf of location name
148 // e.g. file://dir1/dir2/Blah.sxw - > Blah.sxw
149 OUString temp = location;
150 INetURLObject aURLObj( temp );
151 if ( !aURLObj.HasError() )
152 temp = aURLObj.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET );
153 return temp;
157 } // namespace sf_misc
158 #endif
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */