Archive for November, 2004

Strip HTML Tags Using Regular Expressions

Written by coregps on Tuesday, November 30th, 2004 in General.

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

In my current project, I want a function to strip all of the HTML tags from a string. After a long time on Google, I found some good solutions and implemented myself using JavaBean. In addition, I’m more aware of that Regular Expressions is an incredibly powerful tool. I decide to set aside some time to learn Regular Expressions.

 package com.esurfer.common;

 public class CommonUtil {
     /**
      * Function used to strip all HTML tags from strings using Regular Expressions
      * (.|n) - > matches any character or a new line
      * *?  -> 0 or more occurences, and make a non-greedy search
      *
      * @param strHTML A string to be cleared of HTML TAGS
      * @return A string that has been filtered by the function
      */
     public String StripHTMLTags(String strHTML) {
         String sResult = “”;
         if ( strHTML.equals(“”) || (strHTML == null) ) {
             sResult = “”;
         } else {
             sResult = strHTML.replaceAll(“<(.|n)*?>”, “”);
         }
         return sResult;
     }
 }
    

The following is in Javascript:

 <script type=”text/javascript”>
     function StripHTMLTags(s) {
         var strHTML = s;
         var regex = /<(.|n)*?>/;
         var result = strHTML.replace(regex, “”);
         return result;
     }
 </script>

Pager Taglib in practice

Written by coregps on Friday, November 26th, 2004 in Java.

It was few days I’ve not written something here since I got my blog. I’m busy working with an e-business project which I come across the task of pagination. The client requires that he can skip any results page easily. I find that pager taglib is an excellent work. The following is my solution by using pager taglib.

<%@ page contentType=”text/html;charset=gb2312″ language=”java”%>
<%@ page import=”java.sql.*”%>
<%@ taglib uri=”

http://jsptags.com/tags/navigation/pager” prefix=”pg” %>
<%
String username = “…”;
String password = “…”;
String driver   = “com.mysql.jdbc.Driver”;
String surl      = “jdbc:mysql://host:3306/db?autoReconnect=true&useUnicode=true&characterEncoding=gb2312″;
try {
 Class.forName(driver); //Load Database Driver
} catch(java.lang.ClassNotFoundException e) {
 System.err.println(”DBConn():” + e.getMessage());
}

ResultSet rsUserInfo=null;
try {
 Connection conn = DriverManager.getConnection(surl, username, password); //Connect to DBMS
 Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
 rsUserInfo = stmt.executeQuery(”SELECT userid, username FROM userinfo”);
} catch(SQLException ex) {
 System.err.println(”executeQuery():” + ex.getMessage());
}%>
<%
int maxPageItems = 20;
%>
<pg:pager maxPageItems=”<%=maxPageItems%>” export=”currentPageNumber=pageNumber”>
  <table width=”95%” cellspacing=”1″ cellpadding=”0″ align=”center”>
  <tr>
    <td>ID</td>
    <td>Name</td>
  </tr>
  <%while (rsUserInfo.next()) {%>
    <pg:item>
     <tr>
       <td><%=rsUserInfo.getString(1)%></td>
       <td><%=rsUserInfo.getString(2)%></td>
     </tr>
    </pg:item>
  <%}%>
  </table>
  <table width=100% cellpadding=2 cellspacing=0 border=0 bgcolor=e3e9f8>
  <form method=”get”>
  <tr><td align=right nowrap width=1%><font face=arial size=-1>
  <pg:index export=”total=pageCount”>
      <pg:page export=”pageNumber”>
          Results Page:<%= pageNumber %> / <%= total %>
      </pg:page>
     
      <pg:first export=”url” unless=”current”>
          &nbsp;<b><a href=”<%= url %>”>First</a></b>&nbsp;|
      </pg:first>
     
      <pg:prev export=”url,first,last”>
          <b><a href=”<%= url %>”>Prev</a></b>
      </pg:prev>
     
      <pg:next export=”url,first,last”>
          |&nbsp;<b><a href=”<%= url %>”>Next</a></b>
      </pg:next>
     
      <pg:last export=”url”>
          |&nbsp;<b><a href=”<%= url %>”>Last</a></b>
      </pg:last>
     
      &nbsp;Skip To:<select name=”pager.offset” onchange=”submit();”>
      <%
        for (int i = 1; i <= total.intValue(); i++) {%>
        <option value=”<%=(i -1) * maxPageItems%>” <%=i==currentPageNumber.intValue()?”selected”:”"%>> <%=i%> </option><%
        }
      %>
      </select>
      &nbsp;&nbsp;</font></td></tr></form>
  </table>
  </pg:index>
</pg:pager> 

Forcing a long words to wrap in table cell

Written by coregps on Wednesday, November 24th, 2004 in General.

One option is to apply the “word-wrap:break-word;” or “word-break;break-all;” css property to your table cell.

<td style=”word-wrap:break-word;“>
veryveryveryveryveryveryveryveryveryveryverylongtext
</td>

or

<td style=”word-break:break-all;“>
veryveryveryveryveryveryveryveryveryveryverylongtext
</td>

First Issue of online Red Hat Magazine is out

Written by coregps on Sunday, November 21st, 2004 in Linux.

The first online issue of Red Hat Magazine is out. I enjoy each article in it esspecially about technology. Thans to Red Hat for their excellent work. You can read it online http://www.redhat.com/magazine/.

A wolf coming from the north…

Written by coregps on Saturday, November 13th, 2004 in General.

A wolf coming from the north, it is running forever….  From now on, it will leave its track here.

Some notes about RSS

Written by coregps on Thursday, November 11th, 2004 in General.

I’m interested in RSS especially in recent days. The following is some notes about rss:

RSS is a file format designed to make it easy to use the information published on web sites.RSS is an acronym for Really Simple Syndication. It can be used in many ways, but the most common application is for use in software known as news readers or news aggregators. These are dedicated programs which allow you to read RSS files.

Atom is an emerging syndication format for newsfeeds, an attempt to evolve from and improve on the current RSS scene.

OPML is a file format that can be used to import and export subscription lists between programs that read RSS files, such as feed readers and aggregators. It provides a very interesting way to share your favorite RSS sites with your friends.



Site Navigation