Kaydet (Commit) e41cc689 authored tarafından rbuj's avatar rbuj Kaydeden (comit) David Tardon

scripting: Enhanced For-Loops

Change-Id: Ib5e59a8c153e7d788c14153fa3b94c8b2d0a068c
Reviewed-on: https://gerrit.libreoffice.org/11292Reviewed-by: 's avatarDavid Tardon <dtardon@redhat.com>
Tested-by: 's avatarDavid Tardon <dtardon@redhat.com>
üst fd336cf9
......@@ -118,9 +118,8 @@ public class ParcelBrowseNode extends PropertySet
String[] names = parcel.getElementNames();
browsenodes = new ArrayList<XBrowseNode>( names.length );
for ( int index = 0; index < names.length; index++ )
{
browsenodes.add( new ScriptBrowseNode( provider, parcel, names[ index ] ));
for (String name : names) {
browsenodes.add(new ScriptBrowseNode(provider, parcel, name));
}
}
else
......
......@@ -99,25 +99,20 @@ public class ProviderBrowseNode extends PropertySet
LogUtils.DEBUG("** ProviderBrowseNode.getChildNodes(), container is " + container );
String[] parcels = container.getElementNames();
browsenodes = new ArrayList<XBrowseNode>( parcels.length );
for ( int index = 0; index < parcels.length; index++ )
{
try
{
XBrowseNode node = new ParcelBrowseNode( provider, container, parcels[ index ] );
for (String parcel : parcels) {
try {
XBrowseNode node = new ParcelBrowseNode(provider, container, parcel);
browsenodes.add( node );
}
catch ( Exception e )
{
LogUtils.DEBUG("*** Failed to create parcel node for " + parcels[ index ] );
} catch (Exception e) {
LogUtils.DEBUG("*** Failed to create parcel node for " + parcel);
LogUtils.DEBUG( e.toString() );
}
}
ParcelContainer[] packageContainers = container.getChildContainers();
LogUtils.DEBUG("**** For container named " + container.getName() + " with root path " + container.getParcelContainerDir() + " has " + packageContainers.length + " child containers " );
for ( int i = 0; i < packageContainers.length; i++ )
{
XBrowseNode node = new PkgProviderBrowseNode( provider, packageContainers[ i ], m_xCtx );
for (ParcelContainer packageContainer : packageContainers) {
XBrowseNode node = new PkgProviderBrowseNode(provider, packageContainer, m_xCtx);
browsenodes.add( node );
}
}
......
......@@ -62,7 +62,7 @@ public class Parcel implements XNameContainer
public java.lang.Object getByName( String aName ) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException
{
LogUtils.DEBUG("** Parcel.getByName for " + aName );
ScriptEntry script = null;
ScriptEntry thescript = null;
try
{
if ( m_descriptor != null && hasElements() )
......@@ -70,11 +70,9 @@ public class Parcel implements XNameContainer
ScriptEntry[] scripts = m_descriptor.getScriptEntries();
if ( scripts.length != 0 )
{
for ( int index = 0; index < scripts.length; index++ )
{
if ( scripts[ index ].getLanguageName().equals( aName ) )
{
script = scripts[ index ];
for (ScriptEntry script : scripts) {
if (script.getLanguageName().equals(aName)) {
thescript = script;
break;
}
}
......@@ -86,12 +84,12 @@ public class Parcel implements XNameContainer
{
throw new com.sun.star.lang.WrappedTargetException( e.toString() );
}
if ( script == null )
if ( thescript == null )
{
LogUtils.DEBUG("No script for " + aName );
throw new com.sun.star.container.NoSuchElementException("No script named " + aName );
}
ScriptMetaData data = new ScriptMetaData( this, script, null );
ScriptMetaData data = new ScriptMetaData( this, thescript, null );
LogUtils.DEBUG("returning date for " + aName );
return data;
......
......@@ -121,17 +121,13 @@ public class ParcelContainer implements XNameAccess
* @return child <tt>ParcelContainer</tt> or {@code null} if none
* found.
*/
public ParcelContainer getChildContainer( String key )
public ParcelContainer getChildContainer(String key)
{
ParcelContainer result = null;
Iterator<ParcelContainer> iter = childContainers.iterator();
while ( iter.hasNext() )
for (ParcelContainer c : childContainers)
{
ParcelContainer c = iter.next();
String location = ScriptMetaData.getLocationPlaceHolder(
c.containerUrl, c.getName());
if ( key.equals( location ) )
{
result = c;
......@@ -151,14 +147,11 @@ public class ParcelContainer implements XNameAccess
* @return child <tt>ParcelContainer</tt> or {@code null} if none
* found.
*/
public ParcelContainer getChildContainerForURL( String containerUrl )
{
ParcelContainer result = null;
Iterator<ParcelContainer> iter = childContainers.iterator();
while ( iter.hasNext() )
for (ParcelContainer c : childContainers)
{
ParcelContainer c = iter.next();
if ( containerUrl.equals( c.containerUrl ) )
{
result = c;
......@@ -294,6 +287,7 @@ public class ParcelContainer implements XNameAccess
}
return containerUrl;
}
public Object getByName( String aName ) throws com.sun.star.container.NoSuchElementException, WrappedTargetException
{
Parcel parcel = null;
......@@ -301,11 +295,8 @@ public class ParcelContainer implements XNameAccess
{
if ( hasElements() )
{
Iterator<Parcel> iter = parcels.iterator();
while ( iter.hasNext() )
for (Parcel parcelToCheck : parcels)
{
Parcel parcelToCheck = iter.next();
if ( parcelToCheck.getName().equals( aName ) )
{
parcel = parcelToCheck;
......@@ -324,6 +315,7 @@ public class ParcelContainer implements XNameAccess
}
return parcel;
}
public String[] getElementNames()
{
if ( hasElements() )
......@@ -375,18 +367,18 @@ public class ParcelContainer implements XNameAccess
LogUtils.DEBUG( getParcelContainerDir() + " is a folder " );
String[] children = m_xSFA.getFolderContents( getParcelContainerDir(), true );
parcels = new ArrayList<Parcel>(children.length);
for ( int i = 0; i < children.length; i++)
for (String child : children)
{
LogUtils.DEBUG("Processing " + children[ i ] );
LogUtils.DEBUG("Processing " + child);
try
{
loadParcel( children[ i ] );
loadParcel(child);
}
catch (java.lang.Exception e)
{
// print an error message and move on to
// the next parcel
LogUtils.DEBUG("ParcelContainer.loadParcels caught " + e.getClass().getName() + " exception loading parcel " + children[i] + ": " + e.getMessage() );
LogUtils.DEBUG("ParcelContainer.loadParcels caught " + e.getClass().getName() + " exception loading parcel " + child + ": " + e.getMessage());
}
}
}
......
......@@ -221,8 +221,9 @@ public class ParcelDescriptor {
public void setScriptEntries(ScriptEntry[] scripts) {
clearEntries();
for (int i = 0; i < scripts.length; i++)
addScriptEntry(scripts[i]);
for (ScriptEntry script : scripts) {
addScriptEntry(script);
}
}
public void setScriptEntries(Iterator<ScriptEntry> scripts) {
......
......@@ -140,24 +140,17 @@ public class UnoPkgContainer extends ParcelContainer
if ( db != null )
{
String[] packages = db.getDeployedPackages( language );
for ( int i=0; i<packages.length;i++)
{
try
{
processUnoPackage( packages[i], language );
}
catch ( com.sun.star.lang.IllegalArgumentException ila)
{
LogUtils.DEBUG("Failed to process " + packages[i] + " for " + language);
for (String thepackage : packages) {
try {
processUnoPackage(thepackage, language);
} catch (com.sun.star.lang.IllegalArgumentException ila) {
LogUtils.DEBUG("Failed to process " + thepackage + " for " + language);
LogUtils.DEBUG(" Reason: " + ila );
}
catch( Exception e )
{
} catch (Exception e) {
// TODO proper exception or do we wish
// to ignore errors here
LogUtils.DEBUG("Something very wrong!!!!!");
LogUtils.DEBUG("Failed to process " + packages[i] + " for " + language);
LogUtils.DEBUG("Failed to process " + thepackage + " for " + language);
LogUtils.DEBUG(" Reason: " + e );
}
}
......
......@@ -282,12 +282,11 @@ public class ScriptEditorForBeanShell
JPanel p = new JPanel();
p.setLayout(new FlowLayout());
for (int i = 0; i < labels.length; i++) {
JButton b = new JButton(labels[i]);
for (String label : labels) {
JButton b = new JButton(label);
b.addActionListener(this);
p.add(b);
if (labels[i].equals("Save") && filename == null) {
if (label.equals("Save") && filename == null) {
b.setEnabled(false);
}
}
......
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