List of usage examples for java.io IOException getLocalizedMessage
public String getLocalizedMessage()
From source file:com.ibm.issw.odc.gui.BPMArgumentsPanel.java
/** * Add values from the clipboard/* w ww . j ava 2 s . co m*/ */ protected void addFromClipboard() { GuiUtils.stopTableEditing(table); int rowCount = table.getRowCount(); try { String clipboardContent = GuiUtils.getPastedText(); if (clipboardContent == null) { return; } String[] clipboardLines = clipboardContent.split("\n"); for (String clipboardLine : clipboardLines) { String[] clipboardCols = clipboardLine.split("\t"); if (clipboardCols.length > 0) { Argument argument = makeNewArgument(); argument.setName(clipboardCols[0]); if (clipboardCols.length > 1) { argument.setValue(clipboardCols[1]); if (clipboardCols.length > 2) { argument.setDescription(clipboardCols[2]); } } tableModel.addRow(argument); } } if (table.getRowCount() > rowCount) { // Enable DELETE (which may already be enabled, but it won't hurt) delete.setEnabled(true); // Highlight (select) the appropriate rows. int rowToSelect = tableModel.getRowCount() - 1; table.setRowSelectionInterval(rowCount, rowToSelect); } } catch (IOException ioe) { JOptionPane.showMessageDialog(this, "Could not add read arguments from clipboard:\n" + ioe.getLocalizedMessage(), "Error", JOptionPane.ERROR_MESSAGE); } catch (UnsupportedFlavorException ufe) { JOptionPane .showMessageDialog(this, "Could not add retrieve " + DataFlavor.stringFlavor.getHumanPresentableName() + " from clipboard" + ufe.getLocalizedMessage(), "Error", JOptionPane.ERROR_MESSAGE); } }
From source file:org.tomahawk.libtomahawk.resolver.ScriptResolver.java
public void setConfig(Map<String, Object> config) { try {//w w w . j a v a 2 s .c om String rawJsonString = mObjectMapper.writeValueAsString(config); mSharedPreferences.edit().putString(buildPreferenceKey(), rawJsonString).commit(); resolverSaveUserConfig(); } catch (IOException e) { Log.e(TAG, "setConfig: " + e.getClass() + ": " + e.getLocalizedMessage()); } }
From source file:org.tomahawk.libtomahawk.resolver.ScriptResolver.java
/** * @return the Map<String, String> containing the Config information of this resolver *///w w w . j av a 2 s .com public Map<String, Object> getConfig() { String rawJsonString = mSharedPreferences.getString(buildPreferenceKey(), ""); try { return mObjectMapper.readValue(rawJsonString, Map.class); } catch (IOException e) { Log.e(TAG, "getConfig: " + e.getClass() + ": " + e.getLocalizedMessage()); } return new HashMap<String, Object>(); }
From source file:fr.certu.chouette.exchange.xml.neptune.importer.XMLNeptuneImportLinePlugin.java
/** * import ZipFile/*from www .ja v a2 s . co m*/ * * @param filePath * path to zip File * @param validate * process XML and XSD format validation * @param importReport * report to fill * @param optimizeMemory * @param unsharedData * @param sharedData * @return list of loaded lines */ private List<Line> processZipImport(String filePath, boolean validate, Report importReport, Report validationReport, boolean optimizeMemory, SharedImportedData sharedData, UnsharedImportedData unsharedData) { ZipFile zip = null; try { Charset encoding = FileTool.getZipCharset(filePath); if (encoding == null) { ReportItem item = new ExchangeReportItem(ExchangeReportItem.KEY.FILE_ERROR, Report.STATE.ERROR, filePath, "unknown encoding"); importReport.addItem(item); importReport.updateStatus(Report.STATE.ERROR); logger.error("zip import failed (unknown encoding)"); return null; } zip = new ZipFile(filePath); } catch (IOException e) { // report for save ReportItem fileErrorItem = new ExchangeReportItem(ExchangeReportItem.KEY.ZIP_ERROR, Report.STATE.ERROR, e.getLocalizedMessage()); importReport.addItem(fileErrorItem); // log logger.error("zip import failed (cannot open zip)" + e.getLocalizedMessage()); return null; } List<Line> lines = new ArrayList<Line>(); for (Enumeration<? extends ZipEntry> entries = zip.entries(); entries.hasMoreElements();) { ZipEntry entry = entries.nextElement(); // ignore directory without warning if (entry.isDirectory()) continue; String entryName = entry.getName(); if (!FilenameUtils.getExtension(entryName).toLowerCase().equals("xml")) { // report for save ReportItem fileReportItem = new ExchangeReportItem(ExchangeReportItem.KEY.FILE_IGNORED, Report.STATE.OK, entryName); importReport.addItem(fileReportItem); // log logger.info("zip entry " + entryName + " bypassed ; not a XML file"); continue; } logger.info("start import zip entry " + entryName); ReportItem fileReportItem = new ExchangeReportItem(ExchangeReportItem.KEY.FILE, Report.STATE.OK, entryName); importReport.addItem(fileReportItem); try { InputStream stream = zip.getInputStream(entry); stream.close(); } catch (IOException e) { // report for save ReportItem errorItem = new ExchangeReportItem(ExchangeReportItem.KEY.FILE_ERROR, Report.STATE.ERROR, e.getLocalizedMessage()); fileReportItem.addItem(errorItem); // log logger.error("zip entry " + entryName + " import failed (get entry)" + e.getLocalizedMessage()); continue; } ChouettePTNetworkHolder holder = null; try { holder = reader.read(zip, entry, validate); validationReport.addItem(holder.getReport()); } catch (ExchangeRuntimeException e) { // report for save ReportItem errorItem = new ExchangeReportItem(ExchangeReportItem.KEY.FILE_ERROR, Report.STATE.ERROR, e.getLocalizedMessage()); fileReportItem.addItem(errorItem); // log logger.error("zip entry " + entryName + " import failed (read XML)" + e.getLocalizedMessage()); continue; } catch (Exception e) { // report for save ReportItem errorItem = new ExchangeReportItem(ExchangeReportItem.KEY.FILE_ERROR, Report.STATE.ERROR, e.getLocalizedMessage()); fileReportItem.addItem(errorItem); // log logger.error(e.getLocalizedMessage()); continue; } try { Line line = processImport(holder, validate, fileReportItem, validationReport, entryName, sharedData, unsharedData, optimizeMemory); if (line != null) { lines.add(line); } else { logger.error("zip entry " + entryName + " import failed (build model)"); } } catch (ExchangeException e) { // report for save ReportItem errorItem = new ExchangeReportItem(ExchangeReportItem.KEY.FILE_ERROR, Report.STATE.ERROR, e.getLocalizedMessage()); fileReportItem.addItem(errorItem); // log logger.error( "zip entry " + entryName + " import failed (convert to model)" + e.getLocalizedMessage()); continue; } logger.info("zip entry imported"); } try { zip.close(); } catch (IOException e) { logger.info("cannot close zip file"); } if (lines.size() == 0) { logger.error("zip import failed (no valid entry)"); return null; } return lines; }
From source file:org.tomahawk.libtomahawk.resolver.ScriptResolver.java
public void reportStreamUrl(String qid, String url, String stringifiedHeaders) { try {/*from w w w. j a v a 2 s . c o m*/ Map<String, String> headers = null; if (stringifiedHeaders != null) { headers = mObjectMapper.readValue(stringifiedHeaders, Map.class); } String resultKey = mQueryKeys.get(qid); PipeLine.getInstance().sendStreamUrlReportBroadcast(resultKey, url, headers); } catch (IOException e) { Log.e(TAG, "reportStreamUrl: " + e.getClass() + ": " + e.getLocalizedMessage()); } }
From source file:org.tomahawk.libtomahawk.resolver.ScriptResolver.java
public void callback(final int callbackId, final String responseText, final Map<String, List<String>> responseHeaders, final int status, final String statusText) { final Map<String, String> headers = new HashMap<String, String>(); for (String key : responseHeaders.keySet()) { if (key != null) { String concatenatedValues = ""; for (int i = 0; i < responseHeaders.get(key).size(); i++) { if (i > 0) { concatenatedValues += "\n"; }//ww w . java 2 s . co m concatenatedValues += responseHeaders.get(key).get(i); } headers.put(key, concatenatedValues); } } try { String headersString = mObjectMapper.writeValueAsString(headers); loadUrl("javascript: Tomahawk.callback(" + callbackId + "," + "'" + StringEscapeUtils.escapeJavaScript(responseText) + "'," + "'" + StringEscapeUtils.escapeJavaScript(headersString) + "'," + status + "," + "'" + StringEscapeUtils.escapeJavaScript(statusText) + "');"); } catch (IOException e) { Log.e(TAG, "callback: " + e.getClass() + ": " + e.getLocalizedMessage()); } }
From source file:nl.sogeti.android.gpstracker.actions.ShareTrack.java
private void sendToJogmap(Uri fileUri, String contentType) { String authCode = PreferenceManager.getDefaultSharedPreferences(this).getString(Constants.JOGRUNNER_AUTH, "");/* w w w . ja va 2 s.c o m*/ File gpxFile = new File(fileUri.getEncodedPath()); HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = null; URI jogmap = null; String jogmapResponseText = ""; int statusCode = 0; try { jogmap = new URI(getString(R.string.jogmap_post_url)); HttpPost method = new HttpPost(jogmap); MultipartEntity entity = new MultipartEntity(); entity.addPart("id", new StringBody(authCode)); entity.addPart("mFile", new FileBody(gpxFile)); method.setEntity(entity); response = httpclient.execute(method); statusCode = response.getStatusLine().getStatusCode(); InputStream stream = response.getEntity().getContent(); jogmapResponseText = convertStreamToString(stream); } catch (IOException e) { Log.e(TAG, "Failed to upload to " + jogmap.toString(), e); CharSequence text = getString(R.string.jogmap_failed) + e.getLocalizedMessage(); Toast toast = Toast.makeText(this, text, Toast.LENGTH_LONG); toast.show(); } catch (URISyntaxException e) { //Log.e(TAG, "Failed to use configured URI " + jogmap.toString(), e); CharSequence text = getString(R.string.jogmap_failed) + e.getLocalizedMessage(); Toast toast = Toast.makeText(this, text, Toast.LENGTH_LONG); toast.show(); } if (statusCode == 200) { CharSequence text = getString(R.string.jogmap_success) + jogmapResponseText; Toast toast = Toast.makeText(this, text, Toast.LENGTH_LONG); toast.show(); } else { Log.e(TAG, "Wrong status code " + statusCode); CharSequence text = getString(R.string.jogmap_failed) + jogmapResponseText; Toast toast = Toast.makeText(this, text, Toast.LENGTH_LONG); toast.show(); } }
From source file:edu.ku.brc.specify.tools.ireportspecify.MainFrameSpecify.java
/** * @param jasperFile// www. j a v a 2 s .c o m * @param confirmOverwrite * @param newResName this name override the name of the report (which is usually the file name sans the extension) * @return true if the report is successfully imported, otherwise return false. */ public static boolean importJasperReport(final File jasperFile, final boolean confirmOverwrite, final String newResName) { ByteArrayOutputStream xml = null; try { xml = new ByteArrayOutputStream(); xml.write(FileUtils.readFileToByteArray(jasperFile)); } catch (IOException e) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(MainFrameSpecify.class, e); UIRegistry.getStatusBar().setErrorMessage(e.getLocalizedMessage(), e); return false; } String resName = newResName != null ? newResName : FilenameUtils.getBaseName(jasperFile.getName()); AppResAndProps resApp = getAppRes(resName, null, confirmOverwrite); if (resApp != null) { String metaData = resApp.getAppRes().getMetaData(); String newMetaData = "isimport=1"; try { Element element = XMLHelper.readFileToDOM4J(jasperFile); List<?> parameters = element.selectNodes("/jasperReport/parameter"); boolean isDropSite = false; for (Object p : parameters) { Element param = (Element) p; if (param.attributeValue("name").equals(ReportsBaseTask.RECORDSET_PARAM)) { isDropSite = true; break; } } if (isDropSite) { newMetaData += ";hasrsdropparam=1"; } else { newMetaData += ";hasrsdropparam=0"; } } catch (Exception e) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(MainFrameSpecify.class, e); UIRegistry.getStatusBar().setErrorMessage(e.getLocalizedMessage(), e); return false; } if (StringUtils.isEmpty(metaData)) { metaData = newMetaData; } else { metaData += ";" + newMetaData; } resApp.getAppRes().setMetaData(metaData); return saveXML(xml, resApp, null, false); } return false; }
From source file:org.tomahawk.libtomahawk.resolver.ScriptResolver.java
public void addUrlResultString(final String url, final String resultString) { new Thread(new Runnable() { @Override// w w w . java 2s. c om public void run() { ScriptResolverUrlResult result = null; try { result = mObjectMapper.readValue(resultString, ScriptResolverUrlResult.class); } catch (IOException e) { Log.e(TAG, "addUrlResultString: " + e.getClass() + ": " + e.getLocalizedMessage()); } if (result != null) { PipeLine.getInstance().reportUrlResult(url, ScriptResolver.this, result); } mStopped = true; } }).start(); }
From source file:org.tomahawk.libtomahawk.resolver.ScriptResolver.java
/** * Sometimes we need the String returned by a certain javascript function. Therefore we wrap the * function call in a call to "callbackToJava", which is being received by the ScriptInterface. * The ScriptInterface redirects the call to this method, where we can access the returned * String. Throughout this whole process we are passing an id along, which enables us to * identify which call wants to return its result. * * @param id used to identify which function did the callback * @param jsonString the json-string which is the result of the called function. Can be null. *///from w ww. j a v a 2 s. c o m public void handleCallbackToJava(final int id, final String... jsonString) { try { if (id == R.id.scriptresolver_resolver_settings && jsonString != null && jsonString.length == 1) { ScriptResolverSettings settings = mObjectMapper.readValue(jsonString[0], ScriptResolverSettings.class); mWeight = settings.weight; mTimeout = settings.timeout * 1000; resolverGetConfigUi(); } else if (id == R.id.scriptresolver_resolver_get_config_ui && jsonString != null && jsonString.length == 1) { mConfigUi = mObjectMapper.readValue(jsonString[0], ScriptResolverConfigUi.class); } else if (id == R.id.scriptresolver_resolver_init) { resolverSettings(); } else if (id == R.id.scriptresolver_resolver_collection && jsonString != null && jsonString.length == 1) { mCollectionMetaData = mObjectMapper.readValue(jsonString[0], ScriptResolverCollectionMetaData.class); CollectionManager.getInstance().addCollection(new ScriptResolverCollection(this)); } } catch (IOException e) { Log.e(TAG, "handleCallbackToJava: " + e.getClass() + ": " + e.getLocalizedMessage()); } }