Calc/Implementation/Filter in spreadsheet

From Apache OpenOffice Wiki
< Calc‎ | Implementation
Revision as of 06:04, 1 June 2012 by Leiw (Talk | contribs)

Jump to: navigation, search

The whole view of filter

An in-memory Symphony document is represented by it's document model. On disk, the same document is represented as a file. An import component must turn the latter into the former as shown by this diagram.

Filter structure.JPG

Filter in symphony

When open a file in symphony, the supported filters will be initialized by the class of SfxFilterContainer in sfx2\inc\sfx2. It contains a member of SfxFilterContainer_Impl *pImpl. Symphony uses this class to control every SfxFilter.


There are a global variable for storing SfxFilter, the name is static SfxFilterList_Impl* pFilterArr = 0; it is defined in sfx2\source\bastyp\fltfnc.cxx. Indeed SfxFilterList_Impl is a list defined by DECLARE_LIST( SfxFilterList_Impl, SfxFilter* ) in sfx2\inc\arrdecl.hxx. The detail can be traced by the call stack. Callstack.JPG

Get the correct filter to load a document

To import a real document, symphony should get the file type to use the correct filter. To get the filter, Symphony will use flat detection and deep detection. In few words the "flat detection" is a type detection based on document extension, for example,a document named "test.xls", it will get calc to load it by the extension of "xls". The "deep detection" is the detection that analyzes the document contents. For example, if a document named "test.xls",but it is presentation document, then the deep detection should be joined. In the file of filter\source\config\cache\typedetection.cxx, the function of TypeDetection::queryTypeByDescriptor is the entry for getting the filter to loading the document.

  • Flat detection

FilterCache::detectFlatForURL, it can get the correct filter by the extention of the document name. The function is defined in filter\source\config\cache\filtercache.cxx A subset of document types is defined for a real filter. For example, to calc, it is defined in Basis\share\registry\modules\org\openoffice\TypeDetection\Filter\fcfg_calc_filters.xcu, here is an item for MS excel 97 file format. <node oor:name="MS Excel 97" oor:op="replace"> <prop oor:name="Flags"><value>IMPORT EXPORT ALIEN PREFERRED</value></prop> <prop oor:name="UIComponent"/> <prop oor:name="FilterService"/> <prop oor:name="UserData"/> <prop oor:name="UIName"> <value xml:lang="x-default">Microsoft Excel 97/2000/XP</value> </prop> <prop oor:name="FileFormatVersion"><value>0</value></prop> <prop oor:name="Type"><value>calc_MS_Excel_97</value></prop> <prop oor:name="TemplateName"/> <prop oor:name="DocumentService"><value></value></prop> </node> The UIName defines the string of MS excel 97 displayed for open/save dialog. The Type defines the string used in the internal code of Symphony. The DocumentService defines which service is used to import/export such document.


  • Deep detection

Symphony uses the interface XExtendedFilterDetection to look into the document stream to detect the format. It belongs to :: com :: sun :: star :: document. This function is called by TypeDetection::impl_askDetectService in the file filter\source\config\cache\typedetection.cxx sDeepType = xDetector->detect(lDescriptor); In the step 3.1, Symphony has got the filters by the file's extention. The types matching to the given extention. Calc_MS_Excel_40 Calc_MS_Excel_95 Calc_MS_Excel_97 Calc_Text_txt_csv_StarCalc Calc_MS_Excel_5095 By the types, Symphony will do the deep detection. It is realized by a spreadsheet servcie of

In the function of TypeDetection::impl_askDetectService(), It calls xDetector->detect(lDescriptor); The real implement function is ScFilterDetect::detect() It is defined in sc\source\ui\unoobj\scdetect.cxx At first, make a SotStorage by the input stream of MS excel SotStorageRef aStorage = new SotStorage ( pStream, FALSE ); Then check the content of the file, if there is a sub stream named "Workbook" or "Book". String aStreamName(RTL_CONSTASCII_STRINGPARAM("Workbook")); BOOL bExcel97Stream = ( aStorage->IsStream( aStreamName ) );

aStreamName = String(RTL_CONSTASCII_STRINGPARAM("Book")); BOOL bExcel5Stream = ( aStorage->IsStream( aStreamName ) ); Deepdetect.jpg

  • Load a chart in spreadsheet filter

Chart is managed by the class of XclImpObjectManager in spreadsheet. The real implement is XclImpChartObj that is base on XclImplDrawObjBase. XclImpChart will import the parts of chart, for example, diagram, series, title, background, etc.


Personal tools