Пример #1
0
  private boolean delete(String from) {
    if (null != from && from.length() == 3 && from.charAt(1) == '-') {
      char from_start = from.charAt(0);
      char from_end = from.charAt(2);
      for (int i = 0; i < sb_.length(); ++i) {
        char current_char = sb_.charAt(i);
        if (current_char >= from_start && current_char <= from_end) {
          sb_.deleteCharAt(i);
          --i;
        }
      }
      return true;
    } else {
      boolean changed = false;
      for (int i = 0; i < from.length(); i++) {
        int index = sb_.toString().indexOf(from.charAt(i));
        while (index >= 0) {
          sb_.deleteCharAt(index);
          changed = true;

          index = sb_.toString().indexOf(from.charAt(i));
        }
      }

      return changed;
    }
  }
Пример #2
0
 @Override
 public String toString() {
   StringBuffer buf = new StringBuffer("[");
   // 玩家性别
   buf.append("sex:" + sex + ",");
   // 衣服模版ID
   buf.append("clothingmodid:" + clothingmodid + ",");
   // 武器模版ID
   buf.append("weaponmodid:" + weaponmodid + ",");
   // 武器强化等级
   buf.append("weaponStreng:" + weaponStreng + ",");
   // 坐骑模版ID
   buf.append("horsemodid:" + horsemodid + ",");
   // 坐骑模版ID
   buf.append("horseweaponmodid:" + horseweaponmodid + ",");
   // 头像模板ID
   buf.append("avatarid:" + avatarid + ",");
   // 弓箭模板ID
   buf.append("arrowid:" + arrowid + ",");
   //		//暗器模版ID
   //		buf.append("hiddenweaponmodid:" + hiddenweaponmodid +",");
   //		//坐骑锻骨草使用数量
   //		buf.append("horseduangu:" + horseduangu +",");
   // 装备列表信息
   buf.append("equips:{");
   for (int i = 0; i < equips.size(); i++) {
     buf.append(equips.get(i).toString() + ",");
   }
   if (buf.charAt(buf.length() - 1) == ',') buf.deleteCharAt(buf.length() - 1);
   buf.append("},");
   if (buf.charAt(buf.length() - 1) == ',') buf.deleteCharAt(buf.length() - 1);
   buf.append("]");
   return buf.toString();
 }
Пример #3
0
 /**
  * Clean string.
  *
  * @param str the str
  * @return the string
  */
 public static String cleanString(String str) {
   Transliterator accentsconverter =
       Transliterator.getInstance("Latin; NFD; [:Nonspacing Mark:] Remove; NFC;");
   str = accentsconverter.transliterate(str);
   // the character ? seems to not be changed to d by the transliterate
   // function
   StringBuffer cleanedStr = new StringBuffer(str.trim());
   // delete special character
   for (int i = 0; i < cleanedStr.length(); i++) {
     char c = cleanedStr.charAt(i);
     if (c == ' ') {
       if (i > 0 && cleanedStr.charAt(i - 1) == '-') {
         cleanedStr.deleteCharAt(i--);
       } else {
         c = '-';
         cleanedStr.setCharAt(i, c);
       }
       continue;
     }
     if (i > 0 && !(Character.isLetterOrDigit(c) || c == '-')) {
       cleanedStr.deleteCharAt(i--);
       continue;
     }
     if (i > 0 && c == '-' && cleanedStr.charAt(i - 1) == '-') cleanedStr.deleteCharAt(i--);
   }
   return cleanedStr.toString().toLowerCase();
 }
Пример #4
0
 /**
  * suffix stripping (stemming) on the current term. The stripping is reduced to the seven "base"
  * suffixes "e", "s", "n", "t", "em", "er" and * "nd", from which all regular suffixes are build
  * of. The simplification causes some overstemming, and way more irregular stems, but still
  * provides unique. discriminators in the most of those cases. The algorithm is context free,
  * except of the length restrictions.
  */
 private void strip(StringBuffer buffer) {
   boolean doMore = true;
   while (doMore && buffer.length() > 3) {
     if ((buffer.length() + substCount > 5)
         && buffer.substring(buffer.length() - 2, buffer.length()).equals("nd")) {
       buffer.delete(buffer.length() - 2, buffer.length());
     } else if ((buffer.length() + substCount > 4)
         && buffer.substring(buffer.length() - 2, buffer.length()).equals("em")) {
       buffer.delete(buffer.length() - 2, buffer.length());
     } else if ((buffer.length() + substCount > 4)
         && buffer.substring(buffer.length() - 2, buffer.length()).equals("er")) {
       buffer.delete(buffer.length() - 2, buffer.length());
     } else if (buffer.charAt(buffer.length() - 1) == 'e') {
       buffer.deleteCharAt(buffer.length() - 1);
     } else if (buffer.charAt(buffer.length() - 1) == 's') {
       buffer.deleteCharAt(buffer.length() - 1);
     } else if (buffer.charAt(buffer.length() - 1) == 'n') {
       buffer.deleteCharAt(buffer.length() - 1);
     }
     // "t" occurs only as suffix of verbs.
     else if (buffer.charAt(buffer.length() - 1) == 't') {
       buffer.deleteCharAt(buffer.length() - 1);
     } else {
       doMore = false;
     }
   }
 }
