Example usage for java.lang StringBuffer deleteCharAt

List of usage examples for java.lang StringBuffer deleteCharAt

Introduction

In this page you can find the example usage for java.lang StringBuffer deleteCharAt.

Prototype

@Override
public synchronized StringBuffer deleteCharAt(int index) 

Source Link

Usage

From source file:org.apache.hive.jdbc.HivePreparedStatement.java

/**
 * update the SQL string with parameters set by setXXX methods of {@link PreparedStatement}
 *
 * @param sql/*www  . ja v  a2 s  . c o  m*/
 * @param parameters
 * @return updated SQL string
 */
private String updateSql(final String sql, HashMap<Integer, String> parameters) {

    StringBuffer newSql = new StringBuffer(sql);

    int paramLoc = 1;
    while (getCharIndexFromSqlByParamLocation(sql, '?', paramLoc) > 0) {
        // check the user has set the needs parameters
        if (parameters.containsKey(paramLoc)) {
            int tt = getCharIndexFromSqlByParamLocation(newSql.toString(), '?', 1);
            newSql.deleteCharAt(tt);
            newSql.insert(tt, parameters.get(paramLoc));
        }
        paramLoc++;
    }

    return newSql.toString();

}

From source file:org.restcomm.app.qoslib.Services.Events.EventUploader.java

/**
 * Persists the queue of events to the phone's preferences
 *//*from  w  w  w.jav  a  2s  . c  o  m*/
protected void saveEvents(ConcurrentLinkedQueue<EventDataEnvelope> eventQueue) {
    //JSONArray jsonQueue= new JSONArray();
    if (eventQueue == null)
        return;
    StringBuffer sb = new StringBuffer();
    sb.append("[");
    Gson gson = new Gson();
    // remove the oldest events until queue is below 400
    while (eventQueue.size() > 300)
        eventQueue.poll();

    for (EventDataEnvelope eventEnv : eventQueue) {
        try {
            String strJSON = gson.toJson(eventEnv);
            sb.append(strJSON);
            sb.append(",");
            //JSONObject evtJSON =  new JSONObject(strJSON);
            //jsonQueue.put(evtJSON);
        } catch (Exception e) {
            LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "persistQueue", "failed to persist event request",
                    e);
        }
    }
    sb.deleteCharAt(sb.length() - 1);
    sb.append("]");

    SharedPreferences preferenceSettings = MainService.getSecurePreferences(owner);
    String stringQueue = sb.toString();//  jsonQueue.toString();

    preferenceSettings.edit().putString(PreferenceKeys.Miscellaneous.EVENTS_QUEUE, stringQueue).commit();
}

From source file:org.kuali.rice.kim.impl.role.RoleDaoOjb.java

