/** * Create a Transferable to use as the source for a data transfer. * * @param c The component holding the data to be transfered. This argument is provided to enable * sharing of TransferHandlers by multiple components. * @return The representation of the data to be transfered. */ protected Transferable createTransferable(JComponent c) { Object[] values = null; if (c instanceof JList) { values = ((JList) c).getSelectedValues(); } else if (c instanceof JTable) { JTable table = (JTable) c; int[] rows = table.getSelectedRows(); if (rows != null) { values = new Object[rows.length]; for (int i = 0; i < rows.length; i++) { values[i] = table.getValueAt(rows[i], 0); } } } if (values == null || values.length == 0) { return null; } StringBuffer plainBuf = new StringBuffer(); StringBuffer htmlBuf = new StringBuffer(); htmlBuf.append("<html>\n<body>\n<ul>\n"); for (Object obj : values) { String val = ((obj == null) ? "" : obj.toString()); plainBuf.append(val + "\n"); htmlBuf.append(" <li>" + val + "\n"); } // remove the last newline plainBuf.deleteCharAt(plainBuf.length() - 1); htmlBuf.append("</ul>\n</body>\n</html>"); return new FileTransferable(plainBuf.toString(), htmlBuf.toString(), values); }
@Override public Void run(Handler handler) { StringBuffer output = new StringBuffer(); output.append("graph_args --base 1000 -l 0\n"); output.append("graph_vlabel pages\n"); output.append("graph_title KSM usage\n"); output.append("graph_category system\n"); output.append("pages_shared.label pages_shared\n"); output.append("pages_shared.draw LINE\n"); output.append("pages_sharing.label pages_sharing\n"); output.append("pages_sharing.draw LINE\n"); output.append("pages_unshared.label pages_unshared\n"); output.append("pages_unshared.draw LINE\n"); output.append("pages_volatile.label pages_volatile\n"); output.append("pages_volatile.draw LINE"); StringBuffer output2 = new StringBuffer(); try { BufferedReader pages_shared = new BufferedReader(new FileReader("/sys/kernel/mm/ksm/pages_shared")); output2.append("pages_shared.value " + pages_shared.readLine() + "\n"); pages_shared.close(); } catch (IOException e) { } try { BufferedReader pages_sharing = new BufferedReader(new FileReader("/sys/kernel/mm/ksm/pages_sharing")); output2.append("pages_sharing.value " + pages_sharing.readLine() + "\n"); pages_sharing.close(); } catch (IOException e) { } try { BufferedReader pages_unshared = new BufferedReader(new FileReader("/sys/kernel/mm/ksm/pages_unshared")); output2.append("pages_unshared.value " + pages_unshared.readLine() + "\n"); pages_unshared.close(); } catch (IOException e) { } try { BufferedReader pages_volatile = new BufferedReader(new FileReader("/sys/kernel/mm/ksm/pages_volatile")); output2.append("pages_volatile.value " + pages_volatile.readLine()); pages_volatile.close(); } catch (IOException e) { } Bundle bundle = new Bundle(); bundle.putString("name", this.getName()); bundle.putString("config", output.toString()); bundle.putString("update", output2.toString()); Message msg = Message.obtain(handler, 42, bundle); handler.sendMessage(msg); return null; }
public String parse(String format) { StringBuffer buffer = new StringBuffer(); Matcher m = formatPattern.matcher(format); while (m.find()) m.appendReplacement(buffer, getFormatSpecifierValue(m.group())); m.appendTail(buffer); return buffer.toString(); }
/** * Leave only the value for RCS keywords. * * <p>For example, <code>$Revision: 1.1 $</code> becomes <code>1.0</code>. */ public String replaceRcsKeywords(String text) { if (matcher == null) { matcher = Pattern.compile( "\\$(Author|Date|Header|Id|Locker|Log|Name|RCSFile|Revision|Source|State): (.+?) \\$") .matcher(text); } else { matcher.reset(text); } StringBuffer buffer = new StringBuffer(); while (matcher.find()) { String string = matcher.group(2); // For the Date: keyword, have a shot at reformatting string if ("Date".equals(matcher.group(1))) { try { DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date date = dateFormat.parse(string); string = date.toString(); } catch (ParseException e) { } // if we can't parse, return unchanged } matcher.appendReplacement(buffer, string); } matcher.appendTail(buffer); return buffer.toString(); }
void applyDirectives() { findRemoveDirectives(true); StringBuffer buffer = new StringBuffer(); String head = "", toe = "; \n"; if (crispBox.isSelected()) buffer.append(head + "crisp=true" + toe); if (!fontField.getText().trim().equals("")) buffer.append(head + "font=\"" + fontField.getText().trim() + "\"" + toe); if (globalKeyEventsBox.isSelected()) buffer.append(head + "globalKeyEvents=true" + toe); if (pauseOnBlurBox.isSelected()) buffer.append(head + "pauseOnBlur=true" + toe); if (!preloadField.getText().trim().equals("")) buffer.append(head + "preload=\"" + preloadField.getText().trim() + "\"" + toe); /*if ( transparentBox.isSelected() ) buffer.append( head + "transparent=true" + toe );*/ Sketch sketch = editor.getSketch(); SketchCode code = sketch.getCode(0); // first tab if (buffer.length() > 0) { code.setProgram("/* @pjs " + buffer.toString() + " */\n\n" + code.getProgram()); if (sketch.getCurrentCode() == code) // update textarea if on first tab { editor.setText(sketch.getCurrentCode().getProgram()); editor.setSelection(0, 0); } sketch.setModified(false); sketch.setModified(true); } }
public static void main(String[] args) throws IOException { // Get input html StringBuffer sb = new StringBuffer(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); for (String str = in.readLine(); str != null; str = in.readLine()) { sb.append("\n" + str); } String html = sb.toString(); // Match all the questions Matcher matcher = Pattern.compile( "<\\s*div\\s+class\\s*=\\s*\"question-summary\"\\s*id\\s*=\\s*\"question-summary-(?<id>\\d+)\"\\s*>" + ".*?<\\s*div\\s+class\\s*=\\s*\"summary\"\\s*>" + ".*?<\\s*a\\s+.*?class\\s*=\\s*\"question-hyperlink\"\\s*>" + "(?<title>.*?)" + "</\\s*a\\s*>.*?<\\s*div\\s+class\\s*=\\s*\"user-action-time\"\\s*>" + ".*?<\\s*span\\s+.*?>(?<time>.*?)</\\s*span\\s*>", Pattern.CASE_INSENSITIVE | Pattern.DOTALL) .matcher(html); // Output the information while (matcher.find()) { String id = matcher.group("id"); String title = matcher.group("title"); String time = matcher.group("time"); System.out.println(id + ";" + title + ";" + time); } }
public String toString() { StringBuffer sb = new StringBuffer(); sb.append(super.toString()); sb.append('\n'); sb.append("String 1: " + string1Length + " String 2: " + string2Length); return sb.toString(); }
public static String MD5(String in) throws Throwable { MessageDigest md = MessageDigest.getInstance("MD5"); byte[] array = md.digest(in.getBytes()); StringBuffer sb = new StringBuffer(); for (int i = 0; i < array.length; ++i) { sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3)); } return sb.toString(); }
public static String cleanText(String text) { StringBuffer string = new StringBuffer(text.length()); char chars[] = text.toCharArray(); for (int x = 0; x < chars.length; x++) { if (chars[x] != 1 && chars[x] != 2) string.append(chars[x]); } return string.toString(); }
public String toString() { StringBuffer buf = new StringBuffer(); buf.append("(Union (" + unionTypes.size() + "): "); for (InferredType it : unionTypes) { buf.append(it.toString() + ", "); } buf.append(") "); return buf.toString(); }
public String toString() { StringBuffer buf = new StringBuffer(); buf.append("(Struct: "); for (InferredType it : structTypes) { buf.append(it.toString() + ", "); } buf.append(") "); return buf.toString(); }
public static void main(String[] args) throws Exception { Reader trainingFile = null; // Process arguments int restArgs = commandOptions.processOptions(args); // Check arguments if (restArgs != args.length) { commandOptions.printUsage(true); throw new IllegalArgumentException("Unexpected arg " + args[restArgs]); } if (trainFileOption.value == null) { commandOptions.printUsage(true); throw new IllegalArgumentException("Expected --train-file FILE"); } if (modelFileOption.value == null) { commandOptions.printUsage(true); throw new IllegalArgumentException("Expected --model-file FILE"); } // Get the CRF structure specification. ZipFile zipFile = new ZipFile(modelFileOption.value); ZipEntry zipEntry = zipFile.getEntry("crf-info.xml"); CRFInfo crfInfo = new CRFInfo(zipFile.getInputStream(zipEntry)); StringBuffer crfInfoBuffer = new StringBuffer(); BufferedReader reader = new BufferedReader(new InputStreamReader(zipFile.getInputStream(zipEntry))); String line; while ((line = reader.readLine()) != null) { crfInfoBuffer.append(line).append('\n'); } reader.close(); // Create the CRF, and train it. CRF4 crf = createCRF(trainFileOption.value, crfInfo); // Create a new zip file for our output. This will overwrite // the file we used for input. ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(modelFileOption.value)); // Copy the CRF info xml to the output zip file. zos.putNextEntry(new ZipEntry("crf-info.xml")); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(zos)); writer.write(crfInfoBuffer.toString()); writer.flush(); zos.closeEntry(); // Save the CRF classifier model to the output zip file. zos.putNextEntry(new ZipEntry("crf-model.ser")); ObjectOutputStream oos = new ObjectOutputStream(zos); oos.writeObject(crf); oos.flush(); zos.closeEntry(); zos.close(); }
static String combineDummy(String inv, String daikonStr, String esc, String simplify) { StringBuffer combined = new StringBuffer(inv); combined.append(lineSep + "\tDAIKON_FORMAT "); combined.append(daikonStr); combined.append(lineSep + "\tESC_FORMAT "); combined.append(esc); combined.append(lineSep + "\tSIMPLIFY_FORMAT "); combined.append(simplify); return combined.toString(); }
public String formatXMLdata(String xmlData) { Pattern p = Pattern.compile("(<|&|\'|\"|>)"); Matcher m = p.matcher(xmlData); StringBuffer strBuf = new StringBuffer(); while (m.find()) { m.appendReplacement(strBuf, (String) xmlHashMap.get(m.group())); } m.appendTail(strBuf); return strBuf.toString(); }
/** * Removes all sections (both header and content) with the given sectionName * * @param sectionName the name of the section (case insensitive) to remove. * @param markup the markup to be stripped * @return the stripped markup */ public static String stripSection(String markup, String sectionName) { Pattern p = Pattern.compile( "(={2,})\\s*" + sectionName + "\\s*\\1.*?([^=]\\1[^=])", Pattern.CASE_INSENSITIVE + Pattern.DOTALL); Matcher m = p.matcher(markup); StringBuffer sb = new StringBuffer(); int lastIndex = 0; while (m.find()) { sb.append(markup.substring(lastIndex, m.start())); sb.append(m.group(2)); lastIndex = m.end(); } sb.append(markup.substring(lastIndex)); markup = sb.toString(); // if this was the last section in the doc, then it won't be discarded because we can't tell // where it ends. // best we can do is delete the title and the paragraph below it. p = Pattern.compile( "(={2,})\\s*" + sectionName + "\\s*\\1\\W*.*?\n\n", Pattern.CASE_INSENSITIVE + Pattern.DOTALL); m = p.matcher(markup); sb = new StringBuffer(); lastIndex = 0; while (m.find()) { sb.append(markup.substring(lastIndex, m.start())); lastIndex = m.end() - 2; } sb.append(markup.substring(lastIndex)); return sb.toString(); }
public String getDocString() { StringBuffer buf = new StringBuffer(); buf.append("Example data: "); for (Iterator<String> it = sampleStrs.iterator(); it.hasNext(); ) { String tokStr = it.next(); buf.append("'" + tokStr + "'"); if (it.hasNext()) { buf.append(", "); } } return buf.toString(); }
/** * Converts the path back to the string representation. * * @return */ public String toString(Path path) { StringBuffer buffer = new StringBuffer(); boolean first = true; for (Part p : path.parts) { if (!first) { buffer.append(path_seperator); } buffer.append(p.toString(this)); first = false; } return buffer.toString(); }
/** * Strips all non-article links from the given markup; anything like [[this]] is removed unless it * goes to a wikipedia article, redirect, or disambiguation page. * * @param markup the text to be stripped * @return the stripped text */ public static String stripIsolatedLinks(String markup) { Vector<Integer> linkStack = new Vector<Integer>(); Pattern p = Pattern.compile("(\\[\\[|\\]\\])"); Matcher m = p.matcher(markup); StringBuffer sb = new StringBuffer(); int lastIndex = 0; while (m.find()) { String tag = markup.substring(m.start(), m.end()); if (tag.equals("[[")) linkStack.add(m.start()); else { if (!linkStack.isEmpty()) { int linkStart = linkStack.lastElement(); linkStack.remove(linkStack.size() - 1); if (linkStack.isEmpty()) { sb.append(markup.substring(lastIndex, linkStart)); // we have the whole link, with other links nested inside if it's an image String linkMarkup = markup.substring(linkStart + 2, m.start()); // System.out.println(" - " + linkStart + ", " + m.end() + ", " + markup.length()) ; if (markup.substring(Math.max(0, linkStart - 10), linkStart).matches("(?s).*(\\W*)\n") && (m.end() >= markup.length() - 1 || markup .substring(m.end(), Math.min(markup.length() - 1, m.end() + 10)) .matches("(?s)(\\W*)(\n.*|$)"))) { // discarding link } else { sb.append("[["); sb.append(linkMarkup); sb.append("]]"); } lastIndex = m.end(); } } } } if (!linkStack.isEmpty()) System.err.println( "MarkupStripper | Warning: links were not well formed, so we cannot guarantee that they were stripped out correctly. "); sb.append(markup.substring(lastIndex)); return sb.toString(); }
void findRemoveDirectives(boolean clean) { // if ( clean ) editor.startCompoundEdit(); Sketch sketch = editor.getSketch(); for (int i = 0; i < sketch.getCodeCount(); i++) { SketchCode code = sketch.getCode(i); String program = code.getProgram(); StringBuffer buffer = new StringBuffer(); Matcher m = pjsPattern.matcher(program); while (m.find()) { String mm = m.group(); // TODO this urgently needs tests .. /* remove framing */ mm = mm.replaceAll("^\\/\\*\\s*@pjs", "").replaceAll("\\s*\\*\\/\\s*$", ""); /* fix multiline nice formatting */ mm = mm.replaceAll("[\\s]*([^;\\s\\n\\r]+)[\\s]*,[\\s]*[\\n\\r]+", "$1,"); /* fix multiline version without semicolons */ mm = mm.replaceAll("[\\s]*([^;\\s\\n\\r]+)[\\s]*[\\n\\r]+", "$1;"); mm = mm.replaceAll("\n", " ").replaceAll("\r", " "); // System.out.println(mm); if (clean) { m.appendReplacement(buffer, ""); } else { String[] directives = mm.split(";"); for (String d : directives) { // System.out.println(d); parseDirective(d); } } } if (clean) { m.appendTail(buffer); // TODO: not working! code.setProgram(buffer.toString()); code.setModified(true); } } if (clean) { // editor.stopCompoundEdit(); editor.setText(sketch.getCurrentCode().getProgram()); sketch.setModified(false); sketch.setModified(true); } }
/** Return a string representation of this expresssion. */ public String toString() { StringBuffer buf = new StringBuffer(); buf.append("("); buf.append(getImportance()); buf.append(", "); buf.append(getName()); buf.append(", "); buf.append(val); buf.append(")"); return (buf.toString()); }
private String presub(String query, Object[] params) { if (params == null) return query; StringBuffer buf = new StringBuffer(); Matcher matcher = PRE_SUB_PATTERN.matcher(query); while (matcher.find()) { matcher.appendReplacement( buf, ((String) params[Integer.parseInt(matcher.group(1)) - 1]) .replace("\\", "\\\\") .replace("$", "\\$")); } matcher.appendTail(buf); return buf.toString(); }
/** * Removes all section headers. * * @param markup the text to be stripped * @return the stripped markup */ public static String stripHeadings(String markup) { Pattern p = Pattern.compile("(={2,})([^=]+)(\\1)"); Matcher m = p.matcher(markup); StringBuffer sb = new StringBuffer(); int lastIndex = 0; while (m.find()) { sb.append(markup.substring(lastIndex, m.start())); lastIndex = m.end(); } sb.append(markup.substring(lastIndex)); return sb.toString(); }
/* String formatStringWordwrap(String output,int colWidth,char fillchar,String appendStr) { int beginIndex,endIndex; String valueStr; if (output == null) { return null; } // This is the case where the length of the value exceeds the // column width if ((appendStr !=null) && (appendStr.length()> colWidth-output.length())) { //print atleast five fill characters int labelWidth = output.length() + 5; StringBuffer blankOutput = new StringBuffer(); for (int i=0;i<labelWidth;i++) blankOutput.append(' '); output=formatString(output,labelWidth,fillchar); //break the value into multiple strings to print //on separate lines colWidth = colWidth-labelWidth; for (beginIndex=0,endIndex=colWidth; endIndex<=appendStr.length(); beginIndex=endIndex,endIndex+=colWidth) { valueStr = appendStr.substring(beginIndex,endIndex); if (beginIndex==0) output+=valueStr; else output = output + SessionDefaults.lineSeperator + blankOutput + valueStr ; } if (endIndex > appendStr.length()) output = output + SessionDefaults.lineSeperator + blankOutput + appendStr.substring(beginIndex); return output; } if (appendStr != null) { colWidth=colWidth - appendStr.length(); } output=formatString(output,colWidth,fillchar); if (appendStr != null && output != null) { output+=appendStr; } return output; } */ String formatString(String output, int colWidth, char fillchar) { StringBuffer outBuffer = null; if (output == null) { return null; } outBuffer = new StringBuffer(output); if (outBuffer.length() <= colWidth) { for (int i = outBuffer.length(); i < colWidth; i++) outBuffer.append(fillchar); } return outBuffer.toString(); }
/* * Transform the hexadecimal long output into the equivalent * hexadecimal double value. */ static String hexLongStringtoHexDoubleString(String transString) { transString = transString.toLowerCase(); String zeros = ""; StringBuffer result = new StringBuffer(24); for (int i = 0; i < (16 - transString.length()); i++, zeros += "0") ; transString = zeros + transString; // assert transString.length == 16; char topChar; // Extract sign if ((topChar = transString.charAt(0)) >= '8') { // 8, 9, a, A, b, B, ... result.append("-"); // clear sign bit transString = Character.toString(Character.forDigit(Character.digit(topChar, 16) - 8, 16)) + transString.substring(1, 16); } // check for NaN and infinity String signifString = transString.substring(3, 16); if (transString.substring(0, 3).equals("7ff")) { if (signifString.equals("0000000000000")) { result.append("Infinity"); } else result.append("NaN"); } else { // finite value // Extract exponent int exponent = Integer.parseInt(transString.substring(0, 3), 16) - DoubleConsts.EXP_BIAS; result.append("0x"); if (exponent == DoubleConsts.MIN_EXPONENT - 1) { // zero or subnormal if (signifString.equals("0000000000000")) { result.append("0.0p0"); } else { result.append( "0." + signifString.replaceFirst("0+$", "").replaceFirst("^$", "0") + "p-1022"); } } else { // normal value result.append( "1." + signifString.replaceFirst("0+$", "").replaceFirst("^$", "0") + "p" + exponent); } } return result.toString(); }
public static void main(String[] args) throws Exception { // Create a pattern to match cat Pattern p = Pattern.compile("cat"); // Create a matcher with an input string Matcher m = p.matcher("one cat," + " two cats in the yard"); StringBuffer sb = new StringBuffer(); boolean result = m.find(); // Loop through and create a new String // with the replacements while (result) { m.appendReplacement(sb, "dog"); result = m.find(); } // Add the last segment of input to // the new String m.appendTail(sb); System.out.println(sb.toString()); }
protected void setupScoreBoardValues() { new ScoreBoardValue( "%sbto", "ScoreBoard Timeout Owner", getScoreBoard(), ScoreBoard.EVENT_TIMEOUT_OWNER) { public String getValue() { return getScoreBoard().getTimeoutOwner(); } }; new ScoreBoardValue( "%sbip", "ScoreBoard Is In Period", getScoreBoard(), ScoreBoard.EVENT_IN_PERIOD) { public String getValue() { return String.valueOf(getScoreBoard().isInPeriod()); } }; new ScoreBoardValue( "%sbio", "ScoreBoard Is In Overtime", getScoreBoard(), ScoreBoard.EVENT_IN_OVERTIME) { public String getValue() { return String.valueOf(getScoreBoard().isInOvertime()); } }; new ScoreBoardValue( "%sbos", "ScoreBoard Is Score Official", getScoreBoard(), ScoreBoard.EVENT_OFFICIAL_SCORE) { public String getValue() { return String.valueOf(getScoreBoard().isOfficialScore()); } }; setupTeamValues("1", Team.ID_1); setupTeamValues("2", Team.ID_2); setupClockValues("p", Clock.ID_PERIOD); setupClockValues("j", Clock.ID_JAM); setupClockValues("l", Clock.ID_LINEUP); setupClockValues("t", Clock.ID_TIMEOUT); setupClockValues("i", Clock.ID_INTERMISSION); StringBuffer patternBuffer = new StringBuffer(); Iterator<String> patterns = scoreBoardValues.keySet().iterator(); while (patterns.hasNext()) patternBuffer.append(patterns.next() + "|"); String specifiersRegex = patternBuffer.toString().replaceAll("[|]$", ""); formatPattern = Pattern.compile(specifiersRegex); eventPattern = Pattern.compile("^\\s*(" + specifiersRegex + ")"); conditionPattern = Pattern.compile("(" + specifiersRegex + ")(?:(" + comparatorRegex + ")(\\S+))?"); }
/** * Strips all links from the given markup; anything like [[this]] is replaced. If it is a link to * a wikipedia article, then it is replaced with its anchor text. Only links to images are treated * differently: they are discarded entirely. * * <p>You may want to first strip non-article links, isolated links, category links etc before * calling this method. * * @param markup the text to be stripped * @return the stripped text */ public static String stripLinks(String markup) { HashSet<String> discardPrefixes = new HashSet<String>(); discardPrefixes.add("image"); Vector<Integer> linkStack = new Vector<Integer>(); Pattern p = Pattern.compile("(\\[\\[|\\]\\])"); Matcher m = p.matcher(markup); StringBuffer sb = new StringBuffer(); int lastIndex = 0; while (m.find()) { String tag = markup.substring(m.start(), m.end()); if (tag.equals("[[")) linkStack.add(m.start()); else { if (!linkStack.isEmpty()) { int linkStart = linkStack.lastElement(); linkStack.remove(linkStack.size() - 1); if (linkStack.isEmpty()) { sb.append(markup.substring(lastIndex, linkStart)); // we have the whole link, with other links nested inside if it's an image String linkMarkup = markup.substring(linkStart + 2, m.start()); sb.append(stripLink(linkMarkup, discardPrefixes, false)); lastIndex = m.end(); } } } } if (!linkStack.isEmpty()) { System.err.println( "MarkupStripper | Warning: links were not well formed, so we cannot guarantee that they were stripped out correctly. "); } sb.append(markup.substring(lastIndex)); return sb.toString(); }
/** * Removes anything at the start of the markup that is indented. Normally this indicates notes * that the author should have used a template for, such as a "For other uses, see ****" note. * * @param markup the text to be stripped * @return the stripped markup */ public static String stripIndentedStart(String markup) { Pattern p = Pattern.compile("(.*?)\n", Pattern.DOTALL); Matcher m = p.matcher(markup); StringBuffer sb = new StringBuffer(); int newStart = 0; while (m.find()) { // System.out.println(" - \"" + m.group() + "\"\n\n") ; if (m.group().matches("(?s)([\\s\\W]*)([\\:\\*]+)(.*)") || m.group().matches("\\W*")) newStart = m.end(); else break; } sb.append(markup.substring(newStart)); return sb.toString(); }
/** * Gets the instances of <CODE>Template</CODE> that have an ID that is already in the database. * * @return An <CODE>ArrayList</CODE> containing the instances of <CODE>Template</CODE> already in * the database. * @throws java.sql.SQLException Thrown on sql exception. */ public ArrayList findTemplatesInDatabase() throws java.sql.SQLException { ArrayList templatesInDatabase = new ArrayList(); Connection oracleConnection = getDataSource().getConnection(); try { Statement query = oracleConnection.createStatement(); try { StringBuffer sql = new StringBuffer("SELECT TMPL_ID FROM "); sql.append(MPSBrowserView.SCHEMA); sql.append(".TEMPLATE WHERE TMPL_ID IN ("); ArrayList templates = getTemplates(); int templateCount = templates.size(); for (int i = 0; i < templateCount; i++) { if (i > 0) sql.append(", "); sql.append("'"); sql.append(((Template) templates.get(i)).getID()); sql.append("'"); } sql.append(")"); ResultSet result = query.executeQuery(sql.toString()); try { while (result.next()) { String templateID = result.getString("TMPL_ID"); for (int i = 0; i < templateCount; i++) { Template currentTemplate = (Template) templates.get(i); if (templateID.equals(currentTemplate.getID())) { templatesInDatabase.add(currentTemplate); currentTemplate.setInDatabase(true); } } } } finally { result.close(); } } finally { query.close(); } } finally { oracleConnection.close(); } return templatesInDatabase; }
/** Returns the original argument types. */ private String originalArguments(String obfuscatedArguments) { StringBuffer originalArguments = new StringBuffer(); int startIndex = 0; while (true) { int endIndex = obfuscatedArguments.indexOf(',', startIndex); if (endIndex < 0) { break; } originalArguments .append(originalType(obfuscatedArguments.substring(startIndex, endIndex).trim())) .append(','); startIndex = endIndex + 1; } originalArguments.append(originalType(obfuscatedArguments.substring(startIndex).trim())); return originalArguments.toString(); }