Пример #5
0
  /**
   * 获取插入的sql语句
   *
   * @return
   */
  public static SqlInfo buildInsertSql(Object entity) {

    List<KeyValue> keyValueList = getSaveKeyValueListByEntity(entity);

    StringBuffer strSQL = new StringBuffer();
    SqlInfo sqlInfo = null;
    if (keyValueList != null && keyValueList.size() > 0) {

      sqlInfo = new SqlInfo();

      strSQL.append("INSERT INTO ");
      strSQL.append(TableInfo.get(entity.getClass()).getTableName());
      strSQL.append(" (");
      for (KeyValue kv : keyValueList) {
        strSQL.append(kv.getKey()).append(",");
        sqlInfo.addValue(kv.getValue());
      }
      strSQL.deleteCharAt(strSQL.length() - 1);
      strSQL.append(") VALUES ( ");

      int length = keyValueList.size();
      for (int i = 0; i < length; i++) {
        strSQL.append("?,");
      }
      strSQL.deleteCharAt(strSQL.length() - 1);
      strSQL.append(")");

      sqlInfo.setSql(strSQL.toString());
    }

    return sqlInfo;
  }
Пример #6
0
  /**
   * Writes a pattern set into a string buffer.
   *
   * @param separator the character separating values
   * @param numbers if true, pattern numbers are added as single line comments (starting with '#')
   * @param split if true, input values and target values appear on separate lines
   * @return the patterns as string buffer
   */
  public StringBuffer writeValues(char separator, boolean numbers, boolean split) {

    StringBuffer buf = new StringBuffer();

    for (int i = 0; i < size(); i++) { // write patterns
      if (numbers) buf.append("#").append(i + 1).append('\n');
      List<Double> pat = getInputs().get(i); // an input pattern
      for (Double val : pat) // write values
      buf.append(val).append(separator);
      if (split) {
        buf.deleteCharAt(buf.length() - 1); // remove last separator
        buf.append('\n');
      }
      if (i < getTargets().size()) { // there may be no targets
        pat = getTargets().get(i); // a target pattern
        if (pat != null) { // may be null
          for (Double val : pat) // write values
          buf.append(val).append(separator);
          buf.deleteCharAt(buf.length() - 1); // remove last separator
          buf.append('\n');
        }
      }
    }
    return buf;
  }
 /**
  * Delete the character preceding the insertion point in the composed text. If the insertion point
  * is not at the end of the composed text and the preceding text is "\\u" or "\\U", ring the bell.
  */
 private void deletePreviousCharacter() {
   if (insertionPoint == 2) {
     if (buffer.length() == 2) {
       cancelComposition();
     } else {
       // Do not allow deletion of the leading "\\u" or "\\U" if there
       // are other digits in the composed text.
       beep();
     }
   } else if (insertionPoint == 8) {
     if (buffer.length() == 8) {
       if (format == SURROGATE_PAIR) {
         buffer.deleteCharAt(--insertionPoint);
       }
       buffer.deleteCharAt(--insertionPoint);
       sendComposedText();
     } else {
       // Do not allow deletion of the second "\\u" if there are other
       // digits in the composed text.
       beep();
     }
   } else {
     buffer.deleteCharAt(--insertionPoint);
     if (buffer.length() == 0) {
       sendCommittedText();
     } else {
       sendComposedText();
     }
   }
 }
  /**
   * Encodes a list of queue items into JSON text
   *
   * @param items
   * @return
   */
  public static StringBuffer encode(List items) {
    StringBuffer json = new StringBuffer();
    Iterator itr = items.iterator();
    Calendar current = Calendar.getInstance();
    current.get(Calendar.DATE);
    if (items.size() <= 0) json.append("{}");
    else {
      while (itr.hasNext()) {
        QueueItem it = (QueueItem) itr.next();
        PersonName name = it.patient.getPersonName();
        json.append("{");

        json.append("\"status\":\"").append(it.status).append("\",");
        json.append("\"patientIdentifier\":\"")
            .append(it.patient.getPatientIdentifier())
            .append("\",");
        json.append("\"Procedure\":\"").append(it.getProcedureTitle()).append("\",");
        json.append("\"age\":\"").append(it.patient.getAge(null)).append("\",");
        json.append("\"sex\":\"").append(it.patient.getGender()).append("\",");
        json.append("\"dateCreated\":\"").append(it.dateCreated).append("\",");
        json.append("\"name\":{");
        boolean hasContent = addOptionalElement(json, "prefix", name.getPrefix());
        hasContent |= addOptionalElement(json, "givenName", name.getGivenName());
        hasContent |= addOptionalElement(json, "familyName", name.getFamilyName());
        if (hasContent)
          json.deleteCharAt(json.length() - 1); // delete last comma if at least something was added
        json.append("}");
        json.append(",\"patientId\":\"").append(it.patient.getPatientId()).append("\",");
        json.append("\"encounterId\":\"").append(it.encounter.getEncounterId()).append("\"");
        json.append("},");
      }
      json.deleteCharAt(json.length() - 1);
    }
    return json;
  }
