[Libreoffice-commits] core.git: 9 commits - filter/source sd/source

Kohei Yoshida kohei.yoshida at gmail.com
Wed Mar 6 22:42:50 PST 2013


 filter/source/config/cache/typedetection.cxx    |  529 ++++++++++--------------
 filter/source/config/cache/typedetection.hxx    |   78 ---
 filter/source/textfilterdetect/fdcomp.cxx       |   49 --
 filter/source/textfilterdetect/filterdetect.cxx |   49 +-
 filter/source/textfilterdetect/filterdetect.hxx |    7 
 sd/source/ui/unoidl/sddetect.cxx                |   54 +-
 6 files changed, 328 insertions(+), 438 deletions(-)

New commits:
commit dbcad280a8db68d2a05e625571177c642b3db271
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Thu Mar 7 01:40:12 2013 -0500

    Renamed the method to something more appropriate...
    
    Change-Id: I4a0a6ab0998f41ce238d0570fba2133b79c8f19e

diff --git a/filter/source/config/cache/typedetection.cxx b/filter/source/config/cache/typedetection.cxx
index 367797e..3e4c224 100644
--- a/filter/source/config/cache/typedetection.cxx
+++ b/filter/source/config/cache/typedetection.cxx
@@ -400,7 +400,7 @@ void printFlatDetectionList(const char* caption, const FlatDetection& types)
     }
 
     FlatDetection lFlatTypes;
-    impl_getPreselection(aURL, stlDescriptor, lFlatTypes);
+    impl_getAllFormatTypes(aURL, stlDescriptor, lFlatTypes);
 
     aLock.clear();
     // <- SAFE ----------------------------------
@@ -790,7 +790,7 @@ OUString TypeDetection::impl_getTypeFromFilter(const OUString& rFilterName)
     return aType;
 }
 