public List<RoleMemberBo> getRoleMembersForRoleIds(Collection<String> roleIds, String memberTypeCode,
        Map<String, String> qualification) {
    JdbcTemplate template = new JdbcTemplate(dataSource);
    final List<String> roleIDs = new ArrayList<String>(roleIds);
    final String memberTypeCd = memberTypeCode;
    final Map<String, String> qual = qualification;
    final List<RoleMemberBo> roleMemberBos = new ArrayList<RoleMemberBo>();
    List<RoleMemberBo> results = template.execute(new PreparedStatementCreator() {

        /*/*from w  w  w . ja  v  a2  s . co m*/
         SAMPLE QUERY
                
        SELECT A0.ROLE_MBR_ID AS ROLE_MBR_ID,A0.ROLE_ID AS ROLE_ID,A0.MBR_ID AS MBR_ID,A0.MBR_TYP_CD AS MBR_TYP_CD,A0.VER_NBR AS ROLE_MBR_VER_NBR,A0.OBJ_ID AS ROLE_MBR_OBJ_ID,A0.ACTV_FRM_DT AS ROLE_MBR_ACTV_FRM_DT ,A0.ACTV_TO_DT AS ROLE_MBR_ACTV_TO_DT,
        BO.KIM_TYP_ID AS KIM_TYP_ID, BO.KIM_ATTR_DEFN_ID AS KIM_ATTR_DEFN_ID, BO.ATTR_VAL AS ATTR_VAL, BO.ATTR_DATA_ID AS ATTR_DATA_ID, BO.OBJ_ID AS ATTR_DATA_OBJ_ID, BO.VER_NBR AS ATTR_DATA_VER_NBR,
        CO.OBJ_ID AS ATTR_DEFN_OBJ_ID, CO.VER_NBR as ATTR_DEFN_VER_NBR, CO.NM AS ATTR_NAME, CO.LBL as ATTR_DEFN_LBL, CO.ACTV_IND as ATTR_DEFN_ACTV_IND, CO.NMSPC_CD AS ATTR_DEFN_NMSPC_CD, CO.CMPNT_NM AS ATTR_DEFN_CMPNT_NM
        FROM KRIM_ROLE_MBR_T A0 JOIN KRIM_ROLE_MBR_ATTR_DATA_T BO ON A0.ROLE_MBR_ID = BO.ROLE_MBR_ID  JOIN KRIM_ATTR_DEFN_T CO ON BO.KIM_ATTR_DEFN_ID = CO.KIM_ATTR_DEFN_ID
        WHERE A0.ROLE_ID in ('100000')
                
        UNION ALL
                
        SELECT D0.ROLE_MBR_ID AS ROLE_MBR_ID,D0.ROLE_ID AS ROLE_ID,D0.MBR_ID AS MBR_ID,D0.MBR_TYP_CD AS MBR_TYP_CD,D0.VER_NBR AS ROLE_MBR_VER_NBR,D0.OBJ_ID AS ROLE_MBR_OBJ_ID,D0.ACTV_FRM_DT AS ROLE_MBR_ACTV_FRM_DT ,D0.ACTV_TO_DT AS ROLE_MBR_ACTV_TO_DT,
        '' AS KIM_TYP_ID, '' AS KIM_ATTR_DEFN_ID, '' AS ATTR_VAL, '' AS ATTR_DATA_ID, '' AS ATTR_DATA_OBJ_ID, NULL AS ATTR_DATA_VER_NBR,
        '' AS ATTR_DEFN_OBJ_ID, NULL as ATTR_DEFN_VER_NBR, '' AS ATTR_NAME, '' as ATTR_DEFN_LBL, '' as ATTR_DEFN_ACTV_IND, '' AS ATTR_DEFN_NMSPC_CD, '' AS ATTR_DEFN_CMPNT_NM
        FROM KRIM_ROLE_MBR_T D0
        WHERE D0.ROLE_MBR_ID NOT IN (SELECT DISTINCT (E0.ROLE_MBR_ID) FROM KRIM_ROLE_MBR_ATTR_DATA_T E0)
        AND D0.ROLE_ID IN ('100000')
        */

        public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
            /*
             The query returns multiple lines for each role by joining a role with each of its members. This allows us to get all the role member
             and role data in a single query (even though we are duplicating the role information across the role members). The cost of this
             comes out to be cheaper than firing indiviudual queries for each role in cases where there are over 500 roles
            */
            StringBuffer sql1 = new StringBuffer("SELECT "
                    + " A0.ROLE_MBR_ID AS ROLE_MBR_ID,A0.ROLE_ID AS ROLE_ID,A0.MBR_ID AS MBR_ID,A0.MBR_TYP_CD AS MBR_TYP_CD,A0.VER_NBR AS ROLE_MBR_VER_NBR,A0.OBJ_ID AS ROLE_MBR_OBJ_ID,A0.ACTV_FRM_DT AS ROLE_MBR_ACTV_FRM_DT ,A0.ACTV_TO_DT AS ROLE_MBR_ACTV_TO_DT, "
                    + " BO.KIM_TYP_ID AS KIM_TYP_ID, BO.KIM_ATTR_DEFN_ID AS KIM_ATTR_DEFN_ID, BO.ATTR_VAL AS ATTR_VAL, BO.ATTR_DATA_ID AS ATTR_DATA_ID, BO.OBJ_ID AS ATTR_DATA_OBJ_ID, BO.VER_NBR AS ATTR_DATA_VER_NBR,  "
                    + " C0.KIM_ATTR_DEFN_ID AS KIM_ATTR_DEFN_ID, C0.OBJ_ID AS ATTR_DEFN_OBJ_ID, C0.VER_NBR as ATTR_DEFN_VER_NBR, C0.NM AS ATTR_NAME, C0.LBL as ATTR_DEFN_LBL, C0.ACTV_IND as ATTR_DEFN_ACTV_IND, C0.NMSPC_CD AS ATTR_DEFN_NMSPC_CD, C0.CMPNT_NM AS ATTR_DEFN_CMPNT_NM "
                    + " FROM KRIM_ROLE_MBR_T A0 JOIN KRIM_ROLE_MBR_ATTR_DATA_T BO ON A0.ROLE_MBR_ID = BO.ROLE_MBR_ID "
                    + " JOIN KRIM_ATTR_DEFN_T C0 ON BO.KIM_ATTR_DEFN_ID = C0.KIM_ATTR_DEFN_ID  ");

            StringBuffer sql2 = new StringBuffer("SELECT"
                    + " D0.ROLE_MBR_ID AS ROLE_MBR_ID,D0.ROLE_ID AS ROLE_ID,D0.MBR_ID AS MBR_ID,D0.MBR_TYP_CD AS MBR_TYP_CD,D0.VER_NBR AS ROLE_MBR_VER_NBR,D0.OBJ_ID AS ROLE_MBR_OBJ_ID,D0.ACTV_FRM_DT AS ROLE_MBR_ACTV_FRM_DT ,D0.ACTV_TO_DT AS ROLE_MBR_ACTV_TO_DT, "
                    + " '' AS KIM_TYP_ID, '' AS KIM_ATTR_DEFN_ID, '' AS ATTR_VAL, '' AS ATTR_DATA_ID, '' AS ATTR_DATA_OBJ_ID, NULL AS ATTR_DATA_VER_NBR,"
                    + " '' AS KIM_ATTR_DEFN_ID,'' AS ATTR_DEFN_OBJ_ID, NULL as ATTR_DEFN_VER_NBR, '' AS ATTR_NAME, '' as ATTR_DEFN_LBL, '' as ATTR_DEFN_ACTV_IND, '' AS ATTR_DEFN_NMSPC_CD, '' AS ATTR_DEFN_CMPNT_NM "
                    + " FROM KRIM_ROLE_MBR_T D0 "
                    + " WHERE D0.ROLE_MBR_ID NOT IN (SELECT DISTINCT (E0.ROLE_MBR_ID) FROM KRIM_ROLE_MBR_ATTR_DATA_T E0)");

            StringBuffer criteria = new StringBuffer();

            List<String> params1 = new ArrayList<String>();
            List<String> params2 = new ArrayList<String>();

            if (roleIDs != null && !roleIDs.isEmpty()) {
                criteria.append("A0.ROLE_ID IN (");

                for (String roleId : roleIDs) {
                    criteria.append("?,");
                    params1.add(roleId);
                    params2.add(roleId);
                }
                criteria.deleteCharAt(criteria.length() - 1);
                criteria.append(")");
            }

            if (memberTypeCd != null) {
                if (criteria.length() > 0) {
                    criteria.append(" AND ");
                }

                criteria.append("A0.MBR_TYP_CD = ?");
                params1.add(memberTypeCd);
                params2.add(memberTypeCd);
            }

            // Assuming that at least a role id or role member type code is specified
            if (criteria.length() > 0) {
                sql1.append(" WHERE ");
                sql2.append(" AND ");
                sql1.append(criteria);
                sql2.append(criteria.toString().replaceAll("A0", "D0"));
            }

            if (qual != null && CollectionUtils.isNotEmpty(qual.keySet())) {

                // If Qualifiers present then sql2 should not be returning any result as it finds
                // rolemembers with now attributes
                sql2 = new StringBuffer();

                if (criteria.length() > 0) {
                    sql1.append(" AND ");
                } else {
                    sql1.append(" WHERE ");
                }

                sql1.append(" EXISTS (SELECT B1.ROLE_MBR_ID FROM KRIM_ROLE_MBR_ATTR_DATA_T B1 WHERE (");
                for (Map.Entry<String, String> qualifier : qual.entrySet()) {
                    if (StringUtils.isNotEmpty(qualifier.getValue())) {
                        String value = (qualifier.getValue()).replace('*', '%');
                        sql1.append(" (B1.ATTR_VAL LIKE ? AND B1.KIM_ATTR_DEFN_ID = ? ) ");
                        params1.add(value);
                        params1.add(qualifier.getKey());
                    }
                    sql1.append("OR");
                }
                sql1.delete(sql1.length() - 2, sql1.length());
                sql1.append(") AND B1.ROLE_MBR_ID = A0.ROLE_MBR_ID )");

            }

            StringBuffer sql = new StringBuffer(sql1.toString());

            if (sql2.length() > 0) {
                sql.append(" UNION ALL ");
                sql.append(sql2.toString());
            }

            sql.append(" ORDER BY ROLE_MBR_ID ");

            PreparedStatement statement = connection.prepareStatement(sql.toString());
            int i = 1;
            for (String param : params1) {
                statement.setString(i, param);
                i++;
            }

            if (sql2.length() > 0) {
                for (String param : params2) {
                    statement.setString(i, param);
                    i++;
                }
            }

            return statement;
        }
    }, new PreparedStatementCallback<List<RoleMemberBo>>() {
        public List<RoleMemberBo> doInPreparedStatement(PreparedStatement statement)
                throws SQLException, DataAccessException {
            ResultSet rs = statement.executeQuery();
            try {
                RoleMemberBo lastRoleMember = null;
                while (rs.next()) {
                    boolean processRolemember = true;

                    String roleId = rs.getString("ROLE_ID");
                    String id = rs.getString("ROLE_MBR_ID");
                    String memberId = rs.getString("MBR_ID");

                    MemberType memberType = MemberType.fromCode(rs.getString("MBR_TYP_CD"));
                    DateTime activeFromDate = rs.getDate("ROLE_MBR_ACTV_FRM_DT") == null ? null
                            : new DateTime(rs.getDate("ROLE_MBR_ACTV_FRM_DT"));
                    DateTime activeToDate = rs.getDate("ROLE_MBR_ACTV_TO_DT") == null ? null
                            : new DateTime(rs.getDate("ROLE_MBR_ACTV_TO_DT"));

                    // Since we are joining role members and attributes we would have multiple role member rows
                    // but one row per attribute so check if its the first time we are seeing the role member
                    if (lastRoleMember == null || !id.equals(lastRoleMember.getId())) {
                        RoleMember roleMember = RoleMember.Builder.create(roleId, id, memberId, memberType,
                                activeFromDate, activeToDate, new HashMap<String, String>(), "", "").build();
                        Long roleVersionNbr = rs.getLong("ROLE_MBR_VER_NBR");
                        String roleObjId = rs.getString("ROLE_MBR_OBJ_ID");

                        RoleMemberBo roleMemberBo = RoleMemberBo.from(roleMember);
                        roleMemberBo.setVersionNumber(roleVersionNbr);
                        roleMemberBo.setObjectId(roleObjId);
                        List<RoleMemberAttributeDataBo> roleMemAttrBos = new ArrayList<RoleMemberAttributeDataBo>();

                        roleMemberBo.setAttributeDetails(roleMemAttrBos);
                        if (roleMemberBo.isActive(new Timestamp(System.currentTimeMillis()))) {
                            roleMemberBos.add(roleMemberBo);
                        } else {
                            processRolemember = false;
                        }

                        lastRoleMember = roleMemberBo;
                    }

                    String kimTypeId = rs.getString("KIM_TYP_ID");
                    String attrKey = rs.getString("KIM_ATTR_DEFN_ID");
                    String attrVal = rs.getString("ATTR_VAL");
                    if (processRolemember && StringUtils.isNotEmpty(kimTypeId)) {
                        KimType theType = KimApiServiceLocator.getKimTypeInfoService().getKimType(kimTypeId);
                        // Create RoleMemberAttributeDataBo for this row
                        RoleMemberAttributeDataBo roleMemAttrDataBo = new RoleMemberAttributeDataBo();

                        KimAttribute.Builder attrBuilder = KimAttribute.Builder.create(
                                rs.getString("ATTR_DEFN_CMPNT_NM"), rs.getString("ATTR_NAME"),
                                rs.getString("ATTR_DEFN_NMSPC_CD"));
                        attrBuilder.setActive(Truth.strToBooleanIgnoreCase(rs.getString("ATTR_DEFN_ACTV_IND")));
                        attrBuilder.setAttributeLabel(rs.getString("ATTR_DEFN_LBL"));
                        attrBuilder.setId(rs.getString("KIM_ATTR_DEFN_ID"));
                        attrBuilder.setObjectId(rs.getString("ATTR_DEFN_OBJ_ID"));
                        attrBuilder.setVersionNumber(rs.getLong("ATTR_DEFN_VER_NBR"));

                        roleMemAttrDataBo.setId(rs.getString("ATTR_DATA_ID"));
                        roleMemAttrDataBo.setAssignedToId(id);
                        roleMemAttrDataBo.setKimTypeId(kimTypeId);
                        roleMemAttrDataBo.setKimType(KimTypeBo.from(theType));
                        roleMemAttrDataBo.setKimAttributeId(attrBuilder.getId());
                        roleMemAttrDataBo.setAttributeValue(attrVal);
                        roleMemAttrDataBo.setVersionNumber(rs.getLong("ATTR_DATA_VER_NBR"));
                        roleMemAttrDataBo.setObjectId(rs.getString("ATTR_DATA_OBJ_ID"));

                        roleMemAttrDataBo.setKimAttribute(KimAttributeBo.from(attrBuilder.build()));
                        lastRoleMember.getAttributeDetails().add(roleMemAttrDataBo);
                    }

                }
            } finally {
                if (rs != null) {
                    rs.close();
                }
            }
            return roleMemberBos;
        }
    });
    return roleMemberBos;
}