Пример #9
0
 @Override
 public String toString() {
   StringBuffer buf = new StringBuffer("[");
   // 信息类型 1-错误, 2-提示, 3-成功 (暂定,具体见文档)
   buf.append("type:" + type + ",");
   // 信息内容
   if (this.content != null) buf.append("content:" + content.toString() + ",");
   // 付费引导类型
   buf.append("subtype:" + subtype + ",");
   // 数值
   buf.append("values:{");
   for (int i = 0; i < values.size(); i++) {
     buf.append(values.get(i).toString() + ",");
   }
   if (buf.charAt(buf.length() - 1) == ',') buf.deleteCharAt(buf.length() - 1);
   buf.append("},");
   // 物品内容
   buf.append("goodsinfos:{");
   for (int i = 0; i < goodsinfos.size(); i++) {
     buf.append(goodsinfos.get(i).toString() + ",");
   }
   if (buf.charAt(buf.length() - 1) == ',') buf.deleteCharAt(buf.length() - 1);
   buf.append("},");
   if (buf.charAt(buf.length() - 1) == ',') buf.deleteCharAt(buf.length() - 1);
   buf.append("]");
   return buf.toString();
 }
Пример #10
0
 protected String cleanValue(String value) {
   LOG.debug("cleanValue value = " + value);
   int i = value.indexOf('\n');
   if (i == -1) {
     i = value.indexOf('\r');
   }
   if (i != -1) {
     LOG.debug("cleanValue removing newline");
     StringBuffer sb = new StringBuffer(value);
     i = sb.indexOf("\n");
     while (i != -1) {
       sb.deleteCharAt(i);
       i = sb.indexOf("\n");
     }
     i = sb.indexOf("\r");
     while (i != -1) {
       sb.deleteCharAt(i);
       i = sb.indexOf("\r");
     }
     LOG.debug("cleanValue value ut = " + sb.toString());
     return sb.toString();
   } else {
     LOG.debug("cleanValue not modified");
     return value;
   }
 }
Пример #11
0
 @Override
 public String buildSaveSql(
     String sql, List<ColumnMeta> list, String[] primaryKeyNames, Map<String, Object> beanMap)
     throws SQLException {
   String insertSql = "";
   // 用于保存值不为null的字段
   List<ColumnMeta> valueList = new ArrayList<ColumnMeta>();
   // 获得表中一共有几个字段
   int columnCount = list.size();
   // 组装字段
   StringBuffer columnBuffer = new StringBuffer(sql + "(");
   StringBuffer valueBuffer = new StringBuffer(" values(");
   for (int i = 0; i < columnCount; i++) {
     ColumnMeta cm = list.get(i);
     // 获取列名
     String columnName = cm.getColumnName();
     if (beanMap.get(columnName) == null) {
       continue;
     }
     valueList.add(cm);
     columnBuffer.append(columnName + ",");
     if (cm.isAutoIncrement()) {
       valueBuffer.append("null,");
     } else {
       valueBuffer.append("?,");
     }
   }
   beanMap.put("VALUE_LIST", valueList);
   columnBuffer.deleteCharAt(columnBuffer.lastIndexOf(","));
   columnBuffer.append(")");
   valueBuffer.deleteCharAt(valueBuffer.lastIndexOf(","));
   valueBuffer.append(")");
   insertSql = columnBuffer.toString() + valueBuffer.toString();
   return insertSql;
 }
 @Override
 public String toString() {
   StringBuffer buf = new StringBuffer("[");
   // 角色id
   buf.append("playerId:" + playerId + ",");
   // 角色经验
   buf.append("exp:" + exp + ",");
   // 角色真气
   buf.append("zhenqi:" + zhenqi + ",");
   // 头象ID
   buf.append("avatar:" + avatar + ",");
   // 当前章节
   buf.append("chapter:" + chapter + ",");
   // 战场声望
   buf.append("prestige:" + prestige + ",");
   // 装备信息
   if (this.equip != null) buf.append("equip:" + equip.toString() + ",");
   // 宝石信息
   if (this.gem != null) buf.append("gem:" + gem.toString() + ",");
   // 技能信息
   if (this.skills != null) buf.append("skills:" + skills.toString() + ",");
   // 属性列表
   buf.append("attributes:{");
   for (int i = 0; i < attributes.size(); i++) {
     buf.append(attributes.get(i).toString() + ",");
   }
   if (buf.charAt(buf.length() - 1) == ',') buf.deleteCharAt(buf.length() - 1);
   buf.append("},");
   // 战斗力
   buf.append("fightPower:" + fightPower + ",");
   // 坐骑装备
   if (this.horseEquip != null) buf.append("horseEquip:" + horseEquip.toString() + ",");
   // 坐骑技能
   if (this.horseSkill != null) buf.append("horseSkill:" + horseSkill.toString() + ",");
   // 宠物信息
   if (this.pets != null) buf.append("pets:" + pets.toString() + ",");
   // 王城BUFFid
   buf.append("kingcitybuffid:" + kingcitybuffid + ",");
   // VIPid
   buf.append("vipid:" + vipid + ",");
   // 消耗钻石
   buf.append("costgold:" + costgold + ",");
   // 弓箭信息
   if (this.arrowinfo != null) buf.append("arrowinfo:" + arrowinfo.toString() + ",");
   // 骑兵技能列表
   if (this.horseWeaponSkill != null)
     buf.append("horseWeaponSkill:" + horseWeaponSkill.toString() + ",");
   // 暗器技能列表
   if (this.hiddenWeaponSkill != null)
     buf.append("hiddenWeaponSkill:" + hiddenWeaponSkill.toString() + ",");
   // 境界等级
   buf.append("realmlevel:" + realmlevel + ",");
   // 境界强化等级
   buf.append("realmintensifylevel:" + realmintensifylevel + ",");
   if (buf.charAt(buf.length() - 1) == ',') buf.deleteCharAt(buf.length() - 1);
   buf.append("]");
   return buf.toString();
 }
