Kaydet (Commit) 71d322a8 authored tarafından Oliver-Rainer Wittmann's avatar Oliver-Rainer Wittmann

123457: improve ODF filter - suppress import and export of hyperlinks without an URL

üst b6f34391
...@@ -107,13 +107,21 @@ class XMLOFF_DLLPUBLIC XMLTextParagraphExport : public XMLStyleExport ...@@ -107,13 +107,21 @@ class XMLOFF_DLLPUBLIC XMLTextParagraphExport : public XMLStyleExport
::rtl::OUString sOpenRubyCharStyle; ::rtl::OUString sOpenRubyCharStyle;
sal_Bool bOpenRuby; sal_Bool bOpenRuby;
// --> OD 2008-05-07 #refactorlists#
XMLTextListsHelper* mpTextListsHelper; XMLTextListsHelper* mpTextListsHelper;
::std::vector< XMLTextListsHelper* > maTextListsHelperStack; ::std::vector< XMLTextListsHelper* > maTextListsHelperStack;
// <--
enum FrameType { FT_TEXT, FT_GRAPHIC, FT_EMBEDDED, FT_SHAPE }; enum FrameType { FT_TEXT, FT_GRAPHIC, FT_EMBEDDED, FT_SHAPE };
void exportTextRangeSpan(
const ::com::sun::star::uno::Reference< com::sun::star::text::XTextRange > & rTextRange,
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & xPropSet,
::com::sun::star::uno::Reference < ::com::sun::star::beans::XPropertySetInfo > & xPropSetInfo,
const sal_Bool bIsUICharStyle,
const sal_Bool bHasAutoStyle,
const ::rtl::OUString& sStyle,
sal_Bool& rPrevCharIsSpace );
protected: protected:
const ::rtl::OUString sActualSize; const ::rtl::OUString sActualSize;
......
...@@ -684,14 +684,16 @@ inline void SvXMLExport::SetGraphicResolver( ...@@ -684,14 +684,16 @@ inline void SvXMLExport::SetGraphicResolver(
// Helper class to export an element. // Helper class to export an element.
class XMLOFF_DLLPUBLIC SvXMLElementExport class XMLOFF_DLLPUBLIC SvXMLElementExport
{ {
SvXMLExport& rExport; SvXMLExport& mrExport;
::rtl::OUString aName; ::rtl::OUString maElementName;
sal_Bool bIgnWS : 1; const sal_Bool mbIgnoreWhitespaceInside :1;
sal_Bool bDoSomething : 1; const sal_Bool mbDoSomething :1;
SAL_DLLPRIVATE void StartElement( SvXMLExport& rExp, sal_uInt16 nPrefix, SAL_DLLPRIVATE
const ::rtl::OUString& rName, void StartElement(
sal_Bool bIgnWSOutside ); const sal_uInt16 nPrefix,
const ::rtl::OUString& rName,
const sal_Bool bIgnoreWhitespaceOutside );
public: public:
......
...@@ -2627,12 +2627,10 @@ SvXMLExport::AddAttributesRDFa( ...@@ -2627,12 +2627,10 @@ SvXMLExport::AddAttributesRDFa(
mpImpl->mpRDFaHelper->AddRDFa(xMeta); mpImpl->mpRDFaHelper->AddRDFa(xMeta);
} }
// --> OD 2008-11-26 #158694#
sal_Bool SvXMLExport::exportTextNumberElement() const sal_Bool SvXMLExport::exportTextNumberElement() const
{ {
return mpImpl->mbExportTextNumberElement; return mpImpl->mbExportTextNumberElement;
} }
// <--
sal_Bool SvXMLExport::SetNullDateOnUnitConverter() sal_Bool SvXMLExport::SetNullDateOnUnitConverter()
{ {
...@@ -2643,116 +2641,132 @@ sal_Bool SvXMLExport::SetNullDateOnUnitConverter() ...@@ -2643,116 +2641,132 @@ sal_Bool SvXMLExport::SetNullDateOnUnitConverter()
return mpImpl->mbNullDateInitialized; return mpImpl->mbNullDateInitialized;
} }
//=============================================================================
void SvXMLElementExport::StartElement( SvXMLExport& rExp, //=============================================================================
sal_uInt16 nPrefixKey,
const OUString& rLName,
sal_Bool bIWSOutside )
{
aName = rExp.GetNamespaceMap().GetQNameByKey(nPrefixKey, rLName);
rExp.StartElement(aName, bIWSOutside);
}
SvXMLElementExport::SvXMLElementExport( SvXMLExport& rExp,
sal_uInt16 nPrefixKey,
const sal_Char *pLName,
sal_Bool bIWSOutside,
sal_Bool bIWSInside ) :
rExport( rExp ),
bIgnWS( bIWSInside ),
bDoSomething( sal_True )
{
OUString sLName( OUString::createFromAscii(pLName) );
StartElement( rExp, nPrefixKey, sLName, bIWSOutside );
}
SvXMLElementExport::SvXMLElementExport( SvXMLExport& rExp,
sal_uInt16 nPrefixKey,
const OUString& rLName,
sal_Bool bIWSOutside,
sal_Bool bIWSInside ) :
rExport( rExp ),
bIgnWS( bIWSInside ),
bDoSomething( sal_True )
{
StartElement( rExp, nPrefixKey, rLName, bIWSOutside );
}
SvXMLElementExport::SvXMLElementExport( SvXMLExport& rExp,
sal_uInt16 nPrefixKey,
enum XMLTokenEnum eLName,
sal_Bool bIWSOutside,
sal_Bool bIWSInside ) :
rExport( rExp ),
bIgnWS( bIWSInside ),
bDoSomething( sal_True )
{
StartElement( rExp, nPrefixKey, GetXMLToken(eLName), bIWSOutside );
}
SvXMLElementExport::SvXMLElementExport( SvXMLExport& rExp,
sal_Bool bDoSth,
sal_uInt16 nPrefixKey,
const sal_Char *pLName,
sal_Bool bIWSOutside,
sal_Bool bIWSInside ) :
rExport( rExp ),
bIgnWS( bIWSInside ),
bDoSomething( bDoSth )
{
if( bDoSomething )
{
OUString sLName( OUString::createFromAscii(pLName) );
StartElement( rExp, nPrefixKey, sLName, bIWSOutside );
}
}
SvXMLElementExport::SvXMLElementExport( SvXMLExport& rExp,
sal_Bool bDoSth,
sal_uInt16 nPrefixKey,
const OUString& rLName,
sal_Bool bIWSOutside,
sal_Bool bIWSInside ) :
rExport( rExp ),
bIgnWS( bIWSInside ),
bDoSomething( bDoSth )
{
if( bDoSomething )
StartElement( rExp, nPrefixKey, rLName, bIWSOutside );
}
SvXMLElementExport::SvXMLElementExport( SvXMLExport& rExp,
sal_Bool bDoSth,
sal_uInt16 nPrefixKey,
enum XMLTokenEnum eLName,
sal_Bool bIWSOutside,
sal_Bool bIWSInside ) :
rExport( rExp ),
bIgnWS( bIWSInside ),
bDoSomething( bDoSth )
{
if( bDoSomething )
StartElement( rExport, nPrefixKey, GetXMLToken(eLName), bIWSOutside );
}
SvXMLElementExport::SvXMLElementExport( SvXMLExport& rExp, void SvXMLElementExport::StartElement(
const OUString& rQName, const sal_uInt16 nPrefixKey,
sal_Bool bIWSOutside, const OUString& rLName,
sal_Bool bIWSInside ) : const sal_Bool bIgnoreWhitespaceOutside )
rExport( rExp ), {
bIgnWS( bIWSInside ), maElementName = mrExport.GetNamespaceMap().GetQNameByKey(nPrefixKey, rLName);
bDoSomething( sal_True ) mrExport.StartElement(maElementName, bIgnoreWhitespaceOutside);
{ }
aName = rQName;
SvXMLElementExport::SvXMLElementExport(
SvXMLExport& rExp,
sal_uInt16 nPrefixKey,
const sal_Char *pLName,
sal_Bool bIWSOutside,
sal_Bool bIWSInside )
: mrExport( rExp )
, maElementName()
, mbIgnoreWhitespaceInside( bIWSInside )
, mbDoSomething( sal_True )
{
const OUString sLName( OUString::createFromAscii( pLName ) );
StartElement( nPrefixKey, sLName, bIWSOutside );
}
SvXMLElementExport::SvXMLElementExport(
SvXMLExport& rExp,
sal_uInt16 nPrefixKey,
const OUString& rLName,
sal_Bool bIWSOutside,
sal_Bool bIWSInside )
: mrExport( rExp )
, maElementName()
, mbIgnoreWhitespaceInside( bIWSInside )
, mbDoSomething( sal_True )
{
StartElement( nPrefixKey, rLName, bIWSOutside );
}
SvXMLElementExport::SvXMLElementExport(
SvXMLExport& rExp,
sal_uInt16 nPrefixKey,
enum XMLTokenEnum eLName,
sal_Bool bIWSOutside,
sal_Bool bIWSInside )
: mrExport( rExp )
, maElementName()
, mbIgnoreWhitespaceInside( bIWSInside )
, mbDoSomething( sal_True )
{
StartElement( nPrefixKey, GetXMLToken(eLName), bIWSOutside );
}
SvXMLElementExport::SvXMLElementExport(
SvXMLExport& rExp,
sal_Bool bDoSth,
sal_uInt16 nPrefixKey,
const sal_Char *pLName,
sal_Bool bIWSOutside,
sal_Bool bIWSInside )
: mrExport( rExp )
, maElementName()
, mbIgnoreWhitespaceInside( bIWSInside )
, mbDoSomething( bDoSth )
{
if ( mbDoSomething )
{
const OUString sLName( OUString::createFromAscii( pLName ) );
StartElement( nPrefixKey, sLName, bIWSOutside );
}
}
SvXMLElementExport::SvXMLElementExport(
SvXMLExport& rExp,
sal_Bool bDoSth,
sal_uInt16 nPrefixKey,
const OUString& rLName,
sal_Bool bIWSOutside,
sal_Bool bIWSInside )
: mrExport( rExp )
, maElementName()
, mbIgnoreWhitespaceInside( bIWSInside )
, mbDoSomething( bDoSth )
{
if ( mbDoSomething )
StartElement( nPrefixKey, rLName, bIWSOutside );
}
SvXMLElementExport::SvXMLElementExport(
SvXMLExport& rExp,
sal_Bool bDoSth,
sal_uInt16 nPrefixKey,
enum XMLTokenEnum eLName,
sal_Bool bIWSOutside,
sal_Bool bIWSInside )
: mrExport( rExp )
, maElementName()
, mbIgnoreWhitespaceInside( bIWSInside )
, mbDoSomething( bDoSth )
{
if ( mbDoSomething )
StartElement( nPrefixKey, GetXMLToken( eLName ), bIWSOutside );
}
SvXMLElementExport::SvXMLElementExport(
SvXMLExport& rExp,
const OUString& rQName,
sal_Bool bIWSOutside,
sal_Bool bIWSInside )
: mrExport( rExp )
, maElementName()
, mbIgnoreWhitespaceInside( bIWSInside )
, mbDoSomething( sal_True )
{
maElementName = rQName;
rExp.StartElement( rQName, bIWSOutside ); rExp.StartElement( rQName, bIWSOutside );
} }
SvXMLElementExport::~SvXMLElementExport() SvXMLElementExport::~SvXMLElementExport()
{ {
if( bDoSomething ) if ( mbDoSomething )
{ {
rExport.EndElement( aName, bIgnWS ); mrExport.EndElement( maElementName, mbIgnoreWhitespaceInside );
} }
} }
...@@ -2125,7 +2125,8 @@ void XMLTextImportHelper::SetOutlineStyles( sal_Bool bSetEmptyLevels ) ...@@ -2125,7 +2125,8 @@ void XMLTextImportHelper::SetOutlineStyles( sal_Bool bSetEmptyLevels )
{ {
if (!lcl_HasListStyle( if (!lcl_HasListStyle(
m_pImpl->m_pOutlineStylesCandidates[i][j], m_pImpl->m_pOutlineStylesCandidates[i][j],
m_pImpl->m_xParaStyles, GetXMLImport(), m_pImpl->m_xParaStyles,
GetXMLImport(),
s_NumberingStyleName, s_NumberingStyleName,
sOutlineStyleName)) sOutlineStyleName))
{ {
......
This diff is collapsed.
...@@ -338,10 +338,10 @@ public: ...@@ -338,10 +338,10 @@ public:
class XMLImpHyperlinkContext_Impl : public SvXMLImportContext class XMLImpHyperlinkContext_Impl : public SvXMLImportContext
{ {
XMLHints_Impl& rHints; XMLHints_Impl& mrHints;
XMLHyperlinkHint_Impl *pHint; XMLHyperlinkHint_Impl *mpHint;
sal_Bool& rIgnoreLeadingSpace; sal_Bool& mrbIgnoreLeadingSpace;
public: public:
...@@ -367,71 +367,77 @@ public: ...@@ -367,71 +367,77 @@ public:
TYPEINIT1( XMLImpHyperlinkContext_Impl, SvXMLImportContext ); TYPEINIT1( XMLImpHyperlinkContext_Impl, SvXMLImportContext );
XMLImpHyperlinkContext_Impl::XMLImpHyperlinkContext_Impl( XMLImpHyperlinkContext_Impl::XMLImpHyperlinkContext_Impl(
SvXMLImport& rImport, SvXMLImport& rImport,
sal_uInt16 nPrfx, sal_uInt16 nPrfx,
const OUString& rLName, const OUString& rLName,
const Reference< xml::sax::XAttributeList > & xAttrList, const Reference< xml::sax::XAttributeList > & xAttrList,
XMLHints_Impl& rHnts, XMLHints_Impl& rHnts,
sal_Bool& rIgnLeadSpace ) : sal_Bool& rIgnLeadSpace )
SvXMLImportContext( rImport, nPrfx, rLName ), : SvXMLImportContext( rImport, nPrfx, rLName )
rHints( rHnts ), , mrHints( rHnts )
pHint( new XMLHyperlinkHint_Impl( , mpHint( new XMLHyperlinkHint_Impl( GetImport().GetTextImport()->GetCursorAsRange()->getStart() ) )
GetImport().GetTextImport()->GetCursorAsRange()->getStart() ) ), , mrbIgnoreLeadingSpace( rIgnLeadSpace )
rIgnoreLeadingSpace( rIgnLeadSpace )
{ {
OUString sShow; OUString sShow;
const SvXMLTokenMap& rTokenMap = const SvXMLTokenMap& rTokenMap = GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap();
GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap();
sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
for( sal_Int16 i=0; i < nAttrCount; i++ ) for ( sal_Int16 i = 0; i < nAttrCount; i++ )
{ {
const OUString& rAttrName = xAttrList->getNameByIndex( i ); const OUString& rAttrName = xAttrList->getNameByIndex( i );
const OUString& rValue = xAttrList->getValueByIndex( i ); const OUString& rValue = xAttrList->getValueByIndex( i );
OUString aLocalName; OUString aLocalName;
sal_uInt16 nPrefix = const sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, switch (rTokenMap.Get( nPrefix, aLocalName ))
&aLocalName );
switch( rTokenMap.Get( nPrefix, aLocalName ) )
{ {
case XML_TOK_TEXT_HYPERLINK_HREF: case XML_TOK_TEXT_HYPERLINK_HREF:
pHint->SetHRef( GetImport().GetAbsoluteReference( rValue ) ); mpHint->SetHRef( GetImport().GetAbsoluteReference( rValue ) );
break; break;
case XML_TOK_TEXT_HYPERLINK_NAME: case XML_TOK_TEXT_HYPERLINK_NAME:
pHint->SetName( rValue ); mpHint->SetName( rValue );
break; break;
case XML_TOK_TEXT_HYPERLINK_TARGET_FRAME: case XML_TOK_TEXT_HYPERLINK_TARGET_FRAME:
pHint->SetTargetFrameName( rValue ); mpHint->SetTargetFrameName( rValue );
break; break;
case XML_TOK_TEXT_HYPERLINK_SHOW: case XML_TOK_TEXT_HYPERLINK_SHOW:
sShow = rValue; sShow = rValue;
break; break;
case XML_TOK_TEXT_HYPERLINK_STYLE_NAME: case XML_TOK_TEXT_HYPERLINK_STYLE_NAME:
pHint->SetStyleName( rValue ); mpHint->SetStyleName( rValue );
break; break;
case XML_TOK_TEXT_HYPERLINK_VIS_STYLE_NAME: case XML_TOK_TEXT_HYPERLINK_VIS_STYLE_NAME:
pHint->SetVisitedStyleName( rValue ); mpHint->SetVisitedStyleName( rValue );
break; break;
} }
} }
if( sShow.getLength() && !pHint->GetTargetFrameName().getLength() ) if( sShow.getLength() && !mpHint->GetTargetFrameName().getLength() )
{ {
if( IsXMLToken( sShow, XML_NEW ) ) if( IsXMLToken( sShow, XML_NEW ) )
pHint->SetTargetFrameName( mpHint->SetTargetFrameName(
OUString( RTL_CONSTASCII_USTRINGPARAM("_blank" ) ) ); OUString( RTL_CONSTASCII_USTRINGPARAM("_blank" ) ) );
else if( IsXMLToken( sShow, XML_REPLACE ) ) else if( IsXMLToken( sShow, XML_REPLACE ) )
pHint->SetTargetFrameName( mpHint->SetTargetFrameName(
OUString( RTL_CONSTASCII_USTRINGPARAM("_self" ) ) ); OUString( RTL_CONSTASCII_USTRINGPARAM("_self" ) ) );
} }
rHints.Insert( pHint, rHints.Count() );
if ( mpHint->GetHRef().isEmpty() )
{
// hyperlink without an URL is not imported.
delete mpHint;
mpHint = NULL;
}
else
{
mrHints.Insert( mpHint, mrHints.Count() );
}
} }
XMLImpHyperlinkContext_Impl::~XMLImpHyperlinkContext_Impl() XMLImpHyperlinkContext_Impl::~XMLImpHyperlinkContext_Impl()
{ {
if( pHint ) if( mpHint != NULL )
pHint->SetEnd( GetImport().GetTextImport() mpHint->SetEnd( GetImport().GetTextImport()
->GetCursorAsRange()->getStart() ); ->GetCursorAsRange()->getStart() );
} }
...@@ -444,7 +450,7 @@ SvXMLImportContext *XMLImpHyperlinkContext_Impl::CreateChildContext( ...@@ -444,7 +450,7 @@ SvXMLImportContext *XMLImpHyperlinkContext_Impl::CreateChildContext(
{ {
XMLEventsImportContext* pCtxt = new XMLEventsImportContext( XMLEventsImportContext* pCtxt = new XMLEventsImportContext(
GetImport(), nPrefix, rLocalName); GetImport(), nPrefix, rLocalName);
pHint->SetEventsContext(pCtxt); mpHint->SetEventsContext(pCtxt);
return pCtxt; return pCtxt;
} }
else else
...@@ -455,13 +461,13 @@ SvXMLImportContext *XMLImpHyperlinkContext_Impl::CreateChildContext( ...@@ -455,13 +461,13 @@ SvXMLImportContext *XMLImpHyperlinkContext_Impl::CreateChildContext(
return XMLImpSpanContext_Impl::CreateChildContext( return XMLImpSpanContext_Impl::CreateChildContext(
GetImport(), nPrefix, rLocalName, xAttrList, GetImport(), nPrefix, rLocalName, xAttrList,
nToken, rHints, rIgnoreLeadingSpace ); nToken, mrHints, mrbIgnoreLeadingSpace );
} }
} }
void XMLImpHyperlinkContext_Impl::Characters( const OUString& rChars ) void XMLImpHyperlinkContext_Impl::Characters( const OUString& rChars )
{ {
GetImport().GetTextImport()->InsertString( rChars, rIgnoreLeadingSpace ); GetImport().GetTextImport()->InsertString( rChars, mrbIgnoreLeadingSpace );
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
...@@ -1656,25 +1662,23 @@ SvXMLImportContext *XMLImpSpanContext_Impl::CreateChildContext( ...@@ -1656,25 +1662,23 @@ SvXMLImportContext *XMLImpSpanContext_Impl::CreateChildContext(
// test for HyperLinkURL property. If present, insert link as // test for HyperLinkURL property. If present, insert link as
// text property (StarWriter), else try to insert as text // text property (StarWriter), else try to insert as text
// field (StarCalc, StarDraw, ...) // field (StarCalc, StarDraw, ...)
Reference<beans::XPropertySet> xPropSet( Reference< beans::XPropertySet > xPropSet( rImport.GetTextImport()->GetCursor(), UNO_QUERY );
rImport.GetTextImport()->GetCursor(),
UNO_QUERY );
const OUString sHyperLinkURL( static const OUString sHyperLinkURL( RTL_CONSTASCII_USTRINGPARAM( "HyperLinkURL" ) );
RTL_CONSTASCII_USTRINGPARAM("HyperLinkURL"));
if (xPropSet->getPropertySetInfo()->hasPropertyByName(sHyperLinkURL)) if ( xPropSet->getPropertySetInfo()->hasPropertyByName( sHyperLinkURL ) )
{ {
pContext = new XMLImpHyperlinkContext_Impl( rImport, nPrefix, pContext = new XMLImpHyperlinkContext_Impl(
rLocalName, xAttrList, rImport,
rHints, nPrefix,
rIgnoreLeadingSpace ); rLocalName,
xAttrList,
rHints,
rIgnoreLeadingSpace );
} }
else else
{ {
pContext = new XMLUrlFieldImportContext( rImport, pContext = new XMLUrlFieldImportContext( rImport, *rImport.GetTextImport().get(), nPrefix, rLocalName );
*rImport.GetTextImport().get(),
nPrefix, rLocalName);
//whitespace handling like other fields //whitespace handling like other fields
rIgnoreLeadingSpace = sal_False; rIgnoreLeadingSpace = sal_False;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment