Ejemplo n.º 1
0
  @Override
  protected void fillVoiceXmlDocument(
      Document document, Element formElement, VoiceXmlDialogueContext dialogueContext)
      throws VoiceXmlDocumentRenderingException {
    addVariableDeclarations(formElement, mVariables);

    Element blockElement = DomUtils.appendNewElement(formElement, BLOCK_ELEMENT);

    if (mScript != null) {
      Element scriptElement = DomUtils.appendNewElement(blockElement, SCRIPT_ELEMENT);
      DomUtils.appendNewText(scriptElement, mScript);
    }

    StringBuffer scriptBuffer = new StringBuffer();

    scriptBuffer.append(RIVR_SCOPE_OBJECT + ".addValueResult({");
    boolean first = true;
    for (VariableDeclaration variableDeclaration : mVariables) {
      if (!first) {
        scriptBuffer.append(", ");
      } else {
        first = false;
      }
      scriptBuffer.append("\"");
      scriptBuffer.append(variableDeclaration.getName());
      scriptBuffer.append("\": ");
      scriptBuffer.append("dialog.");
      scriptBuffer.append(variableDeclaration.getName());
    }
    scriptBuffer.append("});");

    createScript(blockElement, scriptBuffer.toString());
    createGotoSubmit(blockElement);
  }
Ejemplo n.º 2
0
 private String getMD5(String md5) {
   try {
     MessageDigest md = MessageDigest.getInstance("MD5");
     byte[] array = md.digest(md5.getBytes());
     StringBuffer sb = new StringBuffer();
     for (int i = 0; i < array.length; ++i) {
       sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3));
     }
     return sb.toString();
   } catch (java.security.NoSuchAlgorithmException e) {
     throw new RuntimeException(e);
   }
 }
Ejemplo n.º 3
0
  // 对接收的(click,mouseover,scroll)数据进行处理,并存入events
  @Path("/events/store")
  @POST
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.TEXT_PLAIN)
  public void StoreEvents(String data, @Context HttpServletRequest request)
      throws UnsupportedEncodingException, IOException {

    String schema =
        "browser,os,url,ip,loadtime,time,element,id,text,semantics,event,left,top,height,width";
    HashSet<String> hs_log = new HashSet<String>();
    // System.out.println(data);
    // 读取获得的json数据
    JsonReader reader = Json.createReader(new StringReader(data));
    JsonObject jsonobj = reader.readObject();
    reader.close();
    // 获取来源IP,读取url,time,events等信息
    String ip = "";
    String browser = "";
    String os = "";
    String url = "";
    String loadtime = "";
    ip = getRemoteHost(request);
    browser = jsonobj.getString("browser");
    os = jsonobj.getString("os");
    url = jsonobj.getString("url").split("\\?")[0];
    url = url.replace("http://", "").replace("HTTP://", "").replace("https://", "");
    loadtime = jsonobj.getString("loadtime");
    JsonArray events = jsonobj.getJsonArray("events");

    // 整理数据
    for (int i = 0; i < events.size(); i++) {
      JsonObject obj = events.getJsonObject(i);
      StringBuffer elebuf = new StringBuffer();
      // 先存储头信息
      elebuf.append(browser);
      elebuf.append(",");
      elebuf.append(os);
      elebuf.append(",");
      elebuf.append(url);
      elebuf.append(",");
      elebuf.append(ip);
      elebuf.append(",");
      elebuf.append(loadtime);
      elebuf.append(",");
      // 各个事件的信息
      elebuf.append(obj.getString("time"));
      elebuf.append(",");
      elebuf.append(obj.getString("element"));
      elebuf.append(",");
      try {
        elebuf.append(obj.getString("id"));
      } catch (Exception e) {
        elebuf.append("");
      }
      elebuf.append(",");
      elebuf.append(obj.getString("text"));
      elebuf.append(",");
      // 在这里可以引入SVM标注,标注后在存入数据库
      // 或者可以读取数据在标注
      elebuf.append(""); // semantics,标注后更新
      elebuf.append(",");
      elebuf.append(obj.getString("event"));
      elebuf.append(",");
      elebuf.append(obj.getString("left"));
      elebuf.append(",");
      elebuf.append(obj.getString("top"));
      elebuf.append(",");
      elebuf.append(obj.getString("height"));
      elebuf.append(",");
      elebuf.append(obj.getString("width"));
      // 添加set中,去重
      hs_log.add(elebuf.toString());
    }

    eventsDAO.insertEvents(schema, hs_log);
    //  return "Post Data Success!";
  }
Ejemplo n.º 4
0
  // 对接收的表单数据进行处理,并存入form
  @Path("/form/store")
  @POST
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.TEXT_PLAIN)
  public void StoreForm(String data, @Context HttpServletRequest request)
      throws UnsupportedEncodingException, IOException {
    String schema = "";
    //  System.out.println(data);
    // 读取获得的json数据
    JsonReader reader = Json.createReader(new StringReader(data));
    JsonObject jsonobj = reader.readObject();
    reader.close();
    // 获取来源IP,读取url,time,events等信息
    String ip = "";
    String browser = "";
    String os = "";
    String url = "";
    String loadtime = "";
    String focusTime = "";
    String blurTime = "";
    String text = "";
    String type = "";
    String id = "";
    String name = "";
    String costTime = "";
    ip = getRemoteHost(request);
    browser = jsonobj.getString("browser");
    os = jsonobj.getString("os");
    url = jsonobj.getString("url").split("\\?")[0];
    url = url.replace("http://", "").replace("HTTP://", "").replace("https://", "");
    loadtime = jsonobj.getString("loadTime");
    focusTime = jsonobj.getString("focusTime");
    blurTime = jsonobj.getString("blurTime");
    text = jsonobj.getString("text");
    type = jsonobj.getString("type");
    id = jsonobj.getString("id");
    name = jsonobj.getString("name");
    costTime = jsonobj.getString("costTime");

    schema = "browser,os,url,loadTime,blurTime,id,name,focusTime,text,type,costTime,ip";
    StringBuffer elebuf = new StringBuffer();
    // 先存储头信息
    elebuf.append(browser);
    elebuf.append(",");
    elebuf.append(os);
    elebuf.append(",");
    elebuf.append(url);
    elebuf.append(",");
    elebuf.append(loadtime);
    elebuf.append(",");
    elebuf.append(blurTime + ",");
    elebuf.append(id + ",");
    elebuf.append(name + ",");
    elebuf.append(focusTime + ",");
    elebuf.append(text + ",");
    elebuf.append(type + ",");
    elebuf.append(costTime + ",");
    elebuf.append(ip);
    formDAO.insertForm(schema, elebuf.toString());
    //  return "Post Data Success!";
  }