sw HTML import: avoid custom default page style in reqif mode

Would be "HTML" by default, but reqif-html is mostly very simple
documents and the custom page styles is unexpected.

Change-Id: I3f1b293bcd074305cf5cc87f03248e934d5fac4d
Reviewed-on: https://gerrit.libreoffice.org/62317
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins
diff --git a/sw/qa/extras/htmlimport/data/reqif-page-style.xhtml b/sw/qa/extras/htmlimport/data/reqif-page-style.xhtml
new file mode 100644
index 0000000..36f5aa1
--- /dev/null
+++ b/sw/qa/extras/htmlimport/data/reqif-page-style.xhtml
@@ -0,0 +1 @@
<reqif-xhtml:p>aaa<reqif-xhtml:br/>bbb</reqif-xhtml:p>
diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx
index ad404d7..52a6a71 100644
--- a/sw/qa/extras/htmlimport/htmlimport.cxx
+++ b/sw/qa/extras/htmlimport/htmlimport.cxx
@@ -349,6 +349,14 @@ DECLARE_HTMLIMPORT_TEST(testImageSize, "image-size.html")
    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(aExpected.getHeight()), aSize.Height);
}

DECLARE_HTMLIMPORT_TEST(testReqIfPageStyle, "reqif-page-style.xhtml")
{
    // Without the accompanying fix in place, this test would have failed with
    // 'Expected: Standard, Actual  : HTML'.
    CPPUNIT_ASSERT_EQUAL(OUString("Standard"),
                         getProperty<OUString>(getParagraph(1), "PageStyleName"));
}

CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx
index 2e11911..879a95e 100644
--- a/sw/source/filter/html/swhtml.cxx
+++ b/sw/source/filter/html/swhtml.cxx
@@ -204,6 +204,8 @@ bool HTMLReader::SetStrmStgPtr()
// Call for the general Reader-Interface
ErrCode HTMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPam, const OUString & rName )
{
    SetupFilterOptions();

    if( !m_pStream )
    {
        OSL_ENSURE( m_pStream, "HTML-Read without stream" );
@@ -216,7 +218,7 @@ ErrCode HTMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPam, co

        // Set the HTML page style, when it isn't a HTML document,
        // otherwise it's already set.
        if( !rDoc.getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE) )
        if( !rDoc.getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE) && m_aNamespace != "reqif-xhtml" )
        {
            rDoc.getIDocumentContentOperations().InsertPoolItem( rPam, SwFormatPageDesc(
                rDoc.getIDocumentStylePoolAccess().GetPageDescFromPool( RES_POOLPAGE_HTML, false )) );
@@ -229,7 +231,7 @@ ErrCode HTMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPam, co
    tools::SvRef<SwHTMLParser> xParser = new SwHTMLParser( &rDoc, rPam, *m_pStream,
                                            rName, rBaseURL, !m_bInsertMode, m_pMedium,
                                            IsReadUTF8(),
                                            m_bIgnoreHTMLComments );
                                            m_bIgnoreHTMLComments, m_aNamespace );

    SvParserState eState = xParser->CallParser();

@@ -253,7 +255,8 @@ SwHTMLParser::SwHTMLParser( SwDoc* pD, SwPaM& rCursor, SvStream& rIn,
                            const OUString& rBaseURL,
                            bool bReadNewDoc,
                            SfxMedium* pMed, bool bReadUTF8,
                            bool bNoHTMLComments )
                            bool bNoHTMLComments,
                            const OUString& rNamespace )
    : SfxHTMLParser( rIn, bReadNewDoc, pMed ),
    SwClient( nullptr ),
    m_aPathToFile( rPath ),
@@ -417,7 +420,13 @@ SwHTMLParser::SwHTMLParser( SwDoc* pD, SwPaM& rCursor, SvStream& rIn,
        }
    }

    SetupFilterOptions();
    if (!rNamespace.isEmpty())
    {
        SetNamespace(rNamespace);
        m_bXHTML = true;
        if (rNamespace == "reqif-xhtml")
            m_bReqIF = true;
    }
}

SwHTMLParser::~SwHTMLParser()
@@ -5539,12 +5548,15 @@ void SwHTMLParser::AddMetaUserDefined( OUString const & i_rMetaName )
    }
}

void SwHTMLParser::SetupFilterOptions()
void HTMLReader::SetupFilterOptions()
{
    if (!GetMedium())
    // Reset state from previous Read() invocation.
    m_aNamespace.clear();

    if (!m_pMedium)
        return;

    const SfxItemSet* pItemSet = GetMedium()->GetItemSet();
    const SfxItemSet* pItemSet = m_pMedium->GetItemSet();
    if (!pItemSet)
        return;

@@ -5557,10 +5569,7 @@ void SwHTMLParser::SetupFilterOptions()
    if (aFilterOptions.startsWith(aXhtmlNsKey))
    {
        OUString aNamespace = aFilterOptions.copy(aXhtmlNsKey.getLength());
        SetNamespace(aNamespace);
        m_bXHTML = true;
        if (aNamespace == "reqif-xhtml")
            m_bReqIF = true;
        m_aNamespace = aNamespace;
    }
}

diff --git a/sw/source/filter/html/swhtml.hxx b/sw/source/filter/html/swhtml.hxx
index 12d4dbe..2f9a633a 100644
--- a/sw/source/filter/html/swhtml.hxx
+++ b/sw/source/filter/html/swhtml.hxx
@@ -856,9 +856,6 @@ private:

    bool PendingObjectsInPaM(SwPaM& rPam) const;

    /// Parse FilterOptions passed to the importer.
    void SetupFilterOptions();

    class TableDepthGuard
    {
    private:
@@ -902,7 +899,8 @@ public:
                    const OUString& rBaseURL,
                    bool bReadNewDoc,
                    SfxMedium* pMed, bool bReadUTF8,
                    bool bIgnoreHTMLComments );
                    bool bIgnoreHTMLComments,
                    const OUString& rNamespace);

    virtual SvParserState CallParser() override;

diff --git a/sw/source/filter/inc/fltini.hxx b/sw/source/filter/inc/fltini.hxx
index ca3f9e3..81b0809c 100644
--- a/sw/source/filter/inc/fltini.hxx
+++ b/sw/source/filter/inc/fltini.hxx
@@ -35,6 +35,11 @@ class HTMLReader: public Reader
    virtual bool SetStrmStgPtr() override;
    virtual ErrCode Read(SwDoc &, const OUString& rBaseURL, SwPaM &, const OUString &) override;
    virtual OUString GetTemplateName(SwDoc& rDoc) const override;

    /// Parse FilterOptions passed to the importer.
    void SetupFilterOptions();

    OUString m_aNamespace;
public:
    HTMLReader();
};