-void TypeDetection::impl_getPreselection(
+void TypeDetection::impl_getAllFormatTypes(
     const util::URL& aParsedURL, comphelper::MediaDescriptor& rDescriptor, FlatDetection& rFlatTypes)
 {
     rFlatTypes.clear();
diff --git a/filter/source/config/cache/typedetection.hxx b/filter/source/config/cache/typedetection.hxx
index 3650842..f1dc348 100644
--- a/filter/source/config/cache/typedetection.hxx
+++ b/filter/source/config/cache/typedetection.hxx
@@ -73,31 +73,12 @@ private:
 
     OUString impl_getTypeFromFilter(const OUString& rFilterName);
 
-    /** @short      check if a filter or a type was preselected inside the given
-                    MediaDescriptor and validate this information.
-
-        @descr      Only in case the preselected filter exists and its type registration
-                    seems to be usefully, it would be used realy as valid type detection
-                    result. This method doesnt make any deep detection here. It checks only
-                    if the preselection match to the URL by an URLPattern.
-                    This information has to be added to the given rFlatTypes list too.
-                    The outside code can use it to supress a deep detection then in general.
-                    Because pattern are defined as non detectable at all!
-
-        @param      pDescriptor
-                    provides any easy-to-use stl interface to the MediaDescriptor.
-                    Note : Its content will be adapted to returned result of this method.
-                    Means: The type/filter entries of it will be actualized or removed.
-
-        @param      rFlatTypes
-                    the preselected type (or the registered type of a preselected filter)
-                    will be added here as first(!) element. Further we have to provide the
-                    information, if this type match to the given URL by its URLPattern
-                    registration.
+    /**
+     * Get all format types that we handle.
      */
-    void impl_getPreselection(const css::util::URL&                aParsedURL ,
-                                    ::comphelper::MediaDescriptor& rDescriptor,
-                                    FlatDetection&                 rFlatTypes );
+    void impl_getAllFormatTypes(
+        const com::sun::star::util::URL& aParsedURL, comphelper::MediaDescriptor& rDescriptor,
+        FlatDetection& rFlatTypes);
 
     //---------------------------------------
 
commit e4003b67062e575f9b77772488f9b9691fa9fc38
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Thu Mar 7 01:35:09 2013 -0500

    Make check passes.  Remove deep-only detection for real.
    
    Now the type detection process is a lot more simpler.
    
    Change-Id: I5a3a68afef8276a7f07be75c0b2db8151512b3fb

diff --git a/filter/source/config/cache/typedetection.cxx b/filter/source/config/cache/typedetection.cxx
index aba091d..367797e 100644
--- a/filter/source/config/cache/typedetection.cxx
+++ b/filter/source/config/cache/typedetection.cxx
@@ -426,24 +426,6 @@ void printFlatDetectionList(const char* caption, const FlatDetection& types)
         if (lFlatTypes.size()>0)
             sType = impl_detectTypeFlatAndDeep(stlDescriptor, lFlatTypes, bAllowDeep, lUsedDetectors, sLastChance);
 
-#if 0 // In theory we should no longer need to do deep-only detection, but let's see if it works fine in real life...
-
-        //*******************************************
-        // if no flat detected (nor preselected!) type could be
-        // verified and no error occurred during creation of
-        // the might needed input stream, start detection
-        // which uses all registered deep detection services.
-        if (
-            (sType.isEmpty()) &&
-            (bAllowDeep        )
-           )
-        {
-            // Let's the detection service know we are in a deep detection phase.
-            stlDescriptor[comphelper::MediaDescriptor::PROP_DEEPDETECTION()] <<= sal_True;
-            sType = impl_detectTypeDeepOnly(stlDescriptor, lUsedDetectors);
-        }
-#endif
-
         //*******************************************
         // flat detection failed
         // pure deep detection failed
@@ -969,152 +951,6 @@ void TypeDetection::impl_getPreselection(
     // <- SAFE ----------------------------------
 }
 
-//TO-DO: add a priority entry to filter config, e.g. defaulting to 50 and
-//flag externally that some filters are lower e.g. 25 and are catch-alls
-//to be tried last. Split up writer/calc/etc. filter detection to standalone
-//those problematic formats
-namespace
-{
-    bool sort_catchalls_to_end(const rtl::OUString& rA, const rtl::OUString& rB)
-    {
-        if (rA == rB)
-            return false;
-        if ( rA == "com.sun.star.text.FormatDetector" )
-            return false;
-        if ( rB == "com.sun.star.text.FormatDetector" )
-            return true;
-        return rA < rB;
-    }
-}
-
-::rtl::OUString TypeDetection::impl_detectTypeDeepOnly(      ::comphelper::MediaDescriptor& rDescriptor          ,
-                                                       const OUStringList&                  lOutsideUsedDetectors)
-{
-    // We must know if a detect service was already used:
-    //  i) in a combined flat/deep detection scenario outside or
-    // ii) in this method for a deep detection only.
-    // Reason: Such deep detection services work differently in these two modes!
-    OUStringList                 lInsideUsedDetectors;
-    OUStringList::const_iterator pIt;
-
-    // a)
-    // The list of "already used detect services" correspond to the list
-    // of preselected or flat detected types. But these detect services was called
-    // to check these types explicitly and return black/white ... yes/no only.
-    // Now they are called to return any possible result. But we should preferr
-    // these already used detect services against all other ones!
-    for (  pIt  = lOutsideUsedDetectors.begin();
-           pIt != lOutsideUsedDetectors.end()  ;
-         ++pIt                                 )
-    {
-        const ::rtl::OUString& sDetectService = *pIt;
-              ::rtl::OUString  sDeepType      = impl_askDetectService(sDetectService, rDescriptor);
-        if (!sDeepType.isEmpty())
-            return sDeepType;
-        lInsideUsedDetectors.push_back(sDetectService);
-    }
-
-    // SAFE -> ----------------------------------
-    ::osl::ResettableMutexGuard aLock(m_aLock);
-    OUStringList lDetectors = m_rCache->getItemNames(FilterCache::E_DETECTSERVICE);
-    std::sort(lDetectors.begin(), lDetectors.end(), sort_catchalls_to_end);
-    aLock.clear();
-    // <- SAFE ----------------------------------
-
-    // b)
-    // Sometimes it would be nice to ask a special set of detect services before
-    // any other detect service is asked. E.g. by using a preselection of a DocumentService.
-    // That's needed to prevent us from asking the "wrong application module" and
-    // opening the files into the "wrong application".
-    ::rtl::OUString sPreselDocumentService = rDescriptor.getUnpackedValueOrDefault(
-                                                ::comphelper::MediaDescriptor::PROP_DOCUMENTSERVICE(),
-                                                ::rtl::OUString());
-    if (!sPreselDocumentService.isEmpty())
-    {
-        for (  pIt  = lDetectors.begin();
-               pIt != lDetectors.end()  ;
-             ++pIt                      )
-        {
-            const ::rtl::OUString& sDetectService = *pIt;
-
-            OUStringList::const_iterator pAlreadyUsed = ::std::find(lInsideUsedDetectors.begin(), lInsideUsedDetectors.end(), sDetectService);
-            if (pAlreadyUsed != lInsideUsedDetectors.end())
-                continue;
-
-            // SAFE -> --------------------------------------------------------
-            aLock.reset();
-
-            CacheItem lIProps;
-            lIProps[PROPNAME_DETECTSERVICE] <<= sDetectService;
-            OUStringList lTypes = m_rCache->getMatchingItemsByProps(FilterCache::E_TYPE, lIProps);
-
-            aLock.clear();
-            // <- SAFE --------------------------------------------------------
-
-            sal_Bool bMatchDetectorToDocumentService = sal_False;
-            OUStringList::const_iterator pIt2;
-            for (  pIt2  = lTypes.begin();
-                   pIt2 != lTypes.end()  ;
-                 ++pIt2                  )
-            {
-                const ::rtl::OUString& sType  = *pIt2;
-
-                try
-                {
-                    // SAFE -> ----------------------------------------------------
-                    aLock.reset();
-
-                    CacheItem aType = m_rCache->getItem(FilterCache::E_TYPE, sType);
-                    ::rtl::OUString sFilter;
-                    aType[PROPNAME_PREFERREDFILTER] >>= sFilter;
-                    CacheItem aFilter = m_rCache->getItem(FilterCache::E_FILTER, sFilter);
-                    ::rtl::OUString sCheckDocumentService;
-                    aFilter[PROPNAME_DOCUMENTSERVICE] >>= sCheckDocumentService;
-
-                    aLock.clear();
-                    // <- SAFE
-
-                    if (sCheckDocumentService.equals(sPreselDocumentService))
-                    {
-                        bMatchDetectorToDocumentService = sal_True;
-                        break;
-                    }
-                }
-                catch(const css::uno::Exception&)
-                    { continue; }
-            }
-
-            if (bMatchDetectorToDocumentService)
-            {
-                ::rtl::OUString sDeepType = impl_askDetectService(sDetectService, rDescriptor);
-                if (!sDeepType.isEmpty())
-                    return sDeepType;
-                lInsideUsedDetectors.push_back(sDetectService);
-            }
-        }
-    }
-
-    // c)
-    // Last chance. No "used detectors", no "preselected detectors" ... ask any existing detect services
-    // for this till know unknown format.
-    for (  pIt  = lDetectors.begin();
-           pIt != lDetectors.end()  ;
-         ++pIt                      )
-    {
-        const ::rtl::OUString& sDetectService = *pIt;
-
-        OUStringList::const_iterator pAlreadyUsed = ::std::find(lInsideUsedDetectors.begin(), lInsideUsedDetectors.end(), sDetectService);
-        if (pAlreadyUsed != lInsideUsedDetectors.end())
-            continue;
-
-        ::rtl::OUString sDeepType = impl_askDetectService(sDetectService, rDescriptor);
-        if (!sDeepType.isEmpty())
-            return sDeepType;
-    }
-
-    return ::rtl::OUString();
-}
-
 void TypeDetection::impl_seekStreamToZero(comphelper::MediaDescriptor& rDescriptor)
 {
     // try to seek to 0 ...
diff --git a/filter/source/config/cache/typedetection.hxx b/filter/source/config/cache/typedetection.hxx
index ec41aff..3650842 100644
--- a/filter/source/config/cache/typedetection.hxx
+++ b/filter/source/config/cache/typedetection.hxx
@@ -153,33 +153,6 @@ private:
 
     //---------------------------------------
 
-    /** @short      make a deep type detection only
-
-        @descr      It steps over all well known deep detection services
-                    and check her results. The first positive result will be
-                    used for return. Its more a "try and error" algorithm then
-                    a real type detection and will be used if a flat detection
-                    cant work realy ... e.g. if the extension of an URL is
-                    missing or wrong.
-
-        @param      rDescriptor
-                    provides any easy-to-use stl interface to the MediaDescriptor.
-                    Note : Its content will be adapted to returned result of this method.
-                    Means: The type/filter entries of it will be actualized or removed from it.
-
-        @param      rUsedDetectors
-                    It contains a list of names of all deep detection services,
-                    which was already used inside the method "impl_detectTypeFlatAndDeep()"!
-                    Such detectors must be ignored here!
-
-        @return     The internal name of a detected type.
-                    An empty value if detection failed.
-     */
-    ::rtl::OUString impl_detectTypeDeepOnly(      ::comphelper::MediaDescriptor& rDescriptor   ,
-                                            const OUStringList&                  rUsedDetectors);
-
-    //---------------------------------------
-
     /** @short      seek a might existing stream to position 0.
 
         @descr      This is an optinal action to be more robust
commit cdcd7b0898626b6b5f475f31bb19b55c4fd0c23b
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Thu Mar 7 00:49:34 2013 -0500

    Temporarily disable deep-only detection phase.
    
    In theory we shouldn't have to do this any more now that we do test
    against all possible format types in the first pass.  But let's test
    if my theory is right...
    
    Change-Id: I70d73a99aec56a66deaeb3f942fd2641a2cc7f48

diff --git a/filter/source/config/cache/typedetection.cxx b/filter/source/config/cache/typedetection.cxx
index 50125b8..aba091d 100644
--- a/filter/source/config/cache/typedetection.cxx
+++ b/filter/source/config/cache/typedetection.cxx
@@ -426,6 +426,8 @@ void printFlatDetectionList(const char* caption, const FlatDetection& types)
         if (lFlatTypes.size()>0)
             sType = impl_detectTypeFlatAndDeep(stlDescriptor, lFlatTypes, bAllowDeep, lUsedDetectors, sLastChance);
 
+#if 0 // In theory we should no longer need to do deep-only detection, but let's see if it works fine in real life...
+
         //*******************************************
         // if no flat detected (nor preselected!) type could be
         // verified and no error occurred during creation of
@@ -440,6 +442,7 @@ void printFlatDetectionList(const char* caption, const FlatDetection& types)
             stlDescriptor[comphelper::MediaDescriptor::PROP_DEEPDETECTION()] <<= sal_True;
             sType = impl_detectTypeDeepOnly(stlDescriptor, lUsedDetectors);
         }
+#endif
 
         //*******************************************
         // flat detection failed
commit 7e314a8331c91cce836237173bb9ba73edbd01c8
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Thu Mar 7 00:46:06 2013 -0500

    Some cleanup, comments, and re-organizing...
    
    Change-Id: I5a614ae032149b755d609ff05b9ef2fdb842dadf

diff --git a/filter/source/config/cache/typedetection.cxx b/filter/source/config/cache/typedetection.cxx
index 04e78b9..50125b8 100644
--- a/filter/source/config/cache/typedetection.cxx
+++ b/filter/source/config/cache/typedetection.cxx
@@ -399,38 +399,9 @@ void printFlatDetectionList(const char* caption, const FlatDetection& types)
             return stlDescriptor[comphelper::MediaDescriptor::PROP_TYPENAME()].get<rtl::OUString>();
     }
 
-    // preselected type or document service? use it as first "flat" detected
-    // type later!
     FlatDetection lFlatTypes;
     impl_getPreselection(aURL, stlDescriptor, lFlatTypes);
 
-    {
-        // Get all types that match the URL alone.
-        FlatDetection aFlatByURL;
-        m_rCache->detectFlatForURL(aURL, aFlatByURL);
-        FlatDetection::const_iterator it = aFlatByURL.begin(), itEnd = aFlatByURL.end();
-        for (; it != itEnd; ++it)
-        {
-            FlatDetection::iterator itPos = std::find_if(lFlatTypes.begin(), lFlatTypes.end(), FindByType(it->sType));
-            if (itPos == lFlatTypes.end())
-                // Not in the list yet.
-                lFlatTypes.push_back(*it);
-            else
-            {
-                // Already in the list. Update the flags.
-                FlatDetectionInfo& rInfo = *itPos;
-                const FlatDetectionInfo& rThisInfo = *it;
-                if (rThisInfo.bMatchByExtension)
-                    rInfo.bMatchByExtension = true;
-                if (rThisInfo.bMatchByPattern)
-                    rInfo.bMatchByPattern = true;
-                if (rThisInfo.bPreselectedByDocumentService)
-                    rInfo.bPreselectedByDocumentService = true;
-            }
-        }
-    }
-
-
     aLock.clear();
     // <- SAFE ----------------------------------
 
@@ -839,22 +810,7 @@ void TypeDetection::impl_getPreselection(
 {
     rFlatTypes.clear();
 
-    /* #i55122#
-        Sometimes we must detect files without or with real unknown extensions.
-        If it does not work /which can happen of course .-)/, the user tried to preselect
-        the right format. But some special dialogs (e.g. "Insert->Sheet From File")
-        add it's own preselection too.
-        So we have a combination of preselected values ...
-
-        The we should preferr the most important one - set by the user.
-        And the user normaly preselects a filter or type. The preslected
-        document service cames from the dialog.
-
-        Further it doesnt matter if the user preselected a filter or a document service.
-        A filter selection is always more explicit then a document service selection.
-        So it must be pereferred. An order between type and filter selection cant be discussed .-)
-    */
-
+    // Get all filters that we have.
     OUStringList aFilterNames;
     try
     {
@@ -867,6 +823,7 @@ void TypeDetection::impl_getPreselection(
         return;
     }
 
+    // Retrieve the default type for each of these filters, and store them.
     for (OUStringList::const_iterator it = aFilterNames.begin(); it != aFilterNames.end(); ++it)
     {
         OUString aType = impl_getTypeFromFilter(*it);
@@ -879,15 +836,43 @@ void TypeDetection::impl_getPreselection(
         rFlatTypes.push_back(aInfo);
     }
 
+    {
+        // Get all types that match the URL alone.
+        FlatDetection aFlatByURL;
+        m_rCache->detectFlatForURL(aParsedURL, aFlatByURL);
+        FlatDetection::const_iterator it = aFlatByURL.begin(), itEnd = aFlatByURL.end();
+        for (; it != itEnd; ++it)
+        {
+            FlatDetection::iterator itPos = std::find_if(rFlatTypes.begin(), rFlatTypes.end(), FindByType(it->sType));
+            if (itPos == rFlatTypes.end())
+                // Not in the list yet.
+                rFlatTypes.push_back(*it);
+            else
+            {
+                // Already in the list. Update the flags.
+                FlatDetectionInfo& rInfo = *itPos;
+                const FlatDetectionInfo& rThisInfo = *it;
+                if (rThisInfo.bMatchByExtension)
+                    rInfo.bMatchByExtension = true;
+                if (rThisInfo.bMatchByPattern)
+                    rInfo.bMatchByPattern = true;
+                if (rThisInfo.bPreselectedByDocumentService)
+                    rInfo.bPreselectedByDocumentService = true;
+            }
+        }
+    }
+
     // Remove duplicates.
     rFlatTypes.sort(SortByType());
     rFlatTypes.unique(EqualByType());
 
-    ::rtl::OUString sSelectedType = rDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_TYPENAME(), ::rtl::OUString());
+    // Mark pre-selected type (if any) to have it prioritized.
+    OUString sSelectedType = rDescriptor.getUnpackedValueOrDefault(comphelper::MediaDescriptor::PROP_TYPENAME(), OUString());
     if (!sSelectedType.isEmpty())
         impl_getPreselectionForType(sSelectedType, aParsedURL, rFlatTypes, false);
 
-    ::rtl::OUString sSelectedDoc = rDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_DOCUMENTSERVICE(), ::rtl::OUString());
+    // Mark all types preferred by the current document service, to have it prioritized.
+    OUString sSelectedDoc = rDescriptor.getUnpackedValueOrDefault(comphelper::MediaDescriptor::PROP_DOCUMENTSERVICE(), OUString());
     if (!sSelectedDoc.isEmpty())
         impl_getPreselectionForDocumentService(sSelectedDoc, aParsedURL, rFlatTypes);
 }
commit 96c8251448646b65f6ea0b657417bca66d9a9b6e
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Thu Mar 7 00:28:00 2013 -0500

    fdo#60562: List *all* format types that we support and rank them all properly.
    
    I did my best to check each and every one of them and rank them to the
    best of my ability.  Any mistakes are to be fixed as they are discovered.
    
    Note that while working on this, I've noticed that we don't actually have
    any real type detection codes for many of these format types, especially
    the graphic file formats.  If we ever have trouble loading any file type,
    check if it's caused by not having any detection code for it, and if so,
    we should write one for that file type.  That said, my casual tests on
    loading graphic files didn't cause any trouble.
    
    Change-Id: I1398cbb72b2d4ccf75434a9aa0d2a5c5d17bdaad

diff --git a/filter/source/config/cache/typedetection.cxx b/filter/source/config/cache/typedetection.cxx
index 6b29abf..04e78b9 100644
--- a/filter/source/config/cache/typedetection.cxx
+++ b/filter/source/config/cache/typedetection.cxx
@@ -127,11 +127,23 @@ int getFlatTypeRank(const rtl::OUString& rType)
     // List formats from more complex to less complex.
     // TODO: Add more.
     static const char* ranks[] = {
-        // Compressed XML
+
+        // Compressed XML (ODF XML zip formats)
         "writer8_template",
         "writer8",
         "calc8_template",
         "calc8",
+        "impress8_template",
+        "impress8",
+        "draw8_template",
+        "draw8",
+        "chart8",
+        "math8",
+        "writerglobal8",
+        "writerweb8_writer_template",
+        "StarBase",
+
+        // Compressed XML (OOXML)
         "writer_OOXML_Text_Template",
         "writer_OOXML",
         "writer_MS_Word_2007_Template",
@@ -140,6 +152,28 @@ int getFlatTypeRank(const rtl::OUString& rType)
         "Office Open XML Spreadsheet",
         "MS Excel 2007 XML Template",
         "MS Excel 2007 XML",
+        "MS PowerPoint 2007 XML Template",
+        "MS PowerPoint 2007 XML AutoPlay",
+        "MS PowerPoint 2007 XML",
+
+        // Compressed XML (Uniform/Unified Office Format)
+        "Unified_Office_Format_text",
+        "Unified_Office_Format_spreadsheet",
+        "Unified_Office_Format_presentation",
+
+        // Compressed XML (StarOffice XML zip formats)
+        "calc_StarOffice_XML_Calc",
+        "calc_StarOffice_XML_Calc_Template",
+        "chart_StarOffice_XML_Chart",
+        "draw_StarOffice_XML_Draw",
+        "draw_StarOffice_XML_Draw_Template",
+        "impress_StarOffice_XML_Impress",
+        "impress_StarOffice_XML_Impress_Template",
+        "math_StarOffice_XML_Math",
+        "writer_StarOffice_XML_Writer",
+        "writer_StarOffice_XML_Writer_Template",
+        "writer_globaldocument_StarOffice_XML_Writer_GlobalDocument",
+        "writer_web_StarOffice_XML_Writer_Web_Template",
 
         // Compressed text
         "pdf_Portable_Document_Format",
@@ -164,24 +198,83 @@ int getFlatTypeRank(const rtl::OUString& rType)
         "calc_MS_Excel_40_VorlageTemplate",
         "calc_MS_Excel_40",
         "calc_Pocket_Excel_File",
+        "impress_MS_PowerPoint_97_Vorlage",
+        "impress_MS_PowerPoint_97_AutoPlay",
+        "impress_MS_PowerPoint_97",
         "calc_Lotus",
         "calc_QPro",
         "calc_SYLK",
         "calc_DIF",
         "calc_dBase",
 
+        // Binary (raster and vector image files)
+        "emf_MS_Windows_Metafile",
+        "wmf_MS_Windows_Metafile",
+        "met_OS2_Metafile",
+        "svm_StarView_Metafile",
+        "sgv_StarDraw_20",
+        "tif_Tag_Image_File",
+        "tga_Truevision_TARGA",
+        "sgf_StarOffice_Writer_SGF",
+        "ras_Sun_Rasterfile",
+        "psd_Adobe_Photoshop",
+        "png_Portable_Network_Graphic",
+        "jpg_JPEG",
+        "gif_Graphics_Interchange",
+        "bmp_MS_Windows",
+        "pcx_Zsoft_Paintbrush",
+        "pct_Mac_Pict",
+        "pcd_Photo_CD_Base",
+        "pcd_Photo_CD_Base4",
+        "pcd_Photo_CD_Base16",
+        "impress_CGM_Computer_Graphics_Metafile", // There is binary and ascii variants ?
+        "draw_WordPerfect_Graphics",
+        "draw_Visio_Document",
+        "draw_Publisher_Document",
+        "draw_Corel_Presentation_Exchange",
+        "draw_CorelDraw_Document",
+        "writer_LotusWordPro_Document",
+        "writer_MIZI_Hwp_97", // Hanword (Hancom Office)
+
         // Non-compressed XML
         "writer_ODT_FlatXML",
         "calc_ODS_FlatXML",
+        "impress_ODP_FlatXML",
+        "draw_ODG_FlatXML",
         "calc_MS_Excel_2003_XML",
         "writer_MS_Word_2003_XML",
         "writer_DocBook_File",
         "XHTML_File",
+        "svg_Scalable_Vector_Graphics",
+        "math_MathML_XML_Math",
 
         // Non-compressed text
+        "dxf_AutoCAD_Interchange",
+        "eps_Encapsulated_PostScript",
+        "pbm_Portable_Bitmap",   // There is 'raw' and 'ascii' variants.
+        "ppm_Portable_Pixelmap", // There is 'raw' and 'ascii' variants.
+        "pgm_Portable_Graymap",  // There is 'raw' and 'ascii' variants.
+        "xpm_XPM",
+        "xbm_X_Consortium",
         "writer_Rich_Text_Format",
+        "writer_web_HTML_help",
         "generic_HTML",
-        "generic_Text"
+
+        "generic_Text", // Plain text (catch all)
+
+        // Anything ranked lower than generic_Text will never be used during
+        // type detection (since generic_Text catches all).
+
+        // Export only
+        "writer_layout_dump_xml",
+        "pwp_PlaceWare",
+        "graphic_SWF",
+        "graphic_HTML",
+
+        // Internal use only
+        "StarBaseReportChart",
+        "StarBaseReport",
+        "math_MathType_3x", // MathType equation embedded in Word doc.
     };
 
     size_t n = SAL_N_ELEMENTS(ranks);
@@ -832,7 +925,7 @@ void TypeDetection::impl_getPreselection(
                                      ++pFlatIt                      )
     {
         const FlatDetectionInfo& aFlatTypeInfo = *pFlatIt;
-              ::rtl::OUString    sFlatType     = aFlatTypeInfo.sType;
+        OUString sFlatType = aFlatTypeInfo.sType;
 
         if (!impl_validateAndSetTypeOnDescriptor(rDescriptor, sFlatType))
             continue;
commit c9fbcaa0b97c31216f5da8febd066a029c9bdef2
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 6 16:27:23 2013 -0500

    Reject type detection for zip formats when the stream is not a zip archive.
    
    Else it would incorrectly declare a non-zip archive format as a zip-based
    format.
    
    Change-Id: I017b63768dc89f7fe6e2202a661faf5f692b1a92

diff --git a/sd/source/ui/unoidl/sddetect.cxx b/sd/source/ui/unoidl/sddetect.cxx
index 88b9a83..a3af46b 100644
--- a/sd/source/ui/unoidl/sddetect.cxx
+++ b/sd/source/ui/unoidl/sddetect.cxx
@@ -74,6 +74,27 @@ using namespace ::com::sun::star::lang;
 using namespace ::com::sun::star::ucb;
 using namespace ::rtl;
 
+namespace {
+
+bool isZipStorageType(const OUString& rTypeName)
+{
+    if (rTypeName == "impress8" || rTypeName == "impress8_template")
+        return true;
+
+    if (rTypeName == "draw8" || rTypeName == "draw8_template")
+        return true;
+
+    if (rTypeName == "impress_StarOffice_XML_Impress" || rTypeName == "impress_StarOffice_XML_Impress_Template")
+        return true;
+
+    if (rTypeName == "draw_StarOffice_XML_Draw" || rTypeName == "draw_StarOffice_XML_Draw_Template")
+        return true;
+
+    return false;
+}
+
+}
+
 SdFilterDetect::SdFilterDetect( const REFERENCE < ::com::sun::star::lang::XMultiServiceFactory >&  )
 {
 }
@@ -89,7 +110,7 @@ SdFilterDetect::~SdFilterDetect()
     REFERENCE< XInteractionHandler > xInteraction;
     String aURL;
     ::rtl::OUString sTemp;
-    String aTypeName;            // a name describing the type (from MediaDescriptor, usually from flat detection)
+    OUString aTypeName;            // a name describing the type (from MediaDescriptor, usually from flat detection)
     String aPreselectedFilterName;      // a name describing the filter to use (from MediaDescriptor, usually from UI action)
 
     ::rtl::OUString aDocumentTitle; // interesting only if set in this method
@@ -195,7 +216,7 @@ SdFilterDetect::~SdFilterDetect()
         aMedium.UseInteractionHandler( sal_True );
         if ( aPreselectedFilterName.Len() )
             pFilter = SfxFilter::GetFilterByName( aPreselectedFilterName );
-        else if( aTypeName.Len() )
+        else if (!aTypeName.isEmpty())
         {
             SfxFilterMatcher aMatch;
             pFilter = aMatch.GetFilter4EA( aTypeName );
@@ -208,11 +229,11 @@ SdFilterDetect::~SdFilterDetect()
             xStream = aMedium.GetInputStream();
             xContent = aMedium.GetContent();
             bReadOnly = aMedium.IsReadOnly();
-            sal_Bool bIsStorage = aMedium.IsStorage();
+            bool bIsZipStorage = aMedium.IsStorage();
 
             if (aMedium.GetError() == SVSTREAM_OK)
             {
-                if ( bIsStorage )
+                if (bIsZipStorage)
                 {
                     // PowerPoint needs to be detected via StreamName, all other storage based formats are our own and can
                     // be detected by the ClipboardId, so except for the PPT filter all filters must have a ClipboardId set
@@ -265,7 +286,7 @@ SdFilterDetect::~SdFilterDetect()
                                 return OUString();
 
                             packages::zip::ZipIOException aZipException;
-                            if ( ( aWrap.TargetException >>= aZipException ) && aTypeName.Len() )
+                            if ((aWrap.TargetException >>= aZipException) && !aTypeName.isEmpty())
                             {
                                 if ( xInteraction.is() )
                                 {
@@ -293,7 +314,7 @@ SdFilterDetect::~SdFilterDetect()
 
                                 if ( !bRepairAllowed )
                                 {
-                                    aTypeName.Erase();
+                                    aTypeName = OUString();
                                     pFilter = 0;
                                 }
                             }
@@ -304,11 +325,11 @@ SdFilterDetect::~SdFilterDetect()
                         }
                         catch( uno::Exception& )
                         {
-                            aTypeName.Erase();
+                            aTypeName = OUString();
                             pFilter = 0;
                         }
 
-                        if ( !pFilter && aTypeName.Len() )
+                        if (!pFilter && !aTypeName.isEmpty())
                         {
                             //TODO/LATER: using this method impress is always preferred if no flat detecion has been made
                             // this should been discussed!
@@ -321,12 +342,19 @@ SdFilterDetect::~SdFilterDetect()
                 }
                 else
                 {
-                    SvStream* pStm = aMedium.GetInStream();
-                    if ( !pStm )
+                    if (isZipStorageType(aTypeName))
+                        // This stream is a not zip archive, but a zip archive type is specified.
+                        pFilter = NULL;
+
+                    SvStream* pStm = NULL;
+                    if (pFilter)
                     {
-                        pFilter = 0;
+                        pStm = aMedium.GetInStream();
+                        if (!pStm)
+                            pFilter = NULL;
                     }
-                    else
+
+                    if (pFilter && pStm)
                     {
                         SotStorageRef aStorage = new SotStorage ( pStm, sal_False );
                         if ( !aStorage->GetError() )
@@ -472,7 +500,7 @@ SdFilterDetect::~SdFilterDetect()
     if ( pFilter )
         aTypeName = pFilter->GetTypeName();
     else
-        aTypeName.Erase();
+        aTypeName = OUString();
 
     return aTypeName;
 }
commit 1a3c7b84b7b22109d691a770649af42c1033d709
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 6 02:00:02 2013 -0500

    Test all file format types regardless of document services.
    
    The old type detection would only test file format types that are
    relevant to the current document service.  But this would not work
    if the user tries to open an Excel document whose name ends with a
    non-default extension (such as .tmp) from Writer UI.
    
    To amend this, we need to test all possible format types that are
    supported by all our modules regardless of the current module, but
    prioritize them per current module.
    
    TODO: The above scenario doesn't work yet.  I still need to fix
    the individual type detection services to get it to work.
    
    Change-Id: I51dbdff28299aa64cedc6752b9ff82b96d5d79cf

diff --git a/filter/source/config/cache/typedetection.cxx b/filter/source/config/cache/typedetection.cxx
index d8fb82e..6b29abf 100644
--- a/filter/source/config/cache/typedetection.cxx
+++ b/filter/source/config/cache/typedetection.cxx
@@ -170,7 +170,6 @@ int getFlatTypeRank(const rtl::OUString& rType)
         "calc_DIF",
         "calc_dBase",
 
-
         // Non-compressed XML
         "writer_ODT_FlatXML",
         "calc_ODS_FlatXML",
@@ -227,7 +226,16 @@ struct SortByPriority : public std::binary_function<FlatDetectionInfo, FlatDetec
     }
 };
 
-struct EqualByName : public std::binary_function<FlatDetectionInfo, FlatDetectionInfo, bool>
+struct SortByType : public std::binary_function<FlatDetectionInfo, FlatDetectionInfo, bool>
+
+{
+    bool operator() (const FlatDetectionInfo& r1, const FlatDetectionInfo& r2) const
+    {
+        return r1.sType > r2.sType;
+    }
+};
+
+struct EqualByType : public std::binary_function<FlatDetectionInfo, FlatDetectionInfo, bool>
 {
     bool operator() (const FlatDetectionInfo& r1, const FlatDetectionInfo& r2) const
     {
@@ -235,10 +243,21 @@ struct EqualByName : public std::binary_function<FlatDetectionInfo, FlatDetectio
     }
 };
 
+class FindByType : std::unary_function<FlatDetectionInfo, bool>
+{
+    OUString maType;
+public:
+    FindByType(const OUString& rType) : maType(rType) {}
+    bool operator() (const FlatDetectionInfo& rInfo) const
+    {
+        return rInfo.sType == maType;
+    }
+};
+
 #if DEBUG_TYPE_DETECTION
 void printFlatDetectionList(const char* caption, const FlatDetection& types)
 {
-    cout << "-- " << caption << endl;
+    cout << "-- " << caption << " (size=" << types.size() << ")" << endl;
     FlatDetection::const_iterator it = types.begin(), itEnd = types.end();
     for (; it != itEnd; ++it)
     {
@@ -292,17 +311,39 @@ void printFlatDetectionList(const char* caption, const FlatDetection& types)
     FlatDetection lFlatTypes;
     impl_getPreselection(aURL, stlDescriptor, lFlatTypes);
 
-    //*******************************************
-    // get all types, which match to the given descriptor
-    // That can be true by: extensions/url pattern/mime type etcpp.
-    m_rCache->detectFlatForURL(aURL, lFlatTypes);
+    {
+        // Get all types that match the URL alone.
+        FlatDetection aFlatByURL;
+        m_rCache->detectFlatForURL(aURL, aFlatByURL);
+        FlatDetection::const_iterator it = aFlatByURL.begin(), itEnd = aFlatByURL.end();
+        for (; it != itEnd; ++it)
+        {
+            FlatDetection::iterator itPos = std::find_if(lFlatTypes.begin(), lFlatTypes.end(), FindByType(it->sType));
+            if (itPos == lFlatTypes.end())
+                // Not in the list yet.
+                lFlatTypes.push_back(*it);
+            else
+            {
+                // Already in the list. Update the flags.
+                FlatDetectionInfo& rInfo = *itPos;
+                const FlatDetectionInfo& rThisInfo = *it;
+                if (rThisInfo.bMatchByExtension)
+                    rInfo.bMatchByExtension = true;
+                if (rThisInfo.bMatchByPattern)
+                    rInfo.bMatchByPattern = true;
+                if (rThisInfo.bPreselectedByDocumentService)
+                    rInfo.bPreselectedByDocumentService = true;
+            }
+        }
+    }
+
 
     aLock.clear();
     // <- SAFE ----------------------------------
 
     // Properly prioritize all candidate types.
     lFlatTypes.sort(SortByPriority());
-    lFlatTypes.unique(EqualByName());
+    lFlatTypes.unique(EqualByType());
 
     ::rtl::OUString sType      ;
     ::rtl::OUString sLastChance;
@@ -529,9 +570,8 @@ void TypeDetection::impl_checkResultsAndAddBestFilter(::comphelper::MediaDescrip
 
 
 
-sal_Bool TypeDetection::impl_getPreselectionForType(const ::rtl::OUString& sPreSelType,
-                                                    const css::util::URL&  aParsedURL ,
-                                                          FlatDetection&   rFlatTypes )
+bool TypeDetection::impl_getPreselectionForType(
+    const OUString& sPreSelType, const util::URL& aParsedURL, FlatDetection& rFlatTypes, bool bDocService)
 {
     // Can be used to supress execution of some parts of this method
     // if its already clear that detected type is valid or not.
@@ -547,14 +587,6 @@ sal_Bool TypeDetection::impl_getPreselectionForType(const ::rtl::OUString& sPreS
     // it matches by it's extension too.
     bool bMatchByExtension = false;
 
-    // If we e.g. collect all filters of a factory (be a forced factory preselection)
-    // we should preferr all filters of this factory, where the type match the given URL.
-    // All other types (which sorrespond to filters of the same factory - but dont match
-    // the URL) should be "used later" for detection and sorted at the end of our return vector
-    // rFlatTypes!
-    // => bPreferredPreselection = (matchByExtension || matchByURLPattern)
-    bool bPreferredPreselection = false;
-
     // validate type
     ::rtl::OUString sType(sPreSelType);
     CacheItem       aType;
@@ -603,7 +635,6 @@ sal_Bool TypeDetection::impl_getPreselectionForType(const ::rtl::OUString& sPreS
             {
                 bBreakDetection        = true;
                 bMatchByExtension      = true;
-                bPreferredPreselection = true;
                 break;
             }
         }
@@ -619,7 +650,6 @@ sal_Bool TypeDetection::impl_getPreselectionForType(const ::rtl::OUString& sPreS
                 {
                     bBreakDetection        = true;
                     bMatchByPattern        = true;
-                    bPreferredPreselection = true;
                     break;
                 }
             }
@@ -629,15 +659,16 @@ sal_Bool TypeDetection::impl_getPreselectionForType(const ::rtl::OUString& sPreS
     // if its a valid type - set it on all return values!
     if (!sType.isEmpty())
     {
-        FlatDetectionInfo aInfo;
-        aInfo.sType              = sType;
-        aInfo.bMatchByExtension  = bMatchByExtension;
-        aInfo.bMatchByPattern    = bMatchByPattern;
-
-        if (bPreferredPreselection)
-            rFlatTypes.push_front(aInfo);
-        else
-            rFlatTypes.push_back(aInfo);
+        FlatDetection::iterator it = std::find_if(rFlatTypes.begin(), rFlatTypes.end(), FindByType(sType));
+        if (it != rFlatTypes.end())
+        {
+            if (bMatchByExtension)
+                it->bMatchByExtension = true;
+            if (bMatchByPattern)
+                it->bMatchByPattern = true;
+            if (bDocService)
+                it->bPreselectedByDocumentService = true;
+        }
 
         return true;
     }
@@ -646,59 +677,8 @@ sal_Bool TypeDetection::impl_getPreselectionForType(const ::rtl::OUString& sPreS
     return false;
 }
 
-
-
-sal_Bool TypeDetection::impl_getPreselectionForFilter(const ::rtl::OUString& sPreSelFilter,
-                                                      const css::util::URL&  aParsedURL   ,
-                                                            FlatDetection&   rFlatTypes   )
-{
-    // Can be used to supress execution of some parts of this method
-    // if its already clear that detected filter is valid or not.
-    // Its necessary to use shared code at the end, which update
-    // all return parameters constistency!
-    sal_Bool bBreakDetection = sal_False;
-
-    // validate filter
-    ::rtl::OUString sFilter(sPreSelFilter);
-    CacheItem       aFilter;
-    try
-    {
-        // SAFE -> --------------------------
-        ::osl::ResettableMutexGuard aLock(m_aLock);
-        aFilter = m_rCache->getItem(FilterCache::E_FILTER, sFilter);
-        aLock.clear();
-        // <- SAFE --------------------------
-    }
-    catch(const css::container::NoSuchElementException&)
-    {
-        sFilter = ::rtl::OUString();
-        bBreakDetection = sal_True;
-    }
-
-    if (!bBreakDetection)
-    {
-        // get its type and check if it matches the given URL
-        ::rtl::OUString sType;
-        aFilter[PROPNAME_TYPE] >>= sType;
-
-        bBreakDetection = impl_getPreselectionForType(sType, aParsedURL, rFlatTypes);
-
-        // not a valid type? -> not a valid filter!
-        if (!bBreakDetection)
-            sFilter = ::rtl::OUString();
-    }
-
-    if (!sFilter.isEmpty())
-        return sal_True;
-    else
-        return sal_False;
-}
-
-
-
-sal_Bool TypeDetection::impl_getPreselectionForDocumentService(const ::rtl::OUString& sPreSelDocumentService,
-                                                               const css::util::URL&  aParsedURL            ,
-                                                                     FlatDetection&   rFlatTypes            )
+bool TypeDetection::impl_getPreselectionForDocumentService(
+    const OUString& sPreSelDocumentService, const util::URL& aParsedURL, FlatDetection& rFlatTypes)
 {
     // get all filters, which match to this doc service
     OUStringList lFilters;
@@ -719,7 +699,7 @@ sal_Bool TypeDetection::impl_getPreselectionForDocumentService(const ::rtl::OUSt
         aLock.clear();
         // <- SAFE --------------------------
     }
-    catch(const css::container::NoSuchElementException&)
+    catch (const css::container::NoSuchElementException&)
     {
         lFilters.clear();
     }
@@ -729,36 +709,41 @@ sal_Bool TypeDetection::impl_getPreselectionForDocumentService(const ::rtl::OUSt
     // But use temp. list of "preselected types" instead of incoming rFlatTypes list!
     // The reason behind: we must filter the getted results. And copying of stl entries
     // is an easier job then removing it .-)
-    FlatDetection lPreselections;
     for (OUStringList::const_iterator pFilter  = lFilters.begin();
-                                      pFilter != lFilters.end()  ;
-                                    ++pFilter                    )
+         pFilter != lFilters.end();
+         ++pFilter)
     {
-        const ::rtl::OUString sFilter = *pFilter;
-        impl_getPreselectionForFilter(sFilter, aParsedURL, lPreselections);
-    }
+        OUString aType = impl_getTypeFromFilter(*pFilter);
+        if (aType.isEmpty())
+            continue;
 
-    // We have to mark all retrieved preselection items as "preselected by document service".
-    // Further we must ignore all preselected items, which does not match the URL!
-    FlatDetection::iterator pIt;
-    for (  pIt  = lPreselections.begin();
-           pIt != lPreselections.end()  ;
-         ++pIt                          )
-    {
-        FlatDetectionInfo& rInfo = *pIt;
-        rInfo.bPreselectedByDocumentService = true ;
-        rFlatTypes.push_back(rInfo);
+        impl_getPreselectionForType(aType, aParsedURL, rFlatTypes, true);
     }
 
     return true;
 }
 
+OUString TypeDetection::impl_getTypeFromFilter(const OUString& rFilterName)
+{
+    CacheItem aFilter;
+    try
+    {
+        osl::MutexGuard aLock(m_aLock);
+        aFilter = m_rCache->getItem(FilterCache::E_FILTER, rFilterName);
+    }
+    catch (const container::NoSuchElementException&)
+    {
+        return OUString();
+    }
 
+    OUString aType;
+    aFilter[PROPNAME_TYPE] >>= aType;
+    return aType;
+}
 
 void TypeDetection::impl_getPreselection(
     const util::URL& aParsedURL, comphelper::MediaDescriptor& rDescriptor, FlatDetection& rFlatTypes)
 {
-    // done to be shure, that only valid results leave this function!
     rFlatTypes.clear();
 
     /* #i55122#
@@ -777,9 +762,37 @@ void TypeDetection::impl_getPreselection(
         So it must be pereferred. An order between type and filter selection cant be discussed .-)
     */
 
+    OUStringList aFilterNames;
+    try
+    {
+        osl::MutexGuard aLock(m_aLock);
+        m_rCache->load(FilterCache::E_CONTAINS_FILTERS);
+        aFilterNames = m_rCache->getItemNames(FilterCache::E_FILTER);
+    }
+    catch (const container::NoSuchElementException&)
+    {
+        return;
+    }
+
+    for (OUStringList::const_iterator it = aFilterNames.begin(); it != aFilterNames.end(); ++it)
+    {
+        OUString aType = impl_getTypeFromFilter(*it);
+
+        if (aType.isEmpty())
+            continue;
+
+        FlatDetectionInfo aInfo; // all flags set to false by default.
+        aInfo.sType = aType;
+        rFlatTypes.push_back(aInfo);
+    }
+
+    // Remove duplicates.
+    rFlatTypes.sort(SortByType());
+    rFlatTypes.unique(EqualByType());
+
     ::rtl::OUString sSelectedType = rDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_TYPENAME(), ::rtl::OUString());
     if (!sSelectedType.isEmpty())
-        impl_getPreselectionForType(sSelectedType, aParsedURL, rFlatTypes);
+        impl_getPreselectionForType(sSelectedType, aParsedURL, rFlatTypes, false);
 
     ::rtl::OUString sSelectedDoc = rDescriptor.getUnpackedValueOrDefault(::comphelper::MediaDescriptor::PROP_DOCUMENTSERVICE(), ::rtl::OUString());
     if (!sSelectedDoc.isEmpty())
diff --git a/filter/source/config/cache/typedetection.hxx b/filter/source/config/cache/typedetection.hxx
index d7f89a4..ec41aff 100644
--- a/filter/source/config/cache/typedetection.hxx
+++ b/filter/source/config/cache/typedetection.hxx
@@ -65,25 +65,13 @@ public:
 
 private:
 
-    //---------------------------------------
-    /** TODO document me */
-    sal_Bool impl_getPreselectionForType(const ::rtl::OUString& sPreSelType,
-                                         const css::util::URL&  aParsedURL ,
-                                               FlatDetection&   rFlatTypes );
+    bool impl_getPreselectionForType(
+        const OUString& sPreSelType, const com::sun::star::util::URL& aParsedURL, FlatDetection& rFlatTypes, bool bDocService);
 
-    //---------------------------------------
-    /** TODO document me */
-    sal_Bool impl_getPreselectionForFilter(const ::rtl::OUString& sPreSelFilter,
-                                           const css::util::URL&  aParsedURL   ,
-                                                 FlatDetection&   rFlatTypes   );
+    bool impl_getPreselectionForDocumentService(
+        const OUString& sPreSelDocumentService, const com::sun::star::util::URL& aParsedURL, FlatDetection& rFlatTypes);
 
-    //---------------------------------------
-    /** TODO document me */
-    sal_Bool impl_getPreselectionForDocumentService(const ::rtl::OUString& sPreSelDocumentService,
-                                                     const css::util::URL& aParsedURL            ,
-                                                           FlatDetection&  rFlatTypes            );
-
-    //---------------------------------------
+    OUString impl_getTypeFromFilter(const OUString& rFilterName);
 
     /** @short      check if a filter or a type was preselected inside the given
                     MediaDescriptor and validate this information.
commit 74d68ec05761b001bc82c1c9c2dc168648cde49b
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Wed Mar 6 00:24:35 2013 -0500

    A little boolean cleanups etc.
    
    Change-Id: I5a059f7799255262d46e5248813da4409eb83a9a

diff --git a/filter/source/config/cache/typedetection.cxx b/filter/source/config/cache/typedetection.cxx
index a531f4a..d8fb82e 100644
--- a/filter/source/config/cache/typedetection.cxx
+++ b/filter/source/config/cache/typedetection.cxx
@@ -42,6 +42,8 @@ using std::cout;
 using std::endl;
 #endif
 
+using namespace com::sun::star;
+
 namespace filter{
     namespace config{
 
@@ -535,15 +537,15 @@ sal_Bool TypeDetection::impl_getPreselectionForType(const ::rtl::OUString& sPreS
     // if its already clear that detected type is valid or not.
     // Its necessary to use shared code at the end, which update
     // all return parameters constistency!
-    sal_Bool bBreakDetection = sal_False;
+    bool bBreakDetection = false;
 
     // Further we must know if it matches by pattern
     // Every flat detected type by pattern wont be detected deep!
-    sal_Bool bMatchByPattern = sal_False;
+    bool bMatchByPattern = false;
 
     // And we must know if a preselection must be preferred, because
     // it matches by it's extension too.
-    sal_Bool bMatchByExtension = sal_False;
+    bool bMatchByExtension = false;
 
     // If we e.g. collect all filters of a factory (be a forced factory preselection)
     // we should preferr all filters of this factory, where the type match the given URL.
@@ -551,7 +553,7 @@ sal_Bool TypeDetection::impl_getPreselectionForType(const ::rtl::OUString& sPreS
     // the URL) should be "used later" for detection and sorted at the end of our return vector
     // rFlatTypes!
     // => bPreferredPreselection = (matchByExtension || matchByURLPattern)
-    sal_Bool bPreferredPreselection = sal_False;
+    bool bPreferredPreselection = false;
 
     // validate type
     ::rtl::OUString sType(sPreSelType);
@@ -567,7 +569,7 @@ sal_Bool TypeDetection::impl_getPreselectionForType(const ::rtl::OUString& sPreS
     catch(const css::container::NoSuchElementException&)
     {
         sType = ::rtl::OUString();
-        bBreakDetection = sal_True;
+        bBreakDetection = true;
     }
 
     if (!bBreakDetection)
@@ -575,7 +577,7 @@ sal_Bool TypeDetection::impl_getPreselectionForType(const ::rtl::OUString& sPreS
         // We cant check a preselected type for a given stream!
         // So we must believe, that it can work ...
         if ( aParsedURL.Complete == "private:stream" )
-            bBreakDetection = sal_True;
+            bBreakDetection = true;
     }
 
     if (!bBreakDetection)
@@ -599,9 +601,9 @@ sal_Bool TypeDetection::impl_getPreselectionForType(const ::rtl::OUString& sPreS
             ::rtl::OUString sCheckExtension(pIt->toAsciiLowerCase());
             if (sCheckExtension.equals(sExtension))
             {
-                bBreakDetection        = sal_True;
-                bMatchByExtension      = sal_True;
-                bPreferredPreselection = sal_True;
+                bBreakDetection        = true;
+                bMatchByExtension      = true;
+                bPreferredPreselection = true;
                 break;
             }
         }
@@ -615,9 +617,9 @@ sal_Bool TypeDetection::impl_getPreselectionForType(const ::rtl::OUString& sPreS
                 WildCard aCheck(*pIt);
                 if (aCheck.Matches(aParsedURL.Main))
                 {
-                    bBreakDetection        = sal_True;
-                    bMatchByPattern        = sal_True;
-                    bPreferredPreselection = sal_True;
+                    bBreakDetection        = true;
+                    bMatchByPattern        = true;
+                    bPreferredPreselection = true;
                     break;
                 }
             }
@@ -637,11 +639,11 @@ sal_Bool TypeDetection::impl_getPreselectionForType(const ::rtl::OUString& sPreS
         else
             rFlatTypes.push_back(aInfo);
 
-        return sal_True;
+        return true;
     }
 
     // not valid!
-    return sal_False;
+    return false;
 }
 
 
@@ -744,18 +746,17 @@ sal_Bool TypeDetection::impl_getPreselectionForDocumentService(const ::rtl::OUSt
          ++pIt                          )
     {
         FlatDetectionInfo& rInfo = *pIt;
-        rInfo.bPreselectedByDocumentService = sal_True ;
+        rInfo.bPreselectedByDocumentService = true ;
         rFlatTypes.push_back(rInfo);
     }
 
-    return sal_True;
+    return true;
 }
 
 
 
-void TypeDetection::impl_getPreselection(const css::util::URL&                aParsedURL ,
-                                               ::comphelper::MediaDescriptor& rDescriptor,
-                                               FlatDetection&                 rFlatTypes )
+void TypeDetection::impl_getPreselection(
+    const util::URL& aParsedURL, comphelper::MediaDescriptor& rDescriptor, FlatDetection& rFlatTypes)
 {
     // done to be shure, that only valid results leave this function!
     rFlatTypes.clear();
commit 88ed1bf33789f1eaddc31e37b305cfb2daab4664
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Tue Mar 5 22:51:22 2013 -0500

    Modernize the type detection service instantiation a bit.
    
    Change-Id: If31092ecc2b746acbe5731bf9383560e93aa3a69

diff --git a/filter/source/textfilterdetect/fdcomp.cxx b/filter/source/textfilterdetect/fdcomp.cxx
index 85b9f3b..7e98cad 100644
--- a/filter/source/textfilterdetect/fdcomp.cxx
+++ b/filter/source/textfilterdetect/fdcomp.cxx
@@ -26,47 +26,30 @@
  * instead of those above.
  */
 
-#include <stdio.h>
+#include "sal/config.h"
 
-#include <osl/mutex.hxx>
-#include <osl/thread.h>
-#include <cppuhelper/factory.hxx>
-
-#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#include "cppuhelper/factory.hxx"
+#include "cppuhelper/implementationentry.hxx"
+#include "sal/types.h"
 
 #include "filterdetect.hxx"
 
-using namespace ::cppu;
-using namespace com::sun::star;
-using namespace ::com::sun::star::uno;
-using namespace ::com::sun::star::lang;
-using namespace ::com::sun::star::registry;
-
-extern "C" {
+namespace {
 
-SAL_DLLPUBLIC_EXPORT void * SAL_CALL textfd_component_getFactory(
-    const sal_Char* pImplName, void* pServiceManager, void* /* pRegistryKey */ )
-{
-    void* pRet = NULL;
-    rtl::OUString implName = rtl::OUString::createFromAscii(pImplName);
-    if (pServiceManager && implName == PlainTextFilterDetect_getImplementationName())
-    {
-        uno::Reference<lang::XSingleServiceFactory> xFactory(
-            createSingleFactory(
-            reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager),
-            implName,
-            PlainTextFilterDetect_createInstance, PlainTextFilterDetect_getSupportedServiceNames()));
+static cppu::ImplementationEntry const services[] = {
+    { &PlainTextFilterDetect_createInstance, &PlainTextFilterDetect_getImplementationName,
+      &PlainTextFilterDetect_getSupportedServiceNames,
+      &cppu::createSingleComponentFactory, 0, 0 },
+    { 0, 0, 0, 0, 0, 0 }
+};
 
-        if (xFactory.is())
-        {
-            xFactory->acquire();
-            pRet = xFactory.get();
-        }
-    }
-
-    return pRet;
 }
 
+extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL textfd_component_getFactory(
+    char const * pImplName, void * pServiceManager, void * pRegistryKey)
+{
+    return cppu::component_getFactoryHelper(
+        pImplName, pServiceManager, pRegistryKey, services);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/filter/source/textfilterdetect/filterdetect.cxx b/filter/source/textfilterdetect/filterdetect.cxx
index 7dd2ddd..e4bce81 100644
--- a/filter/source/textfilterdetect/filterdetect.cxx
+++ b/filter/source/textfilterdetect/filterdetect.cxx
@@ -29,8 +29,10 @@
 #include "filterdetect.hxx"
 
 #include "tools/urlobj.hxx"
+#include "ucbhelper/content.hxx"
 
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
 
 #define WRITER_TEXT_FILTER "Text"
 #define CALC_TEXT_FILTER   "Text - txt - csv (StarCalc)"
@@ -39,31 +41,33 @@ using namespace ::com::sun::star;
 
 namespace {
 
-void setFilter(uno::Sequence<beans::PropertyValue>& rProps, sal_Int32 nPos, const rtl::OUString& rFilter)
+template<typename T>
+void setPropValue(uno::Sequence<beans::PropertyValue>& rProps, sal_Int32 nPos, const char* pName, const T& rValue)
 {
     if (nPos >= 0)
-        rProps[nPos].Value <<= rFilter;
+        rProps[nPos].Value <<= rValue;
     else
     {
         sal_Int32 n = rProps.getLength();
         rProps.realloc(n+1);
-        rProps[n].Name = "FilterName";
-        rProps[n].Value <<= rFilter;
+        rProps[n].Name = OUString::createFromAscii(pName);
+        rProps[n].Value <<= rValue;
     }
 }
 
 }
 
-PlainTextFilterDetect::PlainTextFilterDetect(const uno::Reference<lang::XMultiServiceFactory> &xMSF) :
-    mxMSF(xMSF) {}
+PlainTextFilterDetect::PlainTextFilterDetect(const uno::Reference<uno::XComponentContext>& xCxt) :
+    mxCxt(xCxt) {}
 
 PlainTextFilterDetect::~PlainTextFilterDetect() {}
 
 rtl::OUString SAL_CALL PlainTextFilterDetect::detect(uno::Sequence<beans::PropertyValue>& lDescriptor) throw (uno::RuntimeException)
 {
-    rtl::OUString aType;
-    rtl::OUString aDocService;
-    rtl::OUString aExt;
+    OUString aType;
+    OUString aDocService;
+    OUString aExt;
+    OUString aUrl;
 
     sal_Int32 nFilter = -1;
 
@@ -77,11 +81,10 @@ rtl::OUString SAL_CALL PlainTextFilterDetect::detect(uno::Sequence<beans::Proper
             lDescriptor[i].Value >>= aDocService;
         else if (lDescriptor[i].Name == "URL")
         {
-            rtl::OUString aURL;
-            lDescriptor[i].Value >>= aURL;
+            lDescriptor[i].Value >>= aUrl;
 
             // Get the file name extension.
-            INetURLObject aParser(aURL);
+            INetURLObject aParser(aUrl);
             aExt = aParser.getExtension(
                 INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET);
             aExt = aExt.toAsciiLowerCase();
@@ -90,28 +93,30 @@ rtl::OUString SAL_CALL PlainTextFilterDetect::detect(uno::Sequence<beans::Proper
 
     if (aType == "generic_Text")
     {
-        // Generic text type.  Decide which filter to use based on the
-        // document service first, then on extension if that's not available.
+        // Generic text type.
+
+        // Decide which filter to use based on the document service first,
+        // then on extension if that's not available.
 
         if (aDocService == "com.sun.star.sheet.SpreadsheetDocument")
             // Open it in Calc.
-            setFilter(lDescriptor, nFilter, CALC_TEXT_FILTER);
+            setPropValue(lDescriptor, nFilter, "FilterName", OUString(CALC_TEXT_FILTER));
         else if (aDocService == "com.sun.star.text.TextDocument")
             // Open it in Writer.
-            setFilter(lDescriptor, nFilter, WRITER_TEXT_FILTER);
+            setPropValue(lDescriptor, nFilter, "FilterName", OUString(WRITER_TEXT_FILTER));
         else if (aExt == "csv")
-            setFilter(lDescriptor, nFilter, CALC_TEXT_FILTER);
+            setPropValue(lDescriptor, nFilter, "FilterName", OUString(CALC_TEXT_FILTER));
         else if (aExt == "txt")
-            setFilter(lDescriptor, nFilter, WRITER_TEXT_FILTER);
+            setPropValue(lDescriptor, nFilter, "FilterName", OUString(WRITER_TEXT_FILTER));
         else
             // No clue.  Open it in Writer by default.
-            setFilter(lDescriptor, nFilter, WRITER_TEXT_FILTER);
+            setPropValue(lDescriptor, nFilter, "FilterName", OUString(WRITER_TEXT_FILTER));
 
         return aType;
     }
 
     // failed!
-    return rtl::OUString();
+    return OUString();
 }
 
 // XInitialization
@@ -142,9 +147,9 @@ uno::Sequence<rtl::OUString> PlainTextFilterDetect_getSupportedServiceNames()
 }
 
 uno::Reference<uno::XInterface> PlainTextFilterDetect_createInstance(
-    const uno::Reference<lang::XMultiServiceFactory> & rSMgr)
+    const uno::Reference<uno::XComponentContext> & rCxt)
 {
-    return (cppu::OWeakObject*) new PlainTextFilterDetect(rSMgr);
+    return (cppu::OWeakObject*) new PlainTextFilterDetect(rCxt);
 }
 
 // XServiceInfo
diff --git a/filter/source/textfilterdetect/filterdetect.hxx b/filter/source/textfilterdetect/filterdetect.hxx
index b3b2790..dd4aa63 100644
--- a/filter/source/textfilterdetect/filterdetect.hxx
+++ b/filter/source/textfilterdetect/filterdetect.hxx
@@ -23,6 +23,7 @@
 #include <com/sun/star/document/XExtendedFilterDetection.hpp>
 #include <com/sun/star/lang/XInitialization.hpp>
 #include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
 
 #include <cppuhelper/implbase3.hxx>
 
@@ -31,11 +32,11 @@ class PlainTextFilterDetect : public cppu::WeakImplHelper3<
     com::sun::star::lang::XInitialization,
     com::sun::star::lang::XServiceInfo>
 {
-    com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory> mxMSF;
+    com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> mxCxt;
 
 public:
 
-    PlainTextFilterDetect (const com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory> &xMSF);
+    PlainTextFilterDetect (const com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext>& xCxt);
     virtual ~PlainTextFilterDetect();
 
     // XExtendedFilterDetection
@@ -67,7 +68,7 @@ sal_Bool PlainTextFilterDetect_supportsService(const rtl::OUString& ServiceName)
 com::sun::star::uno::Sequence<rtl::OUString> PlainTextFilterDetect_getSupportedServiceNames();
 
 com::sun::star::uno::Reference<com::sun::star::uno::XInterface>
-PlainTextFilterDetect_createInstance(const com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory>& rSMgr);
+PlainTextFilterDetect_createInstance(const com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext>& rCxt);
 
 #endif
 


More information about the Libreoffice-commits mailing list