public void searchTags() { StringBuilder strTags = new StringBuilder(); for (int i = 0; i < tempStrBuilder.length() - 1; i++) { i = tempStrBuilder.indexOf("<"); if (i == -1) { break; } strTags.append(tempStrBuilder.substring(i, tempStrBuilder.indexOf(">") + 1)); tempStrBuilder.delete(i, tempStrBuilder.indexOf(">") + 1); tags.add(strTags.toString()); strTags.delete(0, strTags.length()); } }
private String getTag(Document d) { StringBuilder ab = new StringBuilder( d.getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0].replace( "E:\\I:\\ACM_complete_dataset\\", "")); return ab.substring(0, ab.indexOf("\\")).toString(); }
/** * Given a string, replace all tabs with the appropriate number of spaces. * * @param tabLength the length of each tab. * @param s the String to scan. */ public static void replaceTabs(int tabLength, StringBuilder s) { if (whitespace == null || whitespace.length() < tabLength) whitespace = String.format("%" + tabLength + "s", " "); int index = 0; while ((index = s.indexOf("\t", index)) != -1) { int spaceCount = tabLength - index % tabLength; s.replace(index, index + 1, whitespace.substring(0, spaceCount)); index += spaceCount; } }
/** * Sets a mnemomic for the specified button. * * @param b button * @param mnem mnemonics that have already been assigned */ public static void setMnemonic(final AbstractButton b, final StringBuilder mnem) { // do not set mnemonics for Mac! Alt+key used for special characters. if (Prop.MAC) return; // find and assign unused mnemomic final String label = b.getText(); final int ll = label.length(); for (int l = 0; l < ll; l++) { final char ch = Character.toLowerCase(label.charAt(l)); if (!letter(ch) || mnem.indexOf(Character.toString(ch)) != -1) continue; b.setMnemonic(ch); mnem.append(ch); break; } }
private String readUntil(StringBuilder src, String stop) throws RequestMessageParsingException { int stopIndex = src.indexOf(stop); if (stopIndex == -1) { String message = String.format("String \"%s\" not found in \"%s\".", stop, src.toString()); throw new RequestMessageParsingException(message); } String res = src.substring(0, stopIndex); src.delete(0, stopIndex); return res; }
private void addClassPathToScriptEngine(File jarFile) throws ConfigurationException { try { StringBuilder cmd = new StringBuilder(addClassPathCmd); int tagStartPos = cmd.indexOf(parameterTag); int tageEndPos = tagStartPos + parameterTag.length(); cmd.replace(tagStartPos, tageEndPos, jarFile.getAbsolutePath().replace("\\", "/")); // System.out.println("cmd " + cmd.toString()); engine.eval("add-classpath", 1, 1, cmd.toString()); // $NON-NLS-1$ } catch (Exception ex) { String msg = String.format("Failed to load class path %s", jarFile.getName()); // $NON-NLS-1$ System.err.println(msg + " " + ex); throw new ConfigurationException(msg, ex); } }
/** * Imports a package into the script engine * * @param pkgName the name of the package * @throws ConfigurationException if the package cannot be imported */ private void importPkgToScriptEngine(String pkgName) throws ConfigurationException { try { StringBuilder cmd = new StringBuilder(importPackageCmd); int tagStartPos = cmd.indexOf(parameterTag); int tageEndPos = tagStartPos + parameterTag.length(); cmd.replace(tagStartPos, tageEndPos, pkgName); // System.out.println("cmd " + cmd.toString()); engine.eval("load-packages", 1, 1, cmd.toString()); // $NON-NLS-1$ } catch (Exception ex) { String msg = String.format("Failed to import package %s", pkgName); // $NON-NLS-1$ System.err.println(msg + " " + ex); throw new ConfigurationException(msg, ex); } }
/* * use webView.loadData() to load from an HTML string * 1. fetch the template according to survey style * 2. replace survey's question and survey's options in the template */ private String genSurvey() throws IOException { Log.i(TAG, "the style is: " + style); // String templatePath = "component" + File.separator + getTemplatePath(this.style); String templatePath = "component" + java.io.File.separator + surveyTemplate.get(this.style); BufferedInputStream in = new BufferedInputStream(container.$context().getAssets().open(templatePath)); // BufferedInputStream in = new BufferedInputStream(MediaUtil.openMedia(container.$form(), // templatePath)); // read it with BufferedReader BufferedReader br = new BufferedReader(new InputStreamReader(in)); StringBuilder sb = new StringBuilder(); String line; while ((line = br.readLine()) != null) { sb.append(line); } Log.i(TAG, "Before replace:" + sb.toString()); // A. generate question // find question block start with <h1 id="_txt_qt"> String questionBlk = "<h1 id=\"_txt_qt\">"; int insertPos = sb.indexOf(questionBlk) + questionBlk.length(); int insertQuestionPos = sb.indexOf("Question", insertPos); sb.replace(insertQuestionPos, insertQuestionPos + "Question".length(), this.question); Log.i(TAG, "after replace question:" + sb.toString()); // B. generate options // 1. find options block (depends on style) // only "multipleChoice", "checkBox", and "chooseList" need to replace with options; // 2. For "scale" style, the first three options will be specifying the // min, max and default value of the scale if (this.style.equals(this.MULTIPLECHOICE) || this.style.equals(this.CHECKBOX)) { int startPos = sb.indexOf("</legend>") + "</legend>".length(); int endPos = sb.indexOf("</fieldset>"); Log.i(TAG, "before replace options:"); sb.replace(startPos, endPos, genOptions()); // replace with the filled-in options } if (this.style.equals(this.CHOOSELIST)) { int startPos = sb.indexOf("<select name=\"\">") + "<select name=\"\">".length(); int endPos = sb.indexOf("</select>"); sb.replace(startPos, endPos, genOptions()); } if (this.style.equals(this.SCALE)) { if (!this.options.isEmpty() && this.options.size() == 3) { // replace min int sliderPos = sb.indexOf("input name=\"slider\""); int startPosOfMin = sb.indexOf("min=\"1\"", sliderPos + "input name=\"slider\"".length()); // example: min="1" sb.replace(startPosOfMin, startPosOfMin + 7, "min=\"" + this.options.get(0) + "\""); // replace max // example: replace max="10" to max="100" int startPosOfMax = sb.indexOf("max=\"10\"", sliderPos + "input name=\"slider\"".length()); sb.replace(startPosOfMax, startPosOfMax + 8, "max=\"" + this.options.get(1) + "\""); // replace default initial scale // example: value="5" int startPosOfDefault = sb.indexOf("value=\"5\"", sliderPos + "input name=\"slider\"".length()); sb.replace( startPosOfDefault, startPosOfDefault + 9, "value=\"" + this.options.get(2) + "\""); } else {; // do nothing, use the template } } return sb.toString(); }