List of usage examples for java.lang StringBuffer replace
@Override public synchronized StringBuffer replace(int start, int end, String str)
From source file:de.marcelkapfer.morseconverter.MainActivity.java
public void mll(View view) { EditText editText = (EditText) findViewById(R.id.edit_message); StringBuffer message = new StringBuffer(editText.getText()); if (message.toString().endsWith(" ")) { message = message.deleteCharAt(message.length() - 1); }/*from ww w . j av a 2 s .c om*/ String input; StringBuffer output = new StringBuffer(); input = message.toString().toUpperCase() + "#"; StringBuffer inputToSign = new StringBuffer(input); while (!message.toString().equals(" ")) { int d = 0; boolean signFull = true; StringBuffer sign = new StringBuffer(); while (signFull) { if (inputToSign.toString().startsWith(" ")) { output.append(" "); inputToSign.delete(d, d + 9); } else if (inputToSign.toString().substring(d, d + 3).equals(" ")) { if (d == 0) { inputToSign.delete(0, 3); } else { sign.replace(0, sign.length(), inputToSign.toString().substring(0, d)); inputToSign.delete(0, d); signFull = false; } } else { d++; } } if (sign.toString().equals(".-")) { output.append("A"); } else if (sign.toString().equals("-...")) { output.append("B"); } else if (sign.toString().equals("-.-.")) { output.append("C"); } else if (sign.toString().equals("-..")) { output.append("D"); } else if (sign.toString().equals(".")) { output.append("E"); } else if (sign.toString().equals("..-.")) { output.append("F"); } else if (sign.toString().equals("--.")) { output.append("G"); } else if (sign.toString().equals("....")) { output.append("H"); } else if (sign.toString().equals("..")) { output.append("I"); } else if (sign.toString().equals(".---")) { output.append("J"); } else if (sign.toString().equals("-.-")) { output.append("K"); } else if (sign.toString().equals(".-..")) { output.append("L"); } else if (sign.toString().equals("--")) { output.append("M"); } else if (sign.toString().equals("-.")) { output.append("N"); } else if (sign.toString().equals("---")) { output.append("O"); } else if (sign.toString().equals(".--.")) { output.append("P"); } else if (sign.toString().equals("--.-")) { output.append("Q"); } else if (sign.toString().equals(".-.")) { output.append("R"); } else if (sign.toString().equals("...")) { output.append("S"); } else if (sign.toString().equals("-")) { output.append("T"); } else if (sign.toString().equals("..-")) { output.append("U"); } else if (sign.toString().equals("...-")) { output.append("V"); } else if (sign.toString().equals(".--")) { output.append("W"); } else if (sign.toString().equals("-..-")) { output.append("X"); } else if (sign.toString().equals("-.--")) { output.append("Y"); } else if (sign.toString().equals("--..")) { output.append("Z"); } else if (sign.toString().equals("-----")) { output.append(". (zero)"); } else if (sign.toString().equals(".----")) { output.append("-"); } else if (sign.toString().equals("..---")) { output.append("2"); } else if (sign.toString().equals("...--")) { output.append("3"); } else if (sign.toString().equals("....-")) { output.append("4"); } else if (sign.toString().equals(".....")) { output.append("5"); } else if (sign.toString().equals("-....")) { output.append("6"); } else if (sign.toString().equals("--...")) { output.append("7"); } else if (sign.toString().equals("---..")) { output.append("8"); } else if (sign.toString().equals("----.")) { output.append("9"); } else if (sign.toString().equals(".-.-")) { output.append(""); } else if (sign.toString().equals("---.")) { output.append(""); } else if (sign.toString().equals("..--")) { output.append(""); } else if (sign.toString().equals("...--...")) { output.append(""); } else if (sign.toString().equals("----")) { output.append("CH"); } else if (sign.toString().equals(".-.-.-")) { output.append("."); } else if (sign.toString().equals("--..--")) { output.append(","); } else if (sign.toString().equals("---...")) { output.append(":"); } else if (sign.toString().equals("-.-.-.")) { output.append(";"); } else if (sign.toString().equals("..--..")) { output.append("?"); } else if (sign.toString().equals("-.-.--")) { output.append("!"); } else if (sign.toString().equals("-....-")) { output.append("-"); } else if (sign.toString().equals("..--.-")) { output.append("_"); } else if (sign.toString().equals("-.--.")) { output.append("("); } else if (sign.toString().equals("-.--.-")) { output.append(")"); } else if (sign.toString().equals(".----.")) { output.append("'"); } else if (sign.toString().equals("-...-")) { output.append("="); } else if (sign.toString().equals(".-.-.")) { output.append("+ or End of the signal"); } else if (sign.toString().equals("-..-.")) { output.append("/"); } else if (sign.toString().equals(".--.-.")) { output.append("@"); } else if (sign.toString().equals("-.-.-")) { output.append("Begin of the signal"); } else if (sign.toString().equals("-...-")) { output.append("Wait"); } else if (sign.toString().equals("...-.")) { output.append("Understood"); } else if (sign.toString().equals("...-.-")) { output.append("End of work"); } else if (sign.toString().equals("...---...")) { output.append("SOS"); } else if (sign.toString().equals("........")) { output.append("Error"); } else { tfOutput = "Code not listed or wrong."; } } tfOutput = output.toString(); lastFragment = 1; After(view); }
From source file:org.wso2.carbon.greg.migration.MigrationDatabaseCreator.java
/** * executes content in SQL script/* www. jav a2 s. c om*/ * * @throws Exception */ private void executeSQLScript(String dbscriptName) throws IOException, SQLException { boolean keepFormat = false; StringBuffer sql = new StringBuffer(); BufferedReader reader = null; try { InputStream is = getClass().getResourceAsStream(dbscriptName); reader = new BufferedReader(new InputStreamReader(is)); String line; while ((line = reader.readLine()) != null) { line = line.trim(); if (!keepFormat) { if (line.startsWith("//")) { continue; } if (line.startsWith("--")) { continue; } StringTokenizer st = new StringTokenizer(line); if (st.hasMoreTokens()) { String token = st.nextToken(); if ("REM".equalsIgnoreCase(token)) { continue; } } } sql.append(keepFormat ? "\n" : " ").append(line); if (!keepFormat && line.indexOf("--") >= 0) { sql.append("\n"); } if ((DatabaseCreator.checkStringBufferEndsWith(sql, delimiter))) { executeSQL(sql.substring(0, sql.length() - delimiter.length())); sql.replace(0, sql.length(), ""); } } if (sql.length() > 0) { executeSQL(sql.toString()); } } finally { if (reader != null) { reader.close(); } } }
From source file:org.wso2.carbon.greg.migration.MigrationDatabaseCreator.java
/** * executes content in idp & sp SQL scripts * * @throws Exception// w ww . j a va 2 s .c o m */ private void executeIdentitySQLScript(String dbscriptName) throws Exception { String databaseType = DatabaseCreator.getDatabaseType(this.conn); boolean keepFormat = false; if (Constants.DatabaseTypes.oracle.toString().equals(databaseType)) { delimiter = "/"; } else if (Constants.DatabaseTypes.db2.toString().equals(databaseType)) { delimiter = "/"; } else if ("openedge".equals(databaseType)) { delimiter = "//"; keepFormat = true; } StringBuffer sql = new StringBuffer(); BufferedReader reader = null; try { InputStream is = getClass().getResourceAsStream(dbscriptName); reader = new BufferedReader(new InputStreamReader(is)); String line; while ((line = reader.readLine()) != null) { line = line.trim(); if (!keepFormat) { if (line.startsWith("//")) { continue; } if (line.startsWith("--")) { continue; } StringTokenizer st = new StringTokenizer(line); if (st.hasMoreTokens()) { String token = st.nextToken(); if ("REM".equalsIgnoreCase(token)) { continue; } } } sql.append(keepFormat ? "\n" : " ").append(line); if (!keepFormat && line.indexOf("--") >= 0) { sql.append("\n"); } if ((DatabaseCreator.checkStringBufferEndsWith(sql, delimiter))) { executeSQL(sql.substring(0, sql.length() - delimiter.length())); sql.replace(0, sql.length(), ""); } } if (sql.length() > 0) { executeSQL(sql.toString()); } } finally { if (reader != null) { reader.close(); } } }
From source file:de.marcelkapfer.morseconverter.MainActivity.java
public void encode(View view) { EditText editText = (EditText) findViewById(R.id.edit_message); StringBuffer message = new StringBuffer(editText.getText()); if (message.toString().endsWith(" ")) { message = message.deleteCharAt(message.length() - 1); }/*from w ww.j a va 2s. co m*/ // Variables String input; StringBuffer output = new StringBuffer(); input = message.toString().toUpperCase() + "#"; StringBuffer inputToSign = new StringBuffer(input); while (!inputToSign.toString().equals("#")) { int d = 0; boolean signFull = true; StringBuffer sign = new StringBuffer(); while (signFull) { if (inputToSign.toString().charAt(d) == '+' || inputToSign.toString().charAt(d) == '#') { if (d == 0) { if (inputToSign.toString().startsWith("+")) { output.append(" "); } inputToSign.deleteCharAt(0); } else { sign.replace(0, sign.length(), inputToSign.toString().substring(0, d)); inputToSign.delete(0, d); signFull = false; } } else { d++; } } if (input.equals("")) { break; } else if (sign.toString().equals("01")) { output.append("A"); } else if (sign.toString().equals("1000")) { output.append("B"); } else if (sign.toString().equals("1010")) { output.append("C"); } else if (sign.toString().equals("100")) { output.append("D"); } else if (sign.toString().equals("0")) { output.append("E"); } else if (sign.toString().equals("0010")) { output.append("F"); } else if (sign.toString().equals("110")) { output.append("G"); } else if (sign.toString().equals("0000")) { output.append("H"); } else if (sign.toString().equals("00")) { output.append("I"); } else if (sign.toString().equals("0111")) { output.append("J"); } else if (sign.toString().equals("101")) { output.append("K"); } else if (sign.toString().equals("0100")) { output.append("L"); } else if (sign.toString().equals("11")) { output.append("M"); } else if (sign.toString().equals("10")) { output.append("N"); } else if (sign.toString().equals("111")) { output.append("O"); } else if (sign.toString().equals("0110")) { output.append("P"); } else if (sign.toString().equals("1101")) { output.append("Q"); } else if (sign.toString().equals("010")) { output.append("R"); } else if (sign.toString().equals("000")) { output.append("S"); } else if (sign.toString().equals("1")) { output.append("T"); } else if (sign.toString().equals("001")) { output.append("U"); } else if (sign.toString().equals("0001")) { output.append("V"); } else if (sign.toString().equals("011")) { output.append("W"); } else if (sign.toString().equals("1001")) { output.append("X"); } else if (sign.toString().equals("1011")) { output.append("Y"); } else if (sign.toString().equals("1100")) { output.append("Z"); } else if (sign.toString().equals("11111")) { output.append("0 (zero)"); } else if (sign.toString().equals("01111")) { output.append("1"); } else if (sign.toString().equals("00111")) { output.append("2"); } else if (sign.toString().equals("00011")) { output.append("3"); } else if (sign.toString().equals("00001")) { output.append("4"); } else if (sign.toString().equals("00000")) { output.append("5"); } else if (sign.toString().equals("10000")) { output.append("6"); } else if (sign.toString().equals("11000")) { output.append("7"); } else if (sign.toString().equals("11100")) { output.append("8"); } else if (sign.toString().equals("11110")) { output.append("9"); } else if (sign.toString().equals("0101")) { output.append(""); } else if (sign.toString().equals("1110")) { output.append(""); } else if (sign.toString().equals("0011")) { output.append(""); } else if (sign.toString().equals("00011000")) { output.append(""); } else if (sign.toString().equals("1111")) { output.append("CH"); } else if (sign.toString().equals("010101")) { output.append("."); } else if (sign.toString().equals("110011")) { output.append(","); } else if (sign.toString().equals("111000")) { output.append(":"); } else if (sign.toString().equals("101010")) { output.append(";"); } else if (sign.toString().equals("001100")) { output.append("?"); } else if (sign.toString().equals("101011")) { output.append("!"); } else if (sign.toString().equals("100001")) { output.append("-"); } else if (sign.toString().equals("001101")) { output.append("_"); } else if (sign.toString().equals("10110")) { output.append("("); } else if (sign.toString().equals("101101")) { output.append(")"); } else if (sign.toString().equals("011110")) { output.append("'"); } else if (sign.toString().equals("10001")) { output.append("="); } else if (sign.toString().equals("01010")) { output.append("+ or End of the signal"); } else if (sign.toString().equals("10010")) { output.append("/"); } else if (sign.toString().equals("011010")) { output.append("@"); } else if (sign.toString().equals("10101")) { output.append("Begin of the signal"); } else if (sign.toString().equals("10001")) { output.append("Wait"); } else if (sign.toString().equals("00010")) { output.append("Understood"); } else if (sign.toString().equals("000101")) { output.append("End of work"); } else if (sign.toString().equals("000111000")) { output.append("SOS"); } else if (sign.toString().equals("00000000")) { output.append("Error"); } else { tfOutput = "Code not listed or wrong."; } } tfOutput = output.toString(); lastFragment = 0; After(view); /*} catch (Exception e) { tfOutput.setText("Some error occured. I'm sorry!"); }*/ }
From source file:org.pssframework.xsqlbuilder.XsqlBuilder.java
/** * @see #applyFilters(String, Map)/*from ww w .j a v a 2s . com*/ */ private XsqlFilterResult applyFilters(StringBuffer xsql, Object filters) { LinkedHashMap acceptedFilters = new LinkedHashMap(); for (int i = 0, end = 0, start = xsql.indexOf("/~"); ((start = xsql.indexOf("/~", end)) >= 0); i++) { end = xsql.indexOf("~/", start); KeyMetaDatas metadatas = getKeyMetaDatas(xsql, start, end); if (metadatas.markKeys.isEmpty() && metadatas.replaceKeys.isEmpty()) throw new IllegalArgumentException("Not key found in segment=" + xsql.substring(start, end + 2)); if (isAcceptedAllKeys(filters, metadatas.markKeys) && isAcceptedAllKeys(filters, metadatas.replaceKeys)) { if (logger.isDebugEnabled()) { logger.debug("The filter markKeys=" + metadatas.markKeys + " replaceKeys=" + metadatas.replaceKeys + " is accepted on segment=" + xsql.substring(start, end + 2)); } String segment = xsql.substring(start + 2, end); segment = mergeMarkKeysIntoAcceptedFilters(filters, acceptedFilters, metadatas, segment); segment = replaceReplaceKeysWithValues(filters, metadatas.replaceKeys, segment); xsql.replace(start, end + 2, segment); end = start + segment.length(); } else { if (logger.isDebugEnabled()) { logger.debug( "The filter markKeys=" + metadatas.markKeys + " replaceKeys=" + metadatas.replaceKeys + " is removed from the query on segment=" + xsql.substring(start, end + 2)); } xsql.replace(start, end + 2, ""); end = start; } } return new XsqlFilterResult(xsql.toString(), acceptedFilters); }
From source file:org.opentestsystem.delivery.testreg.domain.Student.java
/** * Returns only accommodation information about a student. * Use toStringArray() to get actual student record information. *///from www . j a va 2s .com @SuppressWarnings("unchecked") @Override public String[][] toMultiRowStringArray() { String[][] rows; Object[] accommodations = this.getAccommodations(); if (accommodations != null && accommodations.length > 0) { rows = new String[this.accommodations.length][toStringArray().length + getAccommodations().length]; int rowCount = 0; int accSize = 0; accSize = accommodations.length; for (int i = 0; i < accSize; i++) { Object obj = accommodations[i]; Map<String, Object> acc = (Map<String, Object>) obj; Set<String> accommodationNames = acc.keySet(); List<String> accommo = new ArrayList<String>(); for (String str : accommodationNames) { if (!str.equalsIgnoreCase("studentId") && !str.equalsIgnoreCase("stateAbbreviation") && !str.equalsIgnoreCase("_id") && !str.equalsIgnoreCase("atleastOneAccommodationField")) { if (acc.get(str).toString().contains("[")) { List<String> multi = (List<String>) acc.get(str); StringBuffer namesSB = new StringBuffer(); if (multi != null) { for (String multiAccomo : multi) { namesSB.append(multiAccomo).append(";"); } } if (namesSB.toString().contains(";")) { namesSB.replace(namesSB.length() - 1, namesSB.length(), ""); } accommo.add(namesSB.toString()); } else { accommo.add(acc.get(str).toString()); } } } String[] tempAccommodations = new String[accommo.size()]; tempAccommodations = accommo.toArray(tempAccommodations); rows[rowCount++] = ObjectArrays.concat(toStringArray(), tempAccommodations, String.class); } } else { rows = new String[1][toStringArray().length]; rows[0] = toStringArray(); } return rows; }
From source file:com.topsec.tsm.sim.report.web.ReportController.java
/** * ?/*from w ww . ja v a2 s. c o m*/ */ @RequestMapping("getSubTitle") @ResponseBody public Object getSubTitle(SID sid, HttpServletRequest request, HttpServletResponse response) { try { SID.setCurrentUser(sid); String subId = request.getParameter(ReportUiConfig.subrptid); String sTime = request.getParameter(ReportUiConfig.sTime); String eTime = request.getParameter(ReportUiConfig.eTime); int talTop = request.getParameter("talTop") == null ? 5 : Integer.valueOf(request.getParameter("talTop")); RptMasterTbService rptMasterTbImp = (RptMasterTbService) SpringContextServlet.springCtx .getBean(ReportUiConfig.MstBean); List<Map> subList = rptMasterTbImp.queryTmpList(ReportUiConfig.SubTitleSql, new Object[] { StringUtil.toInt(subId, 0) }); JSONObject json = null; if (subList.size() > 0) { Map subMap = (Map) subList.get(0); Map<String, Object> rsMap = null; if (dataSourceService == null) { dataSourceService = (DataSourceService) FacadeUtil.getFacadeBean(request, null, "dataSourceService"); } List<String> deviceTypes = ReportModel.getDeviceTypeList(dataSourceService, SID.currentUser()); List<String> deviceIps = ReportModel.getDeviceIpList(dataSourceService, SID.currentUser()); rsMap = ReportModel.getSubTitleData(rptMasterTbImp, deviceTypes, deviceIps, subMap, sTime, eTime, subId, false, request); if (null != rsMap && (null == subMap.get("subName") || ((String) subMap.get("subName")).indexOf("") < 0) && null != rsMap.get("result") && ((List) rsMap.get("result")).size() > talTop) { List result = ((List) rsMap.get("result")).subList(0, talTop); rsMap.put("result", result); } Map<Object, Object> data = ReportModel.reformingResult(subMap, rsMap); String dvctype = request.getParameter("dvctype"); /************************************************/ String logQueryUrl = null; String eventQueryUrl = null; if (!GlobalUtil.isNullOrEmpty(subMap.get("logQueryCondition"))) { String queryCondition = subMap.get("logQueryCondition").toString(); if (queryCondition.contains("REPORT_QUERY_TYPE=EVENT_QUERY")) { eventQueryUrl = ReportUiConfig.reportQueryEventUrl; } else { logQueryUrl = ReportUiConfig.reportQueryLogUrl; } } if ("Esm/Topsec/SystemRunLog".equals(dvctype) && !sid.isOperator()) { logQueryUrl = null; } /************************************************/ Map params = new HashMap(); params.put("dvcType", dvctype); params.put("talTop", talTop); params.put("sTime", sTime); params.put("eTime", eTime); String chartLink = StringUtil.toString(subMap.get("chartLink"), "0"); int _chartLink = Integer.valueOf(chartLink); String[] talCategory = null; String[] categoryValues = request.getParameterValues(ReportUiConfig.talCategory); if (categoryValues != null) { talCategory = new String[categoryValues.length]; for (int i = 0, len = categoryValues.length; i < len; i++) { talCategory[i] = ChangePageEncode.IsoToUtf8(categoryValues[i]); } } StringBuffer url = getUrl(ReportUiConfig.reportUrl, request, params, talCategory); String surl = url.toString(); if (_chartLink > 0) { url.append("&superiorId=").append(subList.get(0).get("mstId")).append("&") .append(ReportUiConfig.mstrptid).append("=").append(chartLink).append("&drill=true"); } data.put("url", _chartLink > 0 ? url.toString() : ""); url.replace(0, url.length(), surl).replace(0, ReportUiConfig.reportUrl.length(), ReportUiConfig.moreUrl); url.append("&").append(ReportUiConfig.mstrptid).append("=").append(subList.get(0).get("mstId")) .append("&").append(ReportUiConfig.subrptid).append("=").append(subId); data.put("moreUrl", url.toString()); if (!GlobalUtil.isNullOrEmpty(logQueryUrl) || !GlobalUtil.isNullOrEmpty(eventQueryUrl)) { if (null != logQueryUrl) { data.put("logQueryUrl", logQueryUrl); } if (null != eventQueryUrl) { data.put("eventQueryUrl", eventQueryUrl); } String nodeId = request.getParameter("nodeId"); if (!GlobalUtil.isNullOrEmpty(nodeId)) { params.put("nodeId", nodeId); } String reportType = request.getParameter("reportType"); if (!GlobalUtil.isNullOrEmpty(reportType)) { params.put("reportType", reportType); } data.put("frontEndParams", params); } int type = StringUtil.toInt(StringUtil.toString(subMap.get("chartType"), "1")); Map<String, Object> rstMap = CreateChartFactory.getInstance().createChart(type, data); if (rstMap != null) { json = new JSONObject(); json.put("subID", subId); json.put("type", StringUtil.toString(rstMap.get("type"), "")); json.put("chart", rstMap.get("chart")); json.put("table", rstMap.get("table")); } } return json; } finally { SID.removeCurrentUser(); } }
From source file:org.wso2.carbon.apimgt.migration.client.MigrationDBCreator.java
private void executeSQLScript() throws Exception { String databaseType = DatabaseCreator.getDatabaseType(this.connection); boolean keepFormat = false; if (Constants.DB_TYPE_ORACLE.equals(databaseType)) { delimiter = "/"; } else if (Constants.DB_TYPE_DB2.equals(databaseType)) { delimiter = "/"; } else if (Constants.DB_TYPE_OPENEDGE.equals(databaseType)) { delimiter = "/"; keepFormat = true;/*from w w w. jav a 2 s.co m*/ } String dbscriptName = getDbScriptLocation(databaseType); StringBuffer sql = new StringBuffer(); BufferedReader reader = null; try { InputStream is = new FileInputStream(dbscriptName); reader = new BufferedReader(new InputStreamReader(is, "UTF8")); String line; while ((line = reader.readLine()) != null) { line = line.trim(); if (!keepFormat) { if (line.startsWith("//")) { continue; } if (line.startsWith("--")) { continue; } StringTokenizer st = new StringTokenizer(line); if (st.hasMoreTokens()) { String token = st.nextToken(); if ("REM".equalsIgnoreCase(token)) { continue; } } } sql.append(keepFormat ? "\n" : " ").append(line); // SQL defines "--" as a comment to EOL // and in Oracle it may contain a hint // so we cannot just remove it, instead we must end it if (!keepFormat && line.indexOf("--") >= 0) { sql.append('\n'); } if ((checkStringBufferEndsWith(sql, delimiter))) { executeSQL(sql.substring(0, sql.length() - delimiter.length())); sql.replace(0, sql.length(), ""); } } // Catch any statements not followed by ; if (sql.length() > 0) { executeSQL(sql.toString()); } } catch (IOException e) { log.error("Error occurred while executing SQL script for creating registry database", e); throw new APIMigrationException( "Error occurred while executing SQL script for creating registry database", e); } finally { if (reader != null) { reader.close(); } } }
From source file:org.wso2.carbon.dashboard.portal.core.datasource.DataBaseInitializer.java
/** * To execute the table creation script depending on the datasource user using * * @throws DashboardPortalException//w w w . j a va2 s.co m */ private void executeSQLScript() throws DashboardPortalException { String databaseType; try { databaseType = getDatabaseType(getDBConnection()); } catch (DashboardPortalException e) { throw new DashboardPortalException("Error occurred while getting database type", e); } if ("oracle".equals(databaseType)) { delimiter = "/"; } String dbScriptLocation = getDbScriptLocation(databaseType); StringBuffer sql = new StringBuffer(); BufferedReader reader = null; try { InputStream is = new FileInputStream(dbScriptLocation); reader = new BufferedReader(new InputStreamReader(is)); String line; while ((line = reader.readLine()) != null) { line = line.trim(); if (line.startsWith("//")) { continue; } if (line.startsWith("--")) { continue; } StringTokenizer st = new StringTokenizer(line); if (st.hasMoreTokens()) { String token = st.nextToken(); if ("REM".equalsIgnoreCase(token)) { continue; } } sql.append(" ").append(line); // SQL defines "--" as a comment to EOL // and in Oracle it may contain a hint // so we cannot just remove it, instead we must end it if (line.contains("--")) { sql.append("\n"); } if ((checkStringBufferEndsWith(sql, delimiter))) { executeSQL(sql.substring(0, sql.length() - delimiter.length())); sql.replace(0, sql.length(), ""); } } // Catch any statements not followed by ; if (sql.length() > 0) { executeSQL(sql.toString()); } } catch (IOException e) { throw new DashboardPortalException( "Error occurred while executing SQL script for creating Dashboard Server database", e); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { log.error("Error occurred while closing stream for Identity SQL script", e); } } } }
From source file:org.eclipse.skalli.gerrit.client.internal.GerritClientImpl.java
@Override public List<String> getGroups(String... projectNames) throws ConnectionException, CommandException { List<String> result = Collections.emptyList(); if (projectNames == null || projectNames.length == 0) { return result; }/*from w w w . j a v a2s .c om*/ // Gerrit throws exceptions for --project options that correspond to // no Gerrit project; thus, we have to filter out thise project names before // sending the ls-groups command Set<String> allProjects = new HashSet<String>(getProjects()); GerritVersion version = getVersion(); if (version.supports(GerritFeature.LS_GROUPS_PROJECT_ATTR)) { StringBuffer sb = new StringBuffer("gerrit ls-groups"); if (version.supports(GerritFeature.LS_GROUPS_VISIBLE_TO_ALL_ATTR)) { appendArgument(sb, "visible-to-all", true); } for (String projectName : projectNames) { if (allProjects.contains(projectName)) { appendArgument(sb, "project", projectName); } } result = sshCommand(sb.toString()); } else if (version.supports(GerritFeature.REF_RIGHTS_TABLE)) { result = new ArrayList<String>(); StringBuffer sb = new StringBuffer(); sb.append("SELECT name FROM ").append(GSQL.Tables.ACCOUNT_GROUP_NAMES) .append(" WHERE group_id IN (SELECT group_id FROM ").append(GSQL.Tables.REF_RIGHTS) .append(" WHERE"); for (String projectName : projectNames) { if (allProjects.contains(projectName)) { sb.append(" project_name='").append(projectName).append("' OR"); } } sb.replace(sb.length() - 3, sb.length(), ""); sb.append(");"); List<String> gsqlResult = gsql(sb.toString(), ResultFormat.JSON); for (String entry : gsqlResult) { if (isRow(entry)) { result.add(JSONUtil.getString(entry, "columns.name")); } } } return result; }