summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Jacobi <sj@openoffice.org>2001-10-01 12:48:15 +0000
committerSven Jacobi <sj@openoffice.org>2001-10-01 12:48:15 +0000
commit55f6249965cd3e6cc2109f2c127ca36ab8f77533 (patch)
tree038889e57d31cf595550950d53bfef564d0a2430
parentba2ea9813fcb472aef23825aab7e04acd036e93f (diff)
#91216# using only one instance to create the INetUrlObject, not using same source and destination variable at ConvertSystemPathToURL, using ConvertPhysicalNameToURL if base is empty
-rw-r--r--svx/source/dialog/hldocntp.cxx315
1 files changed, 134 insertions, 181 deletions
diff --git a/svx/source/dialog/hldocntp.cxx b/svx/source/dialog/hldocntp.cxx
index 6708ed353ea4..1fda5a3aecd4 100644
--- a/svx/source/dialog/hldocntp.cxx
+++ b/svx/source/dialog/hldocntp.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: hldocntp.cxx,v $
*
- * $Revision: 1.12 $
+ * $Revision: 1.13 $
*
- * last change: $Author: ka $ $Date: 2001-07-30 14:46:43 $
+ * last change: $Author: sj $ $Date: 2001-10-01 13:48:15 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -142,6 +142,47 @@ struct DocumentTypeData
{}
};
+sal_Bool SvxHyperlinkNewDocTp::ImplGetURLObject( const String& rPath, const String& rBase, INetURLObject& aURLObject ) const
+{
+ sal_Bool bIsValidURL = rPath.Len() != 0;
+ if ( bIsValidURL )
+ {
+ aURLObject.SetURL( rPath );
+ if ( aURLObject.GetProtocol() == INET_PROT_NOT_VALID ) // test if the source is already a valid url
+ { // if not we have to create a url from a physical file name
+ String aNewURL;
+ if ( !rBase.Len() )
+ utl::LocalFileHelper::ConvertPhysicalNameToURL( rPath, aNewURL );
+ else
+ utl::LocalFileHelper::ConvertSystemPathToURL( rPath, rBase, aNewURL );
+ if ( aNewURL.Len() )
+ aURLObject = INetURLObject( aNewURL );
+ else
+ {
+ aURLObject.SetSmartURL( SvtPathOptions().GetWorkPath() );
+ if( !aURLObject.hasFinalSlash() )
+ aURLObject.setFinalSlash();
+ aURLObject.Append( rPath );
+ }
+ }
+ bIsValidURL = aURLObject.GetProtocol() != INET_PROT_NOT_VALID;
+ if ( bIsValidURL )
+ {
+ String aBase( aURLObject.getName( INetURLObject::LAST_SEGMENT, sal_False ) );
+ if ( ( aBase.Len() == 0 ) || ( aBase.GetChar( 0 ) == '.' ) )
+ bIsValidURL = sal_False;
+ }
+ if ( bIsValidURL )
+ {
+ sal_Int16 nPos = maLbDocTypes.GetSelectEntryPos();
+ if ( nPos != LISTBOX_ENTRY_NOTFOUND )
+ aURLObject.SetExtension( ((DocumentTypeData*)maLbDocTypes.GetEntryData( nPos ))->aStrExt );
+ }
+
+ }
+ return bIsValidURL;
+}
+
/*************************************************************************
|*
|* Contructor / Destructor
@@ -307,55 +348,19 @@ void SvxHyperlinkNewDocTp::GetCurentItemData ( String& aStrURL, String& aStrName
{
// get data from dialog-controls
aStrURL = maCbbPath.GetText();
- if( aStrURL.Len() )
- {
- utl::LocalFileHelper::ConvertSystemPathToURL( aStrURL, maCbbPath.GetBaseURL(), aStrURL );
- if( aStrURL.Len() == 0 )
- {
- INetURLObject aTmpURL( SvtPathOptions().GetWorkPath(), INET_PROT_FILE );
- if( !aTmpURL.hasFinalSlash() )
- aTmpURL.setFinalSlash();
- aTmpURL.Append( maCbbPath.GetText() );
- aStrURL = aTmpURL.GetMainURL( INetURLObject::NO_DECODE );
- }
- }
-
- // does the filename have got a valid extension ?
- INetURLObject aURL( aStrURL );
-
- if ( GetName( aStrURL ) != aEmptyStr &&
- maLbDocTypes.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
+ INetURLObject aURL;
+ if ( ImplGetURLObject( aStrURL, maCbbPath.GetBaseURL(), aURL ) )
{
- // get private-url
- int nPos = maLbDocTypes.GetSelectEntryPos();
- aURL.setExtension ( ( ( DocumentTypeData* )
- maLbDocTypes.GetEntryData( nPos ) )->aStrExt );
+ // get data from standard-fields
+ aStrURL = aURL.GetMainURL( INetURLObject::NO_DECODE );
+ aStrIntName = mpEdText->GetText();
+ aStrName = mpEdIndication->GetText();
+ aStrFrame = mpCbbFrame->GetText();
}
-
- sal_Char const sSep[] = ".";
-
- if( aURL.getFSysPath( INetURLObject::FSYS_DETECT ).Len() - aURL.getName().Len() <= 1 ||
- aURL.getFSysPath( INetURLObject::FSYS_DETECT ).Search( '.' ) == 0 )
- {
- INetURLObject aTmpURL( SvtPathOptions().GetWorkPath(), INET_PROT_FILE );
- if( !aTmpURL.hasFinalSlash() )
- aTmpURL.setFinalSlash();
- aTmpURL.Append( aURL.getName() );
- aURL = aTmpURL;
- }
-
- // get data from standard-fields
- aStrIntName = mpEdText->GetText();
- aStrName = mpEdIndication->GetText();
- aStrFrame = mpCbbFrame->GetText();
eMode = (SvxLinkInsertMode) (mpLbForm->GetSelectEntryPos()+1);
if( IsHTMLDoc() )
eMode = (SvxLinkInsertMode) ( UINT16(eMode) | HLINK_HTMLMODE );
-
- if ( aStrURL != aEmptyStr )
- aStrURL = aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET );
-
- if ( aStrName == aEmptyStr )
+ if ( !aStrName.Len() )
aStrName = aStrURL;
}
@@ -451,15 +456,15 @@ void SvxHyperlinkNewDocTp::SetInitFocus()
|*
\************************************************************************/
-BOOL SvxHyperlinkNewDocTp::AskApply ()
+BOOL SvxHyperlinkNewDocTp::AskApply()
{
- if( GetName( maCbbPath.GetText() ) != aEmptyStr )
- return TRUE;
-
- WarningBox aWarning( this, WB_OK, SVX_RESSTR(RID_SVXSTR_HYPDLG_NOVALIDFILENAME) );
- aWarning.Execute();
-
- return FALSE;
+ sal_Bool bRet = ImplGetURLObject( maCbbPath.GetText(), maCbbPath.GetBaseURL(), INetURLObject() );
+ if ( !bRet )
+ {
+ WarningBox aWarning( this, WB_OK, SVX_RESSTR(RID_SVXSTR_HYPDLG_NOVALIDFILENAME) );
+ aWarning.Execute();
+ }
+ return bRet;
}
/*************************************************************************
@@ -481,110 +486,83 @@ void SvxHyperlinkNewDocTp::DoApply ()
///////////////////////////////////////////////////////
// create a real URL-String
- if( aStrNewName.Len() )
+ INetURLObject aURL;
+ if ( ImplGetURLObject( aStrNewName, maCbbPath.GetBaseURL(), aURL ) )
{
- String aTempName;
- utl::LocalFileHelper::ConvertSystemPathToURL( aStrNewName, maBaseURL, aTempName );
- if( aTempName.Len() == 0 )
- {
- INetURLObject aTmpURL( SvtPathOptions().GetWorkPath() );
- if( !aTmpURL.hasFinalSlash() )
- aTmpURL.setFinalSlash();
- aTmpURL.Append( aStrNewName );
- aTempName = aTmpURL.GetMainURL( INetURLObject::NO_DECODE );
- }
-
- aStrNewName = aTempName;
- }
-
- INetURLObject aURL( aStrNewName );
- int nPos = maLbDocTypes.GetSelectEntryPos();
- if( nPos == LISTBOX_ENTRY_NOTFOUND )
- nPos=0;
- aURL.setExtension ( ( ( DocumentTypeData* )
- maLbDocTypes.GetEntryData( nPos ) )->aStrExt );
+ ///////////////////////////////////////////////////////
+ // create Document
- if( aURL.getFSysPath( INetURLObject::FSYS_DETECT ).Len() - aURL.getName().Len() <= 1 ||
- aURL.getFSysPath( INetURLObject::FSYS_DETECT ).Search( '.' ) == 0 )
- {
- INetURLObject aTmpURL( SvtPathOptions().GetWorkPath() );
- if( !aTmpURL.hasFinalSlash() )
- aTmpURL.setFinalSlash();
- aTmpURL.Append( aURL.getName() );
- aURL = aTmpURL;
- }
- ///////////////////////////////////////////////////////
- // create Document
- aStrNewName = aURL.GetURLPath( INetURLObject::DECODE_WITH_CHARSET );//INetURLObject::FSYS_DETECT );
- sal_Char const sSlash[] = "/";
- if( aStrNewName.SearchAscii( sSlash ) == 0 )
- aStrNewName.Erase( 0, 1 );
-
- SfxViewFrame *pViewFrame = NULL;
- try
- {
- // current document
- SfxViewFrame* pCurrentDocFrame = SFX_APP()->GetViewFrame();
+ aStrNewName = aURL.GetURLPath( INetURLObject::NO_DECODE );
+ sal_Char const sSlash[] = "/";
+ if( aStrNewName.SearchAscii( sSlash ) == 0 )
+ aStrNewName.Erase( 0, 1 );
- if ( aStrNewName != aEmptyStr )
+ SfxViewFrame *pViewFrame = NULL;
+ try
{
- // get private-url
- int nPos = maLbDocTypes.GetSelectEntryPos();
- if( nPos == LISTBOX_ENTRY_NOTFOUND )
- nPos=0;
- String aStrDocName ( ( ( DocumentTypeData* )
- maLbDocTypes.GetEntryData( nPos ) )->aStrURL );
-
- // create items
- SfxStringItem aName( SID_FILE_NAME, aStrDocName );
- SfxStringItem aReferer( SID_REFERER, UniString::CreateFromAscii(
- RTL_CONSTASCII_STRINGPARAM( "private:user" ) ) );
- SfxStringItem aFrame( SID_TARGETNAME, UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "_blank" ) ) );
- //SfxBoolItem aFrame( SID_OPEN_NEW_VIEW, TRUE );
-
- String aStrFlags ( sal_Unicode('S') );
- if ( maRbtEditLater.IsChecked() )
+ // current document
+ SfxViewFrame* pCurrentDocFrame = SFX_APP()->GetViewFrame();
+
+ if ( aStrNewName != aEmptyStr )
{
- aStrFlags += sal_Unicode('H');
+ // get private-url
+ int nPos = maLbDocTypes.GetSelectEntryPos();
+ if( nPos == LISTBOX_ENTRY_NOTFOUND )
+ nPos=0;
+ String aStrDocName ( ( ( DocumentTypeData* )
+ maLbDocTypes.GetEntryData( nPos ) )->aStrURL );
+
+ // create items
+ SfxStringItem aName( SID_FILE_NAME, aStrDocName );
+ SfxStringItem aReferer( SID_REFERER, UniString::CreateFromAscii(
+ RTL_CONSTASCII_STRINGPARAM( "private:user" ) ) );
+ SfxStringItem aFrame( SID_TARGETNAME, UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "_blank" ) ) );
+ //SfxBoolItem aFrame( SID_OPEN_NEW_VIEW, TRUE );
+
+ String aStrFlags ( sal_Unicode('S') );
+ if ( maRbtEditLater.IsChecked() )
+ {
+ aStrFlags += sal_Unicode('H');
+ }
+ SfxStringItem aFlags (SID_OPTIONS, aStrFlags);
+
+ // open url
+ const SfxPoolItem* pReturn = GetDispatcher()->Execute( SID_OPENDOC,
+ SFX_CALLMODE_SYNCHRON,
+ &aName, &aFlags,
+ &aFrame, &aReferer, 0L );
+
+ // save new doc
+ const SfxViewFrameItem *pItem = PTR_CAST( SfxViewFrameItem, pReturn );
+ pViewFrame = pItem->GetFrame();
+ if (pViewFrame)
+ {
+ //SfxViewFrame *pViewFrame = pFrame->GetCurrentViewFrame();
+ SfxStringItem aNewName( SID_FILE_NAME, aURL.GetMainURL( INetURLObject::NO_DECODE ) );
+
+ pViewFrame->GetDispatcher()->Execute( SID_SAVEASDOC,
+ SFX_CALLMODE_SYNCHRON,
+ &aNewName, 0L );
+
+ }
}
- SfxStringItem aFlags (SID_OPTIONS, aStrFlags);
-
- // open url
- const SfxPoolItem* pReturn = GetDispatcher()->Execute( SID_OPENDOC,
- SFX_CALLMODE_SYNCHRON,
- &aName, &aFlags,
- &aFrame, &aReferer, 0L );
-
- // save new doc
- const SfxViewFrameItem *pItem = PTR_CAST( SfxViewFrameItem, pReturn );
- pViewFrame = pItem->GetFrame();
- if (pViewFrame)
- {
- //SfxViewFrame *pViewFrame = pFrame->GetCurrentViewFrame();
- SfxStringItem aNewName( SID_FILE_NAME, aURL.GetMainURL( INetURLObject::NO_DECODE ) );
-
- pViewFrame->GetDispatcher()->Execute( SID_SAVEASDOC,
- SFX_CALLMODE_SYNCHRON,
- &aNewName, 0L );
+ if ( maRbtEditNow.IsChecked() )
+ {
+ pCurrentDocFrame->ToTop();
}
}
-
- if ( maRbtEditNow.IsChecked() )
+ catch( uno::Exception )
{
- pCurrentDocFrame->ToTop();
}
- }
- catch( uno::Exception )
- {
- }
- if ( pViewFrame && maRbtEditLater.IsChecked() )
- {
- SfxObjectShell* pObjShell = pViewFrame->GetObjectShell();
- BOOL bResult = pObjShell->DoClose();
- pObjShell->OwnerLock(FALSE);
+ if ( pViewFrame && maRbtEditLater.IsChecked() )
+ {
+ SfxObjectShell* pObjShell = pViewFrame->GetObjectShell();
+ BOOL bResult = pObjShell->DoClose();
+ pObjShell->OwnerLock(FALSE);
+ }
}
LeaveWait();
@@ -633,8 +611,8 @@ IMPL_LINK ( SvxHyperlinkNewDocTp, ClickNewHdl_Impl, void *, EMPTYARG )
Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
Reference < XFolderPicker > xFolderPicker( xFactory->createInstance( aService ), UNO_QUERY );
- String aStrURL( maCbbPath.GetText() );
- utl::LocalFileHelper::ConvertSystemPathToURL( aStrURL, maCbbPath.GetBaseURL(), aStrURL );
+ String aStrURL, aTempStrURL( maCbbPath.GetText() );
+ utl::LocalFileHelper::ConvertSystemPathToURL( aTempStrURL, maCbbPath.GetBaseURL(), aStrURL );
String aStrPath = GetPath ( aStrURL );
String aStrName = GetName ( aStrURL );
@@ -672,7 +650,6 @@ IMPL_LINK ( SvxHyperlinkNewDocTp, ClickNewHdl_Impl, void *, EMPTYARG )
maCbbPath.SetText ( aStrTmp );
}
-
return( 0L );
}
@@ -686,7 +663,6 @@ IMPL_LINK ( SvxHyperlinkNewDocTp, ModifiedPathHdl_Impl, void *, EMPTYARG )
{
if ( mbNewName )
mpEdIndication->SetText ( maCbbPath.GetText() );
-
return( 0L );
}
@@ -699,7 +675,6 @@ IMPL_LINK ( SvxHyperlinkNewDocTp, ModifiedPathHdl_Impl, void *, EMPTYARG )
IMPL_LINK ( SvxHyperlinkNewDocTp, LostFocusTargetHdl_Impl, void *, EMPTYARG )
{
UpdateExtension();
-
return (0L);
}
@@ -713,15 +688,12 @@ IMPL_LINK ( SvxHyperlinkNewDocTp, DClickDocTypeHdl_Impl, void *, EMPTYARG )
{
if (maCbbPath.GetText().Len() )
LostFocusTargetHdl_Impl (NULL);
-
return (0L);
}
IMPL_LINK ( SvxHyperlinkNewDocTp, SelectDocTypeHdl_Impl, void *, EMPTYARG )
{
-
UpdateExtension();
-
return (0L);
}
@@ -733,49 +705,30 @@ IMPL_LINK ( SvxHyperlinkNewDocTp, SelectDocTypeHdl_Impl, void *, EMPTYARG )
void SvxHyperlinkNewDocTp::UpdateExtension()
{
String aStrURL( maCbbPath.GetText() );
-
const int nDocTypePos = maLbDocTypes.GetSelectEntryPos();
-
// no file? no doctype? no extension!
if( aStrURL.Len() == 0 || nDocTypePos == LISTBOX_ENTRY_NOTFOUND )
return;
-
- utl::LocalFileHelper::ConvertSystemPathToURL( aStrURL, maCbbPath.GetBaseURL(), aStrURL );
-
- // if we have a valid url, use the INetURLObject way
- if( aStrURL.Len() )
+ INetURLObject aURL;
+ if ( ImplGetURLObject( aStrURL, maCbbPath.GetBaseURL(), aURL ) )
{
- // check for file name
- if ( GetName ( aStrURL ) != aEmptyStr )
- {
- INetURLObject aURL( aStrURL );
-
- // get private-url
- aURL.setExtension(((DocumentTypeData*)maLbDocTypes.GetEntryData( nDocTypePos ) )->aStrExt);
-
- String aStrTmp( aURL.GetURLPath( INetURLObject::DECODE_WITH_CHARSET ) );
- sal_Char const sSlash[] = "/";
- if( aStrTmp.SearchAscii( sSlash ) == 0 )
- aStrTmp.Erase( 0, 1 );
- maCbbPath.SetText ( aStrTmp );
-
- ModifiedPathHdl_Impl ( NULL );
- }
+ String aStrTmp( aURL.GetURLPath( INetURLObject::DECODE_UNAMBIGUOUS ) );
+ sal_Char const sSlash[] = "/";
+ if( aStrTmp.SearchAscii( sSlash ) == 0 )
+ aStrTmp.Erase( 0, 1 );
+ maCbbPath.SetText ( aStrTmp );
+ ModifiedPathHdl_Impl ( NULL );
}
else
{
- aStrURL = maCbbPath.GetText();
// since we have no valid url yet, maybe just a file name
// we must add the extensions ourselfs
-
xub_StrLen nIndex = aStrURL.SearchBackward( sal_Unicode('.') );
if( nIndex != -1 )
aStrURL = aStrURL.Copy( 0, nIndex );
-
aStrURL += sal_Unicode( '.' );
- aStrURL += ((DocumentTypeData*)maLbDocTypes.GetEntryData( nDocTypePos ) )->aStrExt;
+ aStrURL += ((DocumentTypeData*)maLbDocTypes.GetEntryData( nDocTypePos ))->aStrExt;
maCbbPath.SetText( aStrURL );
-
ModifiedPathHdl_Impl ( NULL );
}
}