diff --git a/.classpath b/.classpath
index 25e83a6..e9b747e 100644
--- a/.classpath
+++ b/.classpath
@@ -18,7 +18,6 @@
-
diff --git a/lib/README b/lib/README
index 8d7a83c..ec52b26 100644
--- a/lib/README
+++ b/lib/README
@@ -1,7 +1,6 @@
This project is using the following libraries:
# Main requirements:
-devinsy-utils GNU LGPL useful tools (StringList…)
commons-lang3 Apache 2
# Unit testing requirements:
diff --git a/lib/devinsy-utils-0.8.0-sources.zip b/lib/devinsy-utils-0.8.0-sources.zip
deleted file mode 100644
index 5ccaa1c..0000000
Binary files a/lib/devinsy-utils-0.8.0-sources.zip and /dev/null differ
diff --git a/lib/devinsy-utils-0.8.0.jar b/lib/devinsy-utils-0.8.0.jar
deleted file mode 100644
index 10fc71b..0000000
Binary files a/lib/devinsy-utils-0.8.0.jar and /dev/null differ
diff --git a/src/fr/devinsy/xidyn/presenters/PresenterFactory.java b/src/fr/devinsy/xidyn/presenters/PresenterFactory.java
index d213120..eba4050 100644
--- a/src/fr/devinsy/xidyn/presenters/PresenterFactory.java
+++ b/src/fr/devinsy/xidyn/presenters/PresenterFactory.java
@@ -27,7 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
-import fr.devinsy.util.FileTools;
+import fr.devinsy.xidyn.utils.XidynUtils;
import fr.devinsy.xidyn.utils.cache.Cache;
/**
@@ -35,8 +35,6 @@ import fr.devinsy.xidyn.utils.cache.Cache;
*/
public class PresenterFactory
{
- private static Logger logger = LoggerFactory.getLogger(PresenterFactory.class);
-
/**
* http://thecodersbreakfast.net/index.php?post/2008/02/25/26-de-la-bonne-
* implementation-du-singleton-en-java
@@ -46,6 +44,8 @@ public class PresenterFactory
private final static PresenterFactory INSTANCE = new PresenterFactory();
}
+ private static Logger logger = LoggerFactory.getLogger(PresenterFactory.class);
+
private Cache cache;
/**
@@ -110,7 +110,7 @@ public class PresenterFactory
}
else
{
- String localizedSource = FileTools.addBeforeExtension(source.toString(), "-" + locale.getLanguage());
+ String localizedSource = XidynUtils.insertBeforeExtension(source.toString(), "-" + locale.getLanguage());
result = this.cache.get(localizedSource);
@@ -200,7 +200,7 @@ public class PresenterFactory
}
else
{
- File localizedSource = new File(FileTools.addBeforeExtension(source.getAbsolutePath(), "-" + locale.getLanguage()));
+ File localizedSource = new File(XidynUtils.insertBeforeExtension(source.getAbsolutePath(), "-" + locale.getLanguage()));
result = this.cache.get(localizedSource);
@@ -271,7 +271,7 @@ public class PresenterFactory
{
URL localizedSource;
- localizedSource = new URL(FileTools.addBeforeExtension(source.getPath(), "-" + locale.getLanguage()));
+ localizedSource = new URL(XidynUtils.insertBeforeExtension(source.getPath(), "-" + locale.getLanguage()));
result = this.cache.get(localizedSource);
@@ -383,7 +383,7 @@ public class PresenterFactory
}
else
{
- String localizedSource = FileTools.addBeforeExtension(source.toString(), "-" + locale.getLanguage());
+ String localizedSource = XidynUtils.insertBeforeExtension(source.toString(), "-" + locale.getLanguage());
result = create(localizedSource);
@@ -468,7 +468,7 @@ public class PresenterFactory
}
else
{
- File localizedSource = new File(FileTools.addBeforeExtension(source.getAbsolutePath(), "-" + locale.getLanguage()));
+ File localizedSource = new File(XidynUtils.insertBeforeExtension(source.getAbsolutePath(), "-" + locale.getLanguage()));
result = create(localizedSource);
@@ -531,7 +531,7 @@ public class PresenterFactory
}
else
{
- URL localizedSource = new URL(FileTools.addBeforeExtension(source.getPath(), "-" + locale.getLanguage()));
+ URL localizedSource = new URL(XidynUtils.insertBeforeExtension(source.getPath(), "-" + locale.getLanguage()));
result = create(localizedSource);
diff --git a/src/fr/devinsy/xidyn/presenters/TranslatorPresenter.java b/src/fr/devinsy/xidyn/presenters/TranslatorPresenter.java
index e21ffe8..64dc8d4 100644
--- a/src/fr/devinsy/xidyn/presenters/TranslatorPresenter.java
+++ b/src/fr/devinsy/xidyn/presenters/TranslatorPresenter.java
@@ -22,9 +22,9 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
-import fr.devinsy.util.FileTools;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.TagDataManager;
+import fr.devinsy.xidyn.utils.XidynUtils;
/**
* The Class TranslatorPresenter.
@@ -270,7 +270,7 @@ public class TranslatorPresenter implements Presenter
}
else
{
- String adaptedSource = FileTools.addBeforeExtension(this.defaultSource, "-" + language);
+ String adaptedSource = XidynUtils.insertBeforeExtension(this.defaultSource, "-" + language);
result = PresenterFactory.create(adaptedSource);
if (result.isAvailable())
@@ -279,7 +279,7 @@ public class TranslatorPresenter implements Presenter
}
else
{
- adaptedSource = FileTools.addBeforeExtension(this.defaultSource, "_" + language);
+ adaptedSource = XidynUtils.insertBeforeExtension(this.defaultSource, "_" + language);
if (result.isAvailable())
{
diff --git a/src/fr/devinsy/xidyn/utils/XidynUtils.java b/src/fr/devinsy/xidyn/utils/XidynUtils.java
index 8afcb21..8281481 100644
--- a/src/fr/devinsy/xidyn/utils/XidynUtils.java
+++ b/src/fr/devinsy/xidyn/utils/XidynUtils.java
@@ -597,6 +597,45 @@ public class XidynUtils
return result;
}
+ /**
+ * Insert before extension.
+ *
+ * @param fileName
+ * the file name
+ * @param addition
+ * the addition
+ * @return the string
+ */
+ public static String insertBeforeExtension(final String fileName, final String addition)
+ {
+ String result;
+
+ if (fileName == null)
+ {
+ result = null;
+ }
+ else if (addition == null)
+ {
+ result = fileName;
+ }
+ else
+ {
+ int separatorIndex = fileName.lastIndexOf('.');
+
+ if (separatorIndex > 0)
+ {
+ result = fileName.substring(0, separatorIndex) + addition + fileName.substring(separatorIndex);
+ }
+ else
+ {
+ result = fileName + addition;
+ }
+ }
+
+ //
+ return result;
+ }
+
/**
* Load.
*
diff --git a/test/fr/devinsy/xidyn/utils/XidynUtilsTest.java b/test/fr/devinsy/xidyn/utils/XidynUtilsTest.java
index a5e32e9..516bf98 100644
--- a/test/fr/devinsy/xidyn/utils/XidynUtilsTest.java
+++ b/test/fr/devinsy/xidyn/utils/XidynUtilsTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006-2017 Christian Pierre MOMON
+ * Copyright (C) 2006-2023 Christian Pierre MOMON
*
* This file is part of Xidyn.
*
@@ -21,7 +21,7 @@ package fr.devinsy.xidyn.utils;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
-import org.fest.assertions.Assertions;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -49,7 +49,7 @@ public class XidynUtilsTest
String source = "aaaaahellozzzzz";
String target = XidynUtils.extractBodyContent(source);
- Assertions.assertThat(target).isEqualTo("hello");
+ Assert.assertEquals(target, "hello");
}
/**
@@ -61,7 +61,7 @@ public class XidynUtilsTest
String source = "aaaaaaahellozzzzz";
String target = XidynUtils.extractBodyContent(source);
- Assertions.assertThat(target).isEqualTo("");
+ Assert.assertEquals(target, "");
}
/**
@@ -73,7 +73,7 @@ public class XidynUtilsTest
String source = "aaaaazzzzz";
String target = XidynUtils.extractBodyContent(source);
- Assertions.assertThat(target).isEqualTo("");
+ Assert.assertEquals(target, "");
}
/**
@@ -85,7 +85,7 @@ public class XidynUtilsTest
String source = "aaaaa hello zzzzz";
String target = XidynUtils.extractBodyContent(source);
- Assertions.assertThat(target).isEqualTo("hello");
+ Assert.assertEquals(target, "hello");
}
/**
@@ -114,7 +114,7 @@ public class XidynUtilsTest
// System.out.println("[" + source + "]");
String target = XidynUtils.extractBodyContent(source);
- Assertions.assertThat(target).isEqualTo("WELCOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOME");
+ Assert.assertEquals(target, "WELCOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOME");
}
/**
@@ -126,7 +126,7 @@ public class XidynUtilsTest
String source = "aaaaahellozzzzz";
String target = XidynUtils.extractDoctype(source);
- Assertions.assertThat(target).isNull();
+ Assert.assertNull(target);
}
/**
@@ -138,7 +138,7 @@ public class XidynUtilsTest
String source = "aaaaahellozzzzz";
String target = XidynUtils.extractDoctype(source);
- Assertions.assertThat(target).isEqualTo("");
+ Assert.assertEquals(target, "");
}
/**
@@ -150,7 +150,7 @@ public class XidynUtilsTest
String source = "aaaaahellozzzzz";
String target = XidynUtils.extractDoctype(source);
- Assertions.assertThat(target).isEqualTo("");
+ Assert.assertEquals(target, "");
}
/**
@@ -162,7 +162,7 @@ public class XidynUtilsTest
String source = "aaaaahellozzzzz";
String target = XidynUtils.extractDoctype(source);
- Assertions.assertThat(target).isEqualTo("");
+ Assert.assertEquals(target, "");
}
/**
@@ -174,6 +174,150 @@ public class XidynUtilsTest
String source = "aaaaahellozzzzz";
String target = XidynUtils.extractDoctype(source);
- Assertions.assertThat(target).isEqualTo("");
+ Assert.assertEquals(target, "");
+ }
+
+ /**
+ * Test insert before extension 01.
+ */
+ @Test
+ public void testInsertBeforeExtension01()
+ {
+ String source = null;
+
+ String target = XidynUtils.insertBeforeExtension(source, null);
+ Assert.assertNull(target);
+ }
+
+ /**
+ * Test insert before extension 02.
+ */
+ @Test
+ public void testInsertBeforeExtension02()
+ {
+ String source = null;
+
+ String target = XidynUtils.insertBeforeExtension(source, "");
+ Assert.assertNull(target);
+ }
+
+ /**
+ * Test insert before extension 03.
+ */
+ @Test
+ public void testInsertBeforeExtension03()
+ {
+ String source = null;
+
+ String target = XidynUtils.insertBeforeExtension(source, "-fr");
+ Assert.assertNull(target);
+ }
+
+ /**
+ * Test insert before extension 05.
+ */
+ @Test
+ public void testInsertBeforeExtension05()
+ {
+ String source = "";
+
+ String target = XidynUtils.insertBeforeExtension(source, null);
+ Assert.assertEquals(target, "");
+ }
+
+ /**
+ * Test insert before extension 06.
+ */
+ @Test
+ public void testInsertBeforeExtension06()
+ {
+ String source = "";
+
+ String target = XidynUtils.insertBeforeExtension(source, "");
+ Assert.assertEquals(target, "");
+ }
+
+ /**
+ * Test insert before extension 07.
+ */
+ @Test
+ public void testInsertBeforeExtension07()
+ {
+ String source = "";
+
+ String target = XidynUtils.insertBeforeExtension(source, "-fr");
+ Assert.assertEquals(target, "-fr");
+ }
+
+ /**
+ * Test insert before extension 08.
+ */
+ @Test
+ public void testInsertBeforeExtension08()
+ {
+ String source = "foo";
+
+ String target = XidynUtils.insertBeforeExtension(source, null);
+ Assert.assertEquals(target, "foo");
+ }
+
+ /**
+ * Test insert before extension 09.
+ */
+ @Test
+ public void testInsertBeforeExtension09()
+ {
+ String source = "foo";
+
+ String target = XidynUtils.insertBeforeExtension(source, "");
+ Assert.assertEquals(target, "foo");
+ }
+
+ /**
+ * Test insert before extension 10.
+ */
+ @Test
+ public void testInsertBeforeExtension10()
+ {
+ String source = "foo";
+
+ String target = XidynUtils.insertBeforeExtension(source, "-fr");
+ Assert.assertEquals(target, "foo-fr");
+ }
+
+ /**
+ * Test insert before extension 11.
+ */
+ @Test
+ public void testInsertBeforeExtension11()
+ {
+ String source = "foo.txt";
+
+ String target = XidynUtils.insertBeforeExtension(source, null);
+ Assert.assertEquals(target, "foo.txt");
+ }
+
+ /**
+ * Test insert before extension 12.
+ */
+ @Test
+ public void testInsertBeforeExtension12()
+ {
+ String source = "foo.txt";
+
+ String target = XidynUtils.insertBeforeExtension(source, "");
+ Assert.assertEquals(target, "foo.txt");
+ }
+
+ /**
+ * Test insert before extension 13.
+ */
+ @Test
+ public void testInsertBeforeExtension13()
+ {
+ String source = "foo.txt";
+
+ String target = XidynUtils.insertBeforeExtension(source, "-fr");
+ Assert.assertEquals(target, "foo-fr.txt");
}
}