From source file:com.dlshouwen.jspc.zwpc.controller.SelfEvaluateController.java

/**
 * //from   ww  w.java  2  s.  co m
 *
 * @param applyIds ?
 * @param request 
 * @return ajax?
 * @throws Exception 
 */
@RequestMapping(value = "/deleteApply", method = RequestMethod.POST)
@ResponseBody
public AjaxResponse deleteApply(String applyIds, HttpServletRequest request) throws Exception {
    //          ?
    StringBuffer deleteApplayIds = new StringBuffer();

    //          ??
    int totalCount = applyIds.split(",").length;
    int expNowCount = 0;

    //          ???
    StringBuffer successIds = new StringBuffer();
    StringBuffer failureIds = new StringBuffer();

    //          ??
    for (String applyId : applyIds.split(",")) {
        //              ??
        boolean isNowExp = expDao.getExpreviewById(applyId).getStatus().equals("0");
        if (isNowExp) {
            expNowCount++;
            failureIds.append(applyId).append(",");
            continue;
        }

        successIds.append(applyId).append(",");
        //              ?
        deleteApplayIds.append(applyId).append(",");
    }
    if (deleteApplayIds.length() > 0) {
        deleteApplayIds.deleteCharAt(deleteApplayIds.length() - 1);
        //              
        expDao.deleteExpreview(deleteApplayIds.toString());
    }
    //          ???
    StringBuffer message = new StringBuffer();
    message.append("").append(totalCount).append("?<br /><br />");
    message.append("?").append(totalCount - expNowCount).append("?<br />");
    if (expNowCount > 0) {
        message.append("").append(expNowCount)
                .append("?<br />");
    }
    //          ?
    AjaxResponse ajaxResponse = new AjaxResponse();
    ajaxResponse.setSuccess(true);
    ajaxResponse.setSuccessMessage(message.toString());
    ajaxResponse.setData(deleteApplayIds.toString().replaceAll("'", ""));
    //          ?
    LogUtils.updateOperationLog(request, OperationType.DELETE,
            "?" + successIds.toString()
                    + "" + failureIds.toString());
    return ajaxResponse;
}

