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