This question is answered.


Permlink Replies: 16 - Pages: 2 [ 1 2 | Next ] - Last Post: 29-Nov-2017 15:19 Last Post By: AndreWolff Threads: [ Previous | Next ]
AndreWolff

Posts: 2,551
Registered: 14-Dec-2007
Add a function to suppress the generation of a theme image in index.htt
Posted: 27-Nov-2017 10:22
 
  Click to reply to this thread Reply
If you call now setThemeImageProcessor in init.bsh the theme image is always generated, unless of course the theme image has been removed for the current directory.

Calling setThemeImageProcessor in index.htt is not working, because in that case the variables themePath, themeWidth and themeHeight do not get a value.

However if jAlbum offers a function or variable to suppress the generation of the theme image, which can be called in index.htt, you get the possibilities I was looking for like:
  • Generate a them image only for level 0 folders
  • Generate a them image only for folders with level >0
  • Generate a them image only if a folder contains no images
etc.

This should not be too difficult if jAlbum generates the theme images after the execution of the index.htt code, so just before postdir.bsh is called.

Such a function offers an extra possibility: if the suppress function is called jAlbum could investigate whether before a theme image was generated and delete that image in that case, so the potential orphan problem is solved.
davidekholm

Posts: 21,848
Registered: 18-Oct-2002
Re: Add a function to suppress the generation of a theme image in index.htt
Posted: 27-Nov-2017 10:51   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
Suppressing theme images by skin control on a per-folder basis should be easy, just subclass ThemeImageProcessor and add a boolean setter method that you then call from index.htt for instance. Let the boolean flag control whether to generate theme images or not by checking it in the overridden processThemeImage method.

Here's a sample code:
    class MyThemeImageProcessor extends ThemeImageProcessor {
 
        private boolean active = true;
 
        public boolean isActive() {
            return active;
        }
 
        public void setActive(boolean active) {
            this.active = active;
        }
 
        public void processThemeImage(AlbumObject folder, File outputDir) throws IOException {
            if (active) {
                super.processThemeImage(folder, outputDir);
            }
        }
    }
Now you can get the theme image processor in index.htt and call setActive(false); vs setActive(true) on it to control theme image generation on a per-folder basis.
AndreWolff

Posts: 2,551
Registered: 14-Dec-2007
Re: Add a function to suppress the generation of a theme image in index.htt
Posted: 27-Nov-2017 15:01   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Well David, you know I am no JAVA programmer, so it does not work for me with in index.htt statement

setActive(false);

I get an error:
Command not found: setActive( boolean ) : at Line: 49

And if I use

MyThemeImageProcessor.setActive(false);

I get error:

Cannot reach instance method: setActive( boolean ) from static context: MyThemeImageProcessor : at Line: 49
davidekholm

Posts: 21,848
Registered: 18-Oct-2002
Re: Add a function to suppress the generation of a theme image in index.htt
Posted: 27-Nov-2017 15:11   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
It's engine.getThemeImageProcessor().setActive(false);

If it's compiled code and not BeanShell, then you need to cast the return value to MyThemeImageProcessor, like this:

((MyThemeImageProcessor)engine.getThemeImageProcessor()).setActive(false);

Enjoy!
AndreWolff

Posts: 2,551
Registered: 14-Dec-2007
Re: Add a function to suppress the generation of a theme image in index.htt
Posted: 27-Nov-2017 15:34   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
It's engine.getThemeImageProcessor().setActive(false);
That gives the next error:
Target exception: java.lang.NullPointerException: Attempt to invoke method setActive on null value in index.htt at line number 49!
davidekholm

Posts: 21,848
Registered: 18-Oct-2002
Re: Add a function to suppress the generation of a theme image in index.htt
Posted: 27-Nov-2017 16:01   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
AndreWolff wrote:
davidekholm wrote:
It's engine.getThemeImageProcessor().setActive(false);
That gives the next error:
Target exception: java.lang.NullPointerException: Attempt to invoke method setActive on null value in index.htt at line number 49!

