/** * Insert values into tables needed by JDBC devtests * * @param ds * @param out * @param tableName * @param content */ public static void insertEntry(DataSource ds, PrintWriter out, String tableName, String content) { Connection con = null; Statement stmt = null; try { con = ds.getConnection(); stmt = con.createStatement(); stmt.executeUpdate("INSERT INTO " + tableName + " VALUES('" + content + "')"); } catch (SQLException ex) { HtmlUtil.printException(ex, out); } finally { if (stmt != null) { try { stmt.close(); } catch (SQLException ex) { HtmlUtil.printException(ex, out); } } if (con != null) { try { con.close(); } catch (SQLException ex) { HtmlUtil.printException(ex, out); } } } }
/** * Deletes tables used by JDBC devtests. * * @param ds1 * @param out * @param tableName */ public static void deleteTables(DataSource ds1, PrintWriter out, String tableName) { Connection con = null; Statement stmt = null; try { con = ds1.getConnection(); stmt = con.createStatement(); stmt.executeUpdate("drop table " + tableName); } catch (Exception e) { HtmlUtil.printException(e, out); } finally { try { if (stmt != null) { stmt.close(); } } catch (Exception e) { HtmlUtil.printException(e, out); } try { if (con != null) { con.close(); } } catch (Exception e) { HtmlUtil.printException(e, out); } } }
/** * Creates Tables needed to execute JDBC devtests * * @param ds1 * @param out * @param tableName * @param columnName */ public static void createTables( DataSource ds1, PrintWriter out, String tableName, String columnName) { Connection con = null; Statement stmt = null; try { con = ds1.getConnection(); stmt = con.createStatement(); String query = "create table " + tableName + "(" + columnName + " char(50))"; stmt.executeUpdate(query); } catch (Exception e) { HtmlUtil.printException(e, out); } finally { try { if (stmt != null) { stmt.close(); } } catch (Exception e) { HtmlUtil.printException(e, out); } try { if (con != null) { con.close(); } } catch (Exception e) { HtmlUtil.printException(e, out); } } }
@Test public void ignoreWordIfMore() { Assert.assertEquals( "test greterter c a", HtmlUtil.ignoreWordIf( "test <!--[if gte mso 9]> ffff<![endif]--> greterter c <!--[if gte mso 9]> ffff<![endif]--> a")); }
@Test public void ignoreWordInner() { Assert.assertEquals( "greterter c f <![endif]--> a", HtmlUtil.ignoreWordIf( "greterter c <!--[if gte mso 9]> test <!--[if gte mso 9]> ffff<![endif]--> f <![endif]--> a")); }
@Test public void testRemoveIeComments() { String oldText = "<!--[if !supportLineBreakNewLine]-->fdgsdfgsfdg <br> <!--[endif]--><!--[if !supportLineBreakNewLine]-->nnnnnnnnnnnnnnnnnn<!--[endif]-->"; String newText = HtmlUtil.removeIeComments(oldText); Assert.assertEquals("fdgsdfgsfdg <br> nnnnnnnnnnnnnnnnnn", newText); }
@Test public void testRemoveAllTagsExceptBr() { final String withoutHtml = HtmlUtil.removeAllTagsExceptBr( "<div style=\"width:10%;float:left;" + " alt=\"Delete\"\n" + " style='cursor:pointer; display:none;'\n" + "\">\n" + " <img id=\"IMAGE_FILE_UPLOAD17680Image File UploadRemoveFormFileButton\" src=\"/images/cross-circle.png\"\n" + " alt=\"Delete\"\n" + " style='cursor:pointer; display:none;'\n" + " onclick=\"\n" + " removePreviewImage('IMAGE_FILE_UPLOAD17680Image File Upload');\n" + " removeFormFile(\n" + " null,\n" + " null,\n" + " 'IMAGE_FILE_UPLOAD17680Image File Upload',\n" + " 'Image Files',\n" + " '176',\n" + " '2',\n" + " 'Image File Upload',\n" + " 'IMAGE_FILE_UPLOAD',\n" + " 'FORM_FILE');\">\n" + " < br > divhtml <bred> <br/>< br/><br/ ><br />< br / > <br clear=\"all\" / > </div> <her dfas aadsf/ ad>"); Assert.assertEquals( "< br > divhtml <br/>< br/><br/ ><br />< br / > <br clear=\"all\" / >", withoutHtml); }
private String expandIdSelector(String selector, final Map<String, String> clientIdMap) { UIComponent component = new UIComponentBase() { public String getFamily() { return null; } public UIComponent findComponent(String expr) { final String clientId = clientIdMap.get(expr); if (clientId == null) { return null; } return new UIComponentBase() { public String getClientId(FacesContext context) { return clientId; } public String getFamily() { return null; } }; } }; return HtmlUtil.expandIdSelector(selector, component, null); }
/** * Verifies table content by getting the number of rows in it, used by the JDBC devtests. Returns * a true if there are any rows in the table. * * @param ds1 * @param out * @param tableName * @param columnName * @param content * @return boolean result */ public static boolean verifyTableContent( DataSource ds1, PrintWriter out, String tableName, String columnName, String content) { Connection con = null; Statement stmt = null; ResultSet rs = null; boolean result = false; try { con = ds1.getConnection(); stmt = con.createStatement(); rs = stmt.executeQuery( "select count(*) ROW_COUNT from " + tableName + " where " + columnName + " = '" + content + "'"); if (rs.next()) { if (rs.getInt("ROW_COUNT") > 0) { result = true; } } } catch (Exception e) { HtmlUtil.printException(e, out); } finally { try { if (stmt != null) { stmt.close(); } } catch (Exception e) { HtmlUtil.printException(e, out); } try { if (con != null) { con.close(); } } catch (Exception e) { HtmlUtil.printException(e, out); } return result; } }
@Test public void testRemoveEndingSlash() { org.junit.Assert.assertNull(HtmlUtil.removeEndingSlash(null)); org.junit.Assert.assertEquals("", HtmlUtil.removeEndingSlash("")); org.junit.Assert.assertEquals("text", HtmlUtil.removeEndingSlash("text")); org.junit.Assert.assertEquals("text", HtmlUtil.removeEndingSlash("text/")); org.junit.Assert.assertEquals("text/text", HtmlUtil.removeEndingSlash("text/text/")); org.junit.Assert.assertEquals("text/text", HtmlUtil.removeEndingSlash("text/text/ ")); }
public static void getInnerDescs(Node node, StringBuilder sb) { if ("STYLE".equals(node.getNodeName())) { return; } NodeList children = node.getChildNodes(); if (HtmlUtil.isNewLineTag(node.getNodeName().toUpperCase())) { sb.append("\r\n"); } for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if ("#text".equals(child.getNodeName())) { String content = child.getTextContent(); if (content.replaceAll("\\s|\u00A0|\u3000| ?", "").isEmpty()) { continue; } sb.append(StringUtil.trim(content)).append(" "); } else { getInnerDescs(child, sb); } } if (HtmlUtil.isNewLineTag(node.getNodeName().toUpperCase())) { sb.append("\r\n"); } }
@Test public void testContainsIeComments() { String oldText = "<!--[if !supportLineBreakNewLine]-->fdgsdfgsfdg <br> <!--[endif]--><!--[if !supportLineBreakNewLine]-->nnnnnnnnnnnnnnnnnn<!--[endif]-->"; Assert.assertTrue(HtmlUtil.containsIeComments(oldText)); }
@Test public void testRemoveIeComments_withEmpty() { String newText = HtmlUtil.removeIeComments(""); Assert.assertEquals("", newText); }
@Test public void ignoreWordIfEmpty() { Assert.assertEquals( "test greterter", HtmlUtil.ignoreWordIf("test <!--[if !supportEmptyParas]--> gg <!--[endif]--> greterter")); }
@Test public void ignoreWordIfOtherClose() { Assert.assertEquals( "test greterter", HtmlUtil.ignoreWordIf("test <!--[if gte mso 10]> ffff<!--[endif]--> greterter")); }
@Test public void testContainsIeComments_withNull() { Assert.assertFalse(HtmlUtil.containsIeComments(null)); }
@Test public void getContentTypeByExtension() { Assert.assertEquals("image/gif", HtmlUtil.getMimeByExtension("gif")); }
@Test(expected = UnsupportedOperationException.class) public void getContentTypeByExtensionForNull() { HtmlUtil.getMimeByExtension(null); }
@Test public void testReplaceNewLineByBr() { String newString = HtmlUtil.replaceNewLineByBr("<p>12345\n" + "12345\n" + "12345</p>"); Assert.assertEquals(newString, "12345<br>12345<br>12345"); }
@Test public void testReplaceBlockTagsByBr_withNullHtml() { final String withoutHtml = HtmlUtil.replaceBlockTagsByBr(null); Assert.assertEquals(null, withoutHtml); }
@Test public void ignoreHtml() { Assert.assertEquals("<a>", HtmlUtil.ignoreHtml("<a>")); }
@Test public void testContainsIeComments_withEmpty() { Assert.assertFalse(HtmlUtil.containsIeComments("")); }
public void setMessage(String myMessage) { savedArgs.put(MESSAGE, HtmlUtil.asPara(myMessage)); }
@Test public void emptyOrValueForNull() { Assert.assertEquals("", HtmlUtil.emptyOrValue(null)); }
public void testAddToSize() throws Exception { assertEquals("120px", HtmlUtil.addToSize("100", "20px")); assertEquals("120px", HtmlUtil.addToSize("100px", "20")); assertEquals("120px", HtmlUtil.addToSize("100", "20")); assertEquals("120px", HtmlUtil.addToSize("100px", "20px")); }
@Test public void getContentTypeByExtensionForNotFound() { Assert.assertNull(HtmlUtil.getMimeByExtension("fff")); }
@Test public void testRemoveAllTagsExceptBr_null() { final String withoutHtml = HtmlUtil.removeAllTagsExceptBr(null); Assert.assertEquals(null, withoutHtml); }
@Test public void encodeToPercent() { Assert.assertEquals("%3fa%26", HtmlUtil.encodeToPercent("?a&")); }
public void setThreeLineMessage(String msg1, String msg2, String msg3) { savedArgs.put(MESSAGE, HtmlUtil.asPara(msg1) + HtmlUtil.asPara(msg2) + HtmlUtil.asPara(msg3)); }
@Test public void testReplaceBlockTagsByBr() { final String withoutHtml = HtmlUtil.replaceBlockTagsByBr("<div>divText</div>" + "<span>spanText</span>" + "<br>"); Assert.assertEquals("<div>divText<br><span>spanText</span><br>", withoutHtml); }