This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 24 - Pages: 2 [ Previous | 1 2 ] - Last Post: 10 Nov 22, 21:58 Last Post By: AndreWolff
AndreWolff

Posts: 1,116
Registered: 14-Dec-2007
Re: BeanShell to Groovy tutorial?
Posted: 3 Nov 22, 10:01   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
Arrays are differently in Groovy:

BeanShell:
String[] dtChoices = {"2.0", "1.75","1.5", "1.25", "1.0", "0.75", "0.5"};

Groovy:
dtChoices = ["2.0", "1.75","1.5", "1.25", "1.0", "0.75", "0.5"] as String[]
AndreWolff

Posts: 1,116
Registered: 14-Dec-2007
Re: BeanShell to Groovy tutorial?
Posted: 3 Nov 22, 10:27   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
It's not always a number. There may be "b" and "rc" characters there and doing a substring on internalVersion is ugly as it assumes two characters before a dot.
OK, I use now your proposal.

But I have another problem, with code you proposed I think:

I have in index.htt at line number 359 this code:
<ja:if test="<%= jAlbumVersion > 23 %>">
<%
usingFallback()  {
  import net.jalbum.*;
  ImageRenderer renderer = currentObject.getRenderer();
  if (ImageRenderer.getTypical(renderer.getCloseupRenditions()).getFormat() == OutputFormat.WEBP) {
    return false;
  }
  for (Rendition r :  renderer.getCloseupRenditions()) {
    if (r.getFormat() == OutputFormat.WEBP) {
      return true;
    }
  }
  return false;
}
 useFallback = usingFallback() ; %>
</ja:if>
In Groovy I get this:
Making "FB_JustifiedGallery_Simple_groovy" (Changes)
se.datadosen.util.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script715.groovy: 3: Unexpected input: 'usingFallback()  {\r\n  import' in index.htt at line number 359 at column number 3
	at se.datadosen.util.ScriptException.of(ScriptException.java:59)
	at se.datadosen.jalbum.ast.ScriptletNode.doEval(ScriptletNode.java:99

How should I solve this?

Edit:

I moved
import net.jalbum.*;
to init.Groovy, but then I get this error:
 se.datadosen.util.ScriptException: groovy.lang.MissingMethodException: No signature of method: net.jalbum.script.GroovierScriptEngine.usingFallback() is applicable for argument types: (Script1009$_run_closure1) values: [Script1009$_run_closure1@767eb245] in index.htt at line number 359
	at se.datadosen.util.ScriptException.of(ScriptException.java:59)


Edited by: AndreWolff on 3 Nov 2022, 10:53

This is the solution:
<ja:if test="<%= jAlbumVersion > 23 %>">
<%
private usingFallback()  {


Edited by: AndreWolff on 3 Nov 2022, 11:14
davidekholm

Posts: 3,998
Registered: 18-Oct-2002
Re: BeanShell to Groovy tutorial?
Posted: 3 Nov 22, 12:30   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
André, a method declaration need a return value or the keyword "def". In your case, write boolean usingFallback ...
AndreWolff

Posts: 1,116
Registered: 14-Dec-2007
Re: BeanShell to Groovy tutorial?
Posted: 3 Nov 22, 13:16   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Well both private and boolean are accepted in Groovy.
AndreWolff

Posts: 1,116
Registered: 14-Dec-2007
Re: BeanShell to Groovy tutorial?
Posted: 8 Nov 22, 11:09   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
BeanShell:
Integer.toString(w)

Groovy:
w.toString();
AndreWolff

Posts: 1,116
Registered: 14-Dec-2007
Re: BeanShell to Groovy tutorial?
Posted: 10 Nov 22, 18:44   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
BeanShell:
String newString = originalString.substring(0, index + 1) 
                           + stringToBeInserted 
                           + originalString.substring(index + 1); 

Groovy:
String newString = originalString.substring(0, index + 1)  + stringToBeInserted   + originalString.substring(index + 1); 
davidekholm

Posts: 3,998
Registered: 18-Oct-2002
Re: BeanShell to Groovy tutorial?
Posted: 10 Nov 22, 21:47   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
How are those examples different apart from line breaks?
AndreWolff

Posts: 1,116
Registered: 14-Dec-2007
Re: BeanShell to Groovy tutorial?
Posted: 10 Nov 22, 21:51   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
How are those examples different apart from line breaks?
No, if you Google this problem, you will see dat a + sign in front of a string on a new line is not accepted in Groovy, the + sign is only accepted after a string.
davidekholm

Posts: 3,998
Registered: 18-Oct-2002
Re: BeanShell to Groovy tutorial?
Posted: 10 Nov 22, 21:53   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
AndreWolff wrote:
davidekholm wrote:
How are those examples different apart from line breaks?
No, if you Google this problem, you will see dat a + sign in front of a string on a new line is not accepted in Groovy, the + sign is only accepted after a string.

Or rather that there has to be an expression on the same line before the + operator. Good to know!
AndreWolff

Posts: 1,116
Registered: 14-Dec-2007
Re: BeanShell to Groovy tutorial?
Posted: 10 Nov 22, 21:58   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
This is also accepted:
 String newString = originalString.substring(0, index + 1)  +
                            stringToBeInserted  +
                            originalString.substring(index + 1); 
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums