Kaydet (Commit) c88eae08 authored tarafından rbuj's avatar rbuj Kaydeden (comit) Noel Grandin

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/11331Reviewed-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
Tested-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
üst 3bb05281
...@@ -20,7 +20,6 @@ package com.sun.star.wiki; ...@@ -20,7 +20,6 @@ package com.sun.star.wiki;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -214,58 +213,56 @@ public class Settings ...@@ -214,58 +213,56 @@ public class Settings
{ {
try 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(); // remove stored connection information
Map<String,String> ht = m_WikiConnections.get( i ); XNameContainer xContainer = Helper.GetConfigNameContainer(m_xContext, "org.openoffice.Office.Custom.WikiExtension/RecentDocs");
XNameReplace xNewConn = UnoRuntime.queryInterface( XNameReplace.class, oNewConnection ); String[] pNames = xContainer.getElementNames();
for (String pName : pNames)
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(); )
{ {
String key = iter.next(); xContainer.removeByName(pName);
xNewDoc.replaceByName( key, ht.get( key ) );
} }
// store all Docs
xContainer2.insertByName( "d" + i, xNewDoc ); 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 ) catch ( Exception ex )
...@@ -288,16 +285,15 @@ public class Settings ...@@ -288,16 +285,15 @@ public class Settings
Object oList = xAccess.getByName( "ConnectionList" ); Object oList = xAccess.getByName( "ConnectionList" );
XNameAccess xConnectionList = UnoRuntime.queryInterface( XNameAccess.class, oList ); XNameAccess xConnectionList = UnoRuntime.queryInterface( XNameAccess.class, oList );
String [] allCons = xConnectionList.getElementNames(); String [] allCons = xConnectionList.getElementNames();
for ( int i=0; i<allCons.length; i++ ) for (String aConnection : allCons)
{ {
Map<String, String> ht = new HashMap<String, String>(); Map<String, String> ht = new HashMap<String, String>();
ht.put( "Url", allCons[i] ); ht.put("Url", aConnection);
ht.put( "Username", "" ); ht.put( "Username", "" );
ht.put( "Password", "" ); ht.put( "Password", "" );
try try
{ {
XPropertySet xProps = UnoRuntime.queryInterface( XPropertySet.class, xConnectionList.getByName( allCons[i] ) ); XPropertySet xProps = UnoRuntime.queryInterface(XPropertySet.class, xConnectionList.getByName(aConnection));
if ( xProps != null ) if ( xProps != null )
{ {
String aUsername = AnyConverter.toString( xProps.getPropertyValue( "UserName" ) ); String aUsername = AnyConverter.toString( xProps.getPropertyValue( "UserName" ) );
...@@ -309,16 +305,15 @@ public class Settings ...@@ -309,16 +305,15 @@ public class Settings
{ {
e.printStackTrace(); e.printStackTrace();
} }
addWikiCon( ht ); addWikiCon( ht );
} }
Object oDocs = xAccess.getByName( "RecentDocs" ); Object oDocs = xAccess.getByName( "RecentDocs" );
XNameAccess xRecentDocs = UnoRuntime.queryInterface( XNameAccess.class, oDocs ); XNameAccess xRecentDocs = UnoRuntime.queryInterface( XNameAccess.class, oDocs );
String [] allDocs = xRecentDocs.getElementNames(); 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 ); XNameAccess xDoc = UnoRuntime.queryInterface( XNameAccess.class, oDoc );
Map<String, Object> ht = new HashMap<String, Object>(); Map<String, Object> ht = new HashMap<String, Object>();
ht.put( "Url", xDoc.getByName( "Url" ) ); ht.put( "Url", xDoc.getByName( "Url" ) );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment