[Libreoffice-commits] core.git: swext/mediawiki

rbuj robert.buj at gmail.com
Mon Sep 8 01:31:58 PDT 2014


 swext/mediawiki/src/com/sun/star/wiki/Settings.java |  101 +++++++++-----------
 1 file changed, 48 insertions(+), 53 deletions(-)

New commits:
commit c88eae0866b943e7c664819fadbf4d2c4f0c55a8
Author: rbuj <robert.buj at gmail.com>
Date:   Mon Sep 8 02:40:54 2014 +0200

    mediawiki: improve storeConfiguration & loadConfiguration methods
    
    * Use enhanced for-loops (storeConfiguration & loadConfiguration)
    * Use curly braces to reduce the variable scope and, to reuse variable names (storeConfiguration)
    * Avoid map.get(key) in iterations over each map's entry (storeConfiguration):
          for (Map.Entry<String, Object> entry : ht.entrySet())
    
    Change-Id: I678d5a9f205efb2c89ab868b59e1b654419381d8
    Reviewed-on: https://gerrit.libreoffice.org/11331
    Reviewed-by: Noel Grandin <noelgrandin at gmail.com>
    Tested-by: Noel Grandin <noelgrandin at gmail.com>

diff --git a/swext/mediawiki/src/com/sun/star/wiki/Settings.java b/swext/mediawiki/src/com/sun/star/wiki/Settings.java
index 3d87446..74d6018 100644
--- a/swext/mediawiki/src/com/sun/star/wiki/Settings.java
+++ b/swext/mediawiki/src/com/sun/star/wiki/Settings.java
@@ -20,7 +20,6 @@ package com.sun.star.wiki;
 
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -214,58 +213,56 @@ public class Settings
     {
         try
         {
-            // remove stored connection information
-            XNameContainer xContainer = Helper.GetConfigNameContainer( m_xContext, "org.openoffice.Office.Custom.WikiExtension/ConnectionList" );
-            String[] pNames = xContainer.getElementNames();
-            for( int i=0; i<pNames.length; i++ )
             {
-                xContainer.removeByName( pNames[i] );
+                // remove stored connection information
+                XNameContainer xContainer = Helper.GetConfigNameContainer(m_xContext, "org.openoffice.Office.Custom.WikiExtension/ConnectionList");
+                String[] pNames = xContainer.getElementNames();
+                for (String pName : pNames)
+                {
+                    xContainer.removeByName(pName);
+                }
+                // store all connections
+                XSingleServiceFactory xConnectionFactory = UnoRuntime.queryInterface(XSingleServiceFactory.class, xContainer);
+                for (Map<String, String> ht : m_WikiConnections)
+                {
+                    Object oNewConnection = xConnectionFactory.createInstance();
+                    XNameReplace xNewConn = UnoRuntime.queryInterface(XNameReplace.class, oNewConnection);
+                    if (xNewConn != null)
+                    {
+                        xNewConn.replaceByName("UserName", ht.get("Username"));
+                    }
+                    xContainer.insertByName(ht.get("Url"), xNewConn);
+                }
+                // commit changes
+                XChangesBatch xBatch = UnoRuntime.queryInterface(XChangesBatch.class, xContainer);
+                xBatch.commitChanges();
             }
 
-            // store all connections
-            XSingleServiceFactory xConnectionFactory = UnoRuntime.queryInterface( XSingleServiceFactory.class, xContainer );
-            for ( int i=0; i< m_WikiConnections.size(); i++ )
             {
-                Object oNewConnection = xConnectionFactory.createInstance();
-                Map<String,String> ht = m_WikiConnections.get( i );
-                XNameReplace xNewConn = UnoRuntime.queryInterface( XNameReplace.class, oNewConnection );
-
-                if ( xNewConn != null )
-                    xNewConn.replaceByName( "UserName", ht.get( "Username" ) );
-
-                xContainer.insertByName( ht.get( "Url" ), xNewConn );
-            }
-            // commit changes
-            XChangesBatch xBatch = UnoRuntime.queryInterface( XChangesBatch.class, xContainer );
-            xBatch.commitChanges();
-
-            // remove stored connection information
-            XNameContainer xContainer2 = Helper.GetConfigNameContainer( m_xContext, "org.openoffice.Office.Custom.WikiExtension/RecentDocs" );
-            String[] pNames2 = xContainer2.getElementNames();
-            for( int i=0; i<pNames2.length; i++ )
-            {
-                xContainer2.removeByName( pNames2[i] );
-            }
-            // store all Docs
-            XSingleServiceFactory xDocListFactory = UnoRuntime.queryInterface( XSingleServiceFactory.class, xContainer2 );
-            for ( int i=0; i< m_aWikiDocs.size(); i++ )
-            {
-                Map<String,Object> ht = m_aWikiDocs.get( i );
-
-                Object oNewDoc = xDocListFactory.createInstance();
-                XNameReplace xNewDoc = UnoRuntime.queryInterface( XNameReplace.class, oNewDoc );
-
-                for ( Iterator<String> iter = ht.keySet().iterator(); iter.hasNext(); )
+                // remove stored connection information
+                XNameContainer xContainer = Helper.GetConfigNameContainer(m_xContext, "org.openoffice.Office.Custom.WikiExtension/RecentDocs");
+                String[] pNames = xContainer.getElementNames();
+                for (String pName : pNames)
                 {
-                    String key = iter.next();
-                    xNewDoc.replaceByName( key, ht.get( key ) );
+                    xContainer.removeByName(pName);
                 }
-
-                xContainer2.insertByName( "d" + i, xNewDoc );
+                // store all Docs
+                XSingleServiceFactory xDocListFactory = UnoRuntime.queryInterface(XSingleServiceFactory.class, xContainer);
+                int i = 0;
+                for (Map<String, Object> ht : m_aWikiDocs)
+                {
+                    Object oNewDoc = xDocListFactory.createInstance();
+                    XNameReplace xNewDoc = UnoRuntime.queryInterface(XNameReplace.class, oNewDoc);
+                    for (Map.Entry<String, Object> entry : ht.entrySet())
+                    {
+                        xNewDoc.replaceByName(entry.getKey(), entry.getValue());
+                    }
+                    xContainer.insertByName("d" + i++, xNewDoc);
+                }
+                // commit changes
+                XChangesBatch xBatch = UnoRuntime.queryInterface(XChangesBatch.class, xContainer);
+                xBatch.commitChanges();
             }
-            // commit changes
-            XChangesBatch xBatch2 = UnoRuntime.queryInterface( XChangesBatch.class, xContainer2 );
-            xBatch2.commitChanges();
 
         }
         catch ( Exception ex )
@@ -288,16 +285,15 @@ public class Settings
                 Object oList = xAccess.getByName( "ConnectionList" );
                 XNameAccess xConnectionList = UnoRuntime.queryInterface( XNameAccess.class, oList );
                 String [] allCons = xConnectionList.getElementNames();
-                for ( int i=0; i<allCons.length; i++ )
+                for (String aConnection : allCons)
                 {
                     Map<String, String> ht = new HashMap<String, String>();
-                    ht.put( "Url", allCons[i] );
+                    ht.put("Url", aConnection);
                     ht.put( "Username", "" );
                     ht.put( "Password", "" );
-
                     try
                     {
-                        XPropertySet xProps = UnoRuntime.queryInterface( XPropertySet.class, xConnectionList.getByName( allCons[i] ) );
+                        XPropertySet xProps = UnoRuntime.queryInterface(XPropertySet.class, xConnectionList.getByName(aConnection));
                         if ( xProps != null )
                         {
                             String aUsername = AnyConverter.toString( xProps.getPropertyValue( "UserName" ) );
@@ -309,16 +305,15 @@ public class Settings
                     {
                         e.printStackTrace();
                     }
-
                     addWikiCon( ht );
                 }
 
                 Object oDocs = xAccess.getByName( "RecentDocs" );
                 XNameAccess xRecentDocs = UnoRuntime.queryInterface( XNameAccess.class, oDocs );
                 String [] allDocs = xRecentDocs.getElementNames();
-                for ( int i=0; i<allDocs.length; i++ )
+                for (String aDocument : allDocs)
                 {
-                    Object oDoc = xRecentDocs.getByName( allDocs[i] );
+                    Object oDoc = xRecentDocs.getByName(aDocument);
                     XNameAccess xDoc = UnoRuntime.queryInterface( XNameAccess.class, oDoc );
                     Map<String, Object> ht = new HashMap<String, Object>();
                     ht.put( "Url", xDoc.getByName( "Url" ) );


More information about the Libreoffice-commits mailing list