That should only happen if you've forgot to install the theme image processor in init.
AndreWolff

Posts: 2,551
Registered: 14-Dec-2007
Re: Add a function to suppress the generation of a theme image in index.htt
Posted: 27-Nov-2017 16:46   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
That should only happen if you've forgot to install the theme image processor in init.
Originally I replaced engine.setThemeImageProcessor in init.bsh by your code
But I think you meant ‘insert before’ so I have now in init.bsh:
// Start extra code for function setActive, see http://jalbum.net/forum/message.jspa?messageID=322551#322551
    class MyThemeImageProcessor extends ThemeImageProcessor {
 
        private boolean active = true;
 
        public boolean isActive() {
            return active;
        }
 
        public void setActive(boolean active) {
            this.active = active;
        }
 
        public void processThemeImage(AlbumObject folder, File outputDir) throws IOException {
            if (active) {
                super.processThemeImage(folder, outputDir);
            }
        }
    }
// End setActive code
      engine.setThemeImageProcessor(new ThemeImageProcessor());
and in index.htt:
engine.getThemeImageProcessor().setActive(false);
but now I get error:

Error in method invocation: Method setActive( boolean ) not found in class'se.datadosen.jalbum.ThemeImageProcessor' : at Line: 49
davidekholm

Posts: 21,848
Registered: 18-Oct-2002
Re: Add a function to suppress the generation of a theme image in index.htt
Posted: 27-Nov-2017 16:57   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
Add a "public" to class MyThemeImageProcessor and use the alternative syntax I showed:
((MyThemeImageProcessor)engine.getThemeImageProcessor()).setActive(false);
AndreWolff

Posts: 2,551
Registered: 14-Dec-2007
Re: Add a function to suppress the generation of a theme image in index.htt
Posted: 27-Nov-2017 17:06   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
Add a "public" to class MyThemeImageProcessor and use the alternative syntax I showed:
((MyThemeImageProcessor)engine.getThemeImageProcessor()).setActive(false);
This gives error:
se.datadosen.util.ScriptException: bsh.TargetError: Sourced file: inline evaluation of: ``     //  Index page file index.htt    //  "Slide Show 4" Derived from Slide Show . . . '' : at Line: 49 : in file: inline evaluation of: ``     //  Index page file index.htt    //  "Slide Show 4" Derived from Slide Show . . . '' : ( MyThemeImageProcessor ) engine .getThemeImageProcessor ( ) 
 
Target exception: java.lang.ClassCastException: Cannot cast se.datadosen.jalbum.ThemeImageProcessor to MyThemeImageProcessor
 in index.htt at line number 49
	at se.datadosen.jalbum.TemplateParser.eval(TemplateParser.java:889)
	at se.datadosen.jalbum.TemplateParser.handleScriptlet(TemplateParser.java:811)
	at se.datadosen.jalbum.TemplateParser.parseElements(TemplateParser.java:217)
	at se.datadosen.jalbum.TemplateParser.parseElements(TemplateParser.java:178)
	at se.datadosen.jalbum.TemplateParser.parseElements(TemplateParser.java:132)
	at se.datadosen.jalbum.TemplateParser.parseElements(TemplateParser.java:147)
	at se.datadosen.jalbum.AlbumBean.makeIndexPages(AlbumBean.java:3157)
	at se.datadosen.jalbum.AlbumBean.makeAlbumForFolder(AlbumBean.java:1422)
	at se.datadosen.jalbum.AlbumBean.makeAlbum(AlbumBean.java:2710)
	at se.datadosen.jalbum.AlbumBean.smartMakeAlbum(AlbumBean.java:2636)
	at se.datadosen.jalbum.JAlbumFrame$5.run(JAlbumFrame.java:1050)
