summaryrefslogtreecommitdiff
path: root/swext
diff options
context:
space:
mode:
authorrbuj <robert.buj@gmail.com>2014-09-08 02:40:54 +0200
committerNoel Grandin <noelgrandin@gmail.com>2014-09-08 03:31:32 -0500
commitc88eae0866b943e7c664819fadbf4d2c4f0c55a8 (patch)
treec6dbc94a6c84954239aa56747171946fbc6a77b6 /swext
parent3bb05281cb980c01cde07b5412c2e4c440e4ab7d (diff)
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@gmail.com> Tested-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'swext')
-rw-r--r--swext/mediawiki/src/com/sun/star/wiki/Settings.java101
1 files changed, 48 insertions, 53 deletions
diff --git a/swext/mediawiki/src/com/sun/star/wiki/Settings.java b/swext/mediawiki/src/com/sun/star/wiki/Settings.java
index 3d87446e93e5..74d60180ef28 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" ) );