diff --git a/.classpath b/.classpath
index 8e863e4..2242d7d 100644
--- a/.classpath
+++ b/.classpath
@@ -15,5 +15,7 @@
+
+
diff --git a/lib/fest-assert-1.4-sources.jar b/lib/fest-assert-1.4-sources.jar
new file mode 100644
index 0000000..7a8168c
Binary files /dev/null and b/lib/fest-assert-1.4-sources.jar differ
diff --git a/lib/fest-assert-1.4.jar b/lib/fest-assert-1.4.jar
new file mode 100644
index 0000000..1d42207
Binary files /dev/null and b/lib/fest-assert-1.4.jar differ
diff --git a/lib/fest-util-1.1.6-sources.jar b/lib/fest-util-1.1.6-sources.jar
new file mode 100644
index 0000000..4662ea5
Binary files /dev/null and b/lib/fest-util-1.1.6-sources.jar differ
diff --git a/lib/fest-util-1.1.6.jar b/lib/fest-util-1.1.6.jar
new file mode 100644
index 0000000..629e6c0
Binary files /dev/null and b/lib/fest-util-1.1.6.jar differ
diff --git a/src/fr/devinsy/xidyn/presenters/Presenter.java b/src/fr/devinsy/xidyn/presenters/Presenter.java
index f0c6368..3fc0a8b 100644
--- a/src/fr/devinsy/xidyn/presenters/Presenter.java
+++ b/src/fr/devinsy/xidyn/presenters/Presenter.java
@@ -1,5 +1,8 @@
package fr.devinsy.xidyn.presenters;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
import fr.devinsy.xidyn.data.TagDataListById;
import fr.devinsy.xidyn.data.TagDataManager;
@@ -8,6 +11,8 @@ import fr.devinsy.xidyn.data.TagDataManager;
*/
public abstract class Presenter
{
+ public static final Pattern BODY_PATTERN = Pattern.compile("^.*<[bB][oO][dD][yY]>\\s*(.*\\S)\\s*[bB][oO][dD][yY]>.*$");
+
/**
*
* @param datas
@@ -65,27 +70,32 @@ public abstract class Presenter
}
/**
- * TODO implement a trim action.
+ *
*/
- static public String extractBodyContent(final StringBuffer data)
+ static public String extractBodyContent(final CharSequence source)
{
- String result = null;
+ String result;
- // Extract the body content.
- String dataLowerCase = data.toString().toLowerCase();
-
- int startBody = dataLowerCase.indexOf("");
- int endBody = dataLowerCase.indexOf("");
-
- // Note: as failed search is improbable, no care about complexity
- // in failed search case.
- if ((startBody == -1) || (endBody == -1))
+ if (source == null)
{
- result = null;
+ result = "";
}
else
{
- result = data.substring(startBody + 6, endBody);
+ Matcher matcher = BODY_PATTERN.matcher(source);
+ if ((matcher.find()) && (matcher.groupCount() == 1))
+ {
+ // for (int i = 0; i <= matcher.groupCount(); i++)
+ // {
+ // System.out.println(i + " " + matcher.group(i));
+ // }
+
+ result = matcher.group(1);
+ }
+ else
+ {
+ result = "";
+ }
}
//
diff --git a/src/fr/devinsy/xidyn/views/View.java b/src/fr/devinsy/xidyn/views/View.java
index 61cc283..8f555a5 100644
--- a/src/fr/devinsy/xidyn/views/View.java
+++ b/src/fr/devinsy/xidyn/views/View.java
@@ -5,13 +5,11 @@ import fr.devinsy.xidyn.presenters.Presenter;
/**
*
*/
-public class View
-{
+public class View {
/**
*
*/
- public StringBuffer getHtml() throws Exception
- {
+ public StringBuffer getHtml() {
StringBuffer result;
result = null;
@@ -23,26 +21,19 @@ public class View
/**
*
*/
- public StringBuffer getHtmlBody() throws Exception
- {
+ public StringBuffer getHtmlBody() {
StringBuffer result;
StringBuffer html = this.getHtml();
- if (html == null)
- {
+ if (html == null) {
result = new StringBuffer();
- }
- else
- {
+ } else {
String body = Presenter.extractBodyContent(html);
- if (body == null)
- {
+ if (body == null) {
result = new StringBuffer();
- }
- else
- {
+ } else {
result = new StringBuffer(body);
}
}
@@ -50,6 +41,18 @@ public class View
//
return (result);
}
+
+ /**
+ *
+ */
+ public boolean isDeprecated() {
+ boolean result;
+
+ result = true;
+
+ //
+ return result;
+ }
}
// ////////////////////////////////////////////////////////////////////////
\ No newline at end of file
diff --git a/test/fr/devinsy/xidyn/presenters/PresenterTest.java b/test/fr/devinsy/xidyn/presenters/PresenterTest.java
new file mode 100644
index 0000000..67c1b8b
--- /dev/null
+++ b/test/fr/devinsy/xidyn/presenters/PresenterTest.java
@@ -0,0 +1,58 @@
+package fr.devinsy.xidyn.presenters;
+
+import org.fest.assertions.Assertions;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class PresenterTest
+{
+ /**
+ *
+ */
+ @Test
+ public void testExtractBodyContent01()
+ {
+ String source = "aaaaahellozzzzz";
+
+ String target = Presenter.extractBodyContent(source);
+ Assertions.assertThat(target).isEqualTo("hello");
+ }
+
+ /**
+ *
+ */
+ @Test
+ public void testExtractBodyContent02()
+ {
+ String source = "aaaaaaahellozzzzz";
+
+ String target = Presenter.extractBodyContent(source);
+ Assertions.assertThat(target).isEqualTo("");
+ }
+
+ /**
+ *
+ */
+ @Test
+ public void testExtractBodyContent03()
+ {
+ String source = "aaaaazzzzz";
+
+ String target = Presenter.extractBodyContent(source);
+ Assertions.assertThat(target).isEqualTo("");
+ }
+
+ /**
+ *
+ */
+ @Test
+ public void testExtractBodyContent04()
+ {
+ String source = "aaaaa hello zzzzz";
+
+ String target = Presenter.extractBodyContent(source);
+ Assertions.assertThat(target).isEqualTo("hello");
+ }
+}