Пример #13
0
 /**
  * Do some substitutions for the term to reduce overstemming:
  *
  * <p>- Substitute Umlauts with their corresponding vowel: äöü -> aou, "ß" is substituted by "ss"
  * - Substitute a second char of a pair of equal characters with an asterisk: ?? -> ?* -
  * Substitute some common character combinations with a token: sch/ch/ei/ie/ig/st -> $/§/%/&/#/!
  */
 private void substitute(StringBuffer buffer) {
   substCount = 0;
   for (int c = 0; c < buffer.length(); c++) {
     // Replace the second char of a pair of the equal characters with an asterisk
     if (c > 0 && buffer.charAt(c) == buffer.charAt(c - 1)) {
       buffer.setCharAt(c, '*');
     }
     // Substitute Umlauts.
     else if (buffer.charAt(c) == 'ä') {
       buffer.setCharAt(c, 'a');
     } else if (buffer.charAt(c) == 'ö') {
       buffer.setCharAt(c, 'o');
     } else if (buffer.charAt(c) == 'ü') {
       buffer.setCharAt(c, 'u');
     }
     // Fix bug so that 'ß' at the end of a word is replaced.
     else if (buffer.charAt(c) == 'ß') {
       buffer.setCharAt(c, 's');
       buffer.insert(c + 1, 's');
       substCount++;
     }
     // Take care that at least one character is left left side from the current one
     if (c < buffer.length() - 1) {
       // Masking several common character combinations with an token
       if ((c < buffer.length() - 2)
           && buffer.charAt(c) == 's'
           && buffer.charAt(c + 1) == 'c'
           && buffer.charAt(c + 2) == 'h') {
         buffer.setCharAt(c, '$');
         buffer.delete(c + 1, c + 3);
         substCount = +2;
       } else if (buffer.charAt(c) == 'c' && buffer.charAt(c + 1) == 'h') {
         buffer.setCharAt(c, '§');
         buffer.deleteCharAt(c + 1);
         substCount++;
       } else if (buffer.charAt(c) == 'e' && buffer.charAt(c + 1) == 'i') {
         buffer.setCharAt(c, '%');
         buffer.deleteCharAt(c + 1);
         substCount++;
       } else if (buffer.charAt(c) == 'i' && buffer.charAt(c + 1) == 'e') {
         buffer.setCharAt(c, '&');
         buffer.deleteCharAt(c + 1);
         substCount++;
       } else if (buffer.charAt(c) == 'i' && buffer.charAt(c + 1) == 'g') {
         buffer.setCharAt(c, '#');
         buffer.deleteCharAt(c + 1);
         substCount++;
       } else if (buffer.charAt(c) == 's' && buffer.charAt(c + 1) == 't') {
         buffer.setCharAt(c, '!');
         buffer.deleteCharAt(c + 1);
         substCount++;
       }
     }
   }
 }
