1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // @@@ Adjust multi-include-protection-ifdef.
29 #ifndef _MYUCP_CONTENT_HXX
30 #define _MYUCP_CONTENT_HXX
31 
32 #include <list>
33 
34 #include "rtl/ref.hxx"
35 #include "ucbhelper/contenthelper.hxx"
36 
37 namespace com { namespace sun { namespace star { namespace beans {
38 	struct Property;
39 	struct PropertyValue;
40 } } } }
41 
42 namespace com { namespace sun { namespace star { namespace sdbc {
43 	class XRow;
44 } } } }
45 
46 namespace com { namespace sun { namespace star { namespace io {
47 	class XInputStream;
48 } } } }
49 
50 // @@@ Adjust namespace name.
51 namespace myucp
52 {
53 
54 //=========================================================================
55 
56 // @@@ Adjust service name.
57 
58 // UNO service name for the content. Prefix with reversed company domain main.
59 #define MYUCP_CONTENT_SERVICE_NAME "com.sun.star.ucb.MyContent"
60 
61 //=========================================================================
62 
63 struct ContentProperties
64 {
65 	::rtl::OUString aTitle;    		// Title
66 	::rtl::OUString aContentType;	// ContentType
67 	sal_Bool        bIsDocument;    // IsDocument
68 	sal_Bool        bIsFolder;    	// IsFolder
69 
70 	// @@@ Add other properties supported by your content.
71 
72 	ContentProperties()
73 	: bIsDocument( sal_True ), bIsFolder( sal_False ) {}
74 };
75 
76 //=========================================================================
77 
78 class Content : public ::ucbhelper::ContentImplHelper
79 {
80 	ContentProperties m_aProps;
81 
82 private:
83 	virtual com::sun::star::uno::Sequence< com::sun::star::beans::Property >
84 	getProperties( const com::sun::star::uno::Reference<
85 					com::sun::star::ucb::XCommandEnvironment > & xEnv );
86 	virtual com::sun::star::uno::Sequence< com::sun::star::ucb::CommandInfo >
87 	getCommands( const com::sun::star::uno::Reference<
88 					com::sun::star::ucb::XCommandEnvironment > & xEnv );
89     virtual ::rtl::OUString getParentURL();
90 
91 	::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
92 	getPropertyValues( const ::com::sun::star::uno::Sequence<
93                         ::com::sun::star::beans::Property >& rProperties,
94                        const ::com::sun::star::uno::Reference<
95 						::com::sun::star::ucb::XCommandEnvironment >& xEnv );
96     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >
97     setPropertyValues( const ::com::sun::star::uno::Sequence<
98                         ::com::sun::star::beans::PropertyValue >& rValues,
99                        const ::com::sun::star::uno::Reference<
100                         ::com::sun::star::ucb::XCommandEnvironment >& xEnv );
101 
102 #define IMPLEMENT_COMMAND_OPEN
103 #define IMPLEMENT_COMMAND_INSERT
104 #define IMPLEMENT_COMMAND_DELETE
105 
106 #ifdef IMPLEMENT_COMMAND_INSERT
107     typedef rtl::Reference< Content > ContentRef;
108     typedef std::list< ContentRef > ContentRefList;
109     void queryChildren( ContentRefList& rChildren );
110 
111     // Command "insert"
112     void insert( const ::com::sun::star::uno::Reference<
113                  ::com::sun::star::io::XInputStream > & xInputStream,
114                  sal_Bool bReplaceExisting,
115                  const com::sun::star::uno::Reference<
116                  com::sun::star::ucb::XCommandEnvironment >& Environment )
117         throw( ::com::sun::star::uno::Exception );
118 #endif
119 
120 #ifdef IMPLEMENT_COMMAND_DELETE
121 
122     // Command "delete"
123 	void destroy( sal_Bool bDeletePhysical )
124         throw( ::com::sun::star::uno::Exception );
125 #endif
126 
127 public:
128 	Content( const ::com::sun::star::uno::Reference<
129 				::com::sun::star::lang::XMultiServiceFactory >& rxSMgr,
130 			 ::ucbhelper::ContentProviderImplHelper* pProvider,
131 			 const ::com::sun::star::uno::Reference<
132 				::com::sun::star::ucb::XContentIdentifier >& Identifier );
133 	virtual ~Content();
134 
135 	// XInterface
136 	XINTERFACE_DECL()
137 
138 	// XTypeProvider
139 	XTYPEPROVIDER_DECL()
140 
141     // XServiceInfo
142     virtual ::rtl::OUString SAL_CALL
143 	getImplementationName()
144 		throw( ::com::sun::star::uno::RuntimeException );
145     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
146 	getSupportedServiceNames()
147 		throw( ::com::sun::star::uno::RuntimeException );
148 
149 	// XContent
150     virtual rtl::OUString SAL_CALL
151 	getContentType()
152 		throw( com::sun::star::uno::RuntimeException );
153 
154 	// XCommandProcessor
155     virtual com::sun::star::uno::Any SAL_CALL
156 	execute( const com::sun::star::ucb::Command& aCommand,
157 			 sal_Int32 CommandId,
158 			 const com::sun::star::uno::Reference<
159 			 	com::sun::star::ucb::XCommandEnvironment >& Environment )
160     	throw( com::sun::star::uno::Exception,
161 			   com::sun::star::ucb::CommandAbortedException,
162 			   com::sun::star::uno::RuntimeException );
163     virtual void SAL_CALL
164 	abort( sal_Int32 CommandId )
165 		throw( com::sun::star::uno::RuntimeException );
166 
167 	//////////////////////////////////////////////////////////////////////
168 	// Additional interfaces
169 	//////////////////////////////////////////////////////////////////////
170 
171 	// @@@ Add additional interfaces ( like com::sun::star::ucb::XContentCreator ).
172 
173 	//////////////////////////////////////////////////////////////////////
174 	// Non-interface methods.
175 	//////////////////////////////////////////////////////////////////////
176 
177 	// Called from resultset data supplier.
178 	static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow >
179 	getPropertyValues( const ::com::sun::star::uno::Reference<
180 						::com::sun::star::lang::XMultiServiceFactory >& rSMgr,
181 					   const ::com::sun::star::uno::Sequence<
182 					   	::com::sun::star::beans::Property >& rProperties,
183 					   const ContentProperties& rData,
184                        const rtl::Reference<
185 					   	::ucbhelper::ContentProviderImplHelper >& rProvider,
186                        const ::rtl::OUString& rContentId );
187 };
188 
189 }
190 
191 #endif
192