* properly deal with space sequences by default

This commit is contained in:
Reinhard Pointner 2014-06-28 06:07:45 +00:00
parent 1a4c3691b2
commit 07568068c5
2 changed files with 38 additions and 42 deletions

View File

@ -1,6 +1,5 @@
package net.filebot.format;
import static net.filebot.similarity.Normalization.*;
import static net.filebot.util.ExceptionUtilities.*;
import static net.filebot.util.FileUtilities.*;
import groovy.lang.GroovyClassLoader;
@ -24,6 +23,8 @@ import javax.script.ScriptEngine;
import javax.script.ScriptException;
import javax.script.SimpleScriptContext;
import net.filebot.similarity.Normalization;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.control.MultipleCompilationErrorsException;
import org.codehaus.groovy.control.customizers.ImportCustomizer;
@ -163,10 +164,10 @@ public class ExpressionFormat extends Format {
@Override
public StringBuffer format(Object object, StringBuffer sb, FieldPosition pos) {
return format(getBindings(object), sb);
return sb.append(format(getBindings(object)));
}
public StringBuffer format(Bindings bindings, StringBuffer sb) {
public String format(Bindings bindings) {
// use privileged bindings so we are not restricted by the script sandbox
Bindings priviledgedBindings = PrivilegedInvocation.newProxy(Bindings.class, bindings, AccessController.getContext());
@ -177,11 +178,11 @@ public class ExpressionFormat extends Format {
// reset exception state
lastException = null;
StringBuilder sb = new StringBuilder();
for (Object snipped : compilation) {
if (snipped instanceof CompiledScript) {
try {
Object value = normalizeExpressionValue(((CompiledScript) snipped).eval(context));
if (value != null) {
sb.append(value);
}
@ -193,13 +194,13 @@ public class ExpressionFormat extends Format {
}
}
return sb;
return Normalization.replaceSpace(sb.toString(), " ").trim();
}
protected Object normalizeBindingValue(Object value) {
// if the binding value is a String, remove illegal characters
if (value instanceof CharSequence) {
return replaceSpace(replacePathSeparators((CharSequence) value), " ").trim();
return replacePathSeparators((CharSequence) value, " ").trim();
}
// if the binding value is an Object, just leave it

View File

@ -1,7 +1,5 @@
package net.filebot.ui.list;
import static java.awt.Font.*;
import static java.lang.Math.*;
import static net.filebot.ui.NotificationLogging.*;
@ -30,7 +28,6 @@ import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.SpinnerNumberModel;
import net.miginfocom.swing.MigLayout;
import net.filebot.format.ExpressionFormat;
import net.filebot.similarity.SeriesNameMatcher;
import net.filebot.ui.FileBotList;
@ -39,7 +36,7 @@ import net.filebot.ui.transfer.LoadAction;
import net.filebot.ui.transfer.SaveAction;
import net.filebot.util.ExceptionUtilities;
import net.filebot.util.ui.TunedUtilities;
import net.miginfocom.swing.MigLayout;
public class ListPanel extends JComponent {
@ -49,7 +46,6 @@ public class ListPanel extends JComponent {
private SpinnerNumberModel fromSpinnerModel = new SpinnerNumberModel(1, 0, Integer.MAX_VALUE, 1);
private SpinnerNumberModel toSpinnerModel = new SpinnerNumberModel(20, 0, Integer.MAX_VALUE, 1);
public ListPanel() {
list.setTitle("Title");
@ -88,7 +84,6 @@ public class ListPanel extends JComponent {
TunedUtilities.installAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), createAction);
}
private AbstractAction createAction = new AbstractAction("Create") {
@Override
@ -124,7 +119,7 @@ public class ListPanel extends JComponent {
bindings.put("from", from);
bindings.put("to", to);
names.add(format.format(bindings, new StringBuffer()).toString());
names.add(format.format(bindings));
}
if (signum(to - from) < 0) {