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 // @@@ Adjust multi-include-protection-ifdef.
25 #ifndef _MYUCP_CONTENT_HXX
26 #define _MYUCP_CONTENT_HXX
27 
28 #include <list>
29 
30 #include "rtl/ref.hxx"
31 #include "ucbhelper/contenthelper.hxx"
32 
33 namespace com { namespace sun { namespace star { namespace beans {
34 	struct Property;
35 	struct PropertyValue;
36 } } } }
37 
38 namespace com { namespace sun { namespace star { namespace sdbc {
39 	class XRow;
40 } } } }
41 
42 namespace com { namespace sun { namespace star { namespace io {
43 	class XInputStream;
44 } } } }
45 
46 // @@@ Adjust namespace name.
47 namespace myucp
48 {
49 
50 //=========================================================================
51 
52 // @@@ Adjust service name.
53 
54 // UNO service name for the content. Prefix with reversed company domain main.
55 #define MYUCP_CONTENT_SERVICE_NAME "com.sun.star.ucb.MyContent"
56 
57 //=========================================================================
58 
59 struct ContentProperties
60 {
61 	::rtl::OUString aTitle;    		// Title
62 	::rtl::OUString aContentType;	// ContentType
63 	sal_Bool        bIsDocument;    // IsDocument
64 	sal_Bool        bIsFolder;    	// IsFolder
65 
66 	// @@@ Add other properties supported by your content.
67 
ContentPropertiesmyucp::ContentProperties68 	ContentProperties()
69 	: bIsDocument( sal_True ), bIsFolder( sal_False ) {}
70 };
71 
72 //=========================================================================
73 
74 class Content : public ::ucbhelper::ContentImplHelper
75 {
76 	ContentProperties m_aProps;
77 
78 private:
79 	virtual com::sun::star::uno::Sequence< com::sun::star::beans::Property >
80 	getProperties( const com::sun::star::uno::Reference<
81 					com::sun::star::ucb::XCommandEnvironment > & xEnv );
82 	virtual com::sun::star::uno::Sequence< com::sun::star::ucb::CommandInfo >
83 	getCommands( const com::sun::star::uno::Reference<
84 					com::sun::star::ucb::XCommandEnvironment > & xEnv );
85     virtual ::rtl::OUString getParentURL();
86 
87 	::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
88 	getPropertyValues( const ::com::sun::star::uno::Sequence<
89                         ::com::sun::star::beans::Property >& rProperties,
90                        const ::com::sun::star::uno::Reference<
91 						::com::sun::star::ucb::XCommandEnvironment >& xEnv );
92     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >
93     setPropertyValues( const ::com::sun::star::uno::Sequence<
94                         ::com::sun::star::beans::PropertyValue >& rValues,
95                        const ::com::sun::star::uno::Reference<
96                         ::com::sun::star::ucb::XCommandEnvironment >& xEnv );
97 
98 #define IMPLEMENT_COMMAND_OPEN
99 #define IMPLEMENT_COMMAND_INSERT
100 #define IMPLEMENT_COMMAND_DELETE
101 
102 #ifdef IMPLEMENT_COMMAND_INSERT
103     typedef rtl::Reference< Content > ContentRef;
104     typedef std::list< ContentRef > ContentRefList;
105     void queryChildren( ContentRefList& rChildren );
106 
107     // Command "insert"
108     void insert( const ::com::sun::star::uno::Reference<
109                  ::com::sun::star::io::XInputStream > & xInputStream,
110                  sal_Bool bReplaceExisting,
111                  const com::sun::star::uno::Reference<
112                  com::sun::star::ucb::XCommandEnvironment >& Environment )
113         throw( ::com::sun::star::uno::Exception );
114 #endif
115 
116 #ifdef IMPLEMENT_COMMAND_DELETE
117 
118     // Command "delete"
119 	void destroy( sal_Bool bDeletePhysical )
120         throw( ::com::sun::star::uno::Exception );
121 #endif
122 
123 public:
124 	Content( const ::com::sun::star::uno::Reference<
125 				::com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
126 			 ::ucbhelper::ContentProviderImplHelper* pProvider,
127 			 const ::com::sun::star::uno::Reference<
128 				::com::sun::star::ucb::XContentIdentifier >& Identifier );
129 	virtual ~Content();
130 
131 	// XInterface
132 	XINTERFACE_DECL()
133 
134 	// XTypeProvider
135 	XTYPEPROVIDER_DECL()
136 
137     // XServiceInfo
138     virtual ::rtl::OUString SAL_CALL
139 	getImplementationName()
140 		throw( ::com::sun::star::uno::RuntimeException );
141     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
142 	getSupportedServiceNames()
143 		throw( ::com::sun::star::uno::RuntimeException );
144 
145 	// XContent
146     virtual rtl::OUString SAL_CALL
147 	getContentType()
148 		throw( com::sun::star::uno::RuntimeException );
149 
150 	// XCommandProcessor
151     virtual com::sun::star::uno::Any SAL_CALL
152 	execute( const com::sun::star::ucb::Command& aCommand,
153 			 sal_Int32 CommandId,
154 			 const com::sun::star::uno::Reference<
155 			 	com::sun::star::ucb::XCommandEnvironment >& Environment )
156     	throw( com::sun::star::uno::Exception,
157 			   com::sun::star::ucb::CommandAbortedException,
158 			   com::sun::star::uno::RuntimeException );
159     virtual void SAL_CALL
160 	abort( sal_Int32 CommandId )
161 		throw( com::sun::star::uno::RuntimeException );
162 
163 	//////////////////////////////////////////////////////////////////////
164 	// Additional interfaces
165 	//////////////////////////////////////////////////////////////////////
166 
167 	// @@@ Add additional interfaces ( like com::sun::star::ucb::XContentCreator ).
168 
169 	//////////////////////////////////////////////////////////////////////
170 	// Non-interface methods.
171 	//////////////////////////////////////////////////////////////////////
172 
173 	// Called from resultset data supplier.
174 	static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
175 	getPropertyValues( const ::com::sun::star::uno::Reference<
176 						::com::sun::star::lang::XMultiServiceFactory >& rSMgr,
177 					   const ::com::sun::star::uno::Sequence<
178 					   	::com::sun::star::beans::Property >& rProperties,
179 					   const ContentProperties& rData,
180                        const rtl::Reference<
181 					   	::ucbhelper::ContentProviderImplHelper >& rProvider,
182                        const ::rtl::OUString& rContentId );
183 };
184 
185 }
186 
187 #endif
188