From source file:edu.wustl.geneconnect.metadata.MetadataCalculator.java

private void writeSubPaths(String subPathFileName, String subPathFileNameForDB) {
    try {//  w w  w.  j  a va  2s . c o m
        FileWriter opFile = new FileWriter(new File(subPathFileName));
        FileWriter opFileForDB = new FileWriter(new File(subPathFileNameForDB));

        opFileForDB.write("LOAD DATA INFILE * APPEND INTO TABLE SUBPATH FIELDS TERMINATED BY '"
                + FIELD_DELIMITER + "' " + "(PATH_ID, SUBPATH_ID)\n" + "BEGINDATA\n");

        Iterator mapIter = m_pathToSubPathMap.entrySet().iterator();
        for (Iterator iter = m_pathToSubPathMap.entrySet().iterator(); iter.hasNext();) {
            Map.Entry entry = (Map.Entry) iter.next();
            String parentPathID = ((Integer) (entry.getKey())).toString();
            String subpathID;
            StringBuffer line = new StringBuffer();
            line.append(parentPathID + FIELD_DELIMITER);

            StringBuffer lineForDB = new StringBuffer();

            List subPaths = (List) entry.getValue();

            for (int i = 0; i < subPaths.size(); ++i) {
                subpathID = ((Integer) subPaths.get(i)).toString();
                line.append(subpathID + SUBPATH_IDS_DELIMITER);

                lineForDB.append(parentPathID + FIELD_DELIMITER + subpathID + "\n");
            }

            // remove the last '_'
            line.deleteCharAt(line.length() - 1);

            line.append("\n");

            opFile.write(line.toString());
            opFile.flush();

            opFileForDB.write(lineForDB.toString());
            opFileForDB.flush();
        }

        opFile.close();
    } catch (IOException e) {
        System.out.println("Failed to create an output file in current directory" + e.getMessage());
    }
}

