sfx2/source/doc/docfac.cxx       |   44 +++----
 sfx2/source/doc/docinf.cxx       |    4 
 sfx2/source/doc/docinsert.cxx    |    6 -
 sfx2/source/doc/docmacromode.cxx |   10 -
 sfx2/source/doc/doctempl.cxx     |  141 +++++++++---------------
 sfx2/source/doc/doctemplates.cxx |  221 ++++++++++++++-------------------------
 sfx2/source/doc/objmisc.cxx      |   36 ++----
 sfx2/source/view/viewfrm.cxx     |   24 +---
 8 files changed, 186 insertions(+), 300 deletions(-)

New commits:
commit 0191f643a2a79af94630d08abbb3e422c05020e7
Author: Matteo Casalin <matteo.casa...@yahoo.com>
Date:   Mon Apr 17 23:09:44 2017 +0200

    Clarify intended behaviour
    
    Change-Id: Ib1edda4886940223bd32c8a78d3aa4241f57ec84

diff --git a/sfx2/source/doc/doctemplates.cxx b/sfx2/source/doc/doctemplates.cxx
index 167c5337ecb9..ad1e5627efd7 100644
--- a/sfx2/source/doc/doctemplates.cxx
+++ b/sfx2/source/doc/doctemplates.cxx
@@ -1294,7 +1294,8 @@ void 
SfxDocTplService_Impl::RemoveUINamesForTemplateDir_Impl( const OUString& aU
 
     aNewUINames.resize( nNewLen );
 
-    !bChanged || WriteUINamesForTemplateDir_Impl( aUserPath, aNewUINames );
+    if (bChanged)
+        WriteUINamesForTemplateDir_Impl( aUserPath, aNewUINames );
 }
 
 
commit 1d40b59db5eaf548392b8373994e9d793563731d
Author: Matteo Casalin <matteo.casa...@yahoo.com>
Date:   Mon Apr 17 23:00:23 2017 +0200

    Avoid 'else' after a return
    
    Change-Id: Ia530aa2fdaa5f6d77180da3139a47407adf9f519

diff --git a/sfx2/source/doc/doctemplates.cxx b/sfx2/source/doc/doctemplates.cxx
index cd7e93a03753..167c5337ecb9 100644
--- a/sfx2/source/doc/doctemplates.cxx
+++ b/sfx2/source/doc/doctemplates.cxx
@@ -932,8 +932,7 @@ bool SfxDocTplService_Impl::removeContent( const OUString& 
rContentURL )
 
     if ( Content::create( rContentURL, maCmdEnv, 
comphelper::getProcessComponentContext(), aContent ) )
         return removeContent( aContent );
-    else
-        return false;
+    return false;
 }
 
 
@@ -2212,8 +2211,7 @@ uno::Reference< ucb::XContent > SAL_CALL 
SfxDocTplService::getContent()
 {
     if ( pImp->init() )
         return pImp->getContent().get();
-    else
-        return nullptr;
+    return nullptr;
 }
 
 
@@ -2221,10 +2219,7 @@ sal_Bool SAL_CALL SfxDocTplService::storeTemplate( const 
OUString& GroupName,
                                                    const OUString& 
TemplateName,
                                                    const uno::Reference< 
frame::XStorable >& Storable )
 {
-    if ( pImp->init() )
-        return pImp->storeTemplate( GroupName, TemplateName, Storable );
-    else
-        return false;
+    return pImp->init() && pImp->storeTemplate( GroupName, TemplateName, 
Storable );
 }
 
 
@@ -2232,20 +2227,14 @@ sal_Bool SAL_CALL SfxDocTplService::addTemplate( const 
OUString& rGroupName,
                                                  const OUString& rTemplateName,
                                                  const OUString& rSourceURL )
 {
-    if ( pImp->init() )
-        return pImp->addTemplate( rGroupName, rTemplateName, rSourceURL );
-    else
-        return false;
+    return pImp->init() && pImp->addTemplate( rGroupName, rTemplateName, 
rSourceURL );
 }
 
 
 sal_Bool SAL_CALL SfxDocTplService::removeTemplate( const OUString& rGroupName,
                                                     const OUString& 
rTemplateName )
 {
-    if ( pImp->init() )
-        return pImp->removeTemplate( rGroupName, rTemplateName );
-    else
-        return false;
+    return pImp->init() && pImp->removeTemplate( rGroupName, rTemplateName );
 }
 
 
@@ -2256,28 +2245,19 @@ sal_Bool SAL_CALL SfxDocTplService::renameTemplate( 
const OUString& rGroupName,
     if ( rOldName == rNewName )
         return true;
 
-    if ( pImp->init() )
-        return pImp->renameTemplate( rGroupName, rOldName, rNewName );
-    else
-        return false;
+    return pImp->init() && pImp->renameTemplate( rGroupName, rOldName, 
rNewName );
 }
 
 
 sal_Bool SAL_CALL SfxDocTplService::addGroup( const OUString& rGroupName )
 {
-    if ( pImp->init() )
-        return pImp->addGroup( rGroupName );
-    else
-        return false;
+    return pImp->init() && pImp->addGroup( rGroupName );
 }
 
 
 sal_Bool SAL_CALL SfxDocTplService::removeGroup( const OUString& rGroupName )
 {
-    if ( pImp->init() )
-        return pImp->removeGroup( rGroupName );
-    else
-        return false;
+    return pImp->init() && pImp->removeGroup( rGroupName );
 }
 
 
@@ -2287,10 +2267,7 @@ sal_Bool SAL_CALL SfxDocTplService::renameGroup( const 
OUString& rOldName,
     if ( rOldName == rNewName )
         return true;
 
-    if ( pImp->init() )
-        return pImp->renameGroup( rOldName, rNewName );
-    else
-        return false;
+    return pImp->init() && pImp->renameGroup( rOldName, rNewName );
 }
 
 
commit 03518d08cb0a38c1223f51ba7d985291afaec39a
Author: Matteo Casalin <matteo.casa...@yahoo.com>
Date:   Mon Apr 17 22:52:53 2017 +0200

    Fix indentation
    
    Change-Id: If2c567450c27fe442e8c68627888fe7d39a65acb

diff --git a/sfx2/source/doc/doctemplates.cxx b/sfx2/source/doc/doctemplates.cxx
index 295312833853..cd7e93a03753 100644
--- a/sfx2/source/doc/doctemplates.cxx
+++ b/sfx2/source/doc/doctemplates.cxx
@@ -1629,8 +1629,8 @@ bool SfxDocTplService_Impl::renameGroup( const OUString& 
rOldName,
 
     // check that the group can be renamed ( all the contents must be in 
target location )
     bool bCanBeRenamed = false;
