Entire cUser class
public cUser(Connection con, SQLParam param, long UserID){
Statement stmt = null;
try {
System.out.println("cUser.
stmt = con.createStatement();
ResultSet rs=stmt.executeQuery(param
user_id = UserID;
user_name = rs.getString("user_name");
alias = rs.getString("alias");
user_bio = rs.getString("user_bio");
user_bio_short = rs.getString("user_bio_sho
} catch (SQLException e) {
System.out.println(e);
System.out.println("throwi
}
}
Main Topics
Browse All Topics





by: whitej8Posted on 2003-01-09 at 08:37:59ID: 7695114
Entire cUser class
earch.Sing leMetadata "; CHIVE="sea rch.Single MetadataAr chive"; XT="search .SingleMet adataNext" ; EV="search .SingleMet adataPrev" ; METADATA=" search.Sin gleAnnotat ionMetatda ta"; .dbsearche r";
onn"; otation.fi eldlist";
////////// ////////// //////// ter("formn ame")!=nul l?request. getParamet er("formna me"):""; ext/html") ;
;
otation")) { ng Annotation");
am,m_annot ation,fals e); //we cannot update from this form update is an admin feature and must use a different form
); est.getCon textPath() +"/error.j sp");
otation")) {
_id", m_annotation.getUserIDStri ng()); ent", m_annotation.element); e", m_annotation.value); id", m_annotation.oai_id);
, err); est.getCon textPath() + "/annotation.jsp");
ode(reques t.getParam eter("oai_ id")); d); on preview page");
aData(conn ,id);
ation.getA nnotationM etaData(co nn,id);
on preview page");
ON_SINGLE_ METADATA, metadata); ON_SINGLE_ ANNOTATION _METADATA, annotation);
ndex+1); ON_SINGLE_ METADATA_N EXT,next.i d); ON_SINGLE_ METADATA_N EXT,null);
ndex-1); ON_SINGLE_ METADATA_P REV,prev.i d); ON_SINGLE_ METADATA_P REV,null);
est.getCon textPath() +"/annotat ion_previe w.jsp");
Parameter( "user_id") ));
_name", mUser.user_name); _id", mUser.getUserIDString());
est.getCon textPath() +"/annotat ion.jsp?oa i_id=" + request.getParameter("oai_ id"));
////////// ////////// ////////
////////// ////////// ////////
ontext(); nectionSer vlet.KEY); onServlet not started");
l, dbtype); dList(); edFieldlis t();
NNOTATION_ CONN, conn);
NNOTATION_ FIELDS,fie ldlist);
d Annotations");
////////// ////////// ////////
////////// ////////// ////////
s("")) {
ls("")) {
notation.e lement); length); //get maxlength for element
("") || m_annotation.value.length( ) > maxlength) {
.toString( err.isEmpt y()));
package annotation;
import java.io.*;
import java.util.zip.*;
import java.util.*;
import java.lang.*;
import java.awt.event.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import db.*;
import ns.*;
import search.*;
import user.*;
public class Annotation extends HttpServlet
{
public final static String SESSION_SINGLE_METADATA="s
public final static String SESSION_SINGLE_METADATA_AR
public final static String SESSION_SINGLE_METADATA_NE
public final static String SESSION_SINGLE_METADATA_PR
public final static String SESSION_SINGLE_ANNOTATION_
public final static String SESSION_DBSEARCHER="search
public final static String SESSION_USER_INFO = "user.user_info";
public final static String APP_ANNOTATION_CONN = "annotation_connection";
private ConnectionPool cpool;
private static Connection conn;
private int dbtype;
private Vector fieldlist;
private Hashtable fieldhash;
private Hashtable err;
public final static String SESSION_CONN="annotation.c
public final static String APP_ANNOTATION_FIELDS="ann
//////////////////////////
public void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String formname=request.getParame
HttpSession session = request.getSession(true);
response.setContentType("t
conn=cpool.getConnection()
SQLParam param = new MySQLParam();
if (formname.equals("save_ann
// Annotation is ready to be saved
System.out.println("Starti
try{
cAnnotation m_annotation = new cAnnotation(request);
m_annotation.Save(conn,par
} catch (Exception e){
//redirect and display errors
System.out.println("Error"
response.sendRedirect(requ
return;
}
} else if (formname.equals("user_ann
// user has enter annotation and it is ready for preview
cAnnotation m_annotation = new cAnnotation(request);
//return current values to form
session.setAttribute("user
session.setAttribute("elem
session.setAttribute("valu
session.setAttribute("oai_
//is input valid
if (!isValid(m_annotation)){
session.setAttribute("err"
response.sendRedirect(requ
} else {
// get search results for annotated record then display annotation_preview.jsp
String id=null;
try
{
id=java.net.URLDecoder.dec
System.out.println("id="+i
}
catch (Exception e)
{
throw new ServletException("annotati
}
SearchParam search_param=null;
search_param = new BookBagParam(request);
DBSearcher os = new DBSearcher(search_param);
CMetaData metadata=DBSearcher.getMet
Vector annotation=DBSearcherAnnot
if (metadata==null)
{
throw new ServletException("annotati
}
session.setAttribute(SESSI
session.setAttribute(SESSI
int index = os.getIndex (id);
int hits = os.GetNumHits ();
if (index+1<hits)
{
CMetaData next=os.getMetaData(conn,i
session.setAttribute(SESSI
}
else
session.setAttribute(SESSI
if (index-1>=0)
{
CMetaData prev=os.getMetaData(conn,i
session.setAttribute(SESSI
}
else
{
session.setAttribute(SESSI
cpool.close(conn);
response.sendRedirect(requ
}
} //end validation
} else { //formname not set load annotation page for the first time
//TO DO test for user_id and oai_id
//get user name
user.SQLParam user_param = new user.MySQLParam();
cUser mUser = new cUser(conn, user_param, Long.parseLong(request.get
session.setAttribute("user
session.setAttribute("user
response.sendRedirect(requ
}
}
//////////////////////////
public void doPost (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
doGet(request,response);
}
//////////////////////////
public void init (ServletConfig config) throws ServletException
{
//Open DB Connectionafreader
ServletContext context=config.getServletC
Object o=context.getAttribute(Con
if (o==null){
throw new ServletException("Connecti
}
cpool=(ConnectionPool)o;
conn =(Connection) cpool.getConnection ();
dbtype=cpool.getDBType();
//Get field information for new annotations
AnnotationFieldReader afreader=new AnnotationFieldReader(cpoo
afreader.init();
fieldlist=afreader.getFiel
fieldhash=afreader.getHash
context.setAttribute(APP_A
context.setAttribute(APP_A
System.out.println("Starte
}
//////////////////////////
public void destroy()
{
if (cpool!=null)
cpool.destroy();
super.destroy();
}
//////////////////////////
public String getServletInfo() {
return "The Annotation Servlet";
}
public boolean isValid(cAnnotation m_annotation) {
if (err==null) err = new Hashtable();
err.clear(); //clear any previous errors
if (m_annotation.oai_id.equal
err.put("oai_id", "Fatal Error: No oai id");
}
if (m_annotation.element.equa
err.put("element", "Please select a field to annotate");
}
AFInfo af = (AFInfo)fieldhash.get(m_an
int maxlength = Integer.parseInt(af.field_
if (m_annotation.value.equals
err.put("value", "Annotations for " + af.field_label + " must be between 1 and " + maxlength + " characters.");
}
System.out.println(Boolean
return err.isEmpty();
}
}