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
::rtl::OUString sOpenRubyCharStyle;
sal_Bool bOpenRuby;
// --> OD 2008-05-07 #refactorlists#
XMLTextListsHelper* mpTextListsHelper;
::std::vector< XMLTextListsHelper* > maTextListsHelperStack;
// <--
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:
const ::rtl::OUString sActualSize;
......
......@@ -684,14 +684,16 @@ inline void SvXMLExport::SetGraphicResolver(
// Helper class to export an element.
class XMLOFF_DLLPUBLIC SvXMLElementExport
{
SvXMLExport& rExport;
::rtl::OUString aName;
sal_Bool bIgnWS : 1;
sal_Bool bDoSomething : 1;
SAL_DLLPRIVATE void StartElement( SvXMLExport& rExp, sal_uInt16 nPrefix,
const ::rtl::OUString& rName,
sal_Bool bIgnWSOutside );
SvXMLExport& mrExport;
::rtl::OUString maElementName;
const sal_Bool mbIgnoreWhitespaceInside :1;
const sal_Bool mbDoSomething :1;
SAL_DLLPRIVATE
void StartElement(
const sal_uInt16 nPrefix,
const ::rtl::OUString& rName,
const sal_Bool bIgnoreWhitespaceOutside );
public:
......
......@@ -2627,12 +2627,10 @@ SvXMLExport::AddAttributesRDFa(
mpImpl->mpRDFaHelper->AddRDFa(xMeta);
}
// --> OD 2008-11-26 #158694#
sal_Bool SvXMLExport::exportTextNumberElement() const
{
return mpImpl->mbExportTextNumberElement;
}
// <--
sal_Bool SvXMLExport::SetNullDateOnUnitConverter()
{
......@@ -2643,116 +2641,132 @@ sal_Bool SvXMLExport::SetNullDateOnUnitConverter()
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,
const OUString& rQName,
sal_Bool bIWSOutside,
sal_Bool bIWSInside ) :
rExport( rExp ),
bIgnWS( bIWSInside ),
bDoSomething( sal_True )
{
aName = rQName;
void SvXMLElementExport::StartElement(
const sal_uInt16 nPrefixKey,
const OUString& rLName,
const sal_Bool bIgnoreWhitespaceOutside )
{
maElementName = mrExport.GetNamespaceMap().GetQNameByKey(nPrefixKey, rLName);
mrExport.StartElement(maElementName, bIgnoreWhitespaceOutside);
}
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 );
}
SvXMLElementExport::~SvXMLElementExport()
{
if( bDoSomething )
if ( mbDoSomething )
{
rExport.EndElement( aName, bIgnWS );
mrExport.EndElement( maElementName, mbIgnoreWhitespaceInside );
}
}
......@@ -2125,7 +2125,8 @@ void XMLTextImportHelper::SetOutlineStyles( sal_Bool bSetEmptyLevels )
{
if (!lcl_HasListStyle(
m_pImpl->m_pOutlineStylesCandidates[i][j],
m_pImpl->m_xParaStyles, GetXMLImport(),
m_pImpl->m_xParaStyles,
GetXMLImport(),
s_NumberingStyleName,
sOutlineStyleName))
{
......
This diff is collapsed.
......@@ -338,10 +338,10 @@ public:
class XMLImpHyperlinkContext_Impl : public SvXMLImportContext
{
XMLHints_Impl& rHints;
XMLHyperlinkHint_Impl *pHint;
XMLHints_Impl& mrHints;
XMLHyperlinkHint_Impl *mpHint;
sal_Bool& rIgnoreLeadingSpace;
sal_Bool& mrbIgnoreLeadingSpace;
public:
......@@ -367,71 +367,77 @@ public:
TYPEINIT1( XMLImpHyperlinkContext_Impl, SvXMLImportContext );
XMLImpHyperlinkContext_Impl::XMLImpHyperlinkContext_Impl(
SvXMLImport& rImport,
sal_uInt16 nPrfx,
const OUString& rLName,
const Reference< xml::sax::XAttributeList > & xAttrList,
XMLHints_Impl& rHnts,
sal_Bool& rIgnLeadSpace ) :
SvXMLImportContext( rImport, nPrfx, rLName ),
rHints( rHnts ),
pHint( new XMLHyperlinkHint_Impl(
GetImport().GetTextImport()->GetCursorAsRange()->getStart() ) ),
rIgnoreLeadingSpace( rIgnLeadSpace )
SvXMLImport& rImport,
sal_uInt16 nPrfx,
const OUString& rLName,
const Reference< xml::sax::XAttributeList > & xAttrList,
XMLHints_Impl& rHnts,
sal_Bool& rIgnLeadSpace )
: SvXMLImportContext( rImport, nPrfx, rLName )
, mrHints( rHnts )
, mpHint( new XMLHyperlinkHint_Impl( GetImport().GetTextImport()->GetCursorAsRange()->getStart() ) )
, mrbIgnoreLeadingSpace( rIgnLeadSpace )
{
OUString sShow;
const SvXMLTokenMap& rTokenMap =
GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap();
const SvXMLTokenMap& rTokenMap = GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap();
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& rValue = xAttrList->getValueByIndex( i );
OUString aLocalName;
sal_uInt16 nPrefix =
GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
&aLocalName );
switch( rTokenMap.Get( nPrefix, aLocalName ) )
const sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
switch (rTokenMap.Get( nPrefix, aLocalName ))
{
case XML_TOK_TEXT_HYPERLINK_HREF:
pHint->SetHRef( GetImport().GetAbsoluteReference( rValue ) );
mpHint->SetHRef( GetImport().GetAbsoluteReference( rValue ) );
break;
case XML_TOK_TEXT_HYPERLINK_NAME:
pHint->SetName( rValue );
mpHint->SetName( rValue );
break;
case XML_TOK_TEXT_HYPERLINK_TARGET_FRAME:
pHint->SetTargetFrameName( rValue );
mpHint->SetTargetFrameName( rValue );
break;
case XML_TOK_TEXT_HYPERLINK_SHOW:
sShow = rValue;
break;
case XML_TOK_TEXT_HYPERLINK_STYLE_NAME:
pHint->SetStyleName( rValue );
mpHint->SetStyleName( rValue );
break;
case XML_TOK_TEXT_HYPERLINK_VIS_STYLE_NAME:
pHint->SetVisitedStyleName( rValue );
mpHint->SetVisitedStyleName( rValue );
break;
}
}
if( sShow.getLength() && !pHint->GetTargetFrameName().getLength() )
if( sShow.getLength() && !mpHint->GetTargetFrameName().getLength() )
{
if( IsXMLToken( sShow, XML_NEW ) )
pHint->SetTargetFrameName(
mpHint->SetTargetFrameName(
OUString( RTL_CONSTASCII_USTRINGPARAM("_blank" ) ) );
else if( IsXMLToken( sShow, XML_REPLACE ) )
pHint->SetTargetFrameName(
mpHint->SetTargetFrameName(
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()
{
if( pHint )
pHint->SetEnd( GetImport().GetTextImport()
if( mpHint != NULL )
mpHint->SetEnd( GetImport().GetTextImport()
->GetCursorAsRange()->getStart() );
}
......@@ -444,7 +450,7 @@ SvXMLImportContext *XMLImpHyperlinkContext_Impl::CreateChildContext(
{
XMLEventsImportContext* pCtxt = new XMLEventsImportContext(
GetImport(), nPrefix, rLocalName);
pHint->SetEventsContext(pCtxt);
mpHint->SetEventsContext(pCtxt);
return pCtxt;
}
else
......@@ -455,13 +461,13 @@ SvXMLImportContext *XMLImpHyperlinkContext_Impl::CreateChildContext(
return XMLImpSpanContext_Impl::CreateChildContext(
GetImport(), nPrefix, rLocalName, xAttrList,
nToken, rHints, rIgnoreLeadingSpace );
nToken, mrHints, mrbIgnoreLeadingSpace );
}
}
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(
// test for HyperLinkURL property. If present, insert link as
// text property (StarWriter), else try to insert as text
// field (StarCalc, StarDraw, ...)
Reference<beans::XPropertySet> xPropSet(
rImport.GetTextImport()->GetCursor(),
UNO_QUERY );
Reference< beans::XPropertySet > xPropSet( rImport.GetTextImport()->GetCursor(), UNO_QUERY );
const OUString sHyperLinkURL(
RTL_CONSTASCII_USTRINGPARAM("HyperLinkURL"));
static const OUString sHyperLinkURL( RTL_CONSTASCII_USTRINGPARAM( "HyperLinkURL" ) );
if (xPropSet->getPropertySetInfo()->hasPropertyByName(sHyperLinkURL))
if ( xPropSet->getPropertySetInfo()->hasPropertyByName( sHyperLinkURL ) )
{
pContext = new XMLImpHyperlinkContext_Impl( rImport, nPrefix,
rLocalName, xAttrList,
rHints,
rIgnoreLeadingSpace );
pContext = new XMLImpHyperlinkContext_Impl(
rImport,
nPrefix,
rLocalName,
xAttrList,
rHints,
rIgnoreLeadingSpace );
}
else
{
pContext = new XMLUrlFieldImportContext( rImport,
*rImport.GetTextImport().get(),
nPrefix, rLocalName);
pContext = new XMLUrlFieldImportContext( rImport, *rImport.GetTextImport().get(), nPrefix, rLocalName );
//whitespace handling like other fields
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