コード例 #1
0
ファイル: QQImageUtil.java プロジェクト: tasfe/jWebQQ
  public JSONArray convertHTMLToFlag(HTMLDocument htmlDoc) {
    boolean isExistFace = false;
    ElementIterator it = new ElementIterator(htmlDoc);
    Element element;
    while ((element = it.next()) != null) {
      if (element.getName().equals(HTML.Tag.IMG.toString())) {
        isExistFace = true;
        try {
          String name = element.getAttributes().getAttribute(HTML.Attribute.NAME).toString();
          // String src = element.getAttributes().getAttribute(HTML.Attribute.SRC).toString();

          int offset = element.getStartOffset();
          htmlDoc.replace(offset, element.getEndOffset() - offset, "~face:" + name + "~", null);

        } catch (BadLocationException ex) {
          Logger.getLogger(QQImageUtil.class.getName()).log(Level.SEVERE, null, ex);
        }
      }
    }
    String text = null;
    try {
      text = htmlDoc.getText(0, htmlDoc.getLength());
      htmlDoc.remove(0, htmlDoc.getLength());
    } catch (BadLocationException ex) {
      Logger.getLogger(QQImageUtil.class.getName()).log(Level.SEVERE, null, ex);
    }
    if (isExistFace) {
      text = text.replaceFirst("\\n", "");
    }
    // Log.println(text);
    JSONArray msg = new JSONArray();
    String[] arr = text.split("~");
    for (int i = 0; i < arr.length; i++) {
      String temp = arr[i];
      // Log.println(temp);
      if (temp.startsWith("face:")) {
        String[] tempArray = temp.split(":");
        JSONArray face = new JSONArray();
        face.add(tempArray[0]);
        String regex = ",([0-9]*):" + tempArray[1] + ",";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(faceFlag);
        String result = null;
        if (m.find()) {
          result = m.group(1);
        } else {
          result = tempArray[1];
        }
        int faceNumber = Integer.parseInt(result);
        face.add(faceNumber);
        msg.add(face);
      } else {
        msg.add(temp);
      }
    }

    // Log.println(msg);
    return msg;
  }