Caused by: java.lang.ClassCastException: Cannot cast se.datadosen.jalbum.ThemeImageProcessor to MyThemeImageProcessor
davidekholm

Posts: 21,848
Registered: 18-Oct-2002
Re: Add a function to suppress the generation of a theme image in index.htt
Posted: 27-Nov-2017 18:58   in response to: AndreWolff in response to: AndreWolff
Correct
  Click to reply to this thread Reply
Ah, your code in init is wrong. You wrote
  engine.setThemeImageProcessor(new ThemeImageProcessor());
. It should naturally be
  engine.setThemeImageProcessor(new MyThemeImageProcessor());
AndreWolff

Posts: 2,551
Registered: 14-Dec-2007
Re: Add a function to suppress the generation of a theme image in index.htt
Posted: 27-Nov-2017 22:33   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Well David, it was a long way, but it works now!
Thanks for your help!

But I still recommend that you add this function setActive to the core code and implement the extra possibility: if setActive(false) is called jAlbum should investigate whether before a theme image was generated and delete that image in that case, so the potential orphan problem is also solved.
To give no problems with existing implementations, you should set default setActive(true), so that you only have to call setActive(false) to suppress the generation.

If you don’t add it to the core, I think you should extend the theme image developers documentation with the code you supplied here.
davidekholm

Posts: 21,848
Registered: 18-Oct-2002
Re: Add a function to suppress the generation of a theme image in index.htt
Posted: 28-Nov-2017 10:29   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
"anything" can be added, that's the beauty of code. Let's try to gather data on what kind of flexibility is requested by skin developers and then carefully improve the functionality of this class.
AndreWolff

Posts: 2,551
Registered: 14-Dec-2007
Re: Add a function to suppress the generation of a theme image in index.htt
Posted: 28-Nov-2017 11:04   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
Let's try to gather data on what kind of flexibility is requested by skin developers and then carefully improve the functionality of this class.
Yes, but if you wait too long, it is too late because all implementations are finished with local inventions!

Sometimes you have to take the lead!

And how are you going to solve the theme image orphan problem?
davidekholm

Posts: 21,848
Registered: 18-Oct-2002
Re: Add a function to suppress the generation of a theme image in index.htt
Posted: 28-Nov-2017 12:50   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
AndreWolff wrote:
davidekholm wrote:
Let's try to gather data on what kind of flexibility is requested by skin developers and then carefully improve the functionality of this class.
Yes, but if you wait too long, it is too late because all implementations are finished with local inventions!

Sometimes you have to take the lead!

And how are you going to solve the theme image orphan problem?


First I don't consider it a big problem, but if we need clever and safe cleanup routine of orphan theme images, then we can identify them by their embedded xmp metadata.
AndreWolff

Posts: 2,551
Registered: 14-Dec-2007
Re: Add a function to suppress the generation of a theme image in index.htt
Posted: 29-Nov-2017 10:39   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
AndreWolff wrote:
If you don’t add it to the core, I think you should extend the theme image developers documentation with the code you supplied here.
Or RobM could add it to his Skin coding examples thread.

Enclosed is the Minimal test skin with Theme image I used to test this. This version has the following features:

  • Theme image Width and Height can be defined in number fields; if you leave a field empty the corresponding image bound is used
  • Two extra check-marks: ‘Theme image in top album’ and ‘Use Theme image in folder albums’ to test setActive.
  • a check-mark to Use the theme image as background image or as a responsive image.

I tried to delete the theme image in PostDir.bsh if it is not used with this code:
if (deleteThemeImage) (
	File x = new File(outputDirectory + "/folderimage.jpg");
	try {
		x.delete();
	}
}
But there I get an error message:

se.datadosen.util.ScriptException: bsh.ParseException: Parse error at line 19, column 14. Encountered: x in postdir.bsh at line number 19

If somebody can tell me why this does not work I could add this too to the jaskin file.

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