diff --git a/.classpath b/.classpath index 0e4efbc..f9dfdd4 100644 --- a/.classpath +++ b/.classpath @@ -25,13 +25,6 @@ - - - - - - - diff --git a/pom.xml b/pom.xml index d5a602f..96c1115 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.mousetech.gourmet gourmetj - 2.0.4 + 2.0.18 jar GourmetJ @@ -172,6 +172,15 @@ + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.13.0 + + + org.springframework.boot diff --git a/src/main/java/com/mousetech/gourmetj/AdminMainBean.java b/src/main/java/com/mousetech/gourmetj/AdminMainBean.java index 2b2bc7e..130d8ca 100644 --- a/src/main/java/com/mousetech/gourmetj/AdminMainBean.java +++ b/src/main/java/com/mousetech/gourmetj/AdminMainBean.java @@ -1,7 +1,6 @@ package com.mousetech.gourmetj; import java.io.Serializable; -import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; @@ -67,14 +66,6 @@ public class AdminMainBean implements Serializable { return cookieBean; } - /** - * @param cookieBean the cookieBean to set. - * @deprecated Not invoked by @Inject - */ - public void setCookieBean(CookieBean cookieBean) { - this.cookieBean = cookieBean; - } - // ** @Inject private UserSession userSession; @@ -248,6 +239,7 @@ public class AdminMainBean implements Serializable { this.userSession.setLastEdit(null); // Construct a blank recipe to be created. this.userSession.setRecipe(new Recipe()); + this.userSession.setDetailTab(0); // title tab return "detailEdit?faces-redirect=true"; } diff --git a/src/main/java/com/mousetech/gourmetj/CookieBean.java b/src/main/java/com/mousetech/gourmetj/CookieBean.java index 9abe55e..e503aa9 100644 --- a/src/main/java/com/mousetech/gourmetj/CookieBean.java +++ b/src/main/java/com/mousetech/gourmetj/CookieBean.java @@ -124,7 +124,7 @@ public class CookieBean { // ** public Integer getDisplayListSize() { if (!cookieMap.containsKey(KEY_DISPLAY_ROWS)) { - cookieMap.put(KEY_DISPLAY_ROWS, "30"); + cookieMap.put(KEY_DISPLAY_ROWS, "0"); } String st = cookieMap.get(KEY_DISPLAY_ROWS); return Integer.valueOf(String.valueOf(st)); diff --git a/src/main/java/com/mousetech/gourmetj/RecipeDetailBean.java b/src/main/java/com/mousetech/gourmetj/RecipeDetailBean.java index d13d518..65767a0 100644 --- a/src/main/java/com/mousetech/gourmetj/RecipeDetailBean.java +++ b/src/main/java/com/mousetech/gourmetj/RecipeDetailBean.java @@ -243,7 +243,7 @@ public class RecipeDetailBean implements Serializable { this.shop = this.getUserSession().getShoppingList() .contains(recipe); - log.info("Set recipe: " + this.recipe); + log.debug("Set recipe: " + this.recipe); } /** @@ -358,8 +358,8 @@ public class RecipeDetailBean implements Serializable { return ""; } String s = instructions.replace("\r\n", "

") - .replace("\n\n", "

"); - s = s.replace("\n", "
"); + .replace("\n\n", "