Пример #14
0
  /**
   * 分割CSV文件数值,并返回List
   *
   * @param line
   * @return
   */
  private ArrayList<String> getCSVItems(String line) {
    ArrayList<String> v = new ArrayList<String>();
    int startIdx = 0;
    int searchIdx = -1;
    StringBuffer sbLine = new StringBuffer(line);
    while ((searchIdx = sbLine.toString().indexOf(delimiter, startIdx)) != -1) {
      String buf = null;

      if (sbLine.charAt(startIdx) != escape) {
        buf = sbLine.substring(startIdx, searchIdx);
        startIdx = searchIdx + 1;
      } else {

        int escapeIdx = -1;
        searchIdx = startIdx;
        boolean findDelimiter = false;

        while ((escapeIdx = sbLine.toString().indexOf(escape, searchIdx + 1)) != -1
            && sbLine.length() > escapeIdx + 1) {
          char nextChar = sbLine.charAt(escapeIdx + 1);
          if (delimiter.indexOf(nextChar) != -1) {
            buf = sbLine.substring(startIdx + 1, escapeIdx);
            startIdx = escapeIdx + 2;
            findDelimiter = true;
            break;
          }
          if (nextChar == escape) {
            sbLine.deleteCharAt(escapeIdx);
            escapeIdx--;
          }
          searchIdx = escapeIdx + 1;
        }

        if (!findDelimiter) {
          break;
        }
      }

      v.add(buf.trim());
    }

    if (startIdx < sbLine.length()) {
      int lastIdx = sbLine.length() - 1;
      if (sbLine.charAt(startIdx) == escape && sbLine.charAt(lastIdx) == escape) {
        sbLine.deleteCharAt(lastIdx);
        sbLine.deleteCharAt(startIdx);
      }
      v.add(sbLine.substring(startIdx, sbLine.length()).trim());
    } else if (startIdx == sbLine.length()) {
      v.add("");
    }

    return v;
  }
 /**
  * This method will be called when the mouse is clicked over the image being displayed. The
  * coordinates and pixel value will be stored on an ArrayList.
  *
  * @param me the mouse event that caused the execution of this method.
  */
 public void mouseClicked(MouseEvent me) {
   int x = me.getX();
   int y = me.getY();
   System.out.println("Storing " + x + "," + y);
   if ((x >= width) || (y >= height)) {
     clicksInformation.add("No data!");
     return;
   }
   if (isDoubleType) // process the pixel as an array of double values
   {
     StringBuffer coords = new StringBuffer();
     coords.append(x + "," + y + " [");
     readIterator.getPixel(x, y, dpixel); // read the pixel
     for (int b = 0; b < dpixel.length; b++)
       coords.append(dpixel[b] + ","); // append to the StringBuffer
     coords.deleteCharAt(coords.length() - 1); // erase last comma
     coords.append("]");
     // Put the formatted StringBuffer on the
     clicksInformation.add(coords.toString());
   } else // pixel type is not floating point, will be processed as integers.
   {
     if (isIndexed) // if color model is indexed
     {
       StringBuffer coords = new StringBuffer();
       coords.append(x + "," + y + " ");
       readIterator.getPixel(x, y, ipixel); // read the pixel
       // Assume ipixel.length = 1
       coords.append("Index: " + ipixel[0] + " [");
       // Add also the RGB entry from the LUT.
       coords.append(
           " RGB:"
               + lutData[0][ipixel[0]]
               + ","
               + lutData[1][ipixel[0]]
               + ","
               + lutData[2][ipixel[0]]);
       coords.append("]");
       // Put the formatted StringBuffer on the
       clicksInformation.add(coords.toString());
     } else // pixels are of integer type, but not indexed
     {
       StringBuffer coords = new StringBuffer();
       coords.append(x + "," + y + " [");
       readIterator.getPixel(x, y, ipixel); // read the pixel
       for (int b = 0; b < ipixel.length; b++)
         coords.append(ipixel[b] + ","); // append to the StringBuffer
       coords.deleteCharAt(coords.length() - 1); // erase last comma
       coords.append("]");
       // Put the formatted StringBuffer on the
       clicksInformation.add(coords.toString());
     }
   } // pixel is integer type
 } // end of method mouseClicked
 private static void gen(int l, int r, StringBuffer s) { // 递归生成函数:左括号剩余右括号剩余和当前字符串
   if ((l == 0) && (r == 0)) ans.add(s.toString()); // 递归的出口
   if (l > 0) { // 左括号还有剩余
     s.append('('); // 追加左括号
     gen(l - 1, r, s); // 减去一个左括号
     s.deleteCharAt(s.length() - 1); // 恢复原状
   }
   if (r - l > 0) { // 右括号还有剩余
     s.append(')'); // 追加右括号
     gen(l, r - 1, s); // 减去一个右括号
     s.deleteCharAt(s.length() - 1); // 恢复原状
   }
 }
 void MoreLexicalActions() {
   jjimageLen += (lengthOfMatch = jjmatchedPos + 1);
   switch (jjmatchedKind) {
     case 6:
       if (image == null) image = new StringBuffer();
       image.append(input_stream.GetSuffix(jjimageLen));
       jjimageLen = 0;
       image.deleteCharAt(image.length() - 2);
       break;
     case 7:
       if (image == null) image = new StringBuffer();
       image.append(input_stream.GetSuffix(jjimageLen));
       jjimageLen = 0;
       commentNest = 1;
       break;
     case 9:
       if (image == null) image = new StringBuffer();
       image.append(input_stream.GetSuffix(jjimageLen));
       jjimageLen = 0;
       image.deleteCharAt(image.length() - 2);
       break;
     case 10:
       if (image == null) image = new StringBuffer();
       image.append(input_stream.GetSuffix(jjimageLen));
       jjimageLen = 0;
       ++commentNest;
       break;
     case 11:
       if (image == null) image = new StringBuffer();
       image.append(input_stream.GetSuffix(jjimageLen));
       jjimageLen = 0;
       --commentNest;
       if (commentNest == 0) SwitchTo(INCOMMENT);
       break;
     case 13:
       if (image == null) image = new StringBuffer();
       image.append(input_stream.GetSuffix(jjimageLen));
       jjimageLen = 0;
       image.deleteCharAt(image.length() - 1);
       break;
     case 14:
       if (image == null) image = new StringBuffer();
       image.append(input_stream.GetSuffix(jjimageLen));
       jjimageLen = 0;
       image.deleteCharAt(image.length() - 2);
       break;
     default:
       break;
   }
 }
