public synchronized void transferProgress(
      TransferEvent transferEvent, byte[] buffer, int length) {
    Resource resource = transferEvent.getResource();
    if (!downloads.containsKey(resource)) {
      downloads.put(resource, new Long(length));
    } else {
      Long complete = (Long) downloads.get(resource);
      complete = new Long(complete.longValue() + length);
      downloads.put(resource, complete);
    }

    StringBuffer buf = new StringBuffer();
    for (Iterator i = downloads.entrySet().iterator(); i.hasNext(); ) {
      Map.Entry entry = (Map.Entry) i.next();
      Long complete = (Long) entry.getValue();
      String status =
          getDownloadStatusForResource(
              complete.longValue(), ((Resource) entry.getKey()).getContentLength());
      buf.append(status);
      if (i.hasNext()) {
        buf.append(" ");
      }
    }

    if (buf.length() > maxLength) {
      maxLength = buf.length();
    }

    out.print(buf.toString() + "\r");
  }
Beispiel #2
1
  private String format(String src) {
    StringBuffer result = new StringBuffer();
    char[] srcArray = src.toCharArray();
    for (int index = 0; index < src.length(); index++) {
      result.append(srcArray[index]);

      if (BRACE_LEFT.equals(String.valueOf(srcArray[index]))) { // {
        result.append(appendLINE_BREAKAndTAB(++TABLength));
        //                continue;
      }

      if (BRACE_RIGHT.equals(String.valueOf(srcArray[index]))) { // }
        result.insert(result.length() - 1, appendLINE_BREAKAndTAB(--TABLength));
        //                continue;
      }

      if (BRACKET_LEFT.equals(String.valueOf(srcArray[index]))) { // [
        result.append(appendLINE_BREAKAndTAB(++TABLength));
        //                continue;
      }

      if (BRACKET_RIGHT.equals(String.valueOf(srcArray[index]))) { // ]
        result.insert(result.length() - 1, appendLINE_BREAKAndTAB(--TABLength));
        //                continue;
      }

      if (COMMA.equals(String.valueOf(srcArray[index]))) { // ,
        result.append(appendLINE_BREAKAndTAB(TABLength));
        //                continue;
      }
    }
    return result.toString();
  }
  /**
   * Cut or padd the string to the given size
   *
   * @param size the wanted length
   * @param padChar char to use for padding (must be of length()==1!)
   * @return the string with correct lenght, padded with pad if necessary
   */
  public static String forceToSizeLeft(final String str, final int size, final char padChar) {
    if (str != null && str.length() == size) {
      return str;
    }

    final StringBuffer tmp;
    if (str == null) {
      tmp = new StringBuffer(size);
    } else {
      tmp = new StringBuffer(str);
    }

    if (tmp.length() > size) {
      tmp.setLength(size);
      return tmp.toString(); // do cutting
    } else {
      final StringBuffer t2 = new StringBuffer(size);

      final int arsize = size - tmp.length();
      final char[] ar = new char[arsize];
      for (int i = 0; i < arsize; i++) {
        ar[i] = padChar;
      }
      t2.append(ar);
      t2.append(tmp);
      return t2.toString();
    }
  }
