// File: ooofilt.cxx // Contents: Filter Implementation for OpenOffice.Org Document using // Indexing Service // Summary: The LibreOffice filter reads OpenOffice.org XML files (with // the extension .sxw .sxi, etc) and ODF files and extract // their content, author, keywords,subject,comments and title // to be filtered.
static ::std::wstring GetMetaInfoNameFromPropertyId( ULONG ulPropID )
{ switch ( ulPropID )
{ case PIDSI_AUTHOR: return META_INFO_AUTHOR; case PIDSI_TITLE: return META_INFO_TITLE; case PIDSI_SUBJECT: return META_INFO_SUBJECT; case PIDSI_KEYWORDS: return META_INFO_KEYWORDS; case PIDSI_COMMENTS: return META_INFO_DESCRIPTION; default: return EMPTY_STRING;
}
} //M------------------------------------------------------------------------- // Method: COooFilter::GetValue (IFilter::GetValue) // Summary: Retrieves properties for index // Arguments: ppPropValue // [out] Address that receives pointer to property value // Returns: FILTER_E_NO_VALUES // Always // FILTER_E_NO_MORE_VALUES // (not implemented)
SCODE STDMETHODCALLTYPE COooFilter::GetValue(PROPVARIANT ** ppPropValue)
{ if (m_eState == FilterState::FilteringContent) return FILTER_E_NO_VALUES; else// m_eState == FilteringProperty
{ if ( m_cAttributes == 0 || ( m_ulCurrentPropertyNum == m_ulPropertyNum ) ) return FILTER_E_NO_MORE_VALUES;
PROPVARIANT *pPropVar = static_cast<PROPVARIANT *>(CoTaskMemAlloc( sizeof (PROPVARIANT) )); if ( pPropVar == nullptr ) return E_OUTOFMEMORY;
::std::wstring wsTagName= GetMetaInfoNameFromPropertyId( m_pAttributes[m_ulCurrentPropertyNum].GetPropertyPropid() ); if ( wsTagName == EMPTY_STRING ) return FILTER_E_NO_VALUES;
::std::wstring wsTagData = m_pMetaInfoReader->getTagData(wsTagName);
pPropVar->vt = VT_LPWSTR;
size_t cw = wsTagData.length() + 1; // reserve one for the '\0'
pPropVar->pwszVal = static_cast<WCHAR*>( CoTaskMemAlloc(cw*sizeof(WCHAR)) ); if (pPropVar->pwszVal == nullptr)
{
CoTaskMemFree(pPropVar); return E_OUTOFMEMORY;
}
wmemcpy(pPropVar->pwszVal, wsTagData.c_str(), cw);
*ppPropValue = pPropVar;
m_ulCurrentPropertyNum = m_ulPropertyNum; return S_OK;
}
} //M------------------------------------------------------------------------- // Method: COooFilter::BindRegion (IFilter::BindRegion) // Summary: Creates moniker or other interface for indicated text // Arguments: origPos // [in] Description of text location and extent // riid // [in] Reference IID of specified interface // ppunk // [out] Address that receives requested interface pointer // Returns: E_NOTIMPL // Always // FILTER_W_REGION_CLIPPED // (not implemented)
SCODE STDMETHODCALLTYPE COooFilter::BindRegion(
FILTERREGION /*origPos*/,
REFIID /*riid*/, void ** /*ppunk*/)
{ // BindRegion is currently reserved for future use return E_NOTIMPL;
} //M------------------------------------------------------------------------- // Method: COooFilter::GetClassID (IPersist::GetClassID) // Summary: Retrieves the class id of the filter class // Arguments: pClassID // [out] Pointer to the class ID of the filter // Returns: S_OK // Always // E_FAIL // (not implemented)
HRESULT STDMETHODCALLTYPE COooFilter::GetClassID(CLSID * pClassID)
{
*pClassID = CLSID_COooFilter; return S_OK;
} //M------------------------------------------------------------------------- // Method: COooFilter::IsDirty (IPersistFile::IsDirty) // Summary: Checks whether file has changed since last save // Arguments: void // Returns: S_FALSE // Always // S_OK // (not implemented)
HRESULT STDMETHODCALLTYPE COooFilter::IsDirty()
{ // File is opened read-only and never changes return S_FALSE;
} //M------------------------------------------------------------------------- // Method: COooFilter::Load (IPersistFile::Load) // Summary: Opens and initializes the specified file // Arguments: pszFileName // [in] Pointer to zero-terminated string // of absolute path of file to open // dwMode // [in] Access mode to open the file // Returns: S_OK // File was successfully loaded // E_OUTOFMEMORY // File could not be loaded due to insufficient memory // E_FAIL // (not implemented)
HRESULT STDMETHODCALLTYPE COooFilter::Load(LPCOLESTR pszFileName, DWORD /*dwMode*/)
{ // Load just sets the filename for GetChunk to read and ignores the mode
m_pwszFileName = getShortPathName( pszFileName );
// Open the file previously specified in call to IPersistFile::Load and get content. try
{ delete m_pMetaInfoReader;
m_pMetaInfoReader = new CMetaInfoReader(m_pwszFileName);
delete m_pContentReader;
m_pContentReader = new CContentReader(m_pwszFileName, m_pMetaInfoReader->getDefaultLocale());
} catch (const std::exception&)
{ return E_FAIL;
} return S_OK;
} //M------------------------------------------------------------------------- // Method: COooFilter::Save (IPersistFile::Save) // Summary: Saves a copy of the current file being filtered // Arguments: pszFileName // [in] Pointer to zero-terminated string of // absolute path of where to save file // fRemember // [in] Whether the saved copy is made the current file // Returns: E_FAIL // Always // S_OK // (not implemented)
HRESULT STDMETHODCALLTYPE COooFilter::Save(LPCOLESTR /*pszFileName*/, BOOL /*fRemember*/)
{ // File is opened read-only; saving it is an error return E_FAIL;
} //M------------------------------------------------------------------------- // Method: COooFilter::SaveCompleted (IPersistFile::SaveCompleted) // Summary: Determines whether a file save is completed // Arguments: pszFileName // [in] Pointer to zero-terminated string of // absolute path where file was previously saved // Returns: S_OK // Always
HRESULT STDMETHODCALLTYPE COooFilter::SaveCompleted(LPCOLESTR /*pszFileName*/)
{ // File is opened read-only, so "save" is always finished return S_OK;
}
//M------------------------------------------------------------------------- // Method: COooFilter::Load (IPersistStream::Load) // Summary: Initializes an object from the stream where it was previously saved // Arguments: pStm // [in] Pointer to stream from which object should be loaded // Returns: S_OK // E_OUTOFMEMORY // E_FAIL
HRESULT STDMETHODCALLTYPE COooFilter::Load(IStream *pStm)
{
m_pStream = new BufferStream(pStm); try
{ delete m_pMetaInfoReader;
m_pMetaInfoReader = new CMetaInfoReader(m_pStream);
//M------------------------------------------------------------------------- // Method: COooFilter::GetSizeMax (IPersistStream::GetSizeMax) // Summary: Returns the size in bytes of the stream needed to save the object. // Arguments: pcbSize // [out] Pointer to a 64 bit unsigned int indicating the size needed // Returns: E_NOTIMPL
//M------------------------------------------------------------------------- // Method: COooFilter::GetCurFile (IPersistFile::GetCurFile) // Summary: Returns a copy of the current file name // Arguments: ppszFileName // [out] Address to receive pointer to zero-terminated // string for absolute path to current file // Returns: S_OK // A valid absolute path was successfully returned // S_FALSE // (not implemented) // E_OUTOFMEMORY // Operation failed due to insufficient memory // E_FAIL // Operation failed due to some reason // other than insufficient memory
//F------------------------------------------------------------------------- // Function: DllMain // Summary: Called from C-Runtime on process/thread attach/detach // Arguments: hInstance // [in] Handle to the DLL // fdwReason // [in] Reason for calling DLL entry point // lpReserve // [in] Details of DLL initialization and cleanup // Returns: TRUE // Always
extern"C"BOOL WINAPI DllMain(
HINSTANCE hInstance,
DWORD fdwReason,
LPVOID /*lpvReserved*/
)
{ if ( DLL_PROCESS_ATTACH == fdwReason )
DisableThreadLibraryCalls( hInstance ); returnTRUE;
} //F------------------------------------------------------------------------- // Function: DllGetClassObject // Summary: Create LibreOffice filter class factory object // Arguments: cid // [in] Class ID of class that class factory creates // iid // [in] Reference IID of requested class factory interface // ppvObj // [out] Address that receives requested interface pointer // Returns: S_OK // Class factory object was created successfully // CLASS_E_CLASSNOTAVAILABLE // DLL does not support the requested class // E_INVALIDARG // (not implemented // E_OUTOFMEMORY // Insufficient memory to create the class factory object // E_UNEXPECTED // Unsuccessful due to an unexpected condition
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.