From source file:cn.com.sinosoft.cimp.recordsummarize.datadeduplication.service.impl.DataDeduplicationService.java

/** 
  *  Example: //w ww . j ava2s  .  com
  *  List sqhlist=[aa,bb,cc,dd,ee,ff,gg] ; 
  *  Test.getSqlStrByList(sqhList,3,"SHENQINGH")=  
  *  "SHENQING IN ('aa','bb','cc') OR SHENQINGH IN ('dd','ee','ff') OR SHENQINGH IN ('gg')" 
  *  
  *  1000????splitNumsqlin ? 
  * @param sqhList ?List 
  * @param splitNum , 1000 
  * @param columnName SQL?? Z.SHENQINGH  
  * @return 
  */
public String getSqlStrByList(List sqhList, int splitNum, String columnName) {
    if (splitNum > 1000) //?sql??1000.  
        return null;
    StringBuffer sql = new StringBuffer("");
    if (sqhList != null) {
        sql.append(" ").append(columnName).append(" IN ( ");
        for (int i = 0; i < sqhList.size(); i++) {
            sql.append("'").append(sqhList.get(i) + "',");
            if ((i + 1) % splitNum == 0 && (i + 1) < sqhList.size()) {
                sql.deleteCharAt(sql.length() - 1);
                sql.append(" ) OR ").append(columnName).append(" IN (");
            }
        }
        sql.deleteCharAt(sql.length() - 1);
        sql.append(" )");
    }
    return sql.toString();
}

