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