/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at .
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox ,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.db;
import java.sql.*;
import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.htmlcheck.Rewriter;
import com.silverwrist.venice.htmlcheck.RewriterServices;
import com.silverwrist.venice.htmlcheck.MarkupData;
import com.silverwrist.venice.core.IDUtils;
public class UserNameRewriter implements Rewriter
{
/*--------------------------------------------------------------------------------
* Static data members
*--------------------------------------------------------------------------------
*/
public static final String URI_PREFIX = "x-userlink:";
/*--------------------------------------------------------------------------------
* Attributes
*--------------------------------------------------------------------------------
*/
private DataPool datapool;
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
public UserNameRewriter(DataPool datapool)
{
this.datapool = datapool;
} // end constructor
/*--------------------------------------------------------------------------------
* Implementations from interface Rewriter
*--------------------------------------------------------------------------------
*/
public String getName()
{
return null;
} // end getName
public MarkupData rewrite(String data, RewriterServices svc)
{
if (StringUtil.isStringEmpty(data) || (data.length()>64) || !(IDUtils.isValidVeniceID(data)))
return null;
Connection conn = null;
try
{ // get a database connection and create a statement
conn = datapool.getConnection();
Statement stmt = conn.createStatement();
StringBuffer sql = new StringBuffer("SELECT uid FROM users WHERE username = '");
sql.append(SQLUtil.encodeString(data)).append("';");
ResultSet rs = stmt.executeQuery(sql.toString());
if (!(rs.next()))
return null; // not found
} // end try
catch (SQLException e)
{ // if we hit a database error, just return null...
return null;
} // end catch
finally
{ // make sure and release the connection before we go
if (conn!=null)
datapool.releaseConnection(conn);
} // end finally
// build the markup data and return it
StringBuffer open_a = new StringBuffer("');
return new MarkupData(open_a.toString(),data,"");
} // end rewrite
} // end class UserNameRewriter