From 911cc24ba58fac2dd389ed481c5d59abd8af6cf1 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Thu, 4 Feb 2010 16:22:45 +0000 Subject: [PATCH] * better logic for path-separator clean-up for expression bindings * new ant-task to automatically deploy fatjat/webstart-jars --- build.xml | 31 ++++++++++++++++++- .../filebot/format/EpisodeBindingBean.java | 7 ++--- .../rename/EpisodeExpressionFormatter.java | 27 +++++++++++++++- 3 files changed, 58 insertions(+), 7 deletions(-) diff --git a/build.xml b/build.xml index 64e14ff4..d9869f70 100644 --- a/build.xml +++ b/build.xml @@ -2,7 +2,7 @@ - + @@ -248,5 +248,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/source/net/sourceforge/filebot/format/EpisodeBindingBean.java b/source/net/sourceforge/filebot/format/EpisodeBindingBean.java index 4efaa7f8..9d521d03 100644 --- a/source/net/sourceforge/filebot/format/EpisodeBindingBean.java +++ b/source/net/sourceforge/filebot/format/EpisodeBindingBean.java @@ -5,7 +5,6 @@ package net.sourceforge.filebot.format; import static net.sourceforge.filebot.MediaTypes.*; import static net.sourceforge.filebot.format.Define.*; import static net.sourceforge.filebot.hash.VerificationUtilities.*; -import static net.sourceforge.tuned.FileUtilities.*; import java.io.File; import java.io.FileInputStream; @@ -48,8 +47,7 @@ public class EpisodeBindingBean { @Define("n") public String getSeriesName() { - // clean up series name just in case there are any path separators like / or \ - return removePathSeparators(episode.getSeriesName()); + return episode.getSeriesName(); } @@ -67,8 +65,7 @@ public class EpisodeBindingBean { @Define("t") public String getTitle() { - // clean up episode title just in case there are any path separators like / or \ - return removePathSeparators(episode.getTitle()); + return episode.getTitle(); } diff --git a/source/net/sourceforge/filebot/ui/panel/rename/EpisodeExpressionFormatter.java b/source/net/sourceforge/filebot/ui/panel/rename/EpisodeExpressionFormatter.java index 989a1235..91e8c808 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/EpisodeExpressionFormatter.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/EpisodeExpressionFormatter.java @@ -2,11 +2,15 @@ package net.sourceforge.filebot.ui.panel.rename; +import static net.sourceforge.tuned.FileUtilities.*; + import java.io.File; +import javax.script.Bindings; import javax.script.ScriptException; import net.sourceforge.filebot.format.EpisodeBindingBean; +import net.sourceforge.filebot.format.ExpressionBindings; import net.sourceforge.filebot.format.ExpressionFormat; import net.sourceforge.filebot.similarity.Match; import net.sourceforge.filebot.web.Episode; @@ -48,9 +52,30 @@ class EpisodeExpressionFormatter implements MatchFormatter { // lazy initialize script engine if (format == null) { - format = new ExpressionFormat(expression); + format = new ExpressionFormat(expression) { + + @Override + public Bindings getBindings(Object value) { + return new ExpressionBindings(value) { + + @Override + public Object get(Object key) { + Object value = super.get(key); + + // if the binding value is a String, remove illegal characters + if (value instanceof CharSequence) { + return removePathSeparators(value.toString()).trim(); + } + + // if the binding value is an Object, just leave it + return value; + } + }; + } + }; } + // evaluate the expression using the given bindings String result = format.format(new EpisodeBindingBean(episode, mediaFile)).trim(); // if result is empty, check for script exceptions