From source file:com.fujitsu.dc.test.jersey.cell.AclTest.java

() {
    String testBox = "testBox_27481Cell";
    String testRole = "testRole_27481Cell";
    try {// w  ww  .ja va2s . c  o  m
        // Box??
        BoxUtils.create(TEST_CELL1, testBox, TOKEN);

        // Box????Role??
        RoleUtils.create(TEST_CELL1, TOKEN, testBox, testRole, HttpStatus.SC_CREATED);
        // Box??????Role??
        RoleUtils.create(TEST_CELL1, TOKEN, null, testRole, HttpStatus.SC_CREATED);

        // ACLtestcell1?
        Http.request("cell/acl-setting-single.txt")
                .with("url", TEST_CELL1)
                .with("token", TOKEN)
                .with("role1", testRole)
                .with("roleBaseUrl", UrlUtils.roleResource(TEST_CELL1, null, ""))
                .returns()
                .statusCode(HttpStatus.SC_OK);

        // PROPFIND?testcell1?ACL?
        TResponse tresponse = Http.request("cell/propfind-cell-allprop.txt")
                .with("url", TEST_CELL1)
                .with("depth", "0")
                .with("token", TOKEN)
                .returns();
        tresponse.statusCode(HttpStatus.SC_MULTI_STATUS);

        // PROPFOIND???
        List<Map<String, List<String>>> list = new ArrayList<Map<String, List<String>>>();
        Map<String, List<String>> map = new HashMap<String, List<String>>();
        List<String> rolList = new ArrayList<String>();
        rolList.add("auth");
        rolList.add("auth-read");
        map.put(testRole, rolList);
        list.add(map);

        String resorce = UrlUtils.cellRoot(TEST_CELL1);
        Element root = tresponse.bodyAsXml().getDocumentElement();

        StringBuffer sb = new StringBuffer(resorce);

        // 1??
        sb.deleteCharAt(resorce.length() - 1);

        TestMethodUtils.aclResponseTest(root, sb.toString(), list, 1,
                UrlUtils.roleResource(TEST_CELL1, Box.DEFAULT_BOX_NAME, ""), null);

    } finally {
        // ACL???
        Http.request("cell/acl-default.txt")
                .with("url", TEST_CELL1)
                .with("token", TOKEN)
                .with("role1", TEST_ROLE1)
                .with("role2", TEST_ROLE2)
                .with("box", Setup.TEST_BOX1)
                .with("roleBaseUrl", UrlUtils.roleResource(TEST_CELL1, null, ""))
                .with("level", "")
                .returns()
                .statusCode(HttpStatus.SC_OK);
        // Role?(Box?????)
        RoleUtils.delete(TEST_CELL1, TOKEN, testBox, testRole);
        // Role?(Box??????)
        RoleUtils.delete(TEST_CELL1, TOKEN, null, testRole);
        // Box?
        BoxUtils.delete(TEST_CELL1, TOKEN, testBox);
    }
}

