/**
  * 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);
      }
    }
  }
示例#4
0
 @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"));
 }
示例#5
0
 @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"));
 }
示例#6
0
 @Test
 public void testRemoveIeComments() {
   String oldText =
       "&lt;!--[if !supportLineBreakNewLine]--&gt;fdgsdfgsfdg  <br> &lt;!--[endif]--><!--[if !supportLineBreakNewLine]-->nnnnnnnnnnnnnnnnnn<!--[endif]-->";
   String newText = HtmlUtil.removeIeComments(oldText);
   Assert.assertEquals("fdgsdfgsfdg  <br> nnnnnnnnnnnnnnnnnn", newText);
 }
示例#7
0
 @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);
 }
示例#8
0
  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;
    }
  }
示例#10
0
 @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/ "));
 }
示例#11
0
 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|&nbsp;?", "").isEmpty()) {
         continue;
       }
       sb.append(StringUtil.trim(content)).append(" ");
     } else {
       getInnerDescs(child, sb);
     }
   }
   if (HtmlUtil.isNewLineTag(node.getNodeName().toUpperCase())) {
     sb.append("\r\n");
   }
 }
示例#12
0
 @Test
 public void testContainsIeComments() {
   String oldText =
       "&lt;!--[if !supportLineBreakNewLine]--&gt;fdgsdfgsfdg  <br> &lt;!--[endif]--><!--[if !supportLineBreakNewLine]-->nnnnnnnnnnnnnnnnnn<!--[endif]-->";
   Assert.assertTrue(HtmlUtil.containsIeComments(oldText));
 }
示例#13
0
 @Test
 public void testRemoveIeComments_withEmpty() {
   String newText = HtmlUtil.removeIeComments("");
   Assert.assertEquals("", newText);
 }
示例#14
0
 @Test
 public void ignoreWordIfEmpty() {
   Assert.assertEquals(
       "test  greterter",
       HtmlUtil.ignoreWordIf("test <!--[if !supportEmptyParas]--> gg <!--[endif]--> greterter"));
 }
示例#15
0
 @Test
 public void ignoreWordIfOtherClose() {
   Assert.assertEquals(
       "test  greterter",
       HtmlUtil.ignoreWordIf("test <!--[if gte mso 10]> ffff<!--[endif]--> greterter"));
 }
示例#16
0
 @Test
 public void testContainsIeComments_withNull() {
   Assert.assertFalse(HtmlUtil.containsIeComments(null));
 }
示例#17
0
 @Test
 public void getContentTypeByExtension() {
   Assert.assertEquals("image/gif", HtmlUtil.getMimeByExtension("gif"));
 }
示例#18
0
 @Test(expected = UnsupportedOperationException.class)
 public void getContentTypeByExtensionForNull() {
   HtmlUtil.getMimeByExtension(null);
 }
示例#19
0
 @Test
 public void testReplaceNewLineByBr() {
   String newString = HtmlUtil.replaceNewLineByBr("<p>12345\n" + "12345\n" + "12345</p>");
   Assert.assertEquals(newString, "12345<br>12345<br>12345");
 }
示例#20
0
 @Test
 public void testReplaceBlockTagsByBr_withNullHtml() {
   final String withoutHtml = HtmlUtil.replaceBlockTagsByBr(null);
   Assert.assertEquals(null, withoutHtml);
 }
示例#21
0
 @Test
 public void ignoreHtml() {
   Assert.assertEquals("&lt;a&gt;", HtmlUtil.ignoreHtml("<a>"));
 }
示例#22
0
 @Test
 public void testContainsIeComments_withEmpty() {
   Assert.assertFalse(HtmlUtil.containsIeComments(""));
 }
示例#23
0
 public void setMessage(String myMessage) {
   savedArgs.put(MESSAGE, HtmlUtil.asPara(myMessage));
 }
示例#24
0
 @Test
 public void emptyOrValueForNull() {
   Assert.assertEquals("", HtmlUtil.emptyOrValue(null));
 }
示例#25
0
 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"));
 }
示例#26
0
 @Test
 public void getContentTypeByExtensionForNotFound() {
   Assert.assertNull(HtmlUtil.getMimeByExtension("fff"));
 }
示例#27
0
 @Test
 public void testRemoveAllTagsExceptBr_null() {
   final String withoutHtml = HtmlUtil.removeAllTagsExceptBr(null);
   Assert.assertEquals(null, withoutHtml);
 }
示例#28
0
 @Test
 public void encodeToPercent() {
   Assert.assertEquals("%3fa%26", HtmlUtil.encodeToPercent("?a&"));
 }
示例#29
0
 public void setThreeLineMessage(String msg1, String msg2, String msg3) {
   savedArgs.put(MESSAGE, HtmlUtil.asPara(msg1) + HtmlUtil.asPara(msg2) + HtmlUtil.asPara(msg3));
 }
示例#30
0
 @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);
 }