26#include <com/sun/star/awt/XVclWindowPeer.hpp>
27#include <com/sun/star/sdbc/ResultSetType.hpp>
28#include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
29#include <com/sun/star/sdbc/SQLException.hpp>
30#include <com/sun/star/sdb/XColumn.hpp>
31#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
32#include <com/sun/star/sdbc/XRowSet.hpp>
33#include <com/sun/star/frame/XFrameLoader.hpp>
34#include <com/sun/star/lang/XServiceInfo.hpp>
35#include <com/sun/star/lang/XMultiServiceFactory.hpp>
36#include <com/sun/star/beans/PropertyAttribute.hpp>
37#include <com/sun/star/beans/XPropertySet.hpp>
38#include <com/sun/star/container/XNameAccess.hpp>
39#include <com/sun/star/text/BibliographyDataField.hpp>
40#include <com/sun/star/form/XLoadable.hpp>
41#include <com/sun/star/frame/XLayoutManager.hpp>
70class BibliographyLoader :
public cppu::WeakImplHelper
71 < XServiceInfo, XNameAccess, XPropertySet, XFrameLoader >
75 Reference< XNameAccess > m_xColumns;
76 Reference< XResultSet > m_xCursor;
80 void loadView(
const Reference< XFrame > & aFrame,
81 const Reference< XLoadEventListener > & aListener);
84 Reference< XNameAccess >
const & GetDataColumns()
const;
85 Reference< XResultSet >
const & GetDataCursor()
const;
86 Reference< sdb::XColumn > GetIdentifierColumn()
const;
90 virtual ~BibliographyLoader()
override;
98 virtual Any SAL_CALL getByName(
const OUString& aName)
override;
99 virtual Sequence< OUString > SAL_CALL getElementNames()
override;
100 virtual sal_Bool SAL_CALL hasByName(
const OUString& aName)
override;
103 virtual Type SAL_CALL getElementType()
override;
104 virtual sal_Bool SAL_CALL hasElements()
override;
107 virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo()
override;
108 virtual void SAL_CALL
setPropertyValue(
const OUString& PropertyName,
const Any& aValue)
override;
110 virtual void SAL_CALL addPropertyChangeListener(
const OUString& PropertyName,
const Reference< XPropertyChangeListener > & aListener)
override;
111 virtual void SAL_CALL removePropertyChangeListener(
const OUString& PropertyName,
const Reference< XPropertyChangeListener > & aListener)
override;
112 virtual void SAL_CALL addVetoableChangeListener(
const OUString& PropertyName,
const Reference< XVetoableChangeListener > & aListener)
override;
113 virtual void SAL_CALL removeVetoableChangeListener(
const OUString& PropertyName,
const Reference< XVetoableChangeListener > & aListener)
override;
116 virtual void SAL_CALL load(
const Reference< XFrame > & aFrame,
const OUString& aURL,
117 const Sequence< PropertyValue >& aArgs,
118 const Reference< XLoadEventListener > & aListener)
override;
119 virtual void SAL_CALL cancel()
override;
124BibliographyLoader::BibliographyLoader() :
129BibliographyLoader::~BibliographyLoader()
131 Reference< lang::XComponent > xComp(m_xCursor, UNO_QUERY);
140OUString BibliographyLoader::getImplementationName()
142 return "com.sun.star.extensions.Bibliography";
146sal_Bool BibliographyLoader::supportsService(
const OUString& ServiceName)
152Sequence< OUString > BibliographyLoader::getSupportedServiceNames()
154 return {
"com.sun.star.frame.FrameLoader",
"com.sun.star.frame.Bibliography" };
157extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
159 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any>
const&)
161 return cppu::acquire(
new BibliographyLoader());
164void BibliographyLoader::cancel()
170void BibliographyLoader::load(
const Reference< XFrame > & rFrame,
const OUString& rURL,
171 const Sequence< PropertyValue >& ,
172 const Reference< XLoadEventListener > & rListener)
180 Reference<XPropertySet> xPrSet(rFrame, UNO_QUERY);
184 aTitle <<=
BibResId(RID_BIB_STR_FRAME_TITLE);
185 xPrSet->setPropertyValue(
"Title", aTitle);
187 if(aPartName == u
"View" || aPartName == u
"View1")
189 loadView(rFrame, rListener);
194void BibliographyLoader::loadView(
const Reference< XFrame > & rFrame,
195 const Reference< XLoadEventListener > & rListener)
209 if(aSources.hasElements())
210 aBibDesc.
sDataSource = aSources.getConstArray()[0];
213 m_xDatMan->createDatabaseForm( aBibDesc );
215 Reference<awt::XWindow> aWindow = rFrame->getContainerWindow();
224 m_xDatMan->SetView( pView );
228 pMyWindow->createTopFrame(pBeamer);
230 pMyWindow->createBottomFrame(pView);
232 Reference< awt::XWindow > xWin ( pMyWindow->GetComponentInterface(), UNO_QUERY );
236 xCtrRef->attachFrame(rFrame);
237 rFrame->setComponent( xWin, xCtrRef);
238 pBeamer->SetXController(xCtrRef);
243 aWindow->setVisible(
true);
246 Reference<XLoadable>(m_xDatMan)->load();
247 m_xDatMan->RegisterInterceptor(pBeamer);
249 if ( rListener.is() )
250 rListener->loadFinished(
this );
253 Reference< XPropertySet > xPropSet( rFrame, UNO_QUERY );
254 Reference< css::frame::XLayoutManager > xLayoutManager;
259 Any a = xPropSet->getPropertyValue(
"LayoutManager");
260 a >>= xLayoutManager;
262 catch (
const uno::Exception& )
267 if ( xLayoutManager.is() )
268 xLayoutManager->createElement(
"private:resource/menubar/menubar" );
276 const_cast< BibliographyLoader*
>( this )->m_pBibMod =
OpenBibModul();
279 return m_xDatMan.get();
282Reference< XNameAccess >
const & BibliographyLoader::GetDataColumns()
const
284 if (!m_xColumns.is())
287 Reference< XRowSet > xRowSet(xMgr->createInstance(
"com.sun.star.sdb.RowSet"), UNO_QUERY);
288 Reference< XPropertySet > xResultSetProps(xRowSet, UNO_QUERY);
289 DBG_ASSERT(xResultSetProps.is() ,
"BibliographyLoader::GetDataCursor : invalid row set (no XResultSet or no XPropertySet) !");
294 xResultSetProps->setPropertyValue(
"DataSourceName", aBibUrlAny);
296 xResultSetProps->setPropertyValue(
"CommandType", aCommandType);
298 xResultSetProps->setPropertyValue(
"Command", aTableName);
299 Any aResultSetType; aResultSetType <<= sal_Int32(ResultSetType::SCROLL_INSENSITIVE);
300 xResultSetProps->setPropertyValue(
"ResultSetType", aResultSetType);
301 Any aResultSetCurrency; aResultSetCurrency <<= sal_Int32(ResultSetConcurrency::UPDATABLE);
302 xResultSetProps->setPropertyValue(
"ResultSetConcurrency", aResultSetCurrency);
304 bool bSuccess =
false;
310 catch(
const SQLException&)
314 catch(
const Exception& )
322 Reference< XComponent > xSetComp(xRowSet, UNO_QUERY);
328 const_cast<BibliographyLoader*
>(
this)->m_xCursor = xRowSet.get();
330 Reference< sdbcx::XColumnsSupplier > xSupplyCols(m_xCursor, UNO_QUERY);
331 if (xSupplyCols.is())
332 const_cast<BibliographyLoader*
>(
this)->m_xColumns = xSupplyCols->getColumns();
338Reference< sdb::XColumn > BibliographyLoader::GetIdentifierColumn()
const
341 Reference< XNameAccess > xColumns = GetDataColumns();
344 Reference< sdb::XColumn > xReturn;
345 if (xColumns.is() && xColumns->hasByName(sIdentifierColumnName))
347 xReturn.set(xColumns->getByName(sIdentifierColumnName), UNO_QUERY);
352Reference< XResultSet >
const & BibliographyLoader::GetDataCursor()
const
362 const Mapping* pMapping,
const OUString& rColumnName)
364 OUString sColumnName(rColumnName);
367 for(
const auto & aColumnPair :
pMapping->aColumnPairs)
369 if(aColumnPair.sLogicalColumnName == rColumnName)
371 sColumnName = aColumnPair.sRealColumnName;
376 OUString uColumnName(sColumnName);
378 Reference< sdb::XColumn > xCol;
379 if (xColumns->hasByName(uColumnName))
380 xCol.set(xColumns->getByName(uColumnName), UNO_QUERY);
382 uRet = xCol->getString();
386Any BibliographyLoader::getByName(
const OUString& rName)
392 Reference< XResultSet > xCursor = GetDataCursor();
393 Reference< sdbcx::XColumnsSupplier > xSupplyCols(xCursor, UNO_QUERY);
394 Reference< XNameAccess > xColumns;
395 if (!xSupplyCols.is())
397 xColumns = xSupplyCols->getColumns();
398 DBG_ASSERT(xSupplyCols.is(),
"BibliographyLoader::getByName : invalid columns returned by the data cursor (may be the result set is not alive ?) !");
403 Reference< sdb::XColumn >
xColumn;
404 if (xColumns->hasByName(sIdentifierMapping))
405 xColumn.set(xColumns->getByName(sIdentifierMapping), UNO_QUERY);
413 PropertyValue*
pValues = aPropSequ.getArray();
417 for(sal_uInt16 nEntry = 0; nEntry <
COLUMN_COUNT; nEntry++)
421 pValues[nEntry].Name = sColName;
429 while(xCursor->next());
432 catch(
const Exception&)
439Sequence< OUString > BibliographyLoader::getElementNames()
441 Sequence< OUString > aRet(10);
442 int nRealNameCount = 0;
445 Reference< XResultSet > xCursor(GetDataCursor());
446 Reference< sdb::XColumn > xIdColumn(GetIdentifierColumn());
451 OUString sTemp = xIdColumn->getString();
452 if (!sTemp.isEmpty() && !xIdColumn->wasNull())
454 int nLen = aRet.getLength();
455 if(nLen == nRealNameCount)
456 aRet.realloc(nLen + 10);
457 OUString* pArray = aRet.getArray();
458 pArray[nRealNameCount] = sTemp;
462 while (xCursor->next());
465 catch(
const Exception&)
470 aRet.realloc(nRealNameCount);
474sal_Bool BibliographyLoader::hasByName(
const OUString& rName)
479 Reference< XResultSet > xCursor = GetDataCursor();
480 Reference< sdb::XColumn > xIdColumn = GetIdentifierColumn();
486 OUString sCurrentId = xIdColumn->getString();
487 if (!xIdColumn->wasNull() && rName.startsWith(sCurrentId))
493 while(xCursor->next());
496 catch(
const Exception&)
503Type BibliographyLoader::getElementType()
508sal_Bool BibliographyLoader::hasElements()
510 Reference< XNameAccess > xColumns = GetDataColumns();
511 return xColumns.is() && xColumns->getElementNames().hasElements();
514Reference< XPropertySetInfo > BibliographyLoader::getPropertySetInfo()
520 static Reference< XPropertySetInfo > xRet =
525void BibliographyLoader::setPropertyValue(
const OUString& ,
528 throw UnknownPropertyException();
532Any BibliographyLoader::getPropertyValue(
const OUString& rPropertyName)
535 static const sal_uInt16 aInternalMapping[] =
570 if(rPropertyName !=
"BibliographyDataFieldNames")
571 throw UnknownPropertyException(rPropertyName);
573 PropertyValue* pArray =
aSeq.getArray();
575 for(sal_uInt16 i = 0;
i <= text::BibliographyDataField::LOCAL_URL ;
i++)
578 pArray[
i].Value <<=
static_cast<sal_Int16
>(
i);
584void BibliographyLoader::addPropertyChangeListener(
585 const OUString& ,
const Reference< XPropertyChangeListener > & )
590void BibliographyLoader::removePropertyChangeListener(
591 const OUString& ,
const Reference< XPropertyChangeListener > & )
596void BibliographyLoader::addVetoableChangeListener(
597 const OUString& ,
const Reference< XVetoableChangeListener > & )
602void BibliographyLoader::removeVetoableChangeListener(
603 const OUString& ,
const Reference< XVetoableChangeListener > & )
const PropertyValue * pValues
#define ORGANIZATIONS_POS
#define AUTHORITYTYPE_POS
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * extensions_BibliographyLoader_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
static OUString lcl_AddProperty(const Reference< XNameAccess > &xColumns, const Mapping *pMapping, const OUString &rColumnName)
OUString BibResId(TranslateId aId)
void CloseBibModul(HdlBibModul ppBibModul)
HdlBibModul OpenBibModul()
const Mapping * GetMapping(const BibDBDescriptor &rDesc) const
const OUString & GetDefColumnName(sal_uInt16 nIndex) const
BibDBDescriptor GetBibliographyURL()
const OUString & GetIdentifierMapping()
static rtl::Reference< BibDataManager > createDataManager()
static BibConfig * GetConfig()
const css::uno::Sequence< OUString > & GetDataSourceNames()
css::uno::Reference< css::beans::XPropertySetInfo > const & getPropertySetInfo() const
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
#define DBG_ASSERT(sCon, aError)
#define DBG_UNHANDLED_EXCEPTION(...)
Sequence< sal_Int8 > aSeq
Reference< XMultiServiceFactory > getProcessServiceFactory()
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
VBAHELPER_DLLPUBLIC bool setPropertyValue(css::uno::Sequence< css::beans::PropertyValue > &aProp, const OUString &aName, const css::uno::Any &aValue)
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)