") + .replace("\n", "
"); return s; } @@ -643,7 +643,7 @@ public class RecipeDetailBean implements Serializable { * @see #addIngredientList(String) */ public void addIngredient(String ingredientText) { - log.info("Ingredient line: \"" + ingredientText + "\""); + log.debug("Ingredient line: \"" + ingredientText + "\""); Ingredient ing = IngredientDigester.digest(ingredientText); @@ -977,7 +977,7 @@ public class RecipeDetailBean implements Serializable { } public void ajaxUpdateShopcat(IngredientUI item) { - log.warn("SHOPCAT2 "); + log.debug("SHOPCAT2 "); updateShopcat(item); } diff --git a/src/main/java/com/mousetech/gourmetj/UserSession.java b/src/main/java/com/mousetech/gourmetj/UserSession.java index c100fcd..b2c6cf6 100644 --- a/src/main/java/com/mousetech/gourmetj/UserSession.java +++ b/src/main/java/com/mousetech/gourmetj/UserSession.java @@ -1,6 +1,10 @@ package com.mousetech.gourmetj; import java.io.Serializable; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; import java.util.ArrayList; import java.util.List; @@ -144,6 +148,54 @@ public class UserSession implements Serializable { return sb.toString(); } + /** + * Display source. If no "source" and there's a URL, + * use that. + * + * @param ltime + * @return + */ + public String formatSource(Recipe r) { + String s = r.getSource(); + if ( s != null && ! s.isBlank()) { + return s; + } + s = r.getLink(); + return urlToSource(s); + } + + /** + * Take a URL and strip it of everything but + * the base domain name (including ".com") + * @param s URL string. + * @return Processed domain name. + * TestedBy: UserSessionTest + */ + String urlToSource(String s) { + if ( s == null || s.isBlank()) { + return ""; // no source, no URL + } + try { + if ( ! s.startsWith("http")) { + s = "http://" + s; // Convert to absolute URI + } + URL u = new URI(s).toURL(); + String s1 = u.getHost(); + if ( s1.startsWith("www.")) { + s1 = s1.substring("www.".length()); + } + if ( s1.endsWith(".com")) { + // mousetech.com + s1 = s1.substring(0, s1.length() - ".com".length()); + } + return s1; + } catch (MalformedURLException e) { + return s; + } catch (URISyntaxException e) { + return s; + } + } + /* * @Deprecated Using TimeConverter. */ diff --git a/src/main/resources/META-INF/resources/detailEdit.xhtml b/src/main/resources/META-INF/resources/detailEdit.xhtml index c6f6f78..f02eb6d 100644 --- a/src/main/resources/META-INF/resources/detailEdit.xhtml +++ b/src/main/resources/META-INF/resources/detailEdit.xhtml @@ -42,6 +42,10 @@ font-weight: bold; background-color: green; } +.noBorders .noBorders tr, .noBorders td { + background: none !important; + border: none !important; +} - + + - + + + + @@ -126,6 +139,13 @@ converterId="com.mousetech.gourmetj.utils.TimeConverter" /> + + diff --git a/src/main/resources/META-INF/resources/main.xhtml b/src/main/resources/META-INF/resources/main.xhtml index c82ee82..033bc06 100644 --- a/src/main/resources/META-INF/resources/main.xhtml +++ b/src/main/resources/META-INF/resources/main.xhtml @@ -57,7 +57,7 @@ value="#{cookieBean.displayListSize}" /> - + - @@ -65,7 +65,11 @@ action="#{recipeDetailBean.doShop}" update="ctlShop" /> - + @@ -92,14 +96,23 @@ value="#{recipeDetailBean.recipe.cooktime}" converter="com.mousetech.gourmetj.utils.TimeConverter" /> - - + + + +
+ + #{recipeDetailBean.recipe.link} + +
diff --git a/src/test/java/com/mousetech/gourmetj/UserSessionTest.java b/src/test/java/com/mousetech/gourmetj/UserSessionTest.java new file mode 100644 index 0000000..04da6cf --- /dev/null +++ b/src/test/java/com/mousetech/gourmetj/UserSessionTest.java @@ -0,0 +1,25 @@ +package com.mousetech.gourmetj; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +class UserSessionTest { + + @Test + void testformatSource() { + UserSession us = new UserSession(); + + assertEquals("mousetech", + us.urlToSource("www.mousetech.com")); + assertEquals("google", + us.urlToSource("google.com")); + assertEquals("foobar", + us.urlToSource("foobar")); + assertEquals("", + us.urlToSource("\t")); + assertEquals("", + us.urlToSource(null)); + } + +}