From source file:my.home.model.datasource.AutoCompleteItemDataSourceImpl.java

public void markCurrentInput(Context context, String inputString) {
    Log.d(TAG, "mark: " + inputString);
    StringBuffer inputBuffer = new StringBuffer(inputString);
    StringBuffer msgBuffer = new StringBuffer();
    boolean in_if_state = false;
    boolean in_if_then_state = false;
    boolean in_while_state = false;
    boolean in_msg_or_time_ind_state = false;
    String lastString = null;/*from w w  w  . ja  va2s.co  m*/
    String preMsgString = null;
    String curState = mInitState;
    while (inputBuffer.length() > 0) {
        if (in_msg_or_time_ind_state) {
            if (inputBuffer.toString().startsWith(mMessageSeq) || inputBuffer.toString().startsWith(mTimeSeq)) {
                in_msg_or_time_ind_state = false;
                MsgHistoryItem msgHistoryItem = new MsgHistoryItem();
                msgHistoryItem.setFrom(preMsgString);
                msgHistoryItem.setMsg(msgBuffer.toString());
                DBStaticManager.addMsgHistoryItem(context, msgHistoryItem);

                msgBuffer.delete(0, msgBuffer.length());
                preMsgString = null;
            } else {
                msgBuffer.append(inputBuffer.charAt(0));
            }
            inputBuffer.deleteCharAt(0);
            continue;
        }
        boolean found = false;
        String tempInput = inputBuffer.toString();
        if (!mLinks.containsKey(curState)) {
            return;
        }
        for (String nextState : mLinks.get(curState)) {
            if (!in_if_state && !in_while_state) {
                if (nextState.equals("then") || nextState.equals("compare") || nextState.equals("logical"))
                    continue;
            }
            if (!in_if_then_state) {
                if (nextState.equals("else"))
                    continue;
            }
            for (String val : mNodes.get(nextState)) {
                if (tempInput.startsWith(val)) {
                    if (lastString != null) {
                        addNewHistoryItem(context, lastString, val);
                    }

                    inputBuffer.delete(0, val.length());
                    found = true;
                    if (nextState.equals("message") || nextState.equals("time")) {
                        in_msg_or_time_ind_state = true;
                        preMsgString = lastString;
                    } else if (nextState.equals("if")) {
                        in_if_state = true;
                    } else if (nextState.equals("while")) {
                        in_while_state = true;
                    } else if (nextState.equals("then")) {
                        if (in_if_state)
                            in_if_then_state = true;
                        in_if_state = false;
                        in_while_state = false;
                    } else if (in_if_then_state && nextState.equals("else")) {
                        in_if_then_state = false;
                    }
                    lastString = val;
                    curState = nextState;
                    break;
                }
            }
            if (found || inputBuffer.length() == 0)
                break;
        }
        if (inputBuffer.length() == 0) {
            break;
        }
        if (found) {
            if (msgBuffer.length() != 0) {
                MsgHistoryItem msgHistoryItem = new MsgHistoryItem();
                msgHistoryItem.setFrom(preMsgString);
                msgHistoryItem.setMsg(msgBuffer.toString());
                DBStaticManager.addMsgHistoryItem(context, msgHistoryItem);

                msgBuffer.delete(0, msgBuffer.length());
                preMsgString = null;
            }
            continue;
        }
        if (curState.equals("message") || mLinks.get(curState).contains("message")) {
            found = true;
            curState = "message";
            preMsgString = lastString;
            msgBuffer.append(inputBuffer.charAt(0));
            inputBuffer.deleteCharAt(0);
        } else if (curState.equals("time") || mLinks.get(curState).contains("time")) {
            found = true;
            curState = "time";
            preMsgString = lastString;
            msgBuffer.append(inputBuffer.charAt(0));
            inputBuffer.deleteCharAt(0);
        }
        if (!found)
            break;
    }
    if (msgBuffer.length() != 0) {
        MsgHistoryItem msgHistoryItem = new MsgHistoryItem();
        msgHistoryItem.setFrom(preMsgString);
        msgHistoryItem.setMsg(msgBuffer.toString());
        DBStaticManager.addMsgHistoryItem(context, msgHistoryItem);
    }
}