Пример #18
0
 /**
  * Get the header value (i.e. what follows the name:). This merely goes through and lops off the
  * portion that follows the headerName:
  */
 public String getHeaderValue() {
   String encodedHdr = null;
   try {
     encodedHdr = this.encode();
   } catch (Exception ex) {
     return null;
   }
   StringBuffer buffer = new StringBuffer(encodedHdr);
   while (buffer.length() > 0 && buffer.charAt(0) != ':') {
     buffer.deleteCharAt(0);
   }
   if (buffer.length() > 0) buffer.deleteCharAt(0);
   return buffer.toString().trim();
 }
 // return all grantees: thr_0, thr_1, thr_2 ..., excluding itself
 private static String getAllGrantees() {
   StringBuffer aStr = new StringBuffer("  ");
   Map<String, String> userPasswd =
       (Map<String, String>) SQLBB.getBB().getSharedMap().get(SQLSecurityTest.userPasswdMap);
   for (Map.Entry<String, String> e : userPasswd.entrySet()) {
     if (!e.getKey().equalsIgnoreCase("thr_" + RemoteTestModule.getCurrentThread().getThreadId()))
       aStr.append(e.getKey() + ", ");
   }
   if (aStr.charAt(aStr.length() - 2) == ',') {
     aStr.deleteCharAt(aStr.length() - 2);
   }
   aStr.deleteCharAt(0); // delete the leading space
   return aStr.toString();
 }
 @Override
 public String toString() {
   StringBuffer buf = new StringBuffer("[");
   // 婚宴信息列表
   buf.append("weddingInfolist:{");
   for (int i = 0; i < weddingInfolist.size(); i++) {
     buf.append(weddingInfolist.get(i).toString() + ",");
   }
   if (buf.charAt(buf.length() - 1) == ',') buf.deleteCharAt(buf.length() - 1);
   buf.append("},");
   if (buf.charAt(buf.length() - 1) == ',') buf.deleteCharAt(buf.length() - 1);
   buf.append("]");
   return buf.toString();
 }
  private void helper(int n, StringBuffer path) {
    if (n == 0) {
      if (path.length() == 1 || path.charAt(0) != '0') rst.add(new String(path));
      return;
    }

    for (int i = 0; i < 5; i++) {
      path.insert(0, pair1[i]);
      path.append(pair2[i]);
      helper(n - 2, path);
      path.deleteCharAt(0);
      path.deleteCharAt(path.length() - 1);
    }
  }