コード例 #2
0
  @SuppressWarnings("unused")
  @RequestMapping(method = RequestMethod.GET, value = "/resultado.html")
  public void resultadoJSON(
      @RequestParam("total") int total,
      HttpServletRequest request,
      HttpServletResponse response,
      ModelMap model)
      throws UnsupportedEncodingException, JSONException {

    PesquisaForm form = new PesquisaForm();
    Usuario obj = super.getUsuarioLogado();

    Carteira carteira = carteiraService.selectById(obj.getIdCarteira());

    form.setCarteira(carteira);
    form.setPapel(obj.getUsuPapel());
    form.setTotal(total);

    PrintWriter writer = null;

    try {
      writer = response.getWriter();
    } catch (IOException ex) {
      System.err.println(
          PesquisaController.class.getName() + "ocorreu uma exceção: " + ex.getMessage());
    }

    String[] cols = {
      "details.idDocumentoDetalhes",
      "details.tipoDocumento.tipoDocumentoNome",
      "details.nrProtocolo",
      "details.nrDocumento",
      "details.assunto",
      "details.dataEntSistema"
    };

    JSONObject result = new JSONObject();
    JSONArray array = new JSONArray();
    int amount = 5;
    int start = 0;
    int echo = 0;
    int col = 0;

    String id = "";
    String tipo = "";
    String protocolo = "";
    String nrDoc = "";
    String assunto = "";
    String data = "";

    String dir = "asc";
    String sStart = request.getParameter("iDisplayStart");
    String sAmount = request.getParameter("iDisplayLength");
    String sEcho = request.getParameter("sEcho");
    String sCol = request.getParameter("iSortCol_0");
    String sdir = request.getParameter("sSortDir_0");
    boolean bServerSide =
        (((String) request.getParameter("bServerSide")).equals("true") ? true : false);
    form.setServerSide(bServerSide);

    // id = request.getParameter("sSearch_0");

    tipo = request.getParameter("sSearch_0");
    if (tipo != null) form.setTipoDocumento(tipo);

    protocolo = request.getParameter("sSearch_1");
    if (protocolo != null) form.setNrProtocol(protocolo);

    nrDoc = request.getParameter("sSearch_2");
    if (nrDoc != null) form.setNrDocumento(nrDoc);

    assunto = request.getParameter("sSearch_3");
    if (assunto != null) form.setAssunto(assunto);

    data = request.getParameter("sSearch_4");
    if (data != null) form.setDataEntSistema(DataTimeUtil.convertKeyUpFormatBrazilToUS(data));

    if (sStart != null) {
      start = Integer.parseInt(sStart);
      if (start < 0) start = 0;
    }
    form.setStart(start);

    if (sAmount != null) {
      amount = Integer.parseInt(sAmount);
      if (amount < 5 || amount > 100) amount = 10;
    }
    form.setAmount(amount);

    if (sEcho != null) {
      echo = Integer.parseInt(sEcho);
    }
    form.setEcho(echo);

    if (sCol != null) {
      col = Integer.parseInt(sCol);
      if (col < 0 || col > 6) col = 0;
    }
    form.setCol(col);

    if (sdir != null) {
      if (!sdir.equals("asc")) dir = "desc";
    }
    form.setDir(dir);

    String colName = cols[col];
    form.setColName(colName);

    String searchTerm = request.getParameter("sSearch");
    if (searchTerm != null)
      form.setSearchTerm(DataTimeUtil.convertKeyUpFormatBrazilToUS(searchTerm));

    int totalAfterFilter = total;

    List<DocumentoCompleto> docs = (List<DocumentoCompleto>) documentoService.returnSearch(form);

    if (searchTerm != "" || form.getIndividualSearch() != "")
      totalAfterFilter = docs.size() > 0 ? docs.get(0).getTotal() : 0;

    /*for( int i=0; i<docs.size(); i++ ){
    	DocumentoCompleto dc = docs.remove(i);

    	JSONArray ja = new JSONArray();
    	ja.put(String.valueOf(dc.getDocumentoDetalhes().getIdDocumentoDetalhes()));
    	ja.put(dc.getDocumentoDetalhes().getTipoDocumento().getTipoDocumentoNome());
    	ja.put(dc.getDocumentoDetalhes().getNrProtocolo());
    	ja.put(dc.getDocumentoDetalhes().getNrDocumento());
    	ja.put(dc.getDocumentoDetalhes().getAssunto());
    	ja.put(DataTimeUtil.getBrazilFormatDataHora(dc.getDocumentoDetalhes().getDataEntSistema()));
    	array.put(ja);
    }*/

    Iterator<DocumentoCompleto> ite = docs.iterator();

    while (ite.hasNext()) {
      DocumentoCompleto dc = ite.next();

      JSONArray ja = new JSONArray();
      ja.put(String.valueOf(dc.getDocumentoDetalhes().getIdDocumentoDetalhes()));
      ja.put(dc.getDocumentoDetalhes().getTipoDocumento().getTipoDocumentoNome());
      ja.put(dc.getDocumentoDetalhes().getNrProtocolo());
      ja.put(dc.getDocumentoDetalhes().getNrDocumento());
      ja.put(dc.getDocumentoDetalhes().getAssunto());
      ja.put(DataTimeUtil.getBrazilFormatDataHora(dc.getDocumentoDetalhes().getDataEntSistema()));
      array.put(ja);
    }

    docs = null;

    response.setHeader("Content-Type", "application/json; charset=ISO-8859-1");

    result.put("iTotalRecords", total);
    result.put("iTotalDisplayRecords", totalAfterFilter);
    result.put("aaData", array);

    writer.print(result);

    writer.flush();
    writer.close();
  }