00001 00009 package com.rosalfred.core.ia; 00010 00011 import com.rosalfred.core.ia.rivescript.RiveScript; 00012 00019 public class RsContext { 00020 private final RiveScript rs; 00021 00022 public final static String FIND = "find"; 00023 public final static String FIND2 = "find2"; 00024 public final static String FIND3 = "find3"; 00025 public final static String FINDING = "finding"; 00026 public final static String PAGE = "page"; 00027 public final static String LAUNCH = "launch"; 00028 public final static String COUNT = "count"; 00029 public final static String RESUME = "resume"; 00030 00031 int step = 5; 00032 int page = 0; 00033 int count = -1; 00034 //args = {} 00035 00036 public RsContext(RiveScript riveScript) { 00037 this.rs = riveScript; 00038 } 00039 00040 public String getUserParam(String name) { 00041 String user = this.rs.getCurrentUser(); 00042 return this.rs.getUservar(user, name); 00043 } 00044 00045 public void setUserParam(String name, String value) { 00046 String user = this.rs.getCurrentUser(); 00047 this.rs.setUservar(user, name, value); 00048 } 00049 00050 public int getIndexItemPage() { 00051 return (this.step * this.page); 00052 } 00053 00054 public int getStep() { 00055 return this.step; 00056 } 00057 00058 public void checkPage() { 00059 String value = this.getUserParam(PAGE); 00060 if (value != null && !value.equals("")) { 00061 this.page = Integer.parseInt(value); 00062 00063 // Check negatif value 00064 if (this.page < 0) { 00065 this.page = 0; 00066 } 00067 00068 // Check min step 00069 if (this.count > 0 && this.count < this.step) { 00070 this.page = 0; 00071 } 00072 } 00073 } 00074 00075 public static String normalize(String value) { 00076 return value.replace("/[^A-Za-z0-9 ]/", ""); 00077 } 00078 }