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     throw( ucb::IllegalIdentifierException, uno::RuntimeException )
122 {
123 	// Check URL scheme...
124 
125     rtl::OUString aScheme( rtl::OUString::createFromAscii( MYUCP_URL_SCHEME ) );
126     if ( !Identifier->getContentProviderScheme().equalsIgnoreAsciiCase( aScheme ) )
127         throw ucb::IllegalIdentifierException();
128 
129 	// @@@ Further id checks may go here...
130 #if 0
131 	if ( id-check-failes )
132         throw ucb::IllegalIdentifierException();
133 #endif
134 
135 	// @@@ Id normalization may go here...
136 #if 0
137 	// Normalize URL and create new Id.
138     rtl::OUString aCanonicURL = xxxxx( Identifier->getContentIdentifier() );
139     uno::Reference< ucb::XContentIdentifier > xCanonicId
140         = new ::ucbhelper::ContentIdentifier( m_xSMgr, aCanonicURL );
141 #else
142     uno::Reference< ucb::XContentIdentifier > xCanonicId = Identifier;
143 #endif
144 
145 	osl::MutexGuard aGuard( m_aMutex );
146 
147 	// Check, if a content with given id already exists...
148     uno::Reference< ucb::XContent > xContent
149 		= queryExistingContent( xCanonicId ).get();
150 	if ( xContent.is() )
151 		return xContent;
152 
153 	// @@@ Decision, which content implementation to instanciate may be
154 	//     made here ( in case you have different content classes ).
155 
156 	// Create a new content.
157 
158 	xContent = new Content( m_xSMgr, this, xCanonicId );
159     registerNewContent( xContent );
160 
161 	if ( !xContent->getIdentifier().is() )
162         throw ucb::IllegalIdentifierException();
163 
164 	return xContent;
165 }
166 
167 } // namespace
168