List of usage examples for java.lang Exception toString
public String toString()
From source file:gdt.data.entity.BaseHandler.java
/** * Get an array of all facet handlers in the database * @param entigrator instance of the Entigrator class * @return array of facet handlers./* w w w. j av a2 s . c o m*/ */ public static FacetHandler[] listAllHandlers(Entigrator entigrator) { try { ArrayList<FacetHandler> fl = new ArrayList<FacetHandler>(); // System.out.println("BaseHandler:listAllHandlers:BEGIN"); fl.add(new FieldsHandler()); fl.add(new FolderHandler()); fl.add(new WebsetHandler()); fl.add(new BookmarksHandler()); fl.add(new IndexHandler()); fl.add(new ExtensionHandler()); fl.add(new QueryHandler()); fl.add(new ProcedureHandler()); // System.out.println("BaseHandler:listAllHandlers:END EMBEDDED"); FacetHandler[] fha = ExtensionHandler.listExtensionHandlers(entigrator); if (fha != null) { //System.out.println("BaseHandler:listAllHandlers:fha="+fha.length); for (FacetHandler fh : fha) { //System.out.println("BaseHandler:listAllHandlers:fh="+fh.toString()); fl.add(fh); } } //else // System.out.println("BaseHandler:listAllHandlers:no extensions"); // System.out.println("BaseHandler:listAllHandlers:END EXTENSIONS"); return fl.toArray(new FacetHandler[0]); } catch (Exception e) { Logger.getLogger(BaseHandler.class.getName()).severe(e.toString()); return null; } }
From source file:gdt.data.grain.Locator.java
/** * Append the name/value pairs from the other locator. If the name * already exists it will be ignored. * @param locator$ the target locator string * @param locator2$ the second locator string. * @return the result locator string. *//*ww w . j av a2 s . com*/ public static String merge(String locator$, String locator2$) { try { Properties locator = toProperties(locator2$); if (locator == null) return locator$; Enumeration<?> en = locator.keys(); String key$; String value$; while (en.hasMoreElements()) { key$ = (String) en.nextElement(); value$ = locator.getProperty(key$); locator$ = Locator.append(locator$, key$, value$); } return locator$; } catch (Exception e) { Logger.getLogger(Locator.class.getName()).severe(e.toString()); return null; } }
From source file:cz.incad.kramerius.virtualcollections.VirtualCollectionsManager.java
public static List<VirtualCollection> getVirtualCollectionsFromFedora(FedoraAccess fedoraAccess, ArrayList<String> languages) throws Exception { try {// w w w . j a v a 2 s . co m IResourceIndex g = ResourceIndexService.getResourceIndexImpl(); Document doc = g.getVirtualCollections(); NodeList nodes = doc.getDocumentElement().getElementsByTagNameNS(SPARQL_NS, "result"); NodeList children; Node child; String name; String pid; boolean canLeave; ArrayList<String> langs = new ArrayList<String>(); if (languages == null || languages.isEmpty()) { String[] ls = KConfiguration.getInstance().getPropertyList("interface.languages"); for (int i = 0; i < ls.length; i++) { String lang = ls[++i]; langs.add(lang); } } else { langs = new ArrayList<String>(languages); } List<VirtualCollection> vcs = new ArrayList<VirtualCollection>(); for (int i = 0; i < nodes.getLength(); i++) { canLeave = false; name = null; pid = null; Node node = nodes.item(i); children = node.getChildNodes(); for (int j = 0; j < children.getLength(); j++) { child = children.item(j); if ("title".equals(child.getLocalName())) { name = child.getFirstChild().getNodeValue(); } else if ("object".equals(child.getLocalName())) { pid = ((Element) child).getAttribute("uri").replaceAll("info:fedora/", ""); } else if ("canLeave".equals(child.getLocalName())) { canLeave = Boolean.parseBoolean(child.getFirstChild().getNodeValue().replaceAll("\"", "") .substring(("canLeave:").length())); } } if (name != null && pid != null) { try { VirtualCollection vc = new VirtualCollection(name, pid, canLeave); for (String lang : langs) { String dsName = TEXT_DS_PREFIX + lang; String value = IOUtils.readAsString(fedoraAccess.getDataStream(pid, dsName), Charset.forName("UTF8"), true); vc.addDescription(lang, value); } vcs.add(vc); } catch (Exception vcex) { logger.log(Level.WARNING, "Could not get virtual collection for " + pid + ": " + vcex.toString()); } } } return vcs; } catch (Exception ex) { logger.log(Level.SEVERE, "Error getting virtual collections", ex); throw new Exception(ex); } }
From source file:com.tencent.wetest.common.util.DeviceUtil.java
public static String getCpuName() { String result = "--"; try {//from w ww .jav a 2s . c o m FileReader fr = new FileReader("/proc/cpuinfo"); BufferedReader br = new BufferedReader(fr); String text = br.readLine(); String[] array = text.split(":\\s+", 2); result = array[1]; br.close(); } catch (Exception e) { Logger.error("getCpuName Exception: " + e.toString()); } return result; }
From source file:com.etime.ETimeUtils.java
/** * Return a List of Punches for the current day. The list is empty if there are no punches for today. * * @param page the raw html of the user's timecard page * @return A list of Punches for the current day. *///from w ww . j av a2 s. c o m protected static List<Punch> getTodaysPunches(String page) { String curRow; String date; List<Punch> punchesList = new LinkedList<Punch>(); Calendar calendar = Calendar.getInstance(); int month = calendar.get(Calendar.MONTH) + 1; int day = calendar.get(Calendar.DAY_OF_MONTH); String dayOfWeek = daysOfWeek[calendar.get(Calendar.DAY_OF_WEEK) - 1]; if (day < 10) { date = dayOfWeek + " " + Integer.toString(month) + "/0" + Integer.toString(day); } else { date = dayOfWeek + " " + Integer.toString(month) + "/" + Integer.toString(day); } try { Pattern todaysRowsPattern = Pattern.compile("(?i)(>" + date + ")(.*?)(</tr>)", Pattern.MULTILINE | Pattern.DOTALL); Matcher todaysRowsMatcher = todaysRowsPattern.matcher(page); while (todaysRowsMatcher.find()) { curRow = todaysRowsMatcher.group(2); addPunchesFromRowToList(curRow, punchesList); } } catch (Exception e) { Log.w(TAG, e.toString()); } return punchesList; }
From source file:de.itomig.itopenterprise.GetItopJSON.java
/** * request data from itop server in json format - must be called from AsyncTask * * @param operation core/get etc/* w w w. ja v a 2 s .c o m*/ * @param itopClass CI class * @param key itop SELECT expression * @param output_fields attribute fields which should be returned * @return String with json data from server */ public static String postJsonToItopServer(String operation, String itopClass, String key, String output_fields) { AndroidHttpClient client = AndroidHttpClient.newInstance("Android"); String result = ""; try { HttpPost request = new HttpPost(); String url = ItopConfig.getItopUrl(); String req = url + "/webservices/rest.php?version=1.0"; if (debug) Log.i(TAG, "json request=" + req); request.setURI(new URI(req)); ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>(); postParameters.add(ItopConfig.getItopUserNameValuePair()); postParameters.add(ItopConfig.getItopPwdNameValuePair()); JSONObject jsd = new JSONObject(); jsd.put("operation", operation); jsd.put("class", itopClass); jsd.put("key", key); jsd.put("output_fields", output_fields); postParameters.add(new BasicNameValuePair("json_data", jsd.toString())); UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters); request.setEntity(formEntity); // request.addHeader(HTTP.CONTENT_TYPE, "application/json"); HttpResponse response = client.execute(request); String status = response.getStatusLine().toString(); if (debug) Log.i(TAG, "status: " + status); if (status.contains("200") && status.contains("OK")) { // request worked fine, retrieved some data InputStream instream = response.getEntity().getContent(); result = convertStreamToString(instream); //Log.d(TAG, "result is: " + result); } else // some error in http response { Log.e(TAG, "Get data - http-ERROR: " + status); result = "SERVER_ERROR: http status " + status; } } catch (Exception e) { // Toast does not work in background task Log.e(TAG, "Get data - " + e.toString()); result = "SERVER_ERROR: " + e.toString(); } finally { client.close(); // needs to be done for androidhttpclient if (debug) Log.i(TAG, "...finally.. get data finished"); } return result; }
From source file:com.tencent.wetest.common.util.DeviceUtil.java
public static String getCpuMinFreq() { String result = "--"; double cpuMinFreq = 0; try {// w w w . j av a2 s . c o m BufferedReader br = new BufferedReader( new FileReader("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq")); String text = ""; while ((text = br.readLine()) != null) { text = text.trim(); if (!"".equals(text.trim())) { cpuMinFreq = Double.parseDouble(text.trim()) / (1000 * 1000); BigDecimal bg = new BigDecimal(cpuMinFreq).setScale(2, RoundingMode.UP); result = "" + bg.doubleValue(); // DeviceUtil.cpuMinFreq = cpuMinFreq; } break; } br.close(); br = null; } catch (Exception e) { Logger.error("getCpuMinFreqException" + e.toString()); } return result; }
From source file:DateUtil.java
/** * Parse RSS date format to Date object. * Example of RSS date://from www . j av a2s . c om * Sat, 23 Sep 2006 22:25:11 +0000 */ public static Date parseDate(String dateString) { Date pubDate = null; try { // Split date string to values // 0 = week day // 1 = day of month // 2 = month // 3 = year (could be with either 4 or 2 digits) // 4 = time // 5 = GMT int weekDayIndex = 0; int dayOfMonthIndex = 2; int monthIndex = 1; int yearIndex = 5; int timeIndex = 3; int gmtIndex = 4; String[] values = dateString.split(" "); int columnCount = values.length; // Wed Aug 29 20:14:27 +0000 2007 if (columnCount == 5) { // Expected format: // 09 Nov 2006 23:18:49 EST dayOfMonthIndex = 0; monthIndex = 1; yearIndex = 2; timeIndex = 3; gmtIndex = 4; } else if (columnCount == 7) { // Expected format: // Thu, 19 Jul 2007 00:00:00 N yearIndex = 4; timeIndex = 5; gmtIndex = 6; } else if (columnCount < 5 || columnCount > 6) { throw new Exception("Invalid date format: " + dateString); } // Day of month int dayOfMonth = Integer.parseInt(values[dayOfMonthIndex]); // Month String[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; String monthString = values[monthIndex]; int month = 0; for (int monthEnumIndex = 0; monthEnumIndex < 12; monthEnumIndex++) { if (monthString.equals(months[monthEnumIndex])) { month = monthEnumIndex; } } // Year int year = Integer.parseInt(values[yearIndex]); if (year < 100) { year += 2000; } // Time String[] timeValues = values[timeIndex].split(":"); int hours = Integer.parseInt(timeValues[0]); int minutes = Integer.parseInt(timeValues[1]); int seconds = Integer.parseInt(timeValues[2]); pubDate = getCal(dayOfMonth, month, year, hours, minutes, seconds, values[gmtIndex]); } catch (Exception ex) { // TODO: Add exception handling code System.err.println("parseRssDate error while converting date string to object: " + dateString + "," + ex.toString()); } catch (Throwable t) { // TODO: Add exception handling code System.err.println("parseRssDate error while converting date string to object: " + dateString + "," + t.toString()); } return pubDate; }
From source file:edu.umass.cs.msocket.gns.GnsIntegration.java
/** * Lookup the IP address(es) of an MServerSocket by its Human Readable Name * registered in the GNS.//from w w w . j a v a 2 s . c o m * throws UnknownHostException, so that it is similar to * exception thrown on DNS failure * @param name Human readable name of the MServerSocket * @param gnsCredentials GNS credentials to use * @return list of IP addresses or null if not found * @throws Exception */ public static List<InetSocketAddress> getSocketAddressFromGNS(String name, GnsCredentials gnsCredentials) throws UnknownHostException { try { log.trace("Retrieving IP of " + name); if (gnsCredentials == null) { gnsCredentials = GnsCredentials.getDefaultCredentials(); } UniversalGnsClient gnsClient = gnsCredentials.getGnsClient(); String guidString = gnsClient.lookupGuid(name); log.trace("GUID lookup " + guidString); JSONArray resultArray; // Read from the GNS synchronized (gnsClient) { resultArray = gnsClient.fieldRead(guidString, GnsConstants.SERVER_REG_ADDR, null); } Vector<InetSocketAddress> resultVector = new Vector<InetSocketAddress>(); for (int i = 0; i < resultArray.length(); i++) { String str = resultArray.getString(i); log.trace("Value returned from GNS " + str); String[] Parsed = str.split(":"); InetSocketAddress socketAddress = new InetSocketAddress(Parsed[0], Integer.parseInt(Parsed[1])); resultVector.add(socketAddress); } return resultVector; } catch (Exception ex) { ex.printStackTrace(); throw new UnknownHostException(ex.toString()); } }
From source file:com.syaku.commons.DateUtils.java
public static Date setDateString(String date) { Date retDate = null;/*from w w w .j a va2 s . com*/ try { String sysdate_patten = "(^[A-Za-z]{3}), ([0-9]{2}) ([A-Za-z]{3}) ([0-9]{4}) ([0-9]{2}):([0-9]{2}):([0-9]{2}) ([+0-9]{5})$"; String yyyy = date.replaceAll(sysdate_patten, "$4"); String MM = date.replaceAll(sysdate_patten, "$3"); String dd = date.replaceAll(sysdate_patten, "$2"); String hh = date.replaceAll(sysdate_patten, "$5"); String mm = date.replaceAll(sysdate_patten, "$6"); String ss = date.replaceAll(sysdate_patten, "$7"); String timezone = date.replaceAll(sysdate_patten, "$8"); String[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; int months_int = months.length; for (int i = 0; i < months_int; i++) { String month = months[i]; if (StringUtils.equals(MM, month)) { MM = "" + (i + 1); MM = StringUtils.leftPad(MM, 2, '0'); break; } } date = yyyy + MM + dd + hh + mm + ss; date = date("yyyy-MM-dd HH:mm:ss", date); formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); retDate = formatter.parse(date); } catch (Exception e) { log.error("[#MEI DateUtils.setDateString] " + e.toString()); } return retDate; }