From source file:com.openerp.orm.ORM.java

/**
 * Creates the statement./*w w w  .j a  v  a 2s .  c  o m*/
 * 
 * @param table
 *            the table
 * @param fields
 *            the fields
 * @return the sQL statement
 */
private SQLStatement createStatement(String table, List<Fields> fields) {
    SQLStatement statement = new SQLStatement();
    StringBuffer sql = new StringBuffer();
    sql.append("CREATE TABLE IF NOT EXISTS ");
    sql.append(table);
    sql.append(" (");
    for (Fields field : fields) {
        try {
            sql.append(field.getName());
            sql.append(" ");
            sql.append(field.getType());
            sql.append(", ");
        } catch (Exception e) {

        }
    }
    sql.deleteCharAt(sql.lastIndexOf(","));
    sql.append(")");

    statement.setTable_name(table);
    statement.setType("create");
    statement.setStatement(sql.toString());
    return statement;
}

From source file:repast.simphony.relogo.ide.wizards.NetlogoImportWizard.java

protected String camelCase(String text, boolean cap) {
    StringBuffer buf = new StringBuffer(text);
    for (int i = 0; i < buf.length(); i++) {
        if (buf.charAt(i) == '-' && buf.length() > (i + 1)) {
            buf.deleteCharAt(i);
            if (buf.charAt(i) != '?' && buf.charAt(i) != '%') {
                buf.setCharAt(i, Character.toUpperCase(buf.charAt(i)));
            } else if (buf.charAt(i) == '?') {
                buf.setCharAt(i, 'Q');
            } else if (buf.charAt(i) == '%') {
                buf.setCharAt(i, 'P');
            }// ww  w .  jav a 2s . c  o m
        } else if (buf.charAt(i) == '?') {
            buf.setCharAt(i, 'Q');
        } else if (buf.charAt(i) == '%') {
            buf.setCharAt(i, 'p');
        }
    }
    if (cap)
        buf.setCharAt(0, Character.toUpperCase(buf.charAt(0)));
    return buf.toString();
}