merge the formfield patch from ooo-build
[ooovba.git] / ucbhelper / workben / myucp / myucp_content.cxx
blobcc90361b07c5b880e699fc22d69ab88112670090
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: myucp_content.cxx,v $
10 * $Revision: 1.13 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucbhelper.hxx"
34 /**************************************************************************
35 TODO
36 **************************************************************************
38 *************************************************************************/
40 #include "osl/diagnose.h"
42 #include "com/sun/star/beans/PropertyAttribute.hpp"
43 #include "com/sun/star/beans/XPropertyAccess.hpp"
44 #include "com/sun/star/lang/IllegalAccessException.hpp"
45 #include "com/sun/star/sdbc/XRow.hpp"
46 #include "com/sun/star/ucb/XCommandInfo.hpp"
47 #include "com/sun/star/ucb/XPersistentPropertySet.hpp"
48 #include "ucbhelper/contentidentifier.hxx"
49 #include "ucbhelper/propertyvalueset.hxx"
50 #include "ucbhelper/cancelcommandexecution.hxx"
52 #include "myucp_content.hxx"
53 #include "myucp_provider.hxx"
55 #ifdef IMPLEMENT_COMMAND_INSERT
56 #include "com/sun/star/ucb/InsertCommandArgument.hpp"
57 #include "com/sun/star/ucb/MissingInputStreamException.hpp"
58 #include "com/sun/star/ucb/MissingPropertiesException.hpp"
59 #endif
60 #ifdef IMPLEMENT_COMMAND_OPEN
61 #include "com/sun/star/io/XOutputStream.hpp"
62 #include "com/sun/star/io/XActiveDataSink.hpp"
63 #include "com/sun/star/ucb/OpenCommandArgument2.hpp"
64 #include "com/sun/star/ucb/OpenMode.hpp"
65 #include "com/sun/star/ucb/UnsupportedDataSinkException.hpp"
66 #include "com/sun/star/ucb/UnsupportedOpenModeException.hpp"
67 #include "myucp_resultset.hxx"
68 #endif
70 using namespace com::sun::star;
72 // @@@ Adjust namespace name.
73 using namespace myucp;
75 //=========================================================================
76 //=========================================================================
78 // Content Implementation.
80 //=========================================================================
81 //=========================================================================
83 Content::Content( const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
84 ::ucbhelper::ContentProviderImplHelper* pProvider,
85 const uno::Reference< ucb::XContentIdentifier >& Identifier )
86 : ContentImplHelper( rxSMgr, pProvider, Identifier )
88 // @@@ Fill m_aProps here or implement lazy evaluation logic for this.
89 // m_aProps.aTitle =
90 // m_aprops.aContentType =
91 // m_aProps.bIsDocument =
92 // m_aProps.bIsFolder =
95 //=========================================================================
96 // virtual
97 Content::~Content()
101 //=========================================================================
103 // XInterface methods.
105 //=========================================================================
107 // virtual
108 void SAL_CALL Content::acquire()
109 throw()
111 ContentImplHelper::acquire();
114 //=========================================================================
115 // virtual
116 void SAL_CALL Content::release()
117 throw()
119 ContentImplHelper::release();
122 //=========================================================================
123 // virtual
124 uno::Any SAL_CALL Content::queryInterface( const uno::Type & rType )
125 throw ( uno::RuntimeException )
127 uno::Any aRet;
129 // @@@ Add support for additional interfaces.
130 #if 0
131 aRet = cppu::queryInterface( rType,
132 static_cast< yyy::Xxxxxxxxx * >( this ) );
133 #endif
135 return aRet.hasValue() ? aRet : ContentImplHelper::queryInterface( rType );
138 //=========================================================================
140 // XTypeProvider methods.
142 //=========================================================================
144 XTYPEPROVIDER_COMMON_IMPL( Content );
146 //=========================================================================
147 // virtual
148 uno::Sequence< uno::Type > SAL_CALL Content::getTypes()
149 throw( uno::RuntimeException )
151 // @@@ Add own interfaces.
153 static cppu::OTypeCollection* pCollection = 0;
155 if ( !pCollection )
157 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
158 if ( !pCollection )
160 static cppu::OTypeCollection aCollection(
161 CPPU_TYPE_REF( lang::XTypeProvider ),
162 CPPU_TYPE_REF( lang::XServiceInfo ),
163 CPPU_TYPE_REF( lang::XComponent ),
164 CPPU_TYPE_REF( ucb::XContent ),
165 CPPU_TYPE_REF( ucb::XCommandProcessor ),
166 CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ),
167 CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ),
168 CPPU_TYPE_REF( beans::XPropertyContainer ),
169 CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ),
170 CPPU_TYPE_REF( container::XChild ) );
171 pCollection = &aCollection;
175 return (*pCollection).getTypes();
178 //=========================================================================
180 // XServiceInfo methods.
182 //=========================================================================
184 // virtual
185 rtl::OUString SAL_CALL Content::getImplementationName()
186 throw( uno::RuntimeException )
188 // @@@ Adjust implementation name.
189 // Prefix with reversed company domain name.
190 return rtl::OUString::createFromAscii( "com.sun.star.comp.myucp.Content" );
193 //=========================================================================
194 // virtual
195 uno::Sequence< rtl::OUString > SAL_CALL Content::getSupportedServiceNames()
196 throw( uno::RuntimeException )
198 // @@@ Adjust macro name.
199 uno::Sequence< rtl::OUString > aSNS( 1 );
200 aSNS.getArray()[ 0 ]
201 = rtl::OUString::createFromAscii( MYUCP_CONTENT_SERVICE_NAME );
202 return aSNS;
205 //=========================================================================
207 // XContent methods.
209 //=========================================================================
211 // virtual
212 rtl::OUString SAL_CALL Content::getContentType()
213 throw( uno::RuntimeException )
215 // @@@ Adjust macro name ( def in myucp_provider.hxx ).
216 return rtl::OUString::createFromAscii( MYUCP_CONTENT_TYPE );
219 //=========================================================================
221 // XCommandProcessor methods.
223 //=========================================================================
225 // virtual
226 uno::Any SAL_CALL Content::execute(
227 const ucb::Command& aCommand,
228 sal_Int32 /* CommandId */,
229 const uno::Reference< ucb::XCommandEnvironment >& Environment )
230 throw( uno::Exception,
231 ucb::CommandAbortedException,
232 uno::RuntimeException )
234 uno::Any aRet;
236 if ( aCommand.Name.equalsAsciiL(
237 RTL_CONSTASCII_STRINGPARAM( "getPropertyValues" ) ) )
239 //////////////////////////////////////////////////////////////////
240 // getPropertyValues
241 //////////////////////////////////////////////////////////////////
243 uno::Sequence< beans::Property > Properties;
244 if ( !( aCommand.Argument >>= Properties ) )
246 OSL_ENSURE( sal_False, "Wrong argument type!" );
247 ::ucbhelper::cancelCommandExecution(
248 uno::makeAny( lang::IllegalArgumentException(
249 rtl::OUString(),
250 static_cast< cppu::OWeakObject * >( this ),
251 -1 ) ),
252 Environment );
253 // Unreachable
256 aRet <<= getPropertyValues( Properties, Environment );
258 else if ( aCommand.Name.equalsAsciiL(
259 RTL_CONSTASCII_STRINGPARAM( "setPropertyValues" ) ) )
261 //////////////////////////////////////////////////////////////////
262 // setPropertyValues
263 //////////////////////////////////////////////////////////////////
265 uno::Sequence< beans::PropertyValue > aProperties;
266 if ( !( aCommand.Argument >>= aProperties ) )
268 OSL_ENSURE( sal_False, "Wrong argument type!" );
269 ::ucbhelper::cancelCommandExecution(
270 uno::makeAny( lang::IllegalArgumentException(
271 rtl::OUString(),
272 static_cast< cppu::OWeakObject * >( this ),
273 -1 ) ),
274 Environment );
275 // Unreachable
278 if ( !aProperties.getLength() )
280 OSL_ENSURE( sal_False, "No properties!" );
281 ::ucbhelper::cancelCommandExecution(
282 uno::makeAny( lang::IllegalArgumentException(
283 rtl::OUString(),
284 static_cast< cppu::OWeakObject * >( this ),
285 -1 ) ),
286 Environment );
287 // Unreachable
290 aRet <<= setPropertyValues( aProperties, Environment );
292 else if ( aCommand.Name.equalsAsciiL(
293 RTL_CONSTASCII_STRINGPARAM( "getPropertySetInfo" ) ) )
295 //////////////////////////////////////////////////////////////////
296 // getPropertySetInfo
297 //////////////////////////////////////////////////////////////////
299 // Note: Implemented by base class.
300 aRet <<= getPropertySetInfo( Environment );
302 else if ( aCommand.Name.equalsAsciiL(
303 RTL_CONSTASCII_STRINGPARAM( "getCommandInfo" ) ) )
305 //////////////////////////////////////////////////////////////////
306 // getCommandInfo
307 //////////////////////////////////////////////////////////////////
309 // Note: Implemented by base class.
310 aRet <<= getCommandInfo( Environment );
312 #ifdef IMPLEMENT_COMMAND_OPEN
313 else if ( aCommand.Name.equalsAsciiL(
314 RTL_CONSTASCII_STRINGPARAM( "open" ) ) )
316 ucb::OpenCommandArgument2 aOpenCommand;
317 if ( !( aCommand.Argument >>= aOpenCommand ) )
319 OSL_ENSURE( sal_False, "Wrong argument type!" );
320 ::ucbhelper::cancelCommandExecution(
321 uno::makeAny( lang::IllegalArgumentException(
322 rtl::OUString(),
323 static_cast< cppu::OWeakObject * >( this ),
324 -1 ) ),
325 Environment );
326 // Unreachable
329 sal_Bool bOpenFolder =
330 ( ( aOpenCommand.Mode == ucb::OpenMode::ALL ) ||
331 ( aOpenCommand.Mode == ucb::OpenMode::FOLDERS ) ||
332 ( aOpenCommand.Mode == ucb::OpenMode::DOCUMENTS ) );
334 if ( bOpenFolder /*&& isFolder( Environment )*/ )
336 // open as folder - return result set
338 uno::Reference< ucb::XDynamicResultSet > xSet
339 = new DynamicResultSet( m_xSMgr,
340 this,
341 aOpenCommand,
342 Environment );
343 aRet <<= xSet;
346 if ( aOpenCommand.Sink.is() )
348 // Open document - supply document data stream.
350 // Check open mode
351 if ( ( aOpenCommand.Mode
352 == ucb::OpenMode::DOCUMENT_SHARE_DENY_NONE ) ||
353 ( aOpenCommand.Mode
354 == ucb::OpenMode::DOCUMENT_SHARE_DENY_WRITE ) )
356 // Unsupported.
357 ::ucbhelper::cancelCommandExecution(
358 uno::makeAny( ucb::UnsupportedOpenModeException(
359 rtl::OUString(),
360 static_cast< cppu::OWeakObject * >( this ),
361 sal_Int16( aOpenCommand.Mode ) ) ),
362 Environment );
363 // Unreachable
367 rtl::OUString aURL = m_xIdentifier->getContentIdentifier();
368 uno::Reference< io::XOutputStream > xOut
369 = uno::Reference< io::XOutputStream >(
370 aOpenCommand.Sink, uno::UNO_QUERY );
371 if ( xOut.is() )
373 // @@@ write data into xOut
375 else
377 uno::Reference< io::XActiveDataSink > xDataSink(
378 aOpenCommand.Sink, uno::UNO_QUERY );
379 if ( xDataSink.is() )
381 uno::Reference< io::XInputStream > xIn
382 /* @@@ your XInputStream + XSeekable impl. object */;
383 xDataSink->setInputStream( xIn );
385 else
387 // Note: aOpenCommand.Sink may contain an XStream
388 // implementation. Support for this type of
389 // sink is optional...
390 ::ucbhelper::cancelCommandExecution(
391 uno::makeAny( ucb::UnsupportedDataSinkException(
392 rtl::OUString(),
393 static_cast< cppu::OWeakObject * >( this ),
394 aOpenCommand.Sink ) ),
395 Environment );
396 // Unreachable
401 #endif // IMPLEMENT_COMMAND_OPEN
403 #ifdef IMPLEMENT_COMMAND_INSERT
404 else if ( aCommand.Name.equalsAsciiL(
405 RTL_CONSTASCII_STRINGPARAM( "insert" ) ) )
407 //////////////////////////////////////////////////////////////////
408 // insert
409 //////////////////////////////////////////////////////////////////
411 ucb::InsertCommandArgument arg;
412 if ( !( aCommand.Argument >>= arg ) )
414 OSL_ENSURE( sal_False, "Wrong argument type!" );
415 ::ucbhelper::cancelCommandExecution(
416 uno::makeAny( lang::IllegalArgumentException(
417 rtl::OUString(),
418 static_cast< cppu::OWeakObject * >( this ),
419 -1 ) ),
420 Environment );
421 // Unreachable
424 insert( arg.Data, arg.ReplaceExisting, Environment );
426 #endif // IMPLEMENT_COMMAND_INSERT
428 #ifdef IMPLEMENT_COMMAND_DELETE
429 else if ( aCommand.Name.equalsAsciiL(
430 RTL_CONSTASCII_STRINGPARAM( "delete" ) ) )
432 //////////////////////////////////////////////////////////////////
433 // delete
434 //////////////////////////////////////////////////////////////////
436 sal_Bool bDeletePhysical = sal_False;
437 aCommand.Argument >>= bDeletePhysical;
438 destroy( bDeletePhysical );
440 // Remove own and all children's Additional Core Properties.
441 removeAdditionalPropertySet( sal_True );
443 // Remove own and all childrens(!) persistent data.
444 // removeData();
446 #endif // IMPLEMENT_COMMAND_DELETE
447 else
449 //////////////////////////////////////////////////////////////////
450 // Unsupported command
451 //////////////////////////////////////////////////////////////////
453 OSL_ENSURE( sal_False, "Content::execute - unsupported command!" );
455 ::ucbhelper::cancelCommandExecution(
456 uno::makeAny( ucb::UnsupportedCommandException(
457 rtl::OUString(),
458 static_cast< cppu::OWeakObject * >( this ) ) ),
459 Environment );
460 // Unreachable
463 return aRet;
466 //=========================================================================
467 // virtual
468 void SAL_CALL Content::abort( sal_Int32 )
469 throw( uno::RuntimeException )
471 // @@@ Implement logic to abort running commands, if this makes
472 // sense for your content.
475 //=========================================================================
477 // Non-interface methods.
479 //=========================================================================
481 // virtual
482 rtl::OUString Content::getParentURL()
484 rtl::OUString aURL = m_xIdentifier->getContentIdentifier();
486 // @@@ Extract URL of parent from aURL and return it...
488 return rtl::OUString();
491 //=========================================================================
492 // static
493 uno::Reference< sdbc::XRow > Content::getPropertyValues(
494 const uno::Reference< lang::XMultiServiceFactory >& rSMgr,
495 const uno::Sequence< beans::Property >& rProperties,
496 const ContentProperties& rData,
497 const rtl::Reference<
498 ::ucbhelper::ContentProviderImplHelper >& rProvider,
499 const rtl::OUString& rContentId )
501 // Note: Empty sequence means "get values of all supported properties".
503 rtl::Reference< ::ucbhelper::PropertyValueSet > xRow
504 = new ::ucbhelper::PropertyValueSet( rSMgr );
506 sal_Int32 nCount = rProperties.getLength();
507 if ( nCount )
509 uno::Reference< beans::XPropertySet > xAdditionalPropSet;
510 sal_Bool bTriedToGetAdditonalPropSet = sal_False;
512 const beans::Property* pProps = rProperties.getConstArray();
513 for ( sal_Int32 n = 0; n < nCount; ++n )
515 const beans::Property& rProp = pProps[ n ];
517 // Process Core properties.
519 if ( rProp.Name.equalsAsciiL(
520 RTL_CONSTASCII_STRINGPARAM( "ContentType" ) ) )
522 xRow->appendString ( rProp, rData.aContentType );
524 else if ( rProp.Name.equalsAsciiL(
525 RTL_CONSTASCII_STRINGPARAM( "Title" ) ) )
527 xRow->appendString ( rProp, rData.aTitle );
529 else if ( rProp.Name.equalsAsciiL(
530 RTL_CONSTASCII_STRINGPARAM( "IsDocument" ) ) )
532 xRow->appendBoolean( rProp, rData.bIsDocument );
534 else if ( rProp.Name.equalsAsciiL(
535 RTL_CONSTASCII_STRINGPARAM( "IsFolder" ) ) )
537 xRow->appendBoolean( rProp, rData.bIsFolder );
540 // @@@ Process other properties supported directly.
541 #if 0
542 else if ( rProp.Name.equalsAsciiL(
543 RTL_CONSTASCII_STRINGPARAM( "xxxxxx" ) ) )
546 #endif
547 else
549 // @@@ Note: If your data source supports adding/removing
550 // properties, you should implement the interface
551 // XPropertyContainer by yourself and supply your own
552 // logic here. The base class uses the service
553 // "com.sun.star.ucb.Store" to maintain Additional Core
554 // properties. But using server functionality is preferred!
556 // Not a Core Property! Maybe it's an Additional Core Property?!
558 if ( !bTriedToGetAdditonalPropSet && !xAdditionalPropSet.is() )
560 xAdditionalPropSet
561 = uno::Reference< beans::XPropertySet >(
562 rProvider->getAdditionalPropertySet( rContentId,
563 sal_False ),
564 uno::UNO_QUERY );
565 bTriedToGetAdditonalPropSet = sal_True;
568 if ( xAdditionalPropSet.is() )
570 if ( !xRow->appendPropertySetValue(
571 xAdditionalPropSet,
572 rProp ) )
574 // Append empty entry.
575 xRow->appendVoid( rProp );
578 else
580 // Append empty entry.
581 xRow->appendVoid( rProp );
586 else
588 // Append all Core Properties.
589 xRow->appendString (
590 beans::Property( rtl::OUString::createFromAscii( "ContentType" ),
592 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
593 beans::PropertyAttribute::BOUND
594 | beans::PropertyAttribute::READONLY ),
595 rData.aContentType );
596 xRow->appendString (
597 beans::Property( rtl::OUString::createFromAscii( "Title" ),
599 getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
600 beans::PropertyAttribute::BOUND ),
601 rData.aTitle );
602 xRow->appendBoolean(
603 beans::Property( rtl::OUString::createFromAscii( "IsDocument" ),
605 getCppuBooleanType(),
606 beans::PropertyAttribute::BOUND
607 | beans::PropertyAttribute::READONLY ),
608 rData.bIsDocument );
609 xRow->appendBoolean(
610 beans::Property( rtl::OUString::createFromAscii( "IsFolder" ),
612 getCppuBooleanType(),
613 beans::PropertyAttribute::BOUND
614 | beans::PropertyAttribute::READONLY ),
615 rData.bIsFolder );
617 // @@@ Append other properties supported directly.
619 // @@@ Note: If your data source supports adding/removing
620 // properties, you should implement the interface
621 // XPropertyContainer by yourself and supply your own
622 // logic here. The base class uses the service
623 // "com.sun.star.ucb.Store" to maintain Additional Core
624 // properties. But using server functionality is preferred!
626 // Append all Additional Core Properties.
628 uno::Reference< beans::XPropertySet > xSet(
629 rProvider->getAdditionalPropertySet( rContentId, sal_False ),
630 uno::UNO_QUERY );
631 xRow->appendPropertySet( xSet );
634 return uno::Reference< sdbc::XRow >( xRow.get() );
637 //=========================================================================
638 uno::Reference< sdbc::XRow > Content::getPropertyValues(
639 const uno::Sequence< beans::Property >& rProperties,
640 const uno::Reference< ucb::XCommandEnvironment >& /* xEnv */)
642 osl::Guard< osl::Mutex > aGuard( m_aMutex );
643 return getPropertyValues( m_xSMgr,
644 rProperties,
645 m_aProps,
646 rtl::Reference<
647 ::ucbhelper::ContentProviderImplHelper >(
648 m_xProvider.get() ),
649 m_xIdentifier->getContentIdentifier() );
652 //=========================================================================
653 uno::Sequence< uno::Any > Content::setPropertyValues(
654 const uno::Sequence< beans::PropertyValue >& rValues,
655 const uno::Reference< ucb::XCommandEnvironment >& /* xEnv */)
657 osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
659 uno::Sequence< uno::Any > aRet( rValues.getLength() );
660 uno::Sequence< beans::PropertyChangeEvent > aChanges( rValues.getLength() );
661 sal_Int32 nChanged = 0;
663 beans::PropertyChangeEvent aEvent;
664 aEvent.Source = static_cast< cppu::OWeakObject * >( this );
665 aEvent.Further = sal_False;
666 // aEvent.PropertyName =
667 aEvent.PropertyHandle = -1;
668 // aEvent.OldValue =
669 // aEvent.NewValue =
671 const beans::PropertyValue* pValues = rValues.getConstArray();
672 sal_Int32 nCount = rValues.getLength();
674 uno::Reference< ucb::XPersistentPropertySet > xAdditionalPropSet;
675 sal_Bool bTriedToGetAdditonalPropSet = sal_False;
677 for ( sal_Int32 n = 0; n < nCount; ++n )
679 const beans::PropertyValue& rValue = pValues[ n ];
681 if ( rValue.Name.equalsAsciiL(
682 RTL_CONSTASCII_STRINGPARAM( "ContentType" ) ) )
684 // Read-only property!
685 aRet[ n ] <<= lang::IllegalAccessException(
686 rtl::OUString::createFromAscii(
687 "Property is read-only!" ),
688 static_cast< cppu::OWeakObject * >( this ) );
690 else if ( rValue.Name.equalsAsciiL(
691 RTL_CONSTASCII_STRINGPARAM( "IsDocument" ) ) )
693 // Read-only property!
694 aRet[ n ] <<= lang::IllegalAccessException(
695 rtl::OUString::createFromAscii(
696 "Property is read-only!" ),
697 static_cast< cppu::OWeakObject * >( this ) );
699 else if ( rValue.Name.equalsAsciiL(
700 RTL_CONSTASCII_STRINGPARAM( "IsFolder" ) ) )
702 // Read-only property!
703 aRet[ n ] <<= lang::IllegalAccessException(
704 rtl::OUString::createFromAscii(
705 "Property is read-only!" ),
706 static_cast< cppu::OWeakObject * >( this ) );
708 else if ( rValue.Name.equalsAsciiL(
709 RTL_CONSTASCII_STRINGPARAM( "Title" ) ) )
711 rtl::OUString aNewValue;
712 if ( rValue.Value >>= aNewValue )
714 if ( aNewValue != m_aProps.aTitle )
716 aEvent.PropertyName = rValue.Name;
717 aEvent.OldValue = uno::makeAny( m_aProps.aTitle );
718 aEvent.NewValue = uno::makeAny( aNewValue );
720 aChanges.getArray()[ nChanged ] = aEvent;
722 m_aProps.aTitle = aNewValue;
723 nChanged++;
725 else
727 // Old value equals new value. No error!
730 else
732 aRet[ n ] <<= beans::IllegalTypeException(
733 rtl::OUString::createFromAscii(
734 "Property value has wrong type!" ),
735 static_cast< cppu::OWeakObject * >( this ) );
739 // @@@ Process other properties supported directly.
740 #if 0
741 else if ( rValue.Name.equalsAsciiL(
742 RTL_CONSTASCII_STRINGPARAM( "xxxxxx" ) ) )
745 #endif
746 else
748 // @@@ Note: If your data source supports adding/removing
749 // properties, you should implement the interface
750 // XPropertyContainer by yourself and supply your own
751 // logic here. The base class uses the service
752 // "com.sun.star.ucb.Store" to maintain Additional Core
753 // properties. But using server functionality is preferred!
755 // Not a Core Property! Maybe it's an Additional Core Property?!
757 if ( !bTriedToGetAdditonalPropSet && !xAdditionalPropSet.is() )
759 xAdditionalPropSet = getAdditionalPropertySet( sal_False );
760 bTriedToGetAdditonalPropSet = sal_True;
763 if ( xAdditionalPropSet.is() )
767 uno::Any aOldValue
768 = xAdditionalPropSet->getPropertyValue( rValue.Name );
769 if ( aOldValue != rValue.Value )
771 xAdditionalPropSet->setPropertyValue(
772 rValue.Name, rValue.Value );
774 aEvent.PropertyName = rValue.Name;
775 aEvent.OldValue = aOldValue;
776 aEvent.NewValue = rValue.Value;
778 aChanges.getArray()[ nChanged ] = aEvent;
779 nChanged++;
781 else
783 // Old value equals new value. No error!
786 catch ( beans::UnknownPropertyException const & e )
788 aRet[ n ] <<= e;
790 catch ( lang::WrappedTargetException const & e )
792 aRet[ n ] <<= e;
794 catch ( beans::PropertyVetoException const & e )
796 aRet[ n ] <<= e;
798 catch ( lang::IllegalArgumentException const & e )
800 aRet[ n ] <<= e;
803 else
805 aRet[ n ] <<= uno::Exception(
806 rtl::OUString::createFromAscii(
807 "No property set for storing the value!" ),
808 static_cast< cppu::OWeakObject * >( this ) );
813 if ( nChanged > 0 )
815 // @@@ Save changes.
816 // storeData();
818 aGuard.clear();
819 aChanges.realloc( nChanged );
820 notifyPropertiesChange( aChanges );
823 return aRet;
826 #ifdef IMPLEMENT_COMMAND_INSERT
828 //=========================================================================
829 void Content::queryChildren( ContentRefList& rChildren )
831 // @@@ Adapt method to your URL scheme...
833 // Obtain a list with a snapshot of all currently instanciated contents
834 // from provider and extract the contents which are direct children
835 // of this content.
837 ::ucbhelper::ContentRefList aAllContents;
838 m_xProvider->queryExistingContents( aAllContents );
840 ::rtl::OUString aURL = m_xIdentifier->getContentIdentifier();
841 sal_Int32 nPos = aURL.lastIndexOf( '/' );
843 if ( nPos != ( aURL.getLength() - 1 ) )
845 // No trailing slash found. Append.
846 aURL += ::rtl::OUString::createFromAscii( "/" );
849 sal_Int32 nLen = aURL.getLength();
851 ::ucbhelper::ContentRefList::const_iterator it = aAllContents.begin();
852 ::ucbhelper::ContentRefList::const_iterator end = aAllContents.end();
854 while ( it != end )
856 ::ucbhelper::ContentImplHelperRef xChild = (*it);
857 ::rtl::OUString aChildURL
858 = xChild->getIdentifier()->getContentIdentifier();
860 // Is aURL a prefix of aChildURL?
861 if ( ( aChildURL.getLength() > nLen ) &&
862 ( aChildURL.compareTo( aURL, nLen ) == 0 ) )
864 nPos = aChildURL.indexOf( '/', nLen );
866 if ( ( nPos == -1 ) ||
867 ( nPos == ( aChildURL.getLength() - 1 ) ) )
869 // No further slashes / only a final slash. It's a child!
870 rChildren.push_back(
871 ContentRef(
872 static_cast< Content * >( xChild.get() ) ) );
875 ++it;
879 //=========================================================================
880 void Content::insert(
881 const uno::Reference< io::XInputStream > & xInputStream,
882 sal_Bool bReplaceExisting,
883 const uno::Reference< ucb::XCommandEnvironment >& Environment )
884 throw( uno::Exception )
886 osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
888 // Check, if all required properties were set.
890 #if 0
891 // @@@ add checks for property presence
892 if ( m_aProps.xxxx == yyyyy )
894 OSL_ENSURE( sal_False, "Content::insert - property value missing!" );
896 uno::Sequence< rtl::OUString > aProps( 1 );
897 aProps[ 0 ] = rtl::OUString::createFromAscii( "zzzz" );
898 ::ucbhelper::cancelCommandExecution(
899 uno::makeAny( ucb::MissingPropertiesException(
900 rtl::OUString(),
901 static_cast< cppu::OWeakObject * >( this ),
902 aProps ) ),
903 Environment );
904 // Unreachable
906 #endif
908 bool bNeedInputStream = true; // @@@ adjust to real requirements
909 if ( bNeedInputStream && !xInputStream.is() )
911 OSL_ENSURE( sal_False, "Content::insert - No data stream!" );
913 ::ucbhelper::cancelCommandExecution(
914 uno::makeAny( ucb::MissingInputStreamException(
915 rtl::OUString(),
916 static_cast< cppu::OWeakObject * >( this ) ) ),
917 Environment );
918 // Unreachable
921 // Assemble new content identifier...
923 uno::Reference< ucb::XContentIdentifier > xId /* @@@ create content identifier */;
925 // Fail, if a resource with given id already exists.
926 if ( !bReplaceExisting /*&& hasData( xId ) @@@ impl for hasData() */ )
928 uno::Any aProps
929 = uno::makeAny( beans::PropertyValue(
930 rtl::OUString(
931 RTL_CONSTASCII_USTRINGPARAM( "Uri" ) ),
933 uno::makeAny( xId->getContentIdentifier() ),
934 beans::PropertyState_DIRECT_VALUE ) );
935 ucbhelper::cancelCommandExecution(
936 ucb::IOErrorCode_ALREADY_EXISTING,
937 uno::Sequence< uno::Any >(&aProps, 1),
938 Environment,
939 rtl::OUString::createFromAscii( "content already existing!!" ),
940 this );
941 // Unreachable
944 m_xIdentifier = xId;
946 // @@@
947 // storeData();
949 aGuard.clear();
950 inserted();
953 #endif // IMPLEMENT_COMMAND_INSERT
955 #ifdef IMPLEMENT_COMMAND_DELETE
957 //=========================================================================
958 void Content::destroy( sal_Bool bDeletePhysical )
959 throw( uno::Exception )
961 // @@@ take care about bDeletePhysical -> trashcan support
963 uno::Reference< ucb::XContent > xThis = this;
965 deleted();
967 osl::Guard< osl::Mutex > aGuard( m_aMutex );
969 // Process instanciated children...
971 ContentRefList aChildren;
972 queryChildren( aChildren );
974 ContentRefList::const_iterator it = aChildren.begin();
975 ContentRefList::const_iterator end = aChildren.end();
977 while ( it != end )
979 (*it)->destroy( bDeletePhysical );
980 ++it;
984 #endif // IMPLEMENT_COMMAND_DELETE