Пример #22
0
  /**
   * 向浏览器输出JSON数据
   *
   * @param
   * @return void
   */
  public void outDataToBrowser(TableData tableData) {
    StringBuffer outData = new StringBuffer();

    // 向前台输出数据
    outData.append("{pageInfo: {totalRowNum: " + tableData.getTotalRows() + "},");
    outData.append("data: [");
    boolean isFirst = true;

    TableHeaderMetaData headerMetaData = tableData.getTableHeader();
    List<TableDataRow> dataRows = tableData.getRows();
    try {
      for (TableDataRow dataRow : dataRows) {
        List<TableDataCell> dataCells = dataRow.getCells();
        int size = dataCells.size();
        if (!isFirst) {
          outData.append(",{");
          for (int i = 0; i < size; i++) {
            outData.append(
                headerMetaData.getColumnAt(i).getId() + ": '" + dataCells.get(i).getValue() + "',");
          }
          int index = outData.lastIndexOf(",");
          outData.deleteCharAt(index);
          outData.append("}");
        } else {
          outData.append("{");
          for (int i = 0; i < size; i++) {
            outData.append(
                headerMetaData.getColumnAt(i).getId() + ": '" + dataCells.get(i).getValue() + "',");
          }
          int index = outData.lastIndexOf(",");
          outData.deleteCharAt(index);
          outData.append("}");
          isFirst = false;
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    outData.append("]");
    outData.append("}");

    try {
      out.print(outData.toString());
      out.flush();
      out.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Пример #23
0
 private String createOneInsertSql(Object[] oneResult, String tablename) {
   StringBuffer buffer = new StringBuffer();
   buffer.append(
       Constants.ONESQL_PREFIX
           + INSERT_INTO
           + SPLIT
           + tablename
           + SPLIT
           + SPACE
           + VALUES
           + LEFTBRACE);
   for (int j = 0; j < oneResult.length; j++) {
     if (oneResult[j] != null) {
       if (oneResult[j] instanceof Date) {
         buffer.append(QUOTES + oneResult[j] + QUOTES);
       } else if (oneResult[j] instanceof String) {
         buffer.append(QUOTES + StrUtils.replaceKeyString((String) oneResult[j]) + QUOTES);
       } else if (oneResult[j] instanceof Boolean) {
         if ((Boolean) oneResult[j]) {
           buffer.append(1);
         } else {
           buffer.append(0);
         }
       } else {
         buffer.append(oneResult[j]);
       }
     } else {
       buffer.append(oneResult[j]);
     }
     buffer.append(COMMA);
   }
   buffer = buffer.deleteCharAt(buffer.lastIndexOf(COMMA));
   buffer.append(RIGHTBRACE + BRANCH + BR);
   return buffer.toString();
 }
Пример #24
0
 public String getHtmlLink() {
   if (StringUtil.isBlank(getNameKey())) {
     return "";
   }
   StringBuffer _sbLink = new StringBuffer();
   _sbLink.append("<a href='");
   if (StringUtil.isNotBlank(getAction())) {
     if (getAction().startsWith("/")) {
       _sbLink.append(this.m_request.getContextPath());
     }
     _sbLink.append(getAction().trim());
   }
   if (getLabelValueBeans().length > 0) {
     _sbLink.append("?");
   }
   for (int i = 0; i < getLabelValueBeans().length; i++) {
     _sbLink.append(getLabelValueBeans()[i].getLabel()).append("=");
     if (getLabelValueBeans()[i].getValue() != null
         && !getLabelValueBeans()[i].getValue().equals("null")) {
       _sbLink.append(getLabelValueBeans()[i].getValue());
     }
     _sbLink.append("&");
   }
   _sbLink.deleteCharAt(_sbLink.length() - 1);
   if (StringUtil.isNotBlank(getTarget())) {
     _sbLink.append("' target='").append(getTarget().trim());
   }
   _sbLink.append("'>").append(getButtonName()).append("</a>");
   return _sbLink.toString();
 }
Пример #25
0
  private char next() {
    if (input.length() == 0) return '@';

    char c = input.charAt(0);
    input.deleteCharAt(0);
    return c;
  }
Пример #26
0
  public static SqlInfo getUpdateSqlAsSqlInfo(Object entity, String strWhere) {

    TableInfo table = TableInfo.get(entity.getClass());

    List<KeyValue> keyValueList = new ArrayList<KeyValue>();

    // 添加属性
    Collection<Property> propertys = table.propertyMap.values();
    for (Property property : propertys) {
      KeyValue kv = property2KeyValue(property, entity);
      if (kv != null) keyValueList.add(kv);
    }

    if (keyValueList == null || keyValueList.size() == 0) {
      throw new DbException("this entity[" + entity.getClass() + "] has no property");
    }

    SqlInfo sqlInfo = new SqlInfo();
    StringBuffer strSQL = new StringBuffer("UPDATE ");
    strSQL.append(table.getTableName());
    strSQL.append(" SET ");
    for (KeyValue kv : keyValueList) {
      strSQL.append(kv.getKey()).append("=?,");
      sqlInfo.addValue(kv.getValue());
    }
    strSQL.deleteCharAt(strSQL.length() - 1);
    if (!TextUtils.isEmpty(strWhere)) {
      strSQL.append(" WHERE ").append(strWhere);
    }
    sqlInfo.setSql(strSQL.toString());
    return sqlInfo;
  }
Пример #27
0
  public static SqlInfo getUpdateSqlAsSqlInfo(Object entity) {

    TableInfo table = TableInfo.get(entity.getClass());
    Object idvalue = table.getId().getValue(entity);

    if (null == idvalue) { // 主键值不能为null,否则不能更新
      throw new DbException("this entity[" + entity.getClass() + "]'s id value is null");
    }

    List<KeyValue> keyValueList = new ArrayList<KeyValue>();
    // 添加属性
    Collection<Property> propertys = table.propertyMap.values();
    for (Property property : propertys) {
      KeyValue kv = property2KeyValue(property, entity);
      if (kv != null) keyValueList.add(kv);
    }

    if (keyValueList == null || keyValueList.size() == 0) return null;

    SqlInfo sqlInfo = new SqlInfo();
    StringBuffer strSQL = new StringBuffer("UPDATE ");
    strSQL.append(table.getTableName());
    strSQL.append(" SET ");
    for (KeyValue kv : keyValueList) {
      strSQL.append(kv.getKey()).append("=?,");
      sqlInfo.addValue(kv.getValue());
    }
    strSQL.deleteCharAt(strSQL.length() - 1);
    strSQL.append(" WHERE ").append(table.getId().getColumn()).append("=?");
    sqlInfo.addValue(idvalue);
    sqlInfo.setSql(strSQL.toString());
    return sqlInfo;
  }
Пример #28
0
  /**
   * Redirects the user to the current url over HTTPS
   *
   * @param request a HttpServletRequest
   * @param response a HttpServletResponse
   * @param urlStr
   * @param nonSslPort the port Non-SSL requests should be forwarded to
   * @throws ServletException
   * @throws IOException
   */
  public static void redirectOverNonSSL(
      HttpServletRequest request, HttpServletResponse response, String urlStr, int nonSslPort)
      throws ServletException, IOException {

    StringBuffer url = new StringBuffer(urlStr);

    // Make sure we're on http
    if (url.charAt(4) == 's') url.deleteCharAt(4);

    // If there is a non-ssl port, make sure we're on it,
    // otherwise assume we're already on the right port
    if (nonSslPort > 0) {
      int portStart = url.indexOf(":", 8) + 1;
      int portEnd = url.indexOf("/", 8);

      if (portEnd == -1) // If their isn't a trailing slash, then the end is the last char
      portEnd = url.length() - 1;

      if (portStart > 0
          && portStart
              < portEnd) { // If we detected a : before the trailing slash or end of url, delete the
                           // port
        url.delete(portStart, portEnd);
      } else {
        url.insert(portEnd, ':'); // If the url didn't have a port, add in the :
        portStart = portEnd;
      }

      url.insert(portStart, nonSslPort); // Insert the right port where it should be
    }

    LogFactory.getLog(ServletUtils.class).debug("redirectOverSSL sending 301: " + url.toString());
    sendPermanentRedirect(response, url.toString());
  }
Пример #29
0
 /**
  * 生成建表語句
  *
  * @param bean
  * @return
  */
 public static String genCreateTableSql(String bean) {
   List<String> beanPropertyList = getBeanPropertyList(bean);
   StringBuffer sb = new StringBuffer("create table wnk_pdt_" + getBeanName(bean) + "(\n");
   for (String string : beanPropertyList) {
     String[] propertys = string.split("`");
     if (!propertys[1].equals("tableName")
         && !propertys[1].equals("param")
         && !propertys[0].equals("List")) {
       if (propertys[1].equals("id")) {
         sb.append("   id bigint primary key auto_increment,\n");
       } else {
         if (propertys[0].equals("int")) {
           sb.append("   " + propertys[1] + " int default 0 comment '',\n");
         } else if (propertys[0].equals("String")) {
           sb.append("   " + propertys[1] + " varchar(2000) default '' comment '',\n");
         } else if (propertys[0].equals("double")) {
           sb.append("   " + propertys[1] + " double(10,2) default 0.0 comment '',\n");
         } else if (propertys[0].equals("Date")) {
           sb.append("   " + propertys[1] + " datetime comment '',\n");
         }
       }
     }
   }
   sb.append(")");
   sb.deleteCharAt(sb.lastIndexOf(","));
   return sb.toString();
 }
Пример #30
0
  /**
   * 解析url{@link StringBuffer}返回一个新的实例
   *
   * @param url
   * @return UrlRole
   */
  public static UrlRole parse(StringBuffer url) {

    UrlRole def = new UrlRole();

    int point = url.lastIndexOf(".");
    if (point != -1) url.delete(point, url.length());

    int a = url.indexOf("!");

    if (a == url.length() - 1) {
      def.className = url.deleteCharAt(url.length() - 1);
      def.methodName = "execute";
    } else if (a != -1) {
      def.methodName = url.substring(a + 1);
      def.className = url.delete(a, url.length());
    } else {
      def.className = url;
      def.methodName = "execute";
    }

    int b = def.className.lastIndexOf("/");

    char c = def.className.charAt(b + 1);

    if (c >= 'a' && c <= 'z') def.className.setCharAt(b + 1, (char) (c - 32));
    def.className.replace(b, b + 1, ".action.").append("Action");

    while ((b = def.className.indexOf("/")) != -1) {
      def.className.setCharAt(b, '.');
    }

    def.className.insert(0, P3Filter.ACTION_PACKAGE);
    if (logger.isDebugEnabled()) logger.debug("action define : " + def);
    return def;
  }