Beispiel #4
0
  private static String getBanJi(String cids) {
    StringBuffer sql = new StringBuffer();
    StringBuffer classid = new StringBuffer();
    StringBuffer condition = new StringBuffer(63);
    if (!"".equals(cids) && cids != null) {
      if (cids.indexOf(",") != -1) {
        String[] cid = cids.split(",");
        condition.append("where classId  in (");
        for (int i = 0; i < cid.length; i++) {
          condition.append("'" + cid[i] + "',");
        }
        condition.delete(condition.length() - 1, condition.length());
        condition.append(" )");
      } else {
        condition.append("where classId ='" + cids + "'");
      }
      sql.append("select className from jcsc_BanJi ").append(condition);
      ResultSet rs = null;
      try {
        rs = dba.executeQuery(sql.toString());
        while (rs.next()) {
          classid.append(rs.getString(1) + ",");
        }
        if (classid.length() > 0) {
          classid.setLength(classid.length() - 1);
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    return classid.toString();
  }
  /**
   * Converts the given format into a pattern accepted by <code>java.text.SimpleDataFormat</code>
   *
   * @param format
   */
  public static String toJavaDatePattern(String format) {

    int len = format.length();
    char ch;
    StringBuffer sb = new StringBuffer(len);
    Tokenizer tokenizer = new Tokenizer();

    for (int i = 0; i <= len; i++) {
      ch = (i == len) ? e : format.charAt(i);

      if (!tokenizer.next(ch, dateTokens)) {
        int index = tokenizer.getLastMatch();

        if (index >= 0) {
          sb.setLength(sb.length() - tokenizer.length());
          sb.append(javaDateTokens[index]);
        }

        tokenizer.reset();

        if (tokenizer.isConsumed()) {
          continue;
        }
      }

      sb.append(ch);
    }

    sb.setLength(sb.length() - 1);

    String javaPattern = sb.toString();

    return javaPattern;
  }
 private String a()
 {
   boolean bool = DialogToastListActivity.f;
   StringBuffer localStringBuffer = new StringBuffer();
   TreeSet localTreeSet = new TreeSet();
   Iterator localIterator1 = this.p.iterator();
   do
   {
     if (!localIterator1.hasNext())
       break;
     zq localzq = (zq)localIterator1.next();
     if (localzq.l)
       localTreeSet.add(localzq.b);
   }
   while (!bool);
   Iterator localIterator2 = localTreeSet.iterator();
   do
   {
     if (!localIterator2.hasNext())
       break;
     localStringBuffer.append((String)localIterator2.next()).append(",");
   }
   while (!bool);
   if (localStringBuffer.length() > 0);
   for (String str = localStringBuffer.substring(0, -1 + localStringBuffer.length()); ; str = null)
   {
     return str;
     localTreeSet.clear();
   }
 }
Beispiel #7
0
  /**
   * Adds a syntax to the syntaxsection
   *
   * @param doc, doc item that has to be add to the syntax section
   */
  void addSyntax(Doc doc) {
    if (doc.isConstructor() || doc.isMethod()) {
      StringBuffer syntaxBuffer = new StringBuffer();
      for (Parameter parameter : ((ExecutableMemberDoc) doc).parameters()) {
        syntaxBuffer.append(parameter.typeName() + " " + parameter.name());
        syntaxBuffer.append(", ");
      }
      if (syntaxBuffer.length() > 2) {
        syntaxBuffer.delete(syntaxBuffer.length() - 2, syntaxBuffer.length());
      }

      String returnType = "";

      if (doc.isMethod()) {
        MethodDoc methodDoc = (MethodDoc) doc;
        returnType = methodDoc.returnType().toString();
        int lastDot = returnType.lastIndexOf('.');
        if (lastDot != -1) {
          returnType = returnType.substring(lastDot + 1);
        }
        returnType += " ";
      }

      if (doc.isConstructor()) {
        addSyntax("<em>" + doc.commentText() + "</em>");
      }

      addSyntax(returnType + doc.name() + "(" + syntaxBuffer.toString() + ")");
    } else if (doc.isField()) {
      FieldDoc fieldDoc = (FieldDoc) doc;
      addSyntax(fieldDoc.type().typeName() + " " + doc.name());
    }
  }
 @Override
 protected void addRoleQualification(Object businessObject, Map<String, String> attributes) {
   super.addRoleQualification(businessObject, attributes);
   attributes.put(PurapKimAttributes.DOCUMENT_SENSITIVE, "false");
   ElectronicInvoiceRejectDocument purapDoc = (ElectronicInvoiceRejectDocument) businessObject;
   if (purapDoc.getAccountsPayablePurchasingDocumentLinkIdentifier() != null) {
     List<SensitiveData> sensitiveDataList =
         SpringContext.getBean(SensitiveDataService.class)
             .getSensitiveDatasAssignedByRelatedDocId(
                 purapDoc.getAccountsPayablePurchasingDocumentLinkIdentifier());
     StringBuffer sensitiveDataCodes = new StringBuffer();
     for (SensitiveData sensitiveData : sensitiveDataList) {
       sensitiveDataCodes.append(sensitiveData.getSensitiveDataCode()).append(";");
     }
     if (sensitiveDataCodes.length() > 0) {
       attributes.put(PurapKimAttributes.DOCUMENT_SENSITIVE, "true");
       attributes.put(
           PurapKimAttributes.SENSITIVE_DATA_CODE,
           sensitiveDataCodes.toString().substring(0, sensitiveDataCodes.length() - 1));
       attributes.put(
           PurapKimAttributes.ACCOUNTS_PAYABLE_PURCHASING_DOCUMENT_LINK_IDENTIFIER,
           purapDoc.getAccountsPayablePurchasingDocumentLinkIdentifier().toString());
     }
   }
 }
  // reconstruct the unused tokens from the phrase (since it didn't match)
  // need to recompute the token positions based on the length of the currentPhrase,
  // the current ending position and the length of each token.
  private void discardCharTokens(StringBuffer phrase, ArrayList<Token> tokenList) {
    Log.debug("discardCharTokens: '" + phrase.toString() + "'");
    OffsetAttribute offAttr = getOffsetAttribute();
    int endPos = offAttr.endOffset();
    int startPos = endPos - phrase.length();

    int lastSp = 0;
    for (int i = 0; i < phrase.length(); i++) {
      char chAt = phrase.charAt(i);
      if (isSpaceChar(chAt) && i > lastSp) {
        char[] tok = new char[i - lastSp];
        phrase.getChars(lastSp, i, tok, 0);
        if (lastEmitted == null || !endsWith(lastEmitted, tok)) {
          Token token = new Token();
          token.tok = tok;

          token.startPos = startPos + lastSp;
          token.endPos = token.startPos + tok.length;
          Log.debug("discard " + new String(tok) + ": " + token.startPos + ", " + token.endPos);
          tokenList.add(token);
        }
        lastSp = i + 1;
      }
    }
    char[] tok = new char[phrase.length() - lastSp];
    phrase.getChars(lastSp, phrase.length(), tok, 0);

    Token token = new Token();
    token.tok = tok;
    token.endPos = endPos;
    token.startPos = endPos - tok.length;
    tokenList.add(token);
  }
  public String renderTool(HttpServletResponse response, Controller controller) {
    Hashtable jsImageProperties = new Hashtable();
    StringBuffer propertyValue = new StringBuffer();
    String fullEnabledImageLink = controller.getPathWithContext(enabledImageLink_);
    generateOnMouseValue(propertyValue, response, fullEnabledImageLink);
    int propertyValueLength = propertyValue.length();
    jsImageProperties.put("class", "normal");
    jsImageProperties.put("onMouseOut", propertyValue.append(";mouseout(this)").toString());
    propertyValue.delete(propertyValueLength, propertyValue.length());
    jsImageProperties.put("onMouseUp", propertyValue.append(";mouseup(this)").toString());
    propertyValue.setLength(0);
    generateOnMouseValue(
        propertyValue, response, controller.getPathWithContext(highlightedImageLink_));
    propertyValueLength = propertyValue.length();
    jsImageProperties.put("onMouseOver", propertyValue.append(";mouseover(this)").toString());
    propertyValue.delete(propertyValueLength, propertyValue.length());
    jsImageProperties.put("onMouseDOwn", propertyValue.append(";mousedown(this)").toString());

    String imageTag =
        HTMLUtils.getHTMLImageTag(
            response, fullEnabledImageLink, alt_, "16", "16", jsImageProperties);
    return HTMLUtils.getHTMLLinkTag(
        response,
        controller.getPathWithContext(getSelectToolActionHref(false)),
        getSelectToolActionTarget(),
        null,
        imageTag,
        null);
  }
Beispiel #11
0
  /**
   * Gets the user supplied gvim arguments from the preferences.
   *
   * @return Array of arguments to be passed to gvim.
   */
  protected String[] getUserArgs() {
    String opts = VimPlugin.getDefault().getPreferenceStore().getString(PreferenceConstants.P_OPTS);

    // FIXME: doesn't currently handle escaped spaces/quotes
    char[] chars = opts.toCharArray();
    char quote = ' ';
    StringBuffer arg = new StringBuffer();
    ArrayList<String> args = new ArrayList<String>();
    for (char c : chars) {
      if (c == ' ' && quote == ' ') {
        if (arg.length() > 0) {
          args.add(arg.toString());
          arg = new StringBuffer();
        }
      } else if (c == '"' || c == '\'') {
        if (quote != ' ' && c == quote) {
          quote = ' ';
        } else if (quote == ' ') {
          quote = c;
        } else {
          arg.append(c);
        }
      } else {
        arg.append(c);
      }
    }

    if (arg.length() > 0) {
      args.add(arg.toString());
    }

    return args.toArray(new String[args.size()]);
  }
Beispiel #12
0
  public String toString(int zero) {
    StringBuffer ret = new StringBuffer(256);
    boolean first = true;

    if (isValid()) {
      int tooMuch = 0;
      int saveLen;
      for (ListIterator<MultipleSyntaxElements> i = getChildContainers().listIterator();
          i.hasNext(); ) {
        if (!first) ret.append('+');

        saveLen = ret.length();
        MultipleSyntaxElements dataList = i.next();
        if (dataList != null) ret.append(dataList.toString(0));

        if (ret.length() == saveLen && !first) {
          tooMuch++;
        } else {
          tooMuch = 0;
        }
        first = false;
      }

      int retlen = ret.length();
      ret.delete(retlen - tooMuch, retlen);
      ret.append('\'');
    }

    return ret.toString();
  }
 public static String removeParameter(String parameterString, String parameter) {
   StringBuffer sb = new StringBuffer(parameterString);
   int startPos = 0;
   if (parameterString.startsWith(parameter + "=")) {
     int pos = parameterString.indexOf('&');
     if (pos < 0) {
       sb.setLength(0);
     } else {
       sb.replace(0, pos, "");
     }
     startPos = 0;
   } else {
     int pos = parameterString.indexOf("&" + parameter + "=");
     if (pos >= 0) {
       int endPos = parameterString.indexOf("&", pos + 1);
       if (endPos < 0) {
         endPos = sb.length();
       }
       sb.replace(pos + 1, endPos, "");
       startPos = pos + 1;
     } else {
       startPos = sb.length();
     }
   }
   int pos = sb.indexOf("&" + parameter + "=", startPos);
   while (pos >= 0) {
     int endPos = sb.indexOf("&", pos + 1);
     if (endPos < 0) {
       endPos = sb.length();
     }
     sb.replace(pos, endPos, "");
     pos = sb.indexOf("&" + parameter + "=", pos);
   }
   return sb.toString();
 }
Beispiel #14
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;
  }
Beispiel #15
0
  /**
   * Print the contents of the tag.
   *
   * @return An string describing the tag. For text that looks like HTML use #toHtml().
   */
  public String toString() {
    String text;
    String type;
    Cursor start;
    Cursor end;
    StringBuffer ret;

    text = getText();
    ret = new StringBuffer(20 + text.length());
    if (isEndTag()) type = "End";
    else type = "Tag";
    start = new Cursor(getPage(), getStartPosition());
    end = new Cursor(getPage(), getEndPosition());
    ret.append(type);
    ret.append(" (");
    ret.append(start);
    ret.append(",");
    ret.append(end);
    ret.append("): ");
    if (80 < ret.length() + text.length()) {
      text = text.substring(0, 77 - ret.length());
      ret.append(text);
      ret.append("...");
    } else ret.append(text);

    return (ret.toString());
  }
  private void handleNoSelection(Editor editor) {
    CaretModel caretModel = editor.getCaretModel();
    Document doc = editor.getDocument();
    if ((caretModel == null) || (doc == null) || (doc.getTextLength() == 0)) {
      return;
    }

    char[] allChars = doc.getChars();
    int maxOffset = allChars.length;

    int startOffset = caretModel.getOffset();

    while ((startOffset < maxOffset) && (!Character.isLetterOrDigit(allChars[startOffset]))) {
      startOffset++;
    }

    StringBuffer word = new StringBuffer();
    int i = startOffset;
    while ((i < maxOffset) && (Character.isLetterOrDigit(allChars[i]))) {
      word.append(allChars[i]);

      i++;
    }

    if (word.length() > 0) {
      this.m_transformer.transform(word);
      int newOffset = startOffset + word.length();
      doc.replaceString(startOffset, newOffset, word.toString());

      caretModel.moveToOffset(newOffset);
    }
  }
Beispiel #17
0
 public static String getId() {
   StringBuffer buffer = new StringBuffer();
   for (int i = 1; i < 32; i++) buffer.append("0");
   String strTime = "" + System.currentTimeMillis(); // +longFlag+(int)(Math.random()*1000+1000);
   if (longFlag < 10) {
     strTime = strTime + "000" + longFlag;
   } else if (longFlag < 100) {
     strTime = strTime + "00" + longFlag;
   } else if (longFlag < 1000) {
     strTime = strTime + "0" + longFlag;
   } else if (longFlag < 10000) {
     strTime = strTime + longFlag;
   }
   strTime = strTime + (int) (Math.random() * 1000 + 1000);
   if (strTime.length() > 31) {
     strTime = strTime.substring(strTime.length() - 31);
   }
   buffer.replace(buffer.length() - strTime.length(), buffer.length(), strTime);
   longFlag++;
   if (longFlag > 9999) {
     longFlag = 0;
   }
   return buffer.toString();
   //		return strTime.substring(7,strTime.length());
 }
Beispiel #18
0
 public DynamicLayerConfig addCQLDynamicLayerOnAttributes(String[] attributes, int gtype) {
   if (attributes == null) {
     return addCQLDynamicLayerOnGeometryType(gtype);
   } else {
     StringBuffer name = new StringBuffer();
     StringBuffer query = new StringBuffer();
     if (gtype != GTYPE_GEOMETRY) {
       query.append(makeGeometryCQL(gtype));
     }
     for (int i = 0; i < attributes.length; i += 2) {
       String key = attributes[i];
       if (name.length() > 0) {
         name.append("-");
       }
       if (query.length() > 0) {
         query.append(" AND ");
       }
       if (attributes.length > i) {
         String value = attributes[i + 1];
         name.append(key).append("-").append(value);
         query.append(key).append(" = '").append(value).append("'");
       } else {
         name.append(key);
         query.append(key).append(" IS NOT NULL");
       }
     }
     return addLayerConfig("CQL:" + name.toString(), gtype, query.toString());
   }
 }
 /**
  * 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();
     }
   }
 }
  @Override
  public void write(final String bytes) {
    if (current() != null && bytes != null && bytes.length() > 0) {
      StringBuffer outputBuffer = (StringBuffer) current().getBuffer();
      int idxNL = bytes.indexOf(NEWLINE);
      if (idxNL < 0) {
        outputBuffer.append(bytes);
        return;
      }

      String s = new String(bytes);
      if (isNewLine(s.charAt(0))
          && outputBuffer.length() > 0
          && isNewLine(outputBuffer.charAt(outputBuffer.length() - 1))) {
        int i;
        for (i = 1; i < s.length(); i++) {
          if (!isNewLine(s.charAt(i))) break;
        }
        s = s.substring(i);
        idxNL = s.indexOf(NEWLINE);
      }
      outputBuffer.append((idxNL < s.length() - 1) ? s.substring(0, idxNL + 1) : s);
      if (idxNL + 1 < s.length()) {
        write(s.substring(idxNL + 1));
      }
    }
  }
Beispiel #21
0
 /**
  * Gets the time/distance text.
  *
  * @param context the context
  * @param isRecording true if recording
  * @param isPaused true if paused
  * @param sharedOwner the shared owner
  * @param totalTime the total time
  * @param totalDistance the total distance
  */
 private static String getTimeDistance(
     Context context,
     boolean isRecording,
     boolean isPaused,
     String sharedOwner,
     String totalTime,
     String totalDistance) {
   if (isRecording) {
     return context.getString(isPaused ? R.string.generic_paused : R.string.generic_recording);
   }
   StringBuffer buffer = new StringBuffer();
   if (sharedOwner != null && sharedOwner.length() != 0) {
     buffer.append(sharedOwner);
   }
   if (totalTime != null && totalTime.length() != 0) {
     if (buffer.length() != 0) {
       buffer.append(" \u2027 ");
     }
     buffer.append(totalTime);
   }
   if (totalDistance != null && totalDistance.length() != 0) {
     if (buffer.length() != 0) {
       buffer.append(" ");
     }
     buffer.append("(" + totalDistance + ")");
   }
   return buffer.toString();
 }
Beispiel #22
0
  private String[] spritParamater(String param) {
    boolean inQuate = false;

    List commands = new ArrayList();
    StringBuffer buffer = new StringBuffer();

    for (int i = 0; i < param.length(); i++) {
      char c = param.charAt(i);

      if (c == ' ' && !inQuate && buffer.length() > 0) {
        commands.add(buffer.toString());
        buffer.setLength(0);

        continue;
      }

      if (c == '\"') {
        inQuate = !inQuate;
        continue;
      }

      buffer.append(c);
    }

    if (buffer.length() > 0) {
      commands.add(buffer.toString());
    }

    return (String[]) commands.toArray(new String[0]);
  }
Beispiel #23
0
  /**
   * Glues the sentences back to paragraph.
   *
   * <p>As sentences are returned by {@link #segment(String, List)} without spaces before and after
   * them, this method adds spaces if needed:
   *
   * <ul>
   *   <li>For translation to Japanese does <b>not</b> add any spaces. <br>
   *       A special exceptions are the Break SRX rules that break on space, i.e. before and after
   *       patterns consist of spaces (they get trimmed to an empty string). For such rules all the
   *       spaces are added
   *   <li>For translation from Japanese adds one space
   *   <li>For all other language combinations adds those spaces as were in the paragraph before.
   * </ul>
   *
   * @param sentences list of translated sentences
   * @param spaces information about spaces in original paragraph
   * @param brules rules that account to breaks
   * @return glued translated paragraph
   */
  public static String glue(
      Language sourceLang,
      Language targetLang,
      List<String> sentences,
      List<StringBuffer> spaces,
      List<Rule> brules) {
    if (sentences.size() <= 0) return "";

    StringBuffer res = new StringBuffer();
    res.append(sentences.get(0));

    for (int i = 1; i < sentences.size(); i++) {
      StringBuffer sp = new StringBuffer();
      sp.append(spaces.get(2 * i - 1));
      sp.append(spaces.get(2 * i));

      if (CJK_LANGUAGES.contains(targetLang.getLanguageCode().toUpperCase(Locale.ENGLISH))) {
        Rule rule = brules.get(i - 1);
        char lastChar = res.charAt(res.length() - 1);
        if ((lastChar != '.')
            && (!PatternConsts.SPACY_REGEX.matcher(rule.getBeforebreak()).matches()
                || !PatternConsts.SPACY_REGEX.matcher(rule.getAfterbreak()).matches()))
          sp.setLength(0);
      } else if (CJK_LANGUAGES.contains(sourceLang.getLanguageCode().toUpperCase(Locale.ENGLISH))
          && sp.length() == 0) sp.append(" ");

      res.append(sp);
      res.append(sentences.get(i));
    }
    return res.toString();
  }
Beispiel #24
0
 private void formatDate(final long now, final StringBuffer sbuf) {
   final int millis = (int) (now % 1000);
   final long rounded = now - millis;
   if (rounded != lastTimeMillis) {
     synchronized (calendar) {
       final int start = sbuf.length();
       calendar.setTimeInMillis(rounded);
       sbuf.append(calendar.get(Calendar.YEAR));
       sbuf.append('-');
       sbuf.append(toTwoDigits(calendar.get(Calendar.MONTH) + 1));
       sbuf.append('-');
       sbuf.append(toTwoDigits(calendar.get(Calendar.DAY_OF_MONTH)));
       sbuf.append(' ');
       sbuf.append(toTwoDigits(calendar.get(Calendar.HOUR_OF_DAY)));
       sbuf.append(':');
       sbuf.append(toTwoDigits(calendar.get(Calendar.MINUTE)));
       sbuf.append(':');
       sbuf.append(toTwoDigits(calendar.get(Calendar.SECOND)));
       sbuf.append(',');
       sbuf.getChars(start, sbuf.length(), lastTimeString, 0);
       lastTimeMillis = rounded;
     }
   } else {
     sbuf.append(lastTimeString);
   }
   sbuf.append(String.format("%03d", millis));
 }
Beispiel #25
0
  /**
   * 排序字段名替换成序号
   *
   * @param src
   * @param replacExpression
   * @return
   */
  public static String sortFieldNameToIndex(String src, String replacExpression) {
    if (strIsEmpty(src)) return null;
    List<String> replacList = Arrays.asList(replacExpression.toUpperCase().split(","));
    boolean isCopy = false;
    StringBuffer desc = new StringBuffer();
    StringBuffer v = new StringBuffer();

    for (char c : (src + " ").toUpperCase().toCharArray()) {
      if (c == 44) { // 逗号
        if (v.length() > 0) {
          int idx = replacList.indexOf(v.toString());
          if (idx == -1) desc.append(v.toString());
          else desc.append(idx + 1);
          desc.append(" ASC");
          v = new StringBuffer();
        }
        isCopy = false;
        desc.append(c);
      } else if (isCopy) {
        desc.append(c);
      } else if (c == 9 || c == 32) { // tab符, 空格
        if (v.length() > 0) {
          int idx = replacList.indexOf(v.toString());
          if (idx == -1) desc.append(v.toString());
          else desc.append(idx + 1);
          v = new StringBuffer();
          isCopy = true;
          desc.append(c);
        }
      } else {
        v.append(c);
      }
    }
    return desc.toString();
  }
Beispiel #26
0
  public static List<QueryPVisitor> confirmTicket(List<Long> ticketList)
      throws DataException, IOException, DocumentException {
    String msgIdValue = System.currentTimeMillis() + "";
    String reqIdValue = "802";
    StringBuffer sb = new StringBuffer();
    for (Long id : ticketList) {
      sb.append(id + ",");
    }
    sb.delete(sb.length() - 1, sb.length());
    Map<String, String> ParamMap = new LinkedHashMap<String, String>();
    ParamMap.put("ReqId", reqIdValue);
    ParamMap.put("MsgId", msgIdValue);
    ParamMap.put("ReqParam", sb.toString());
    ParamMap.put("ReqKey", MD5.md5(reqIdValue + msgIdValue + sb.toString() + key).toLowerCase());

    String returnString = HttpclientUtil.Utf8HttpClientUtils(reUrl, ParamMap);
    Document doc = DocumentHelper.parseText(returnString);
    Element root = doc.getRootElement();
    Element ticket;
    QueryPVisitor queryPVisitor;
    List<QueryPVisitor> returnTicketList = Lists.newArrayList();
    for (Iterator i = root.elementIterator("Ticket"); i.hasNext(); ) {
      ticket = (Element) i.next();
      queryPVisitor = new QueryPVisitor();
      ticket.accept(queryPVisitor);
      returnTicketList.add(queryPVisitor);
    }
    if (returnTicketList.isEmpty()) {
      Document document = DocumentHelper.parseText(returnString);
      queryPVisitor = new QueryPVisitor();
      document.accept(queryPVisitor);
      returnTicketList.add(queryPVisitor);
    }
    return returnTicketList;
  }
Beispiel #27
0
 public static String encodeParameters(
     final List<HttpParameter> httpParams, final String splitter, final boolean quot) {
   final StringBuffer buf = new StringBuffer();
   for (final HttpParameter param : httpParams) {
     if (!param.isFile()) {
       if (buf.length() != 0) {
         if (quot) {
           buf.append("\"");
         }
         buf.append(splitter);
       }
       buf.append(HttpParameter.encode(param.getName())).append("=");
       if (quot) {
         buf.append("\"");
       }
       buf.append(HttpParameter.encode(param.getValue()));
     }
   }
   if (buf.length() != 0) {
     if (quot) {
       buf.append("\"");
     }
   }
   return buf.toString();
 }
Beispiel #28
0
 // Serialize the bean using the specified namespace prefix & uri
 public String serialize(Object bean) throws IntrospectionException, IllegalAccessException {
   // Use the class name as the name of the root element
   String className = bean.getClass().getName();
   String rootElementName = null;
   if (bean.getClass().isAnnotationPresent(ObjectXmlAlias.class)) {
     AnnotatedElement annotatedElement = bean.getClass();
     ObjectXmlAlias aliasAnnotation = annotatedElement.getAnnotation(ObjectXmlAlias.class);
     rootElementName = aliasAnnotation.value();
   }
   // Use the package name as the namespace URI
   Package pkg = bean.getClass().getPackage();
   nsURI = pkg.getName();
   // Remove a trailing semi-colon (;) if present (i.e. if the bean is an array)
   className = StringUtils.deleteTrailingChar(className, ';');
   StringBuffer sb = new StringBuffer(className);
   String objectName = sb.delete(0, sb.lastIndexOf(".") + 1).toString();
   domDocument = createDomDocument(objectName);
   document = domDocument.getDocument();
   Element root = document.getDocumentElement();
   // Parse the bean elements
   getBeanElements(root, rootElementName, className, bean);
   StringBuffer xml = new StringBuffer();
   if (prettyPrint)
     xml.append(domDocument.serialize(lineSeperator, indentChars, includeXmlProlog));
   else xml.append(domDocument.serialize(includeXmlProlog));
   if (!includeTypeInfo) {
     int index = xml.indexOf(root.getNodeName());
     xml.delete(index - 1, index + root.getNodeName().length() + 2);
     xml.delete(xml.length() - root.getNodeName().length() - 4, xml.length());
   }
   return xml.toString();
 }
Beispiel #29
0
 /**
  * 将数组中重复的字符串 去除
  *
  * @param destmsisdns
  * @return
  */
 public static String removeSameDestmsisdn(String destmsisdns) {
   String tmp = null;
   StringBuffer sb_destmsisdn = new StringBuffer();
   String[] destmsisdnArray = destmsisdns.split(",");
   if (destmsisdnArray == null || destmsisdnArray.length == 0) {
     return null;
   }
   ArrayList<String> resultList = new ArrayList<String>();
   for (int i = 0; i < destmsisdnArray.length; i++) {
     if (resultList.contains(destmsisdnArray[i])) {
       continue;
     } else {
       resultList.add(destmsisdnArray[i]);
     }
   }
   for (int i = 0; i < resultList.size(); i++) {
     sb_destmsisdn.append(resultList.get(i));
     sb_destmsisdn.append(",");
   }
   if (sb_destmsisdn.length() > 0) {
     tmp = sb_destmsisdn.substring(0, sb_destmsisdn.length() - 1);
   } else {
     tmp = sb_destmsisdn.toString();
   }
   return tmp;
 }
  /**
   * 解析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;
  }