1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_ucbhelper.hxx"
26
27 /**************************************************************************
28 TODO
29 **************************************************************************
30
31 *************************************************************************/
32
33 #include "osl/diagnose.h"
34 #include "osl/mutex.hxx"
35
36 #include "ucbhelper/contentidentifier.hxx"
37
38 #include "myucp_provider.hxx"
39 #include "myucp_content.hxx"
40
41 using namespace com::sun::star;
42
43 // @@@ Adjust namespace name.
44 namespace myucp {
45
46 //=========================================================================
47 //=========================================================================
48 //
49 // ContentProvider Implementation.
50 //
51 //=========================================================================
52 //=========================================================================
53
ContentProvider(const uno::Reference<lang::XMultiServiceFactory> & rSMgr)54 ContentProvider::ContentProvider(
55 const uno::Reference< lang::XMultiServiceFactory >& rSMgr )
56 : ::ucbhelper::ContentProviderImplHelper( rSMgr )
57 {
58 }
59
60 //=========================================================================
61 // virtual
~ContentProvider()62 ContentProvider::~ContentProvider()
63 {
64 }
65
66 //=========================================================================
67 //
68 // XInterface methods.
69 //
70 //=========================================================================
71
72 // @@@ Add own interfaces.
73 XINTERFACE_IMPL_3( ContentProvider,
74 lang::XTypeProvider,
75 lang::XServiceInfo,
76 ucb::XContentProvider );
77
78 //=========================================================================
79 //
80 // XTypeProvider methods.
81 //
82 //=========================================================================
83
84 // @@@ Add own interfaces.
85 XTYPEPROVIDER_IMPL_3( ContentProvider,
86 lang::XTypeProvider,
87 lang::XServiceInfo,
88 ucb::XContentProvider );
89
90 //=========================================================================
91 //
92 // XServiceInfo methods.
93 //
94 //=========================================================================
95
96 // @@@ Adjust implementation name. Keep the prefix "com.sun.star.comp."!
97 // @@@ Adjust service name.
98 XSERVICEINFO_IMPL_1( ContentProvider,
99 rtl::OUString::createFromAscii(
100 "com.sun.star.comp.myucp.ContentProvider" ),
101 rtl::OUString::createFromAscii(
102 MYUCP_CONTENT_PROVIDER_SERVICE_NAME ) );
103
104 //=========================================================================
105 //
106 // Service factory implementation.
107 //
108 //=========================================================================
109
110 ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider );
111
112 //=========================================================================
113 //
114 // XContentProvider methods.
115 //
116 //=========================================================================
117
118 // virtual
queryContent(const uno::Reference<ucb::XContentIdentifier> & Identifier)119 uno::Reference< ucb::XContent > SAL_CALL ContentProvider::queryContent(
120 const uno::Reference< ucb::XContentIdentifier >& Identifier )
121 {
122 // Check URL scheme...
123
124 rtl::OUString aScheme( rtl::OUString::createFromAscii( MYUCP_URL_SCHEME ) );
125 if ( !Identifier->getContentProviderScheme().equalsIgnoreAsciiCase( aScheme ) )
126 throw ucb::IllegalIdentifierException();
127
128 // @@@ Further id checks may go here...
129 #if 0
130 if ( id-check-failes )
131 throw ucb::IllegalIdentifierException();
132 #endif
133
134 // @@@ Id normalization may go here...
135 #if 0
136 // Normalize URL and create new Id.
137 rtl::OUString aCanonicURL = xxxxx( Identifier->getContentIdentifier() );
138 uno::Reference< ucb::XContentIdentifier > xCanonicId
139 = new ::ucbhelper::ContentIdentifier( m_xSMgr, aCanonicURL );
140 #else
141 uno::Reference< ucb::XContentIdentifier > xCanonicId = Identifier;
142 #endif
143
144 osl::MutexGuard aGuard( m_aMutex );
145
146 // Check, if a content with given id already exists...
147 uno::Reference< ucb::XContent > xContent
148 = queryExistingContent( xCanonicId ).get();
149 if ( xContent.is() )
150 return xContent;
151
152 // @@@ Decision, which content implementation to instantiate may be
153 // made here ( in case you have different content classes ).
154
155 // Create a new content.
156
157 xContent = new Content( m_xSMgr, this, xCanonicId );
158 registerNewContent( xContent );
159
160 if ( !xContent->getIdentifier().is() )
161 throw ucb::IllegalIdentifierException();
162
163 return xContent;
164 }
165
166 } // namespace
167