-       try
-       {
+    try
+    {
         uno::Reference< XResultSet > xResultSet;
         Sequence< OUString > aProps { TARGET_URL };
         ResultSetInclude eInclude = INCLUDE_DOCUMENTS_ONLY;
@@ -1638,11 +1638,11 @@ bool SfxDocTplService_Impl::renameGroup( const 
OUString& rOldName,
 
         if ( xResultSet.is() )
         {
-               uno::Reference< XContentAccess > xContentAccess( xResultSet, 
UNO_QUERY_THROW );
-               uno::Reference< XRow > xRow( xResultSet, UNO_QUERY_THROW );
+            uno::Reference< XContentAccess > xContentAccess( xResultSet, 
UNO_QUERY_THROW );
+            uno::Reference< XRow > xRow( xResultSet, UNO_QUERY_THROW );
 
-               while ( xResultSet->next() )
-               {
+            while ( xResultSet->next() )
+            {
                 if ( !::utl::UCBContentHelper::IsSubPath( aGroupTargetURL, 
xRow->getString( 1 ) ) )
                     throw uno::Exception();
             }
commit ddfb69a290a16bed3dddd3146caa4840f6f338f0
Author: Matteo Casalin <matteo.casa...@yahoo.com>
Date:   Mon Apr 17 22:49:10 2017 +0200

    OUStrings: constify and reduce temporaries
    
    Change-Id: I34f6d51ad3088d1561f103a21b78f4bb6780f95c

diff --git a/sfx2/source/doc/doctemplates.cxx b/sfx2/source/doc/doctemplates.cxx
index 75caffce5435..295312833853 100644
--- a/sfx2/source/doc/doctemplates.cxx
+++ b/sfx2/source/doc/doctemplates.cxx
@@ -393,15 +393,13 @@ void SfxDocTplService_Impl::init_Impl()
         getDefaultLocale();
 
     // convert locale to string
-    OUString aLang = LanguageTag::convertToBcp47( maLocale);
-
     // set maRootContent to the root of the templates hierarchy. Create the
     // entry if necessary
 
-    maRootURL = ( TEMPLATE_ROOT_URL "/" ) + aLang;
+    maRootURL = ( TEMPLATE_ROOT_URL "/" ) + 
LanguageTag::convertToBcp47(maLocale);
 
-    OUString aTemplVersPropName( TEMPLATE_VERSION  );
-    OUString aTemplVers( TEMPLATE_VERSION_VALUE  );
+    const OUString aTemplVersPropName( TEMPLATE_VERSION  );
+    const OUString aTemplVers( TEMPLATE_VERSION_VALUE  );
     if ( Content::create( maRootURL, maCmdEnv, 
comphelper::getProcessComponentContext(), maRootContent ) )
     {
         uno::Any aValue;
@@ -527,7 +525,6 @@ OUString SfxDocTplService_Impl::getLongName( const 
OUString& rShortName )
 
 void SfxDocTplService_Impl::getDirList()
 {
-    OUString aPropName( PROPERTY_DIRLIST  );
     Any      aValue;
 
     // Get the template dir list
@@ -564,8 +561,7 @@ void SfxDocTplService_Impl::getDirList()
         css::util::thePathSettings::get(mxContext);
 
     // load internal paths
-    OUString sProp( "Template_internal" );
-    Any aAny = xPathSettings->getPropertyValue( sProp );
+    Any aAny = xPathSettings->getPropertyValue( "Template_internal" );
     aAny >>= maInternalTemplateDirs;
 
     nCount = maInternalTemplateDirs.getLength();
@@ -578,18 +574,17 @@ void SfxDocTplService_Impl::getDirList()
     }
 
     // Store the template dir list
-    setProperty( maRootContent, aPropName, aValue );
+    setProperty( maRootContent, PROPERTY_DIRLIST, aValue );
 }
 
 
 bool SfxDocTplService_Impl::needsUpdate()
 {
-    OUString aPropName( PROPERTY_NEEDSUPDATE  );
     bool bNeedsUpdate = true;
     Any      aValue;
 
     // Get the template dir list
-    bool bHasProperty = getProperty( maRootContent, aPropName, aValue );
+    bool bHasProperty = getProperty( maRootContent, PROPERTY_NEEDSUPDATE, 
aValue );
 
     if ( bHasProperty )
         aValue >>= bNeedsUpdate;
@@ -654,7 +649,7 @@ bool SfxDocTplService_Impl::getTitleFromURL( const 
OUString& rURL, OUString& aTi
 
     if ( aType.isEmpty() && mxType.is() )
     {
-        OUString aDocType = mxType->queryTypeByURL( rURL );
+        const OUString aDocType {mxType->queryTypeByURL( rURL )};
         if ( !aDocType.isEmpty() )
             try
             {
@@ -693,7 +688,7 @@ bool SfxDocTplService_Impl::addEntry( Content& 
rParentFolder,
     aLinkObj.insertName( rTitle, false,
                       INetURLObject::LAST_SEGMENT,
                       INetURLObject::EncodeMechanism::All );
-    OUString aLinkURL = aLinkObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE );
+    const OUString aLinkURL {aLinkObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE )};
 
     Content aLink;
 
@@ -709,13 +704,10 @@ bool SfxDocTplService_Impl::addEntry( Content& 
rParentFolder,
         aValues[1] <<= false;
         aValues[2] <<= rTargetURL;
 
-        OUString aType( TYPE_LINK  );
-        OUString aAdditionalProp( PROPERTY_TYPE  );
-
         try
         {
-            rParentFolder.insertNewContent( aType, aNames, aValues, aLink );
-            setProperty( aLink, aAdditionalProp, makeAny( rType ) );
+            rParentFolder.insertNewContent( TYPE_LINK, aNames, aValues, aLink 
);
+            setProperty( aLink, PROPERTY_TYPE, makeAny( rType ) );
             bAddedEntry = true;
         }
         catch( Exception& )
@@ -733,8 +725,8 @@ bool SfxDocTplService_Impl::createFolder( const OUString& 
rNewFolderURL,
     Content         aParent;
     bool        bCreatedFolder = false;
     INetURLObject   aParentURL( rNewFolderURL );
-    OUString        aFolderName = aParentURL.getName( 
INetURLObject::LAST_SEGMENT, true,
-                                                      
INetURLObject::DecodeMechanism::WithCharset );
+    const OUString aFolderName {aParentURL.getName( 
INetURLObject::LAST_SEGMENT, true,
+                                                    
INetURLObject::DecodeMechanism::WithCharset )};
 
     // compute the parent folder url from the new folder url
     // and remove the final slash, because Content::create doesn't
@@ -823,9 +815,7 @@ bool 
SfxDocTplService_Impl::CreateNewUniqueFolderWithPrefix( const OUString& aPa
                 aValues[0] <<= aTryName;
                 aValues[1] <<= true;
 
-                OUString aType( TYPE_FSYS_FOLDER  );
-
-                bCreated = aParent.insertNewContent( aType, aNames, aValues, 
aNewFolder );
+                bCreated = aParent.insertNewContent( TYPE_FSYS_FOLDER, aNames, 
aValues, aNewFolder );
             }
             catch( ucb::NameClashException& )
             {
@@ -889,9 +879,7 @@ OUString 
SfxDocTplService_Impl::CreateNewUniqueFileWithPrefix( const OUString& a
                 aValues[0] <<= aTryName;
                 aValues[1] <<= true;
 
-                OUString aType( TYPE_FSYS_FILE  );
-
-                bCreated = aParent.insertNewContent( aType, aNames, aValues, 
aNewFile );
+                bCreated = aParent.insertNewContent( TYPE_FSYS_FILE, aNames, 
aValues, aNewFile );
             }
             catch( ucb::NameClashException& )
             {
@@ -926,10 +914,9 @@ bool SfxDocTplService_Impl::removeContent( Content& 
rContent )
     bool bRemoved = false;
     try
     {
-        OUString aCmd( COMMAND_DELETE  );
         Any aArg = makeAny( true );
 
-        rContent.executeCommand( aCmd, aArg );
+        rContent.executeCommand( COMMAND_DELETE, aArg );
         bRemoved = true;
     }
     catch ( RuntimeException& ) {}
@@ -1134,7 +1121,7 @@ void SfxDocTplService_Impl::doUpdate()
 {
     ::osl::MutexGuard aGuard( maMutex );
 
-    OUString aPropName( PROPERTY_NEEDSUPDATE  );
+    const OUString aPropName( PROPERTY_NEEDSUPDATE );
     Any      aValue;
 
     aValue <<= true;
@@ -1389,10 +1376,9 @@ OUString SfxDocTplService_Impl::CreateNewGroupFsys( 
const OUString& rGroupName,
         }
 
         // Now set the target url for this group and we are done
-        OUString aPropName( TARGET_DIR_URL  );
         Any aValue = makeAny( aResultURL );
 
-        if ( ! setProperty( aGroup, aPropName, aValue ) )
+        if ( ! setProperty( aGroup, TARGET_DIR_URL, aValue ) )
         {
             removeContent( aNewFolder );
             return OUString();
@@ -1472,10 +1458,9 @@ bool SfxDocTplService_Impl::addGroup( const OUString& 
rGroupName )
     }
 
     // Now set the target url for this group and we are done
-    OUString aPropName( TARGET_DIR_URL  );
     Any aValue = makeAny( aNewFolderURL );
 
-    if ( ! setProperty( aNewGroup, aPropName, aValue ) )
+    if ( ! setProperty( aNewGroup, TARGET_DIR_URL, aValue ) )
     {
         removeContent( aNewGroup );
         removeContent( aNewFolder );
@@ -1503,11 +1488,11 @@ bool SfxDocTplService_Impl::removeGroup( const 
OUString& rGroupName )
 
     // Get the target url
     Content  aGroup;
-    OUString    aGroupURL = aGroupObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE );
+    const OUString aGroupURL = aGroupObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE );
 
     if ( Content::create( aGroupURL, maCmdEnv, 
comphelper::getProcessComponentContext(), aGroup ) )
     {
-        OUString    aPropName( TARGET_DIR_URL  );
+        const OUString aPropName( TARGET_DIR_URL  );
         Any      aValue;
 
         OUString    aGroupTargetURL;
@@ -1624,9 +1609,8 @@ bool SfxDocTplService_Impl::renameGroup( const OUString& 
rOldName,
     OUString aGroupTargetURL;
     // there is no need to check whether target dir url is in target path, 
since if the target path is changed
     // the target dir url should be already generated new
-    OUString    aPropName( TARGET_DIR_URL  );
     Any      aValue;
-    if ( getProperty( aGroup, aPropName, aValue ) )
+    if ( getProperty( aGroup, TARGET_DIR_URL, aValue ) )
         aValue >>= aGroupTargetURL;
 
     if ( aGroupTargetURL.isEmpty() )
@@ -1659,9 +1643,7 @@ bool SfxDocTplService_Impl::renameGroup( const OUString& 
rOldName,
 
                while ( xResultSet->next() )
                {
-                   OUString aTemplTargetURL( xRow->getString( 1 ) );
-
-                if ( !::utl::UCBContentHelper::IsSubPath( aGroupTargetURL, 
aTemplTargetURL ) )
+                if ( !::utl::UCBContentHelper::IsSubPath( aGroupTargetURL, 
xRow->getString( 1 ) ) )
                     throw uno::Exception();
             }
 
@@ -1673,7 +1655,7 @@ bool SfxDocTplService_Impl::renameGroup( const OUString& 
rOldName,
     if ( bCanBeRenamed )
     {
         INetURLObject aGroupTargetObj( aGroupTargetURL );
-        OUString aFsysName = aGroupTargetObj.getName( 
INetURLObject::LAST_SEGMENT, true, INetURLObject::DecodeMechanism::WithCharset 
);
+        const OUString aFsysName = aGroupTargetObj.getName( 
INetURLObject::LAST_SEGMENT, true, INetURLObject::DecodeMechanism::WithCharset 
);
 
         if ( aGroupTargetObj.removeSegment()
           && ReplaceUINamesForTemplateDir_Impl( aGroupTargetObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE ),
@@ -1682,11 +1664,10 @@ bool SfxDocTplService_Impl::renameGroup( const 
OUString& rOldName,
                                                 rNewName ) )
         {
             // rename the group in the hierarchy
-            OUString aTitleProp( TITLE  );
             Any aTitleValue;
             aTitleValue <<= rNewName;
 
-            return setProperty( aGroup, aTitleProp, aTitleValue );
+            return setProperty( aGroup, TITLE, aTitleValue );
         }
     }
 
@@ -1703,23 +1684,20 @@ bool SfxDocTplService_Impl::storeTemplate( const 
OUString& rGroupName,
     // Check, whether or not there is a group with this name
     // Return false, if there is no group with the given name
     Content         aGroup, aTemplate, aTargetGroup, aTemplateToRemove;
-    OUString        aGroupURL, aTemplateURL, aTemplateToRemoveTargetURL;
     INetURLObject   aGroupObj( maRootURL );
     bool        bRemoveOldTemplateContent = false;
-    OUString sDocServiceName;
 
     aGroupObj.insertName( rGroupName, false,
                       INetURLObject::LAST_SEGMENT,
                       INetURLObject::EncodeMechanism::All );
-    aGroupURL = aGroupObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
+    const OUString aGroupURL {aGroupObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE )};
 
     if ( ! Content::create( aGroupURL, maCmdEnv, 
comphelper::getProcessComponentContext(), aGroup ) )
         return false;
 
     OUString aGroupTargetURL;
-    OUString aPropName( TARGET_DIR_URL  );
     Any      aValue;
-    if ( getProperty( aGroup, aPropName, aValue ) )
+    if ( getProperty( aGroup, TARGET_DIR_URL, aValue ) )
         aValue >>= aGroupTargetURL;
 
 
@@ -1730,14 +1708,14 @@ bool SfxDocTplService_Impl::storeTemplate( const 
OUString& rGroupName,
     aGroupObj.insertName( rTemplateName, false,
                       INetURLObject::LAST_SEGMENT,
                       INetURLObject::EncodeMechanism::All );
-    aTemplateURL = aGroupObj.GetMainURL( INetURLObject::DecodeMechanism::NONE 
);
+    const OUString aTemplateURL {aGroupObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE )};
+
+    OUString aTemplateToRemoveTargetURL;
 
     if ( Content::create( aTemplateURL, maCmdEnv, 
comphelper::getProcessComponentContext(), aTemplateToRemove ) )
     {
-        OUString    aTargetTemplPropName( TARGET_URL  );
-
         bRemoveOldTemplateContent = true;
-        if ( getProperty( aTemplateToRemove, aTargetTemplPropName, aValue ) )
+        if ( getProperty( aTemplateToRemove, TARGET_URL, aValue ) )
             aValue >>= aTemplateToRemoveTargetURL;
 
         if ( aGroupTargetURL.isEmpty() || !maTemplateDirs.getLength()
@@ -1751,13 +1729,11 @@ bool SfxDocTplService_Impl::storeTemplate( const 
OUString& rGroupName,
 
         // get document service name
         uno::Reference< frame::XModuleManager2 > xModuleManager( 
frame::ModuleManager::create(xContext) );
-        sDocServiceName = xModuleManager->identify( uno::Reference< 
uno::XInterface >( rStorable, uno::UNO_QUERY ) );
+        const OUString sDocServiceName {xModuleManager->identify( 
uno::Reference< uno::XInterface >( rStorable, uno::UNO_QUERY ) )};
         if ( sDocServiceName.isEmpty() )
             throw uno::RuntimeException();
 
         // get the actual filter name
-        OUString aFilterName;
-
         uno::Reference< lang::XMultiServiceFactory > xConfigProvider =
                 configuration::theDefaultProvider::get( xContext );
 
@@ -1778,18 +1754,19 @@ bool SfxDocTplService_Impl::storeTemplate( const 
OUString& rGroupName,
         if ( !xApplConfig.is() )
             throw uno::RuntimeException();
 
+        OUString aFilterName;
         xApplConfig->getByName("ooSetupFactoryActualTemplateFilter") >>= 
aFilterName;
         if ( aFilterName.isEmpty() )
             throw uno::RuntimeException();
 
         // find the related type name
-        OUString aTypeName;
         uno::Reference< container::XNameAccess > xFilterFactory(
             
mxContext->getServiceManager()->createInstanceWithContext("com.sun.star.document.FilterFactory",
 mxContext),
             uno::UNO_QUERY_THROW );
 
         uno::Sequence< beans::PropertyValue > aFilterData;
         xFilterFactory->getByName( aFilterName ) >>= aFilterData;
+        OUString aTypeName;
         for ( sal_Int32 nInd = 0; nInd < aFilterData.getLength(); nInd++ )
             if ( aFilterData[nInd].Name == "Type" )
                 aFilterData[nInd].Value >>= aTypeName;
@@ -1813,8 +1790,8 @@ bool SfxDocTplService_Impl::storeTemplate( const 
OUString& rGroupName,
         if ( !aAllExt.getLength() )
             throw uno::RuntimeException();
 
-        OUString aMediaType = 
aTypeProps.getUnpackedValueOrDefault("MediaType", OUString() );
-        OUString aExt = aAllExt[0];
+        const OUString aMediaType 
{aTypeProps.getUnpackedValueOrDefault("MediaType", OUString() )};
+        const OUString aExt {aAllExt[0]};
 
         if ( aMediaType.isEmpty() || aExt.isEmpty() )
             throw uno::RuntimeException();
@@ -1859,7 +1836,7 @@ bool SfxDocTplService_Impl::storeTemplate( const 
OUString& rGroupName,
              * if the old template was the standard template
              * it is necessary to change the standard template with the new 
file name
              */
-            OUString sStdTmplFile = SfxObjectFactory::GetStandardTemplate( 
sDocServiceName );
+            const OUString sStdTmplFile = 
SfxObjectFactory::GetStandardTemplate( sDocServiceName );
             if ( INetURLObject( sStdTmplFile ) == INetURLObject( 
aTemplateToRemoveTargetURL ) )
             {
                 SfxObjectFactory::SetStandardTemplate( sDocServiceName, 
aNewTemplateTargetURL );
@@ -1889,13 +1866,12 @@ bool SfxDocTplService_Impl::addTemplate( const 
OUString& rGroupName,
     // Check, whether or not there is a group with this name
     // Return false, if there is no group with the given name
     Content         aGroup, aTemplate, aTargetGroup;
-    OUString        aGroupURL, aTemplateURL;
     INetURLObject   aGroupObj( maRootURL );
 
     aGroupObj.insertName( rGroupName, false,
                       INetURLObject::LAST_SEGMENT,
                       INetURLObject::EncodeMechanism::All );
-    aGroupURL = aGroupObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
+    const OUString aGroupURL = aGroupObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE );
 
     if ( ! Content::create( aGroupURL, maCmdEnv, 
comphelper::getProcessComponentContext(), aGroup ) )
         return false;
@@ -1905,17 +1881,16 @@ bool SfxDocTplService_Impl::addTemplate( const 
OUString& rGroupName,
     aGroupObj.insertName( rTemplateName, false,
                       INetURLObject::LAST_SEGMENT,
                       INetURLObject::EncodeMechanism::All );
-    aTemplateURL = aGroupObj.GetMainURL( INetURLObject::DecodeMechanism::NONE 
);
+    const OUString aTemplateURL {aGroupObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE )};
 
     if ( Content::create( aTemplateURL, maCmdEnv, 
comphelper::getProcessComponentContext(), aTemplate ) )
         return false;
 
     // get the target url of the group
     OUString    aTargetURL;
-    OUString    aPropName( TARGET_DIR_URL  );
     Any         aValue;
 
-    if ( getProperty( aGroup, aPropName, aValue ) )
+    if ( getProperty( aGroup, TARGET_DIR_URL, aValue ) )
         aValue >>= aTargetURL;
 
     if ( aTargetURL.isEmpty() )
@@ -1927,7 +1902,7 @@ bool SfxDocTplService_Impl::addTemplate( const OUString& 
rGroupName,
     }
 
     // Get the content type
-    OUString aTitle, aType, aTargetURL2;
+    OUString aTitle, aType;
 
     bool bDocHasTitle = false;
     if( !getTitleFromURL( rSourceURL, aTitle, aType, bDocHasTitle ) )
@@ -1948,7 +1923,7 @@ bool SfxDocTplService_Impl::addTemplate( const OUString& 
rGroupName,
                       INetURLObject::EncodeMechanism::All );
         aTargetObj.setExtension( aSourceObj.getExtension() );
 
-        aTargetURL2 = aTargetObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE );
+        const OUString aTargetURL2 = aTargetObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE );
 
         if ( aTargetURL2 == rSourceURL )
             return addEntry( aGroup, rTemplateName, aTargetURL2, aType );
@@ -1958,11 +1933,11 @@ bool SfxDocTplService_Impl::addTemplate( const 
OUString& rGroupName,
 
     INetURLObject aTmpURL( aSourceObj );
     aTmpURL.CutExtension();
-    OUString aPattern = aTmpURL.getName( INetURLObject::LAST_SEGMENT, true, 
INetURLObject::DecodeMechanism::WithCharset );
+    const OUString aPattern {aTmpURL.getName( INetURLObject::LAST_SEGMENT, 
true, INetURLObject::DecodeMechanism::WithCharset )};
 
-    OUString aNewTemplateTargetURL = CreateNewUniqueFileWithPrefix( 
aTargetURL, aPattern, aSourceObj.getExtension() );
+    const OUString aNewTemplateTargetURL {CreateNewUniqueFileWithPrefix( 
aTargetURL, aPattern, aSourceObj.getExtension() )};
     INetURLObject aNewTemplateTargetObj( aNewTemplateTargetURL );
-    OUString aNewTemplateTargetName = aNewTemplateTargetObj.getName( 
INetURLObject::LAST_SEGMENT, true, INetURLObject::DecodeMechanism::WithCharset 
);
+    const OUString aNewTemplateTargetName {aNewTemplateTargetObj.getName( 
INetURLObject::LAST_SEGMENT, true, INetURLObject::DecodeMechanism::WithCharset 
)};
     if ( aNewTemplateTargetURL.isEmpty() || aNewTemplateTargetName.isEmpty() )
         return false;
 
@@ -1990,7 +1965,7 @@ bool SfxDocTplService_Impl::addTemplate( const OUString& 
rGroupName,
         Content aResultContent;
         if ( Content::create( aNewTemplateTargetURL, xEnv, 
comphelper::getProcessComponentContext(), aResultContent ) )
         {
-            OUString aPropertyName( "IsReadOnly"  );
+            const OUString aPropertyName( "IsReadOnly" );
             uno::Any aProperty;
             bool bReadOnly = false;
             if ( getProperty( aResultContent, aPropertyName, aProperty ) && ( 
aProperty >>= bReadOnly ) && bReadOnly )
@@ -2062,13 +2037,12 @@ bool SfxDocTplService_Impl::removeTemplate( const 
OUString& rGroupName,
     // Check, whether or not there is a group with this name
     // Return false, if there is no group with the given name
     Content         aGroup, aTemplate;
-    OUString        aGroupURL, aTemplateURL;
     INetURLObject   aGroupObj( maRootURL );
 
     aGroupObj.insertName( rGroupName, false,
                       INetURLObject::LAST_SEGMENT,
                       INetURLObject::EncodeMechanism::All );
-    aGroupURL = aGroupObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
+    const OUString aGroupURL {aGroupObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE )};
 
     if ( ! Content::create( aGroupURL, maCmdEnv, 
comphelper::getProcessComponentContext(), aGroup ) )
         return false;
@@ -2078,17 +2052,16 @@ bool SfxDocTplService_Impl::removeTemplate( const 
OUString& rGroupName,
     aGroupObj.insertName( rTemplateName, false,
                       INetURLObject::LAST_SEGMENT,
                       INetURLObject::EncodeMechanism::All );
-    aTemplateURL = aGroupObj.GetMainURL( INetURLObject::DecodeMechanism::NONE 
);
+    const OUString aTemplateURL {aGroupObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE )};
 
     if ( !Content::create( aTemplateURL, maCmdEnv, 
comphelper::getProcessComponentContext(), aTemplate ) )
         return false;
 
     // get the target URL from the template
     OUString    aTargetURL;
-    OUString    aPropName( TARGET_URL  );
     Any         aValue;
 
-    if ( getProperty( aTemplate, aPropName, aValue ) )
+    if ( getProperty( aTemplate, TARGET_URL, aValue ) )
         aValue >>= aTargetURL;
 
     // delete the target template
@@ -2114,13 +2087,12 @@ bool SfxDocTplService_Impl::renameTemplate( const 
OUString& rGroupName,
     // Check, whether or not there is a group with this name
     // Return false, if there is no group with the given name
     Content         aGroup, aTemplate;
-    OUString        aGroupURL, aTemplateURL;
     INetURLObject   aGroupObj( maRootURL );
 
     aGroupObj.insertName( rGroupName, false,
                       INetURLObject::LAST_SEGMENT,
                       INetURLObject::EncodeMechanism::All );
-    aGroupURL = aGroupObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
+    const OUString aGroupURL {aGroupObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE )};
 
     if ( ! Content::create( aGroupURL, maCmdEnv, 
comphelper::getProcessComponentContext(), aGroup ) )
         return false;
@@ -2130,7 +2102,7 @@ bool SfxDocTplService_Impl::renameTemplate( const 
OUString& rGroupName,
     aGroupObj.insertName( rNewName, false,
                       INetURLObject::LAST_SEGMENT,
                       INetURLObject::EncodeMechanism::All );
-    aTemplateURL = aGroupObj.GetMainURL( INetURLObject::DecodeMechanism::NONE 
);
+    OUString aTemplateURL {aGroupObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE )};
 
     if ( Content::create( aTemplateURL, maCmdEnv, 
comphelper::getProcessComponentContext(), aTemplate ) )
         return false;
@@ -2147,21 +2119,19 @@ bool SfxDocTplService_Impl::renameTemplate( const 
OUString& rGroupName,
         return false;
 
     OUString    aTemplateTargetURL;
-    OUString    aTargetProp( TARGET_URL  );
     Any         aTargetValue;
 
-    if ( getProperty( aTemplate, aTargetProp, aTargetValue ) )
+    if ( getProperty( aTemplate, TARGET_URL, aTargetValue ) )
         aTargetValue >>= aTemplateTargetURL;
 
     if ( !setTitleForURL( aTemplateTargetURL, rNewName ) )
         return false;
 
     // rename the template entry in the cache
-    OUString    aTitleProp( TITLE  );
     Any         aTitleValue;
     aTitleValue <<= rNewName;
 
-    return setProperty( aTemplate, aTitleProp, aTitleValue );
+    return setProperty( aTemplate, TITLE, aTitleValue );
 }
 
 
@@ -2406,10 +2376,10 @@ void SfxDocTplService_Impl::addHierGroup( 
GroupList_Impl& rList,
                 bool             bUpdateType = false;
                 DocTemplates_EntryData_Impl  *pData;
 
-                OUString aTitle( xRow->getString( 1 ) );
-                OUString aTargetDir( xRow->getString( 2 ) );
+                const OUString aTitle( xRow->getString( 1 ) );
+                const OUString aTargetDir( xRow->getString( 2 ) );
                 OUString aType( xRow->getString( 3 ) );
-                OUString aHierURL = 
xContentAccess->queryContentIdentifierString();
+                const OUString aHierURL 
{xContentAccess->queryContentIdentifierString()};
 
                 if ( aType.isEmpty() )
                 {
@@ -2506,7 +2476,7 @@ void SfxDocTplService_Impl::addFsysGroup( GroupList_Impl& 
rList,
             while ( xResultSet->next() )
             {
                 OUString aChildTitle( xRow->getString( 1 ) );
-                OUString aTargetURL = 
xContentAccess->queryContentIdentifierString();
+                const OUString aTargetURL 
{xContentAccess->queryContentIdentifierString()};
                 OUString aType;
                 OUString aHierURL;
 
@@ -2530,12 +2500,12 @@ void SfxDocTplService_Impl::createFromContent( 
GroupList_Impl& rList,
                                                bool bHierarchy,
                                                bool bWriteableContent )
 {
-    OUString aTargetURL = 
rContent.get()->getIdentifier()->getContentIdentifier();
+    const OUString aTargetURL 
{rContent.get()->getIdentifier()->getContentIdentifier()};
 
     // when scanning the file system, we have to add the 'standard' group, too
     if ( ! bHierarchy )
     {
-        OUString aUIStdTitle = getLongName( STANDARD_FOLDER );
+        const OUString aUIStdTitle {getLongName( STANDARD_FOLDER )};
         addFsysGroup( rList, OUString(), aUIStdTitle, aTargetURL, 
bWriteableContent );
     }
 
@@ -2567,8 +2537,8 @@ void SfxDocTplService_Impl::createFromContent( 
GroupList_Impl& rList,
             while ( xResultSet->next() )
             {
                 // TODO/LATER: clarify the encoding of the Title
-                OUString aTitle( xRow->getString( 1 ) );
-                OUString aTargetSubfolderURL( 
xContentAccess->queryContentIdentifierString() );
+                const OUString aTitle( xRow->getString( 1 ) );
+                const OUString aTargetSubfolderURL( 
xContentAccess->queryContentIdentifierString() );
 
                 if ( bHierarchy )
                     addHierGroup( rList, aTitle, aTargetSubfolderURL );
@@ -2618,7 +2588,7 @@ void SfxDocTplService_Impl::addToHierarchy( 
GroupData_Impl *pGroup,
                       INetURLObject::LAST_SEGMENT,
                       INetURLObject::EncodeMechanism::All );
 
-    OUString aTemplateURL = aGroupObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE );
+    const OUString aTemplateURL {aGroupObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE )};
 
     if ( Content::create( aTemplateURL, maCmdEnv, 
comphelper::getProcessComponentContext(), aTemplate ) )
         return;
@@ -2636,25 +2606,20 @@ void SfxDocTplService_Impl::updateData( 
DocTemplates_EntryData_Impl *pData )
     if ( ! Content::create( pData->getHierarchyURL(), maCmdEnv, 
comphelper::getProcessComponentContext(), aTemplate ) )
         return;
 
-    OUString aPropName;
-
     if ( pData->getUpdateType() )
     {
-        aPropName =  PROPERTY_TYPE;
-        setProperty( aTemplate, aPropName, makeAny( pData->getType() ) );
+        setProperty( aTemplate, PROPERTY_TYPE, makeAny( pData->getType() ) );
     }
 
     if ( pData->getUpdateLink() )
     {
-        aPropName = TARGET_URL;
-        setProperty( aTemplate, aPropName, makeAny( pData->getTargetURL() ) );
+        setProperty( aTemplate, TARGET_URL, makeAny( pData->getTargetURL() ) );
     }
 }
 
 
 void SfxDocTplService_Impl::addGroupToHierarchy( GroupData_Impl *pGroup )
 {
-    OUString aAdditionalProp( TARGET_DIR_URL  );
     Content aGroup;
 
     INetURLObject aNewGroupObj( maRootURL );
@@ -2662,11 +2627,11 @@ void SfxDocTplService_Impl::addGroupToHierarchy( 
GroupData_Impl *pGroup )
           INetURLObject::LAST_SEGMENT,
           INetURLObject::EncodeMechanism::All );
 
-    OUString aNewGroupURL = aNewGroupObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE );
+    const OUString aNewGroupURL {aNewGroupObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE )};
 
     if ( createFolder( aNewGroupURL, false, false, aGroup ) )
     {
-        setProperty( aGroup, aAdditionalProp, makeAny( pGroup->getTargetURL() 
) );
+        setProperty( aGroup, TARGET_DIR_URL, makeAny( pGroup->getTargetURL() ) 
);
         pGroup->setHierarchyURL( aNewGroupURL );
 
         sal_uIntPtr nCount = pGroup->count();
commit e0d164754f4b1a83ad58b2fcbbebb0017110d2ae
Author: Matteo Casalin <matteo.casa...@yahoo.com>
Date:   Mon Apr 17 20:54:46 2017 +0200

    Reduce scope and simplify by early return
    
    Change-Id: I12f8c6cb002cb0af63a096c7b66dd1e7d2db92a5

diff --git a/sfx2/source/doc/doctempl.cxx b/sfx2/source/doc/doctempl.cxx
index 4c09b9543b82..3e40d2c3ff36 100644
--- a/sfx2/source/doc/doctempl.cxx
+++ b/sfx2/source/doc/doctempl.cxx
@@ -1136,37 +1136,29 @@ bool SfxDocumentTemplates::GetLogicNames
     aFullPath.SetURL( rPath );
     const OUString aPath( aFullPath.GetMainURL( 
INetURLObject::DecodeMechanism::NONE ) );
 
-    RegionData_Impl *pData = nullptr;
-    DocTempl_EntryData_Impl  *pEntry = nullptr;
-    bool         bFound = false;
-
     const sal_uInt16 nCount = GetRegionCount();
 
-    for ( sal_uInt16 i=0; !bFound && (i<nCount); i++ )
+    for ( sal_uInt16 i=0; i<nCount; ++i )
     {
-        pData = pImp->GetRegion( i );
+        RegionData_Impl *pData = pImp->GetRegion( i );
         if ( pData )
         {
-            sal_uInt16 nChildCount = pData->GetCount();
+            const sal_uInt16 nChildCount = pData->GetCount();
 
-            for ( sal_uInt16 j=0; !bFound && (j<nChildCount); j++ )
+            for ( sal_uInt16 j=0; j<nChildCount; ++j )
             {
-                pEntry = pData->GetEntry( j );
+                DocTempl_EntryData_Impl *pEntry = pData->GetEntry( j );
                 if ( pEntry && pEntry->GetTargetURL() == aPath )
                 {
-                    bFound = true;
+                    rRegion = pData->GetTitle();
+                    rName = pEntry->GetTitle();
+                    return true;
                 }
             }
         }
     }
 
-    if ( bFound )
-    {
-        rRegion = pData->GetTitle();
-        rName = pEntry->GetTitle();
-    }
-
-    return bFound;
+    return false;
 }
 
 
commit ee82052acf89f17bdbba0641324f96060b285a3d
Author: Matteo Casalin <matteo.casa...@yahoo.com>
Date:   Mon Apr 17 20:15:31 2017 +0200

    Reduce scope and simplify
    
    Change-Id: I055e05ff04c9a839fb142be5cbf08e40e7eb35f3

diff --git a/sfx2/source/doc/doctempl.cxx b/sfx2/source/doc/doctempl.cxx
index a07c1bbfbb1d..4c09b9543b82 100644
--- a/sfx2/source/doc/doctempl.cxx
+++ b/sfx2/source/doc/doctempl.cxx
@@ -339,9 +339,7 @@ sal_uInt16 SfxDocumentTemplates::GetRegionCount() const
     if ( !pImp->Construct() )
         return 0;
 
-    sal_uInt16 nCount = pImp->GetRegionCount();
-
-    return nCount;
+    return pImp->GetRegionCount();
 }
 
 
@@ -366,12 +364,11 @@ sal_uInt16 SfxDocumentTemplates::GetCount
         return 0;
 
     RegionData_Impl *pData = pImp->GetRegion( nRegion );
-    sal_uInt16            nCount = 0;
 
-    if ( pData )
-        nCount = pData->GetCount();
+    if ( !pData )
+        return 0;
 
-    return nCount;
+    return pData->GetCount();
 }
 
 
@@ -395,14 +392,14 @@ OUString SfxDocumentTemplates::GetName
 
     if ( pImp->Construct() )
     {
-        DocTempl_EntryData_Impl  *pEntry = nullptr;
         RegionData_Impl *pRegion = pImp->GetRegion( nRegion );
 
         if ( pRegion )
-            pEntry = pRegion->GetEntry( nIdx );
-
-        if ( pEntry )
-            return pEntry->GetTitle();
+        {
+            DocTempl_EntryData_Impl *pEntry = pRegion->GetEntry( nIdx );
+            if ( pEntry )
+                return pEntry->GetTitle();
+        }
     }
 
     return OUString();
@@ -429,16 +426,16 @@ OUString SfxDocumentTemplates::GetPath
     if ( !pImp->Construct() )
         return OUString();
 
-    DocTempl_EntryData_Impl  *pEntry = nullptr;
     RegionData_Impl *pRegion = pImp->GetRegion( nRegion );
 
     if ( pRegion )
-        pEntry = pRegion->GetEntry( nIdx );
+    {
+        DocTempl_EntryData_Impl *pEntry = pRegion->GetEntry( nIdx );
+        if ( pEntry )
+            return pEntry->GetTargetURL();
+    }
 
-    if ( pEntry )
-        return pEntry->GetTargetURL();
-    else
-        return OUString();
+    return OUString();
 }
 
 
@@ -846,7 +843,7 @@ bool SfxDocumentTemplates::CopyFrom
                 if ( nIdx == USHRT_MAX )
                     nIdx = 0;
                 else
-                    nIdx += 1;
+                    ++nIdx;
 
                 // todo: fix SfxDocumentTemplates to handle size_t instead of 
sal_uInt16
                 size_t temp_nIdx = nIdx;
@@ -1143,7 +1140,7 @@ bool SfxDocumentTemplates::GetLogicNames
     DocTempl_EntryData_Impl  *pEntry = nullptr;
     bool         bFound = false;
 
-    sal_uInt16 nCount = GetRegionCount();
+    const sal_uInt16 nCount = GetRegionCount();
 
     for ( sal_uInt16 i=0; !bFound && (i<nCount); i++ )
     {
@@ -1287,10 +1284,9 @@ RegionData_Impl::~RegionData_Impl()
 size_t RegionData_Impl::GetEntryPos( const OUString& rTitle, bool& rFound ) 
const
 {
 #if 1   // Don't use binary search today
-    size_t i;
-    size_t nCount = maEntries.size();
+    const size_t nCount = maEntries.size();
 
-    for ( i=0; i<nCount; i++ )
+    for ( size_t i=0; i<nCount; ++i )
     {
         DocTempl_EntryData_Impl *pData = maEntries[ i ];
 
@@ -1302,7 +1298,7 @@ size_t RegionData_Impl::GetEntryPos( const OUString& 
rTitle, bool& rFound ) cons
     }
 
     rFound = false;
-    return i;
+    return nCount;
 
 #else
     // use binary search to find the correct position
@@ -1409,8 +1405,7 @@ DocTempl_EntryData_Impl* RegionData_Impl::GetEntry( const 
OUString& rName ) cons
 
     if ( bFound )
         return maEntries[ nPos ];
-    else
-        return nullptr;
+    return nullptr;
 }
 
 
@@ -1436,9 +1431,7 @@ void RegionData_Impl::DeleteEntry( size_t nIndex )
 
 int RegionData_Impl::Compare( RegionData_Impl* pCompare ) const
 {
-    int nCompare = maTitle.compareTo( pCompare->maTitle );
-
-    return nCompare;
+    return maTitle.compareTo( pCompare->maTitle );
 }
 
 
commit 6730b9a3a3e02edcd485e9c1888ac12e9bdf7b40
Author: Matteo Casalin <matteo.casa...@yahoo.com>
Date:   Mon Apr 17 19:31:00 2017 +0200

    OUStrings: constify and avoid temporaries
    
    Change-Id: I91d5969468da6d9bd61bc7bd321cc065910f7639

diff --git a/sfx2/source/doc/doctempl.cxx b/sfx2/source/doc/doctempl.cxx
index 2552c54a625b..a07c1bbfbb1d 100644
--- a/sfx2/source/doc/doctempl.cxx
+++ b/sfx2/source/doc/doctempl.cxx
@@ -275,7 +275,6 @@ OUString SfxDocumentTemplates::GetFullRegionName
 
 {
     // First: find the RegionData for the index
-    OUString aName;
 
     DocTemplLocker_Impl aLocker( *pImp );
 
@@ -284,14 +283,14 @@ OUString SfxDocumentTemplates::GetFullRegionName
         RegionData_Impl *pData1 = pImp->GetRegion( nIdx );
 
         if ( pData1 )
-            aName = pData1->GetTitle();
+            return pData1->GetTitle();
 
         // --**-- here was some code which appended the path to the
         //      group if there was more than one with the same name.
         //      this should not happen anymore
     }
 
-    return aName;
+    return OUString();
 }
 
 
@@ -310,8 +309,6 @@ OUString SfxDocumentTemplates::GetRegionName
 
 */
 {
-    OUString aTmpString;
-
     DocTemplLocker_Impl aLocker( *pImp );
 
     if ( pImp->Construct() )
@@ -319,10 +316,10 @@ OUString SfxDocumentTemplates::GetRegionName
         RegionData_Impl *pData = pImp->GetRegion( nIdx );
 
         if ( pData )
-            aTmpString = pData->GetTitle();
+            return pData->GetTitle();
     }
 
-    return aTmpString;
+    return OUString();
 }
 
 
@@ -396,8 +393,6 @@ OUString SfxDocumentTemplates::GetName
 {
     DocTemplLocker_Impl aLocker( *pImp );
 
-    OUString aTmpString;
-
     if ( pImp->Construct() )
     {
         DocTempl_EntryData_Impl  *pEntry = nullptr;
@@ -407,10 +402,10 @@ OUString SfxDocumentTemplates::GetName
             pEntry = pRegion->GetEntry( nIdx );
 
         if ( pEntry )
-            aTmpString = pEntry->GetTitle();
+            return pEntry->GetTitle();
     }
 
-    return aTmpString;
+    return OUString();
 }
 
 
@@ -463,17 +458,16 @@ OUString 
SfxDocumentTemplates::GetTemplateTargetURLFromComponent( const OUString
                         INetURLObject::EncodeMechanism::All );
 
 
-    OUString aResult;
     Content aTemplate;
     uno::Reference< XCommandEnvironment > aCmdEnv;
     if ( Content::create( aTemplateObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE ), aCmdEnv, 
comphelper::getProcessComponentContext(), aTemplate ) )
     {
-        OUString aPropName( TARGET_URL  );
-        getTextProperty_Impl( aTemplate, aPropName, aResult );
-        aResult = SvtPathOptions().SubstituteVariable( aResult );
+        OUString aResult;
+        getTextProperty_Impl( aTemplate, TARGET_URL, aResult );
+        return SvtPathOptions().SubstituteVariable( aResult );
     }
 
-    return aResult;
+    return OUString();
 }
 
 
@@ -562,7 +556,7 @@ bool SfxDocumentTemplates::CopyOrMove
     if ( !pTargetRgn )
         return false;
 
-    OUString aTitle = pSource->GetTitle();
+    const OUString aTitle = pSource->GetTitle();
 
     uno::Reference< XDocumentTemplates > xTemplates = pImp->getDocTemplates();
 
@@ -570,7 +564,7 @@ bool SfxDocumentTemplates::CopyOrMove
                                   aTitle,
                                   pSource->GetTargetURL() ) )
     {
-        OUString aNewTargetURL = GetTemplateTargetURLFromComponent( 
pTargetRgn->GetTitle(), aTitle );
+        const OUString aNewTargetURL = GetTemplateTargetURLFromComponent( 
pTargetRgn->GetTitle(), aTitle );
         if ( aNewTargetURL.isEmpty() )
             return false;
 
@@ -703,11 +697,11 @@ bool SfxDocumentTemplates::CopyTo
 
     INetURLObject aTargetURL( rName );
 
-    OUString aTitle( aTargetURL.getName( INetURLObject::LAST_SEGMENT, true,
+    const OUString aTitle( aTargetURL.getName( INetURLObject::LAST_SEGMENT, 
true,
                                          
INetURLObject::DecodeMechanism::WithCharset ) );
     aTargetURL.removeSegment();
 
-    OUString aParentURL = aTargetURL.GetMainURL( 
INetURLObject::DecodeMechanism::NONE );
+    const OUString aParentURL = aTargetURL.GetMainURL( 
INetURLObject::DecodeMechanism::NONE );
 
     uno::Reference< XCommandEnvironment > aCmdEnv;
     Content aTarget;
@@ -723,9 +717,7 @@ bool SfxDocumentTemplates::CopyTo
         aTransferInfo.NameClash = NameClash::RENAME;
 
         Any aArg = makeAny( aTransferInfo );
-        OUString aCmd( COMMAND_TRANSFER  );
-
-        aTarget.executeCommand( aCmd, aArg );
+        aTarget.executeCommand( COMMAND_TRANSFER, aArg );
     }
     catch ( ContentCreationException& )
     { return false; }
@@ -841,7 +833,7 @@ bool SfxDocumentTemplates::CopyFrom
         aTemplObj.insertName( aTitle, false,
                               INetURLObject::LAST_SEGMENT,
                               INetURLObject::EncodeMechanism::All );
-        OUString aTemplURL = aTemplObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE );
+        const OUString aTemplURL = aTemplObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE );
 
         uno::Reference< XCommandEnvironment > aCmdEnv;
         Content aTemplCont;
@@ -849,9 +841,7 @@ bool SfxDocumentTemplates::CopyFrom
         if( Content::create( aTemplURL, aCmdEnv, 
comphelper::getProcessComponentContext(), aTemplCont ) )
         {
             OUString aTemplName;
-            OUString aPropName( TARGET_URL  );
-
-            if( getTextProperty_Impl( aTemplCont, aPropName, aTemplName ) )
+            if( getTextProperty_Impl( aTemplCont, TARGET_URL, aTemplName ) )
             {
                 if ( nIdx == USHRT_MAX )
                     nIdx = 0;
@@ -1147,7 +1137,7 @@ bool SfxDocumentTemplates::GetLogicNames
 
     aFullPath.SetSmartProtocol( INetProtocol::File );
     aFullPath.SetURL( rPath );
-    OUString aPath( aFullPath.GetMainURL( INetURLObject::DecodeMechanism::NONE 
) );
+    const OUString aPath( aFullPath.GetMainURL( 
INetURLObject::DecodeMechanism::NONE ) );
 
     RegionData_Impl *pData = nullptr;
     DocTempl_EntryData_Impl  *pEntry = nullptr;
@@ -1266,9 +1256,7 @@ const OUString& DocTempl_EntryData_Impl::GetTargetURL()
 
         if ( Content::create( GetHierarchyURL(), aCmdEnv, 
comphelper::getProcessComponentContext(), aRegion ) )
         {
-            OUString aPropName( TARGET_URL  );
-
-            getTextProperty_Impl( aRegion, aPropName, maTargetURL );
+            getTextProperty_Impl( aRegion, TARGET_URL, maTargetURL );
         }
         else
         {
@@ -1365,7 +1353,7 @@ void RegionData_Impl::AddEntry( const OUString& rTitle,
     aLinkObj.insertName( rTitle, false,
                       INetURLObject::LAST_SEGMENT,
                       INetURLObject::EncodeMechanism::All );
-    OUString aLinkURL = aLinkObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE );
+    const OUString aLinkURL = aLinkObj.GetMainURL( 
INetURLObject::DecodeMechanism::NONE );
 
     bool        bFound = false;
     size_t          nPos = GetEntryPos( rTitle, bFound );
@@ -1555,10 +1543,7 @@ void SfxDocTemplate_Impl::AddRegion( const OUString& 
rTitle,
         {
             while ( xResultSet->next() )
             {
-                OUString aTitle( xRow->getString( 1 ) );
-                OUString aTargetDir( xRow->getString( 2 ) );
-
-                pRegion->AddEntry( aTitle, aTargetDir, nullptr );
+                pRegion->AddEntry( xRow->getString( 1 ), xRow->getString( 2 ), 
nullptr );
             }
         }
         catch ( Exception& ) {}
@@ -1591,12 +1576,10 @@ void SfxDocTemplate_Impl::CreateFromHierarchy( Content 
&rTemplRoot )
         {
             while ( xResultSet->next() )
             {
-                OUString aTitle( xRow->getString( 1 ) );
-
-                OUString aId = xContentAccess->queryContentIdentifierString();
+                const OUString aId = 
xContentAccess->queryContentIdentifierString();
                 Content  aContent( aId, aCmdEnv, 
comphelper::getProcessComponentContext() );
 
-                AddRegion( aTitle, aContent );
+                AddRegion( xRow->getString( 1 ), aContent );
             }
         }
         catch ( Exception& ) {}
@@ -1730,8 +1713,7 @@ bool SfxDocTemplate_Impl::GetTitleFromURL( const 
OUString& rURL,
             uno::Reference< XPropertySet > aPropSet( mxInfo, UNO_QUERY );
             if ( aPropSet.is() )
             {
-                OUString aPropName( TITLE  );
-                Any aValue = aPropSet->getPropertyValue( aPropName );
+                Any aValue = aPropSet->getPropertyValue( TITLE );
                 aValue >>= aTitle;
             }
         }
commit d4b3fe8c65272ba029292ce6e714782926ff5db7
Author: Matteo Casalin <matteo.casa...@yahoo.com>
Date:   Mon Apr 17 19:09:09 2017 +0200

    OUStrings: constify and avoid temporaries
    
    Change-Id: I06e058d3ae16bbf504f2e5d8f72b00527c53e336

diff --git a/sfx2/source/doc/docinf.cxx b/sfx2/source/doc/docinf.cxx
index 27d986f3e83a..3241a0146e55 100644
--- a/sfx2/source/doc/docinf.cxx
+++ b/sfx2/source/doc/docinf.cxx
@@ -151,7 +151,7 @@ sal_uInt32 LoadOlePropertySet(
         for( ::std::vector< sal_Int32 >::const_iterator aIt = aPropIds.begin(),
              aEnd = aPropIds.end(); aIt != aEnd; ++aIt )
         {
-            OUString aPropName = xCustomSect->GetPropertyName( *aIt );
+            const OUString aPropName = xCustomSect->GetPropertyName( *aIt );
             uno::Any aPropValue = xCustomSect->GetAnyValue( *aIt );
             if( !aPropName.isEmpty() && aPropValue.hasValue() )
             {
@@ -209,7 +209,7 @@ bool SaveOlePropertySet(
     SfxOleSection& rGlobSect = aGlobSet.AddSection( SECTION_GLOBAL );
     rGlobSect.SetStringValue( PROPID_TITLE,    i_xDocProps->getTitle() );
     rGlobSect.SetStringValue( PROPID_SUBJECT,  i_xDocProps->getSubject() );
-    OUString aStr = ::comphelper::string::convertCommaSeparated(
+    const OUString aStr = ::comphelper::string::convertCommaSeparated(
         i_xDocProps->getKeywords() );
     rGlobSect.SetStringValue( PROPID_KEYWORDS, aStr );
     rGlobSect.SetStringValue( PROPID_TEMPLATE, i_xDocProps->getTemplateName() 
);
diff --git a/sfx2/source/doc/docmacromode.cxx b/sfx2/source/doc/docmacromode.cxx
index 4df381c8e1fe..952576d5505a 100644
--- a/sfx2/source/doc/docmacromode.cxx
+++ b/sfx2/source/doc/docmacromode.cxx
@@ -198,12 +198,10 @@ namespace sfx2
 
         try
         {
-            OUString sReferrer( 
m_xData->m_rDocumentAccess.getDocumentLocation() );
-
             // get document location from medium name and check whether it is 
a trusted one
             // the service is created ohne document version, since it is not 
of interest here
             Reference< XDocumentDigitalSignatures > 
xSignatures(DocumentDigitalSignatures::createDefault(::comphelper::getProcessComponentContext()));
-            INetURLObject aURLReferer( sReferrer );
+            INetURLObject aURLReferer( 
m_xData->m_rDocumentAccess.getDocumentLocation() );
 
             OUString aLocation;
             if ( aURLReferer.removeSegment() )
@@ -308,15 +306,15 @@ namespace sfx2
                     bHasMacroLib = false;
                 else
                 {
-                    OUString aStdLibName( "Standard" );
-                    OUString aVBAProject( "VBAProject" );
+                    const OUString aStdLibName( "Standard" );
+                    const OUString aVBAProject( "VBAProject" );
                     Sequence< OUString > aElements = 
xContainer->getElementNames();
                     if ( aElements.getLength() )
                     {
                         sal_Int32 nElements = aElements.getLength();
                         for( sal_Int32 i = 0; i < nElements; ++i )
                         {
-                            OUString aElement = aElements[i];
+                            const OUString aElement = aElements[i];
                             if( aElement == aStdLibName || aElement == 
aVBAProject )
                             {
                                 Reference < XNameAccess > xLib;
commit 429c7a4958b11da43f2ada79adde778464a745b3
Author: Matteo Casalin <matteo.casa...@yahoo.com>
Date:   Mon Apr 17 18:56:24 2017 +0200

    OUStrings: constify and avoid temporaries
    
    Change-Id: I8ba379d2418eec012de62354dab474e6e7c8a1c6

diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx
index 465bd904ba1a..af0eedd07ba7 100644
--- a/sfx2/source/view/viewfrm.cxx
+++ b/sfx2/source/view/viewfrm.cxx
@@ -274,7 +274,7 @@ void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq )
                 SfxAllItemSet aSet( pApp->GetPool() );
                 aSet.Put( SfxStringItem( SID_FILE_NAME, 
pMed->GetURLObject().GetMainURL(INetURLObject::DecodeMechanism::NONE) ) );
                 aSet.Put( SfxBoolItem( SID_TEMPLATE, true ) );
-                aSet.Put( SfxStringItem( SID_TARGETNAME, OUString("_blank") ) 
);
+                aSet.Put( SfxStringItem( SID_TARGETNAME, "_blank" ) );
                 const SfxStringItem* pReferer = 
SfxItemSet::GetItem<SfxStringItem>(pMed->GetItemSet(), SID_REFERER, false);
                 if ( pReferer )
                     aSet.Put( *pReferer );
@@ -322,7 +322,7 @@ void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq )
                   && ( pSh->GetModifyPasswordHash() || 
pSh->GetModifyPasswordInfo().getLength() )
                   && !pSh->IsModifyPasswordEntered() )
                 {
-                    OUString aDocumentName = INetURLObject( pMed->GetOrigURL() 
).GetMainURL( INetURLObject::DecodeMechanism::WithCharset );
+                    const OUString aDocumentName = INetURLObject( 
pMed->GetOrigURL() ).GetMainURL( INetURLObject::DecodeMechanism::WithCharset );
                     if( !AskPasswordToModify_Impl( 
pMed->GetInteractionHandler(), aDocumentName, pMed->GetOrigFilter(), 
pSh->GetModifyPasswordHash(), pSh->GetModifyPasswordInfo() ) )
                     {
                         // this is a read-only document, if it has "Password 
to modify"
@@ -364,9 +364,9 @@ void SfxViewFrame::ExecReload_Impl( SfxRequest& rReq )
 
             // doing
 
-            OUString aTemp;
-            osl::FileBase::getFileURLFromSystemPath( pMed->GetPhysicalName(), 
aTemp );
-            INetURLObject aPhysObj( aTemp );
+            OUString sTemp;
+            osl::FileBase::getFileURLFromSystemPath( pMed->GetPhysicalName(), 
sTemp );
+            INetURLObject aPhysObj( sTemp );
             const SfxInt16Item* pVersionItem = 
SfxItemSet::GetItem<SfxInt16Item>(pSh->GetMedium()->GetItemSet(), SID_VERSION, 
false);
 
             INetURLObject aMedObj( pMed->GetName() );
@@ -1881,7 +1881,7 @@ void SfxViewFrame::SaveCurrentViewData_Impl( const 
SfxInterfaceId i_nNewViewId )
         for ( sal_Int32 i=0; i<nCount; ++i )
         {
             const ::comphelper::NamedValueCollection aCurViewData( 
xViewData->getByIndex(i) );
-            OUString sViewId( aCurViewData.getOrDefault( "ViewId", OUString() 
) );
+            const OUString sViewId( aCurViewData.getOrDefault( "ViewId", 
OUString() ) );
             if ( sViewId.isEmpty() )
                 continue;
 
@@ -2376,8 +2376,8 @@ void SfxViewFrame::AddDispatchMacroToBasic_Impl( const 
OUString& sMacro )
         if ( xUrl.is() )
         {
             // get name
-            OUString aName = xUrl->getName();
-            sal_Unicode cTok = '.';
+            const OUString aName = xUrl->getName();
+            const sal_Unicode cTok = '.';
             sal_Int32 nIndex = 0;
             aLibName = aName.getToken( 0, cTok, nIndex );
             if ( nIndex != -1 )
@@ -2457,7 +2457,6 @@ void SfxViewFrame::AddDispatchMacroToBasic_Impl( const 
OUString& sMacro )
         }
 
         // pack the macro as direct usable "sub" routine
-        OUString sCode;
         OUStringBuffer sRoutine(10000);
         bool bReplace = false;
 
@@ -2470,6 +2469,7 @@ void SfxViewFrame::AddDispatchMacroToBasic_Impl( const 
OUString& sMacro )
             }
             else
             {
+                OUString sCode;
                 aTemp = xLib->getByName(aModuleName);
                 aTemp >>= sCode;
                 sRoutine.append( sCode );
commit 9f1046587a26a3f673b465ad8dfe911905e71c5f
Author: Matteo Casalin <matteo.casa...@yahoo.com>
Date:   Mon Apr 17 18:41:31 2017 +0200

    Remove isEmpty check on (just set) non-empty sURL
    
    Change-Id: I669b720c976c51d248dadb11b5e93ab1708ccfbb

diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx
index 6127ce8ab611..465bd904ba1a 100644
--- a/sfx2/source/view/viewfrm.cxx
+++ b/sfx2/source/view/viewfrm.cxx
@@ -1766,12 +1766,8 @@ SfxViewShell* SfxViewFrame::LoadViewIntoFrame_Impl( 
const SfxObjectShell& i_rDoc
     else
         aTransformLoadArgs.remove( "Hidden" );
 
-    OUString sURL( "private:object"  );
-    if ( sURL.isEmpty() )
-        sURL = i_rDoc.GetFactory().GetFactoryURL();
-
     Reference< XComponentLoader > xLoader( i_rFrame, UNO_QUERY_THROW );
-    xLoader->loadComponentFromURL( sURL, "_self", 0,
+    xLoader->loadComponentFromURL( "private:object", "_self", 0,
         aTransformLoadArgs.getPropertyValues() );
 
     SfxViewShell* pViewShell = SfxViewShell::Get( i_rFrame->getController() );
commit 54838cd2ef8dfbee5112ed0fee19eb2ece49706a
Author: Matteo Casalin <matteo.casa...@yahoo.com>
Date:   Mon Apr 17 14:55:38 2017 +0200

    OUStrings: constify and avoid temporaries
    
    Change-Id: Ib69ad52577f8d94dbd363ba1799d5294db7a580a

diff --git a/sfx2/source/doc/docfac.cxx b/sfx2/source/doc/docfac.cxx
index f5fa98958ad4..339c2bb8fed6 100644
--- a/sfx2/source/doc/docfac.cxx
+++ b/sfx2/source/doc/docfac.cxx
@@ -173,20 +173,19 @@ void SfxObjectFactory::SetSystemTemplate( const OUString& 
rServiceName, const OU
 {
     static const int nMaxPathSize = 16000;
 
-    OUString CONF_PATH = "Office/Factories/" + rServiceName;
+    const OUString sConfPath = "Office/Factories/" + rServiceName;
     static const char PROP_DEF_TEMPL_CHANGED[] = 
"ooSetupFactorySystemDefaultTemplateChanged";
 
     static const char DEF_TPL_STR[] = "/soffice.";
 
-    OUString sURL;
+    OUString sUserTemplateURL;
     OUString sPath;
     sal_Unicode aPathBuffer[nMaxPathSize];
     if ( SystemPath::GetUserTemplateLocation( aPathBuffer, nMaxPathSize ))
         sPath = OUString( aPathBuffer );
-    osl::FileBase::getFileURLFromSystemPath( sPath, sURL );
+    osl::FileBase::getFileURLFromSystemPath( sPath, sUserTemplateURL );
 
-    OUString aUserTemplateURL( sURL );
-    if ( !aUserTemplateURL.isEmpty())
+    if ( !sUserTemplateURL.isEmpty())
     {
         try
         {
@@ -195,9 +194,9 @@ void SfxObjectFactory::SetSystemTemplate( const OUString& 
rServiceName, const OU
                 ::comphelper::getProcessComponentContext(), 
"/org.openoffice.Setup", ::comphelper::EConfigurationModes::Standard );
 
             OUString aActualFilter;
-            ::comphelper::ConfigurationHelper::readRelativeKey( xConfig, 
CONF_PATH, "ooSetupFactoryActualFilter" ) >>= aActualFilter;
+            ::comphelper::ConfigurationHelper::readRelativeKey( xConfig, 
sConfPath, "ooSetupFactoryActualFilter" ) >>= aActualFilter;
             bool bChanged(false);
-            ::comphelper::ConfigurationHelper::readRelativeKey( xConfig, 
CONF_PATH, PROP_DEF_TEMPL_CHANGED ) >>= bChanged;
+            ::comphelper::ConfigurationHelper::readRelativeKey( xConfig, 
sConfPath, PROP_DEF_TEMPL_CHANGED ) >>= bChanged;
 
             uno::Reference< container::XNameAccess > xFilterFactory(
                 xFactory->createInstance( 
"com.sun.star.document.FilterFactory" ), uno::UNO_QUERY_THROW );
@@ -214,10 +213,9 @@ void SfxObjectFactory::SetSystemTemplate( const OUString& 
rServiceName, const OU
             uno::Sequence< OUString > aAllExt =
                 aProps1.getUnpackedValueOrDefault("Extensions", uno::Sequence< 
OUString >() );
             //To-do: check if aAllExt is empty first
-            OUString aExt = aAllExt[0];
+            const OUString aExt = DEF_TPL_STR + aAllExt[0];
 
-            aUserTemplateURL += DEF_TPL_STR;
-            aUserTemplateURL += aExt;
+            sUserTemplateURL += aExt;
 
             uno::Reference<ucb::XSimpleFileAccess3> xSimpleFileAccess(
                 ucb::SimpleFileAccess::create( 
::comphelper::getComponentContext(xFactory) ) );
@@ -229,13 +227,12 @@ void SfxObjectFactory::SetSystemTemplate( const OUString& 
rServiceName, const OU
             if ( !xSimpleFileAccess->exists( aBackupURL ) )
                 xSimpleFileAccess->createFolder( aBackupURL );
 
-            aBackupURL += DEF_TPL_STR;
             aBackupURL += aExt;
 
             if ( !rTemplateName.isEmpty() )
             {
-                if ( xSimpleFileAccess->exists( aUserTemplateURL ) && 
!bChanged )
-                    xSimpleFileAccess->copy( aUserTemplateURL, aBackupURL );
+                if ( xSimpleFileAccess->exists( sUserTemplateURL ) && 
!bChanged )
+                    xSimpleFileAccess->copy( sUserTemplateURL, aBackupURL );
 
                 uno::Reference< document::XTypeDetection > xTypeDetector( 
xTypeDetection, uno::UNO_QUERY );
                 ::comphelper::SequenceAsHashMap aProps2( 
xTypeDetection->getByName( xTypeDetector->queryTypeByURL( rTemplateName ) ) );
@@ -248,7 +245,7 @@ void SfxObjectFactory::SetSystemTemplate( const OUString& 
rServiceName, const OU
                 aArgs[1].Name = "AsTemplate";
                 aArgs[1].Value <<= true;
                 aArgs[2].Name = "URL";
-                aArgs[2].Value <<= OUString( rTemplateName );
+                aArgs[2].Value <<= rTemplateName;
 
                 uno::Reference< frame::XLoadable > xLoadable( 
xFactory->createInstance( rServiceName ), uno::UNO_QUERY );
                 xLoadable->load( aArgs );
@@ -258,17 +255,17 @@ void SfxObjectFactory::SetSystemTemplate( const OUString& 
rServiceName, const OU
                 aArgs[1].Value <<= true;
 
                 uno::Reference< frame::XStorable > xStorable( xLoadable, 
uno::UNO_QUERY );
-                xStorable->storeToURL( aUserTemplateURL, aArgs );
-                ::comphelper::ConfigurationHelper::writeRelativeKey( xConfig, 
CONF_PATH, PROP_DEF_TEMPL_CHANGED, uno::makeAny( true ));
+                xStorable->storeToURL( sUserTemplateURL, aArgs );
+                ::comphelper::ConfigurationHelper::writeRelativeKey( xConfig, 
sConfPath, PROP_DEF_TEMPL_CHANGED, uno::makeAny( true ));
                 ::comphelper::ConfigurationHelper::flush( xConfig );
             }
             else
             {
                 DBG_ASSERT( bChanged, "invalid 
ooSetupFactorySystemDefaultTemplateChanged value!" );
 
-                xSimpleFileAccess->copy( aBackupURL, aUserTemplateURL );
+                xSimpleFileAccess->copy( aBackupURL, sUserTemplateURL );
                 xSimpleFileAccess->kill( aBackupURL );
-                ::comphelper::ConfigurationHelper::writeRelativeKey( xConfig, 
CONF_PATH, PROP_DEF_TEMPL_CHANGED, uno::makeAny( false ));
+                ::comphelper::ConfigurationHelper::writeRelativeKey( xConfig, 
sConfPath, PROP_DEF_TEMPL_CHANGED, uno::makeAny( false ));
                 ::comphelper::ConfigurationHelper::flush( xConfig );
             }
         }
@@ -296,11 +293,10 @@ OUString SfxObjectFactory::GetStandardTemplate( const 
OUString& rServiceName )
     if (eFac == SvtModuleOptions::EFactory::UNKNOWN_FACTORY)
         eFac = SvtModuleOptions::ClassifyFactoryByShortName(rServiceName);
 
-    OUString sTemplate;
     if (eFac != SvtModuleOptions::EFactory::UNKNOWN_FACTORY)
-        sTemplate = SvtModuleOptions().GetFactoryStandardTemplate(eFac);
+        return SvtModuleOptions().GetFactoryStandardTemplate(eFac);
 
-    return sTemplate;
+    return OUString();
 }
 
 std::shared_ptr<const SfxFilter> SfxObjectFactory::GetTemplateFilter() const
@@ -353,10 +349,8 @@ OUString SfxObjectFactory::GetModuleName() const
         css::uno::Reference< css::frame::XModuleManager2 > xModuleManager(
             css::frame::ModuleManager::create(xContext));
 
-        OUString sDocService(GetDocumentServiceName());
-        ::comphelper::SequenceAsHashMap aPropSet( 
xModuleManager->getByName(sDocService) );
-        OUString sModuleName = 
aPropSet.getUnpackedValueOrDefault("ooSetupFactoryUIName", OUString());
-        return sModuleName;
+        ::comphelper::SequenceAsHashMap aPropSet( 
xModuleManager->getByName(GetDocumentServiceName()) );
+        return aPropSet.getUnpackedValueOrDefault("ooSetupFactoryUIName", 
OUString());
     }
     catch(const css::uno::RuntimeException&)
     {
commit ac48e590d3ef6aa6dc62651182e6f13ce113f9d9
Author: Matteo Casalin <matteo.casa...@yahoo.com>
Date:   Mon Apr 17 13:02:14 2017 +0200

    OUStrings: constify and avoid temporaries
    
    Change-Id: I4459c84afbe68d29f1fd8dbce3c4aa6f7846a912

diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx
index 95978350fb78..79f17cbb4968 100644
--- a/sfx2/source/doc/objmisc.cxx
+++ b/sfx2/source/doc/objmisc.cxx
@@ -525,7 +525,7 @@ bool SfxObjectShell::SwitchToShared( bool bShared, bool 
bSave )
             }
             else
             {
-                OUString aTempFileURL = pMedium->GetURLObject().GetMainURL( 
INetURLObject::DecodeMechanism::NONE );
+                const OUString aTempFileURL = 
pMedium->GetURLObject().GetMainURL( INetURLObject::DecodeMechanism::NONE );
                 GetMedium()->SwitchDocumentToFile( GetSharedFileURL() );
                 (pImpl->m_aSharedFileURL).clear();
 
@@ -769,7 +769,7 @@ OUString SfxObjectShell::GetTitle( sal_uInt16  nMaxLength ) 
const
         return aNoName;
     }
 
-    const INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : OUString( 
GetMedium()->GetName() ) );
+    const INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : 
GetMedium()->GetName() );
     if ( nMaxLength > SFX_TITLE_CAPTION && nMaxLength <= SFX_TITLE_HISTORY )
     {
         sal_uInt16 nRemote;
@@ -783,9 +783,8 @@ OUString SfxObjectShell::GetTitle( sal_uInt16  nMaxLength ) 
const
     // Local file?
     if ( aURL.GetProtocol() == INetProtocol::File )
     {
-        OUString aName( aURL.HasMark() ? INetURLObject( aURL.GetURLNoMark() 
).PathToFileName() : aURL.PathToFileName() );
         if ( nMaxLength == SFX_TITLE_FULLNAME )
-            return aName;
+            return aURL.HasMark() ? INetURLObject( aURL.GetURLNoMark() 
).PathToFileName() : aURL.PathToFileName();
         else if ( nMaxLength == SFX_TITLE_FILENAME )
             return aURL.getName(INetURLObject::LAST_SEGMENT, true, 
INetURLObject::DecodeMechanism::WithCharset);
         else if ( pImpl->aTitle.isEmpty() )
@@ -796,23 +795,16 @@ OUString SfxObjectShell::GetTitle( sal_uInt16  nMaxLength 
) const
     {
         if ( nMaxLength >= SFX_TITLE_MAXLEN )
         {
-            OUString aComplete( aURL.GetMainURL( 
INetURLObject::DecodeMechanism::NONE ) );
+            const OUString aComplete( aURL.GetMainURL( 
INetURLObject::DecodeMechanism::NONE ) );
             if( aComplete.getLength() > nMaxLength )
-            {
-                OUString aRet( "..." );
-                aRet += aComplete.copy( aComplete.getLength() - nMaxLength + 
3, nMaxLength - 3 );
-                return aRet;
-            }
+                return "..." + aComplete.copy( aComplete.getLength() - 
nMaxLength + 3, nMaxLength - 3 );
             else
                 return aComplete;
         }
         else if ( nMaxLength == SFX_TITLE_FILENAME )
         {
-            OUString aName( aURL.GetBase() );
-            aName = INetURLObject::decode( aName, 
INetURLObject::DecodeMechanism::WithCharset );
-            if( aName.isEmpty() )
-                aName = aURL.GetURLNoPass();
-            return aName;
+            const OUString aName = INetURLObject::decode( aURL.GetBase(), 
INetURLObject::DecodeMechanism::WithCharset );
+            return aName.isEmpty() ? aURL.GetURLNoPass() : aName;
         }
         else if ( nMaxLength == SFX_TITLE_FULLNAME )
             return aURL.GetMainURL( INetURLObject::DecodeMechanism::ToIUri );
@@ -1051,13 +1043,12 @@ void SfxObjectShell::InitOwnModel_Impl()
         uno::Reference< frame::XModel >  xModel ( GetModel(), uno::UNO_QUERY );
         if ( xModel.is() )
         {
-            OUString aURL = GetMedium()->GetOrigURL();
             SfxItemSet *pSet = GetMedium()->GetItemSet();
             if ( !GetMedium()->IsReadOnly() )
                 pSet->ClearItem( SID_INPUTSTREAM );
             uno::Sequence< beans::PropertyValue > aArgs;
             TransformItems( SID_OPENDOC, *pSet, aArgs );
-            xModel->attachResource( aURL, aArgs );
+            xModel->attachResource( GetMedium()->GetOrigURL(), aArgs );
             impl_addToModelCollection(xModel);
         }
 
@@ -1109,7 +1100,7 @@ void SfxObjectShell::FinishedLoading( SfxLoadedFlags 
nFlags )
         pImpl->nFlagsInProgress |= SfxLoadedFlags::IMAGES;
         uno::Reference<document::XDocumentProperties> xDocProps(
             getDocProperties());
-        OUString url(xDocProps->getAutoloadURL());
+        const OUString url(xDocProps->getAutoloadURL());
         sal_Int32 delay(xDocProps->getAutoloadSecs());
         SetAutoLoad( INetURLObject(url), delay * 1000,
                      (delay > 0) || !url.isEmpty() );
@@ -1169,7 +1160,7 @@ void SfxObjectShell::TemplateDisconnectionAfterLoad()
     SfxMedium* pTmpMedium = pMedium;
     if ( pTmpMedium )
     {
-        OUString aName( pTmpMedium->GetName() );
+        const OUString aName( pTmpMedium->GetName() );
         const SfxStringItem* pTemplNamItem = 
SfxItemSet::GetItem<SfxStringItem>(pTmpMedium->GetItemSet(), SID_TEMPLATE_NAME, 
false);
         OUString aTemplateName;
         if ( pTemplNamItem )
@@ -1471,7 +1462,7 @@ void SfxHeaderAttributes_Impl::SetAttribute( const 
SvKeyValue& rKV )
     if( rKV.GetKey().equalsIgnoreAsciiCase("refresh") && 
!rKV.GetValue().isEmpty() )
     {
         sal_uInt32 nTime = aValue.getToken(  0, ';' ).toInt32() ;
-        OUString aURL = comphelper::string::strip(aValue.getToken( 1, ';' ), ' 
');
+        const OUString aURL = comphelper::string::strip(aValue.getToken( 1, 
';' ), ' ');
         uno::Reference<document::XDocumentProperties> xDocProps(
             pDoc->getDocProperties());
         if( aURL.startsWithIgnoreAsciiCase( "url=" ) )
@@ -1544,8 +1535,7 @@ bool SfxObjectShell::IsPreview() const
     if ( pFlags )
     {
         // Distributed values among individual items
-        OUString aFileFlags = pFlags->GetValue();
-        aFileFlags = aFileFlags.toAsciiUpperCase();
+        const OUString aFileFlags = pFlags->GetValue().toAsciiUpperCase();
         if ( -1 != aFileFlags.indexOf( 'B' ) )
             bPreview = true;
     }
@@ -1573,7 +1563,7 @@ void SfxObjectShell::SetWaitCursor( bool bSet ) const
 
 OUString SfxObjectShell::GetAPIName() const
 {
-    INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : OUString( 
GetMedium()->GetName() ) );
+    INetURLObject aURL( IsDocShared() ? GetSharedFileURL() : 
GetMedium()->GetName() );
     OUString aName( aURL.GetBase() );
     if( aName.isEmpty() )
         aName = aURL.GetURLNoPass();
commit af40888989dfc38b62f0ccd0161b2a28f28d6aca
Author: Matteo Casalin <matteo.casa...@yahoo.com>
Date:   Mon Apr 17 11:17:08 2017 +0200

    Avoid temporary OUStrings
    
    Change-Id: I0fb456874595814339a420b61fbf4cb957af095e

diff --git a/sfx2/source/doc/docinsert.cxx b/sfx2/source/doc/docinsert.cxx
index 29cd9ee68808..61954b8922aa 100644
--- a/sfx2/source/doc/docinsert.cxx
+++ b/sfx2/source/doc/docinsert.cxx
@@ -108,9 +108,8 @@ SfxMedium* DocumentInserter::CreateMedium(char const*const 
pFallbackHack)
     if (!m_nError && m_pItemSet && !m_pURLList.empty())
     {
         DBG_ASSERT( m_pURLList.size() == 1, "DocumentInserter::CreateMedium(): 
invalid URL list count" );
-        OUString sURL(m_pURLList[0]);
         pMedium.reset(new SfxMedium(
-                sURL, SFX_STREAM_READONLY,
+                m_pURLList[0], SFX_STREAM_READONLY,
                 SfxGetpApp()->GetFilterMatcher().GetFilter4FilterName( 
m_sFilter ), m_pItemSet ));
         pMedium->UseInteractionHandler( true );
         std::unique_ptr<SfxFilterMatcher> pMatcher;
@@ -223,8 +222,7 @@ IMPL_LINK_NOARG(DocumentInserter, DialogClosedHdl, 
sfx2::FileDialogHelper*, void
                     short nRet = aPasswordDlg->Execute();
                     if ( RET_OK == nRet )
                     {
-                        OUString aPasswd = aPasswordDlg->GetPassword();
-                        m_pItemSet->Put( SfxStringItem( SID_PASSWORD, aPasswd 
) );
+                        m_pItemSet->Put( SfxStringItem( SID_PASSWORD, 
aPasswordDlg->GetPassword() ) );
                     }
                     else
                     {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to