List of usage examples for java.lang NumberFormatException toString
public String toString()
From source file:com.wabacus.system.component.application.report.abstractreport.AbsListReportType.java
public int beforeReportLoading(ReportBean reportbean, List<XmlElementBean> lstEleReportBeans) { XmlElementBean eleReportBean = lstEleReportBeans.get(0); AbsListReportBean alrbean = (AbsListReportBean) reportbean.getExtendConfigDataForReportType(KEY); if (alrbean == null) { alrbean = new AbsListReportBean(reportbean); reportbean.setExtendConfigDataForReportType(KEY, alrbean); }/* w ww . ja v a 2 s. c om*/ String fixedcols = eleReportBean.attributeValue("fixedcols"); if (fixedcols != null) { fixedcols = fixedcols.trim(); if (fixedcols.equals("")) { alrbean.setFixedcols(null, 0); } else { try { alrbean.setFixedcols(null, Integer.parseInt(fixedcols)); } catch (NumberFormatException e) { log.warn("" + reportbean.getPath() + "<report/>fixedcols?" + fixedcols + "" + e.toString()); alrbean.setFixedcols(null, 0); } } } if (alrbean.getFixedcols(null) < 0) alrbean.setFixedcols(null, 0); String fixedrows = eleReportBean.attributeValue("fixedrows"); if (fixedrows != null) { fixedrows = fixedrows.trim(); if (fixedrows.equals("")) { alrbean.setFixedrows(0); } else if (fixedrows.toLowerCase().equals("title")) { alrbean.setFixedrows(Integer.MAX_VALUE); } else { try { alrbean.setFixedrows(Integer.parseInt(fixedrows)); } catch (NumberFormatException e) { log.warn("" + reportbean.getPath() + "<report/>fixedrows?" + fixedrows + "" + e.toString()); alrbean.setFixedrows(0); } } } if (alrbean.getFixedrows() < 0) alrbean.setFixedrows(0); String rowselect = eleReportBean.attributeValue("rowselect"); if (rowselect != null) { rowselect = rowselect.toLowerCase().trim(); boolean isSelectRowCrossPages = false; int idx = rowselect.indexOf("|"); if (idx > 0) { isSelectRowCrossPages = rowselect.substring(idx + 1).trim().equals("true"); rowselect = rowselect.substring(0, idx).trim(); } if (rowselect.equals("")) { alrbean.setRowSelectType(null); } else { if (!Consts.lstAllRowSelectTypes.contains(rowselect)) { throw new WabacusConfigLoadingException("" + reportbean.getPath() + "?rowselect" + rowselect + "??"); } alrbean.setRowSelectType(rowselect); alrbean.setSelectRowCrossPages(isSelectRowCrossPages); } } String rowselectcallback = eleReportBean.attributeValue("selectcallback"); if (rowselectcallback != null) { rowselectcallback = rowselectcallback.trim(); if (rowselectcallback.equals("")) { alrbean.setLstRowSelectCallBackFuncs(null); } else { List<String> lstTemp = Tools.parseStringToList(rowselectcallback, ";", false); for (String strfun : lstTemp) { if (strfun == null || strfun.trim().equals("")) continue; alrbean.addRowSelectCallBackFunc(strfun.trim()); } } } String rowordertype = eleReportBean.attributeValue("rowordertype"); if (rowordertype != null) { rowordertype = rowordertype.toLowerCase().trim(); if (rowordertype.equals("")) { alrbean.setLoadStoreRoworderObject(null); alrbean.setLstRoworderTypes(null); } else { List<String> lstRoworderTypes = new ArrayList<String>(); List<String> lstTmp = Tools.parseStringToList(rowordertype, "|", false); for (String roworderTmp : lstTmp) { if (roworderTmp == null || roworderTmp.trim().equals("")) continue; roworderTmp = roworderTmp.trim(); if (!Consts.lstAllRoworderTypes.contains(roworderTmp)) { throw new WabacusConfigLoadingException("" + reportbean.getPath() + "?rowordertype" + roworderTmp + "??"); } if (!lstRoworderTypes.contains(roworderTmp)) lstRoworderTypes.add(roworderTmp); } if (lstRoworderTypes.size() == 0) { alrbean.setLoadStoreRoworderObject(null); alrbean.setLstRoworderTypes(null); } else { alrbean.setLstRoworderTypes(lstRoworderTypes); String roworderclass = eleReportBean.attributeValue("roworderclass"); if (roworderclass != null) { roworderclass = roworderclass.trim(); if (roworderclass.equals("")) { alrbean.setLoadStoreRoworderObject(null); } else { Object obj = null; try { obj = ConfigLoadManager.currentDynClassLoader .loadClassByCurrentLoader(roworderclass).newInstance(); } catch (Exception e) { throw new WabacusConfigLoadingException("" + reportbean.getPath() + "" + roworderclass + "", e); } if (!(obj instanceof IListReportRoworderPersistence)) { throw new WabacusConfigLoadingException("" + reportbean.getPath() + "roworderclass?" + roworderclass + "" + IListReportRoworderPersistence.class.getName() + "?"); } alrbean.setLoadStoreRoworderObject((IListReportRoworderPersistence) obj); } } if (alrbean.getLoadStoreRoworderObject() == null && Config.default_roworder_object == null) {//??? throw new WabacusConfigLoadingException("" + reportbean.getPath() + "wabacus.cfg.xmldefault-roworderclass????<report/>?roworderclass??"); } } } } return 1; }
From source file:com.FFLive.MySQLConnection.java
public void updatePlayers(int gw, boolean namesOnly) { Main.log.log(5, "Updating All Player Info... \r"); try {/* ww w.j a v a 2s .c o m*/ PreparedStatement SelPID = conn.prepareStatement("SELECT playerID FROM playersGW?"); SelPID.setInt(1, gw); ResultSet playerList = SelPID.executeQuery(); //statement.executeQuery("SELECT playerID FROM playersGW" + gw); int counter = 0; while (playerList.next()) { if (counter % 30 == 0) { Main.log.log(5, "Updating All Player Info. \r"); } else if (counter % 30 == 10) { Main.log.log(5, "Updating All Player Info.. \r"); } else if (counter % 30 == 20) { Main.log.log(5, "Updating All Player Info... \r"); } counter++; try { Player player = new Player(Integer.toString(playerList.getInt("playerID")), gw); player.getPlayer(); if (!namesOnly || player.playerID.equals("-1")) { PreparedStatement UpPGw = conn.prepareStatement("UPDATE playersGW? set " + "firstName =?, " + "lastName =?, " + "webName = ?, " + "score = ?, " + "gameweekBreakdown = ?, " + "teamID = ?, " + "teamName = ?, " + "currentFixture = ?, " + "nextFixture = ?, " + "status = ?, " + "news = ?, " + "photo = ? " + "WHERE playerID = ?"); UpPGw.setInt(1, gw); UpPGw.setString(2, player.firstName); UpPGw.setString(3, player.lastName); UpPGw.setString(4, player.playerName); UpPGw.setInt(5, player.playerScore); UpPGw.setString(6, player.gameweekBreakdown); UpPGw.setInt(7, player.teamNumber); UpPGw.setString(8, player.playerTeam); UpPGw.setString(9, player.currentFixture); UpPGw.setString(10, player.nextFixture); UpPGw.setString(11, player.status); UpPGw.setString(12, player.news); UpPGw.setString(13, player.photo); UpPGw.setInt(14, Integer.parseInt(player.playerID)); UpPGw.executeUpdate(); UpPGw.close(); } else { PreparedStatement UpPGw = conn.prepareStatement( "UPDATE playersGW? set " + "firstName =?, " + "lastName =?, " + "webName = ?, " + "teamID = ?, " + "teamName = ?, " + "photo = ? " + "WHERE playerID = ?"); UpPGw.setInt(1, gw); UpPGw.setString(2, player.firstName); UpPGw.setString(3, player.lastName); UpPGw.setString(4, player.playerName); UpPGw.setInt(5, player.teamNumber); UpPGw.setString(6, player.playerTeam); UpPGw.setString(7, player.photo); UpPGw.setInt(8, Integer.parseInt(player.playerID)); UpPGw.executeUpdate(); UpPGw.close(); } } catch (MysqlDataTruncation g) { Main.log.ln(4); Main.log.log(4, g + " - while updating Players, Skipping Player\n"); } catch (SQLException f) { Main.log.ln(2); Main.log.log(2, "Error Updating Players, Skipping Player\n"); Main.log.log(2, f.toString()); Main.log.log(9, f); } catch (NumberFormatException n) { Main.log.ln(2); Main.log.log(2, "Invalid Player ID, Skipping Player\n"); Main.log.log(2, n.toString()); Main.log.log(9, n); } } } catch (Exception e) { Main.log.ln(1); Main.log.log(1, "Critical Error Updating Players\n"); Main.log.log(1, e.toString()); Main.log.log(9, e); System.exit(1097); } Main.log.log(5, "Updating All Player Info... Done! \r"); }
From source file:com.FFLive.MySQLConnection.java
public void contructLeagueData(String leagueIDsGWs) { boolean logChanged = false; if (Main.log.logLevel == 5) { //Changing Logging Level for cleaner console output Main.log.logLevel(4);/*from w ww. jav a 2s.co m*/ logChanged = true; } //New Leagues Construct Leagues leagues = new Leagues(); String[] rebuild = leagueIDsGWs.split(","); for (String leagueIDGW : rebuild) { String[] splitLeagueIDGW = leagueIDGW.split("/"); if (splitLeagueIDGW.length != 2) { Main.log.log(2, "Invalid Format given for buildLeague for " + leagueIDGW + "- Input in format leagueID/Gameweek with leagues split by commas (,), skipping...\n"); } else { try { leagues.addLeague(Integer.parseInt(splitLeagueIDGW[0].trim()), Integer.parseInt(splitLeagueIDGW[1].trim())); Main.log.log(5, "Rebuilding All League Data for League:" + splitLeagueIDGW[0] + " Starting from GW:" + splitLeagueIDGW[1] + "\n"); } catch (NumberFormatException e) { Main.log.log(2, "Please confirm your League ID and Gameweek are valid, in the form leagueID/Gameweek and are numbers\n"); Main.log.log(2, e.toString()); } } } for (ClassicLeague classicLeague : leagues.classicLeague) { rebuildLeague(classicLeague); } for (H2HLeague H2HLeague : leagues.h2hLeague) { rebuildLeague(H2HLeague); } if (logChanged) { //Returning to Default Main.log.logLevel(5); } }
From source file:org.opencms.flex.CmsFlexCacheKey.java
/** * Parse a String in the Flex cache language and construct * the key data structure from this.<p> * * @param key the String to parse (usually read from the file property "cache") */// w w w . j ava2 s . c o m private void parseFlexKey(String key) { List<String> tokens = CmsStringUtil.splitAsList(key, ';', false); Iterator<String> i = tokens.iterator(); try { while (i.hasNext()) { String t = i.next(); String k = null; String v = null; int idx = t.indexOf('='); if (idx >= 0) { k = t.substring(0, idx).trim(); if (t.length() > idx) { v = t.substring(idx + 1).trim(); } } else { k = t.trim(); } m_always = 0; if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_FLEXCACHEKEY_PARSE_FLEXKEY_3, t, k, v)); } switch (CACHE_COMMANDS.indexOf(k)) { case 0: // always case 12: // true m_always = 1; // continue processing (make sure we find a "never" behind "always") break; case 1: // never case 10: // false m_always = -1; // no need for any further processing return; case 2: // uri m_uri = IS_USED; // marks m_uri as being used break; case 3: // user m_user = IS_USED; // marks m_user as being used break; case 4: // params if (v != null) { m_params = parseValueList(v); } else { m_params = Collections.emptySet(); } if (m_params.contains(I_CmsResourceLoader.PARAMETER_ELEMENT)) { // workaround for element setting by parameter in OpenCms < 6.0 m_element = IS_USED; m_params.remove(I_CmsResourceLoader.PARAMETER_ELEMENT); if (m_params.size() == 0) { m_params = null; } } break; case 5: // no-params if (v != null) { // no-params are present m_noparams = parseValueList(v); } else { // never cache with parameters m_noparams = Collections.emptySet(); } break; case 6: // timeout m_timeout = Integer.parseInt(v); break; case 7: // session m_session = parseValueList(v); if (m_session.size() <= 0) { // session must have at last one variable set m_parseError = true; } break; case 8: // schemes m_schemes = parseValueList(v); break; case 9: // ports Set<String> ports = parseValueList(v); m_ports = new HashSet<Integer>(ports.size()); for (String p : ports) { try { m_ports.add(Integer.valueOf(p)); } catch (NumberFormatException e) { // ignore this number } } break; case 11: // previous parse error - ignore break; case 13: // ip m_ip = IS_USED; // marks ip as being used break; case 14: // element m_element = IS_USED; break; case 15: // locale m_locale = IS_USED; break; case 16: // encoding m_encoding = IS_USED; break; case 17: // site m_site = IS_USED; break; case 18: // attrs if (v != null) { m_attrs = parseValueList(v); } else { m_attrs = null; } break; case 19: // no-attrs if (v != null) { // no-attrs are present m_noattrs = parseValueList(v); } else { // never cache with attributes m_noattrs = Collections.emptySet(); } break; case 20: // device m_device = IS_USED; // marks m_device as being used break; case 21: // container element m_containerElement = IS_USED; break; default: // unknown directive, throw error m_parseError = true; } } } catch (Exception e) { // any Exception here indicates a parsing error if (LOG.isErrorEnabled()) { LOG.error(Messages.get().getBundle().key(Messages.LOG_FLEXCACHEKEY_PARSE_ERROR_1, e.toString())); } m_parseError = true; } if (m_parseError) { // If string is invalid set cache to "never" m_always = -1; } }
From source file:com.onehippo.gogreen.importer.NonWorkflowWikiImporterComponent.java
@Override public void doAction(HstRequest request, HstResponse response) throws HstComponentException { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser;/*from w ww .j av a 2 s . co m*/ String numberStr = request.getParameter("number"); int numberOfWikiDocs; try { numberOfWikiDocs = Integer.parseInt(numberStr); } catch (NumberFormatException e) { response.setRenderParameter("message", "number must be a number but was '" + numberStr + "'"); return; } if (numberOfWikiDocs <= 0) { response.setRenderParameter("message", "number must be a number larger than 0 but was '" + numberStr + "'"); return; } String offsetStr = request.getParameter("offset"); int offset = 0; if (StringUtils.isNotBlank(offsetStr)) { try { offset = Integer.parseInt(offsetStr); if (offset < 0) { offset = 0; } } catch (NumberFormatException e) { offset = 0; } } String wikiContentFileSystem = request.getParameter("filesystemLocation"); if (StringUtils.isEmpty(wikiContentFileSystem)) { throw new IllegalArgumentException("filesystemLocation should be correct"); } String type = request.getParameter("type"); if (type == null || !(type.equals("news") || type.equals("products"))) { response.setRenderParameter("message", "Invalid type. Must be 'news' or 'products' but was '" + type + "'"); throw new IllegalArgumentException("type should be set"); } try { parser = factory.newSAXParser(); File f = new File(wikiContentFileSystem); WikiPediaToJCRHandler handler = null; long start = System.currentTimeMillis(); try { Session writableSession = this.getPersistableSession(request); Node baseNode = writableSession .getNode(request.getRequestContext().getSiteContentBaseBean().getPath()); Node wikiFolder; if (!baseNode.hasNode(type)) { wikiFolder = baseNode.addNode(type, "hippostd:folder"); wikiFolder.addMixin("mix:referenceable"); } else { wikiFolder = baseNode.getNode(type); } handler = new WikiPediaToJCRHandler(wikiFolder, numberOfWikiDocs, offset, type); parser.parse(f, handler); } catch (ForcedStopException e) { // succesfull handler quits after numberOfWikiDocs has been achieved } catch (Exception e) { log.warn("Exception during importing wikipedia docs", e); response.setRenderParameter("message", "An exception happened. Did not import wiki docs. " + e.toString()); } response.setRenderParameter("message", "Successfully imported '" + handler.count + "' wikipedia documents in '" + (System.currentTimeMillis() - start) + "' ms."); } catch (ParserConfigurationException | SAXException e) { response.setRenderParameter("message", "Did not import wiki: " + e.toString()); } }
From source file:com.piusvelte.sonet.core.SonetService.java
private void buildWidgetButtons(Integer appWidgetId, boolean updatesReady, int page, boolean hasbuttons, int scrollable, int buttons_bg_color, int buttons_color, int buttons_textsize, boolean display_profile, int margin) { final String widget = Integer.toString(appWidgetId); // Push update for this widget to the home screen int layout;/*from w w w .ja v a 2 s . c om*/ if (hasbuttons) { if (sNativeScrollingSupported) { if (margin > 0) layout = R.layout.widget_margin_scrollable; else layout = R.layout.widget_scrollable; } else if (display_profile) { if (margin > 0) layout = R.layout.widget_margin; else layout = R.layout.widget; } else { if (margin > 0) layout = R.layout.widget_noprofile_margin; else layout = R.layout.widget_noprofile; } } else { if (sNativeScrollingSupported) { if (margin > 0) layout = R.layout.widget_nobuttons_margin_scrollable; else layout = R.layout.widget_nobuttons_scrollable; } else if (display_profile) { if (margin > 0) layout = R.layout.widget_nobuttons_margin; else layout = R.layout.widget_nobuttons; } else { if (margin > 0) layout = R.layout.widget_nobuttons_noprofile_margin; else layout = R.layout.widget_nobuttons_noprofile; } } // wrap RemoteViews for backward compatibility RemoteViews views = new RemoteViews(getPackageName(), layout); if (hasbuttons) { Bitmap buttons_bg = Bitmap.createBitmap(1, 1, Config.ARGB_8888); Canvas buttons_bg_canvas = new Canvas(buttons_bg); buttons_bg_canvas.drawColor(buttons_bg_color); views.setImageViewBitmap(R.id.buttons_bg, buttons_bg); views.setTextColor(R.id.buttons_bg_clear, buttons_bg_color); views.setFloat(R.id.buttons_bg_clear, "setTextSize", buttons_textsize); views.setOnClickPendingIntent(R.id.button_post, PendingIntent.getActivity(SonetService.this, 0, Sonet.getPackageIntent(SonetService.this, SonetCreatePost.class) .setAction(LauncherIntent.Action.ACTION_VIEW_CLICK) .setData(Uri.withAppendedPath(Widgets.getContentUri(SonetService.this), widget)), 0)); views.setTextColor(R.id.button_post, buttons_color); views.setFloat(R.id.button_post, "setTextSize", buttons_textsize); views.setOnClickPendingIntent(R.id.button_configure, PendingIntent.getActivity(SonetService.this, 0, Sonet.getPackageIntent(SonetService.this, ManageAccounts.class).setAction(widget), 0)); views.setTextColor(R.id.button_configure, buttons_color); views.setFloat(R.id.button_configure, "setTextSize", buttons_textsize); views.setOnClickPendingIntent(R.id.button_refresh, PendingIntent.getService(SonetService.this, 0, Sonet.getPackageIntent(SonetService.this, SonetService.class).setAction(widget), 0)); views.setTextColor(R.id.button_refresh, buttons_color); views.setFloat(R.id.button_refresh, "setTextSize", buttons_textsize); views.setTextColor(R.id.page_up, buttons_color); views.setFloat(R.id.page_up, "setTextSize", buttons_textsize); views.setTextColor(R.id.page_down, buttons_color); views.setFloat(R.id.page_down, "setTextSize", buttons_textsize); } // set margin if (scrollable == 0) { final AppWidgetManager mgr = AppWidgetManager.getInstance(SonetService.this); // check if native scrolling is supported if (sNativeScrollingSupported) { // native scrolling try { final Intent intent = SonetRemoteViewsServiceWrapper.getRemoteAdapterIntent(SonetService.this); if (intent != null) { intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); intent.putExtra(Widgets.DISPLAY_PROFILE, display_profile); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); sSetRemoteAdapter.invoke(views, appWidgetId, R.id.messages, intent); // empty sSetEmptyView.invoke(views, R.id.messages, R.id.empty_messages); // onclick // Bind a click listener template for the contents of the message list final Intent onClickIntent = Sonet.getPackageIntent(SonetService.this, SonetWidget.class); onClickIntent.setAction(ACTION_ON_CLICK); onClickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); onClickIntent.setData(Uri.parse(onClickIntent.toUri(Intent.URI_INTENT_SCHEME))); final PendingIntent onClickPendingIntent = PendingIntent.getBroadcast(SonetService.this, 0, onClickIntent, PendingIntent.FLAG_UPDATE_CURRENT); sSetPendingIntentTemplate.invoke(views, R.id.messages, onClickPendingIntent); } else { // fallback on non-scrolling widget sNativeScrollingSupported = false; } } catch (NumberFormatException e) { Log.e(TAG, e.toString()); } catch (IllegalArgumentException e) { Log.e(TAG, e.toString()); } catch (IllegalAccessException e) { Log.e(TAG, e.toString()); } catch (InvocationTargetException e) { Log.e(TAG, e.toString()); } } if (!sNativeScrollingSupported) { Cursor statuses_styles = getContentResolver().query( Uri.withAppendedPath(Statuses_styles.getContentUri(SonetService.this), widget), new String[] { Statuses_styles._ID, Statuses_styles.FRIEND, Statuses_styles.PROFILE, Statuses_styles.MESSAGE, Statuses_styles.CREATEDTEXT, Statuses_styles.MESSAGES_COLOR, Statuses_styles.FRIEND_COLOR, Statuses_styles.CREATED_COLOR, Statuses_styles.MESSAGES_TEXTSIZE, Statuses_styles.FRIEND_TEXTSIZE, Statuses_styles.CREATED_TEXTSIZE, Statuses_styles.STATUS_BG, Statuses_styles.ICON, Statuses_styles.PROFILE_BG, Statuses_styles.FRIEND_BG, Statuses_styles.IMAGE_BG, Statuses_styles.IMAGE }, null, null, Statuses_styles.CREATED + " DESC LIMIT " + page + ",-1"); if (statuses_styles.moveToFirst()) { int count_status = 0; views.removeAllViews(R.id.messages); while (!statuses_styles.isAfterLast() && (count_status < 16)) { int friend_color = statuses_styles.getInt(6), created_color = statuses_styles.getInt(7), friend_textsize = statuses_styles.getInt(9), created_textsize = statuses_styles.getInt(10), messages_color = statuses_styles.getInt(5), messages_textsize = statuses_styles.getInt(8); // get the item wrapper RemoteViews itemView; if (display_profile) { itemView = new RemoteViews(getPackageName(), R.layout.widget_item); // set profiles background byte[] profile_bg = statuses_styles.getBlob(13); if (profile_bg != null) { Bitmap profile_bgbmp = BitmapFactory.decodeByteArray(profile_bg, 0, profile_bg.length, sBFOptions); if (profile_bgbmp != null) itemView.setImageViewBitmap(R.id.profile_bg, profile_bgbmp); } byte[] profile = statuses_styles.getBlob(2); if (profile != null) { Bitmap profilebmp = BitmapFactory.decodeByteArray(profile, 0, profile.length, sBFOptions); if (profilebmp != null) itemView.setImageViewBitmap(R.id.profile, profilebmp); } } else itemView = new RemoteViews(getPackageName(), R.layout.widget_item_noprofile); itemView.setTextViewText(R.id.friend_bg_clear, statuses_styles.getString(1)); itemView.setFloat(R.id.friend_bg_clear, "setTextSize", friend_textsize); itemView.setTextViewText(R.id.message_bg_clear, statuses_styles.getString(3)); itemView.setFloat(R.id.message_bg_clear, "setTextSize", messages_textsize); // set friends background byte[] friend_bg = statuses_styles.getBlob(14); if (friend_bg != null) { Bitmap friend_bgbmp = BitmapFactory.decodeByteArray(friend_bg, 0, friend_bg.length, sBFOptions); if (friend_bgbmp != null) itemView.setImageViewBitmap(R.id.friend_bg, friend_bgbmp); } // set messages background byte[] status_bg = statuses_styles.getBlob(11); if (status_bg != null) { Bitmap status_bgbmp = BitmapFactory.decodeByteArray(status_bg, 0, status_bg.length, sBFOptions); if (status_bgbmp != null) itemView.setImageViewBitmap(R.id.status_bg, status_bgbmp); } // set an image byte[] image_bg = statuses_styles.getBlob(15); byte[] image = statuses_styles.getBlob(16); if ((image_bg != null) && (image != null)) { Bitmap image_bgBmp = BitmapFactory.decodeByteArray(image_bg, 0, image_bg.length, sBFOptions); if (image_bgBmp != null) { Bitmap imageBmp = BitmapFactory.decodeByteArray(image, 0, image.length, sBFOptions); itemView.setImageViewBitmap(R.id.image_clear, image_bgBmp); itemView.setImageViewBitmap(R.id.image, imageBmp); } } itemView.setTextViewText(R.id.message, statuses_styles.getString(3)); itemView.setTextColor(R.id.message, messages_color); itemView.setFloat(R.id.message, "setTextSize", messages_textsize); itemView.setOnClickPendingIntent(R.id.item, PendingIntent.getActivity(SonetService.this, 0, Sonet.getPackageIntent(SonetService.this, StatusDialog.class) .setData(Uri.withAppendedPath( Statuses_styles.getContentUri(SonetService.this), Long.toString(statuses_styles.getLong(0)))), 0)); itemView.setTextViewText(R.id.friend, statuses_styles.getString(1)); itemView.setTextColor(R.id.friend, friend_color); itemView.setFloat(R.id.friend, "setTextSize", friend_textsize); itemView.setTextViewText(R.id.created, statuses_styles.getString(4)); itemView.setTextColor(R.id.created, created_color); itemView.setFloat(R.id.created, "setTextSize", created_textsize); // set icons byte[] icon = statuses_styles.getBlob(12); if (icon != null) { Bitmap iconbmp = BitmapFactory.decodeByteArray(icon, 0, icon.length, sBFOptions); if (iconbmp != null) itemView.setImageViewBitmap(R.id.icon, iconbmp); } views.addView(R.id.messages, itemView); count_status++; statuses_styles.moveToNext(); } if (hasbuttons && (page < statuses_styles.getCount())) { // there are more statuses to show, allow paging down views.setOnClickPendingIntent(R.id.page_down, PendingIntent.getService(SonetService.this, 0, Sonet.getPackageIntent(SonetService.this, SonetService.class) .setAction(ACTION_PAGE_DOWN) .setData(Uri.withAppendedPath(Widgets.getContentUri(SonetService.this), widget)) .putExtra(ACTION_PAGE_DOWN, page + 1), PendingIntent.FLAG_UPDATE_CURRENT)); } } statuses_styles.close(); if (hasbuttons && (page > 0)) views.setOnClickPendingIntent(R.id.page_up, PendingIntent.getService(SonetService.this, 0, Sonet.getPackageIntent(SonetService.this, SonetService.class).setAction(ACTION_PAGE_UP) .setData(Uri.withAppendedPath(Widgets.getContentUri(SonetService.this), widget)) .putExtra(ACTION_PAGE_UP, page - 1), PendingIntent.FLAG_UPDATE_CURRENT)); } Log.d(TAG, "update native widget: " + appWidgetId); mgr.updateAppWidget(appWidgetId, views); if (sNativeScrollingSupported) { Log.d(TAG, "trigger widget query: " + appWidgetId); try { // trigger query sNotifyAppWidgetViewDataChanged.invoke(mgr, appWidgetId, R.id.messages); } catch (NumberFormatException e) { Log.e(TAG, e.toString()); } catch (IllegalArgumentException e) { Log.e(TAG, e.toString()); } catch (IllegalAccessException e) { Log.e(TAG, e.toString()); } catch (InvocationTargetException e) { Log.e(TAG, e.toString()); } } } else if (updatesReady) { // Log.d(TAG, "notify updatesReady"); getContentResolver().notifyChange(Statuses_styles.getContentUri(SonetService.this), null); } else { AppWidgetManager.getInstance(SonetService.this).updateAppWidget(Integer.parseInt(widget), views); buildScrollableWidget(appWidgetId, scrollable, display_profile); } }
From source file:com.shafiq.myfeedle.core.MyfeedleService.java
private void buildWidgetButtons(Integer appWidgetId, boolean updatesReady, int page, boolean hasbuttons, int scrollable, int buttons_bg_color, int buttons_color, int buttons_textsize, boolean display_profile, int margin) { final String widget = Integer.toString(appWidgetId); // Push update for this widget to the home screen int layout;// w ww .j a v a 2 s . com if (hasbuttons) { if (sNativeScrollingSupported) { if (margin > 0) layout = R.layout.widget_margin_scrollable; else layout = R.layout.widget_scrollable; } else if (display_profile) { if (margin > 0) layout = R.layout.widget_margin; else layout = R.layout.widget; } else { if (margin > 0) layout = R.layout.widget_noprofile_margin; else layout = R.layout.widget_noprofile; } } else { if (sNativeScrollingSupported) { if (margin > 0) layout = R.layout.widget_nobuttons_margin_scrollable; else layout = R.layout.widget_nobuttons_scrollable; } else if (display_profile) { if (margin > 0) layout = R.layout.widget_nobuttons_margin; else layout = R.layout.widget_nobuttons; } else { if (margin > 0) layout = R.layout.widget_nobuttons_noprofile_margin; else layout = R.layout.widget_nobuttons_noprofile; } } // wrap RemoteViews for backward compatibility RemoteViews views = new RemoteViews(getPackageName(), layout); if (hasbuttons) { Bitmap buttons_bg = Bitmap.createBitmap(1, 1, Config.ARGB_8888); Canvas buttons_bg_canvas = new Canvas(buttons_bg); buttons_bg_canvas.drawColor(buttons_bg_color); views.setImageViewBitmap(R.id.buttons_bg, buttons_bg); views.setTextColor(R.id.buttons_bg_clear, buttons_bg_color); views.setFloat(R.id.buttons_bg_clear, "setTextSize", buttons_textsize); views.setOnClickPendingIntent(R.id.button_post, PendingIntent.getActivity(MyfeedleService.this, 0, Myfeedle.getPackageIntent(MyfeedleService.this, MyfeedleCreatePost.class) .setAction(LauncherIntent.Action.ACTION_VIEW_CLICK).setData(Uri .withAppendedPath(Widgets.getContentUri(MyfeedleService.this), widget)), 0)); views.setTextColor(R.id.button_post, buttons_color); views.setFloat(R.id.button_post, "setTextSize", buttons_textsize); views.setOnClickPendingIntent(R.id.button_configure, PendingIntent.getActivity(MyfeedleService.this, 0, Myfeedle.getPackageIntent(MyfeedleService.this, ManageAccounts.class).setAction(widget), 0)); views.setTextColor(R.id.button_configure, buttons_color); views.setFloat(R.id.button_configure, "setTextSize", buttons_textsize); views.setOnClickPendingIntent(R.id.button_refresh, PendingIntent.getService(MyfeedleService.this, 0, Myfeedle.getPackageIntent(MyfeedleService.this, MyfeedleService.class).setAction(widget), 0)); views.setTextColor(R.id.button_refresh, buttons_color); views.setFloat(R.id.button_refresh, "setTextSize", buttons_textsize); views.setTextColor(R.id.page_up, buttons_color); views.setFloat(R.id.page_up, "setTextSize", buttons_textsize); views.setTextColor(R.id.page_down, buttons_color); views.setFloat(R.id.page_down, "setTextSize", buttons_textsize); } // set margin if (scrollable == 0) { final AppWidgetManager mgr = AppWidgetManager.getInstance(MyfeedleService.this); // check if native scrolling is supported if (sNativeScrollingSupported) { // native scrolling try { final Intent intent = MyfeedleRemoteViewsServiceWrapper .getRemoteAdapterIntent(MyfeedleService.this); if (intent != null) { intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); intent.putExtra(Widgets.DISPLAY_PROFILE, display_profile); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); sSetRemoteAdapter.invoke(views, appWidgetId, R.id.messages, intent); // empty sSetEmptyView.invoke(views, R.id.messages, R.id.empty_messages); // onclick // Bind a click listener template for the contents of the message list final Intent onClickIntent = Myfeedle.getPackageIntent(MyfeedleService.this, MyfeedleWidget.class); onClickIntent.setAction(ACTION_ON_CLICK); onClickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); onClickIntent.setData(Uri.parse(onClickIntent.toUri(Intent.URI_INTENT_SCHEME))); final PendingIntent onClickPendingIntent = PendingIntent.getBroadcast(MyfeedleService.this, 0, onClickIntent, PendingIntent.FLAG_UPDATE_CURRENT); sSetPendingIntentTemplate.invoke(views, R.id.messages, onClickPendingIntent); } else { // fallback on non-scrolling widget sNativeScrollingSupported = false; } } catch (NumberFormatException e) { Log.e(TAG, e.toString()); } catch (IllegalArgumentException e) { Log.e(TAG, e.toString()); } catch (IllegalAccessException e) { Log.e(TAG, e.toString()); } catch (InvocationTargetException e) { Log.e(TAG, e.toString()); } } if (!sNativeScrollingSupported) { Cursor statuses_styles = getContentResolver().query( Uri.withAppendedPath(Statuses_styles.getContentUri(MyfeedleService.this), widget), new String[] { Statuses_styles._ID, Statuses_styles.FRIEND, Statuses_styles.PROFILE, Statuses_styles.MESSAGE, Statuses_styles.CREATEDTEXT, Statuses_styles.MESSAGES_COLOR, Statuses_styles.FRIEND_COLOR, Statuses_styles.CREATED_COLOR, Statuses_styles.MESSAGES_TEXTSIZE, Statuses_styles.FRIEND_TEXTSIZE, Statuses_styles.CREATED_TEXTSIZE, Statuses_styles.STATUS_BG, Statuses_styles.ICON, Statuses_styles.PROFILE_BG, Statuses_styles.FRIEND_BG, Statuses_styles.IMAGE_BG, Statuses_styles.IMAGE }, null, null, Statuses_styles.CREATED + " DESC LIMIT " + page + ",-1"); if (statuses_styles.moveToFirst()) { int count_status = 0; views.removeAllViews(R.id.messages); while (!statuses_styles.isAfterLast() && (count_status < 16)) { int friend_color = statuses_styles.getInt(6), created_color = statuses_styles.getInt(7), friend_textsize = statuses_styles.getInt(9), created_textsize = statuses_styles.getInt(10), messages_color = statuses_styles.getInt(5), messages_textsize = statuses_styles.getInt(8); // get the item wrapper RemoteViews itemView; if (display_profile) { itemView = new RemoteViews(getPackageName(), R.layout.widget_item); // set profiles background byte[] profile_bg = statuses_styles.getBlob(13); if (profile_bg != null) { Bitmap profile_bgbmp = BitmapFactory.decodeByteArray(profile_bg, 0, profile_bg.length, sBFOptions); if (profile_bgbmp != null) itemView.setImageViewBitmap(R.id.profile_bg, profile_bgbmp); } byte[] profile = statuses_styles.getBlob(2); if (profile != null) { Bitmap profilebmp = BitmapFactory.decodeByteArray(profile, 0, profile.length, sBFOptions); if (profilebmp != null) itemView.setImageViewBitmap(R.id.profile, profilebmp); } } else itemView = new RemoteViews(getPackageName(), R.layout.widget_item_noprofile); itemView.setTextViewText(R.id.friend_bg_clear, statuses_styles.getString(1)); itemView.setFloat(R.id.friend_bg_clear, "setTextSize", friend_textsize); itemView.setTextViewText(R.id.message_bg_clear, statuses_styles.getString(3)); itemView.setFloat(R.id.message_bg_clear, "setTextSize", messages_textsize); // set friends background byte[] friend_bg = statuses_styles.getBlob(14); if (friend_bg != null) { Bitmap friend_bgbmp = BitmapFactory.decodeByteArray(friend_bg, 0, friend_bg.length, sBFOptions); if (friend_bgbmp != null) itemView.setImageViewBitmap(R.id.friend_bg, friend_bgbmp); } // set messages background byte[] status_bg = statuses_styles.getBlob(11); if (status_bg != null) { Bitmap status_bgbmp = BitmapFactory.decodeByteArray(status_bg, 0, status_bg.length, sBFOptions); if (status_bgbmp != null) itemView.setImageViewBitmap(R.id.status_bg, status_bgbmp); } // set an image byte[] image_bg = statuses_styles.getBlob(15); byte[] image = statuses_styles.getBlob(16); if ((image_bg != null) && (image != null)) { Bitmap image_bgBmp = BitmapFactory.decodeByteArray(image_bg, 0, image_bg.length, sBFOptions); if (image_bgBmp != null) { Bitmap imageBmp = BitmapFactory.decodeByteArray(image, 0, image.length, sBFOptions); itemView.setImageViewBitmap(R.id.image_clear, image_bgBmp); itemView.setImageViewBitmap(R.id.image, imageBmp); } } itemView.setTextViewText(R.id.message, statuses_styles.getString(3)); itemView.setTextColor(R.id.message, messages_color); itemView.setFloat(R.id.message, "setTextSize", messages_textsize); itemView.setOnClickPendingIntent(R.id.item, PendingIntent.getActivity(MyfeedleService.this, 0, Myfeedle.getPackageIntent(MyfeedleService.this, StatusDialog.class) .setData(Uri.withAppendedPath( Statuses_styles.getContentUri(MyfeedleService.this), Long.toString(statuses_styles.getLong(0)))), 0)); itemView.setTextViewText(R.id.friend, statuses_styles.getString(1)); itemView.setTextColor(R.id.friend, friend_color); itemView.setFloat(R.id.friend, "setTextSize", friend_textsize); itemView.setTextViewText(R.id.created, statuses_styles.getString(4)); itemView.setTextColor(R.id.created, created_color); itemView.setFloat(R.id.created, "setTextSize", created_textsize); // set icons byte[] icon = statuses_styles.getBlob(12); if (icon != null) { Bitmap iconbmp = BitmapFactory.decodeByteArray(icon, 0, icon.length, sBFOptions); if (iconbmp != null) itemView.setImageViewBitmap(R.id.icon, iconbmp); } views.addView(R.id.messages, itemView); count_status++; statuses_styles.moveToNext(); } if (hasbuttons && (page < statuses_styles.getCount())) { // there are more statuses to show, allow paging down views.setOnClickPendingIntent(R.id.page_down, PendingIntent.getService(MyfeedleService.this, 0, Myfeedle.getPackageIntent(MyfeedleService.this, MyfeedleService.class) .setAction(ACTION_PAGE_DOWN) .setData(Uri.withAppendedPath(Widgets.getContentUri(MyfeedleService.this), widget)) .putExtra(ACTION_PAGE_DOWN, page + 1), PendingIntent.FLAG_UPDATE_CURRENT)); } } statuses_styles.close(); if (hasbuttons && (page > 0)) views.setOnClickPendingIntent(R.id.page_up, PendingIntent.getService(MyfeedleService.this, 0, Myfeedle.getPackageIntent(MyfeedleService.this, MyfeedleService.class) .setAction(ACTION_PAGE_UP) .setData(Uri.withAppendedPath(Widgets.getContentUri(MyfeedleService.this), widget)) .putExtra(ACTION_PAGE_UP, page - 1), PendingIntent.FLAG_UPDATE_CURRENT)); } Log.d(TAG, "update native widget: " + appWidgetId); mgr.updateAppWidget(appWidgetId, views); if (sNativeScrollingSupported) { Log.d(TAG, "trigger widget query: " + appWidgetId); try { // trigger query sNotifyAppWidgetViewDataChanged.invoke(mgr, appWidgetId, R.id.messages); } catch (NumberFormatException e) { Log.e(TAG, e.toString()); } catch (IllegalArgumentException e) { Log.e(TAG, e.toString()); } catch (IllegalAccessException e) { Log.e(TAG, e.toString()); } catch (InvocationTargetException e) { Log.e(TAG, e.toString()); } } } else if (updatesReady) { // Log.d(TAG, "notify updatesReady"); getContentResolver().notifyChange(Statuses_styles.getContentUri(MyfeedleService.this), null); } else { AppWidgetManager.getInstance(MyfeedleService.this).updateAppWidget(Integer.parseInt(widget), views); buildScrollableWidget(appWidgetId, scrollable, display_profile); } }
From source file:org.etudes.jforum.view.forum.PostAction.java
/** * save the post/* w w w . j a v a 2 s . c o m*/ * * @throws Exception */ public void insertSave() throws Exception { if (logger.isDebugEnabled()) logger.debug("starting insertSave()"); int forumId = this.request.getIntParameter("forum_id"); try { boolean facilitator = JForumUserUtil.isJForumFacilitator(UserDirectoryService.getCurrentUser().getId()); boolean participant = JForumUserUtil.isJForumParticipant(UserDirectoryService.getCurrentUser().getId()); if (!(facilitator || participant)) { this.context.put("errorMessage", I18n.getMessage("User.NotAuthorized")); this.setTemplateName(TemplateKeys.USER_NOT_AUTHORIZED); return; } JForumForumService jforumForumService = (JForumForumService) ComponentManager .get("org.etudes.api.app.jforum.JForumForumService"); org.etudes.api.app.jforum.Forum forum = null; try { forum = jforumForumService.getForum(forumId, UserDirectoryService.getCurrentUser().getId()); } catch (JForumAccessException e) { this.context.put("errorMessage", I18n.getMessage("User.NotAuthorized")); this.setTemplateName(TemplateKeys.USER_NOT_AUTHORIZED); return; } JForumPostService jforumPostService = (JForumPostService) ComponentManager .get("org.etudes.api.app.jforum.JForumPostService"); if (this.request.getParameter("topic_id") != null) { int topicId = Integer.parseInt(this.request.getParameter("topic_id")); // posting reply org.etudes.api.app.jforum.Topic topic = jforumPostService.getTopic(topicId); JForumUserService jforumUserService = (JForumUserService) ComponentManager .get("org.etudes.api.app.jforum.JForumUserService"); org.etudes.api.app.jforum.User postedBy = jforumUserService .getBySakaiUserId(SessionFacade.getUserSession().getSakaiUserId()); topic.setPostedBy(postedBy); org.etudes.api.app.jforum.Post post = jforumPostService.newPost(); fillPost(post, false); if (post.getSubject() == null || post.getSubject().trim() == "") { post.setSubject(topic.getTitle()); } processPostAttachments(jforumPostService, post); topic.getPosts().clear(); topic.getPosts().add(post); try { jforumPostService.createPost(topic); } catch (JForumAccessException e) { this.context.put("errorMessage", I18n.getMessage("User.NotAuthorized")); this.setTemplateName(TemplateKeys.USER_NOT_AUTHORIZED); return; } catch (JForumAttachmentOverQuotaException e) { JForum.enableCancelCommit(); this.request.addParameter("topic_id", this.request.getParameter("topic_id")); this.context.put("errorMessage", e.getMessage()); this.context.put("post", post); this.insert(); return; } catch (JForumAttachmentBadExtensionException e) { JForum.enableCancelCommit(); this.request.addParameter("topic_id", this.request.getParameter("topic_id")); this.context.put("errorMessage", e.getMessage()); this.context.put("post", post); this.insert(); return; } // Topic watch if (this.request.getParameter("notify") != null) { jforumPostService.subscribeUserToTopic(topic.getId(), post.getPostedBy().getSakaiUserId()); } String path = this.request.getContextPath() + "/posts/list/"; int start = ViewCommon.getStartPage(); path += this.startPage(topic, start) + "/"; path += topic.getId() + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION) + "#" + post.getId(); JForum.setRedirect(path); //this.response.setIntHeader("X-XSS-Protection", 0); } else { // creating new topic //topic type, forum id, title(subject), dates, postedBy if topic is gradable grade information. org.etudes.api.app.jforum.Topic topic = jforumPostService.newTopic(); if (this.request.getParameter("topic_type") != null) { topic.setType(this.request.getIntParameter("topic_type")); } topic.setForumId(forumId); topic.setTitle(this.request.getParameter("subject")); // topic - mark for export if (this.request.getParameter("topic_export") != null) { topic.setExportTopic(true); } else { topic.setExportTopic(false); } String startDateParam = this.request.getParameter("start_date"); // dates if (startDateParam != null && startDateParam.trim().length() > 0) { Date startDate = null; try { startDate = DateUtil.getDateFromString(startDateParam.trim()); } catch (ParseException e) { if (logger.isErrorEnabled()) { logger.error(e, e); } } topic.getAccessDates().setOpenDate(startDate); String hideUntilOpen = this.request.getParameter("hide_until_open"); if (hideUntilOpen != null && "1".equals(hideUntilOpen)) { topic.getAccessDates().setHideUntilOpen(Boolean.TRUE); } else { topic.getAccessDates().setHideUntilOpen(Boolean.FALSE); } } else { topic.getAccessDates().setOpenDate(null); topic.getAccessDates().setHideUntilOpen(Boolean.FALSE); } // due date String endDateParam = this.request.getParameter("end_date"); if (endDateParam != null && endDateParam.trim().length() > 0) { Date endDate = null; try { endDate = DateUtil.getDateFromString(endDateParam.trim()); } catch (ParseException e) { if (logger.isErrorEnabled()) { logger.error(e, e); } } topic.getAccessDates().setDueDate(endDate); } else { topic.getAccessDates().setDueDate(null); } // allow until String allowUntilDateParam = this.request.getParameter("allow_until_date"); if (allowUntilDateParam != null && allowUntilDateParam.trim().length() > 0) { Date allowUntilDate = null; try { allowUntilDate = DateUtil.getDateFromString(allowUntilDateParam.trim()); } catch (ParseException e) { if (logger.isErrorEnabled()) { logger.error(e, e); } } topic.getAccessDates().setAllowUntilDate(allowUntilDate); } else { topic.getAccessDates().setAllowUntilDate(null); } //grade topic if (facilitator && this.request.getParameter("grade_topic") != null) { org.etudes.api.app.jforum.Grade grade = topic.getGrade(); if (this.request.getIntParameter("grade_topic") == Topic.GRADE_NO) { topic.setGradeTopic(false); } else if (this.request.getIntParameter("grade_topic") == Topic.GRADE_YES) { topic.setGradeTopic(true); } try { Float points = Float.parseFloat(this.request.getParameter("point_value")); if (points.floatValue() < 0) points = Float.valueOf(0.0f); if (points.floatValue() > 1000) points = Float.valueOf(1000.0f); points = Float.valueOf(((float) Math.round(points.floatValue() * 100.0f)) / 100.0f); grade.setPoints(points); } catch (NumberFormatException ne) { grade.setPoints(0f); if (logger.isWarnEnabled()) { logger.warn(ne.toString(), ne); } } String minPostsRequired = this.request.getParameter("min_posts_required"); if ((minPostsRequired != null) && ("1".equals(minPostsRequired))) { grade.setMinimumPostsRequired(true); try { int minimumPosts = this.request.getIntParameter("min_posts"); grade.setMinimumPosts(minimumPosts); } catch (NumberFormatException e) { if (logger.isWarnEnabled()) { logger.warn(e.toString(), e); } } } String sendToGradebook = this.request.getParameter("send_to_grade_book"); boolean addToGradeBook = false; if ((sendToGradebook != null) && (Integer.parseInt(sendToGradebook) == 1)) { addToGradeBook = true; } grade.setAddToGradeBook(addToGradeBook); } JForumUserService jforumUserService = (JForumUserService) ComponentManager .get("org.etudes.api.app.jforum.JForumUserService"); org.etudes.api.app.jforum.User postedBy = jforumUserService .getBySakaiUserId(SessionFacade.getUserSession().getSakaiUserId()); topic.setPostedBy(postedBy); org.etudes.api.app.jforum.Post post = jforumPostService.newPost(); fillPost(post, false); processPostAttachments(jforumPostService, post); topic.getPosts().add(post); try { jforumPostService.createTopicWithAttachments(topic); } catch (JForumAccessException e) { this.context.put("errorMessage", I18n.getMessage("User.NotAuthorized")); this.setTemplateName(TemplateKeys.USER_NOT_AUTHORIZED); return; } catch (JForumAttachmentOverQuotaException e) { JForum.enableCancelCommit(); this.context.put("errorMessage", e.getMessage()); this.context.put("post", post); this.insert(); return; } catch (JForumAttachmentBadExtensionException e) { JForum.enableCancelCommit(); this.context.put("errorMessage", e.getMessage()); this.context.put("post", post); this.insert(); return; } // Topic watch if (this.request.getParameter("notify") != null) { jforumPostService.subscribeUserToTopic(topic.getId(), post.getPostedBy().getSakaiUserId()); } if (facilitator) { org.etudes.api.app.jforum.Post newPost = jforumPostService.getPost(post.getId()); org.etudes.api.app.jforum.Topic newTopic = null; newTopic = newPost.getTopic(); if (newTopic.isGradeTopic() && newTopic.getFirstPostId() == post.getId()) { String sendToGradebook = this.request.getParameter("send_to_grade_book"); boolean addToGradeBook = false; if ((sendToGradebook != null) && (Integer.parseInt(sendToGradebook) == 1)) { addToGradeBook = true; } if (addToGradeBook) { if (newTopic.isGradeTopic() && !newTopic.getGrade().isAddToGradeBook()) { if (newTopic.getGrade().getPoints() <= 0) { this.context.put("errorMessage", I18n.getMessage( "Grade.AddEditTopicGradeBookAssignmentHasIllegalPointsException")); } else { this.context.put("errorMessage", I18n.getMessage( "Grade.AddEditTopicGradeBookConflictingAssignmentNameException")); } this.request.addParameter("post_id", String.valueOf(post.getId())); this.request.addParameter("start", "0"); this.edit(); return; } } } } String path = this.request.getContextPath() + "/posts/list/"; path += topic.getId() + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION); JForum.setRedirect(path); } } catch (Exception e) { if (logger.isErrorEnabled()) { logger.error(e.toString(), e); } throw e; /*String path = this.request.getContextPath() +"/forums/show/"+ forumId + SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION); JForum.setRedirect(path);*/ } }
From source file:ukhas.Habitat_interface.java
private boolean getPayloadDataSince(long timestampStart, long timestampStop, int limit, String payloadID, String callsign) {//from w ww . j a v a2s .c o m double prevAltitude = -99999999; double maxAltitude = -99999999; long prevtime = -1; try { //open DB connection if (s == null) { s = new Session(_habitat_url, 80); db = s.getDatabase(_habitat_db);// + "/_design/payload_telemetry/_update/add_listener"); } else if (db == null) db = s.getDatabase(_habitat_db); View v = new View("payload_telemetry/payload_time"); long starttime; if (timestampStart > 0) starttime = timestampStart; else starttime = (System.currentTimeMillis() / 1000L) - _prev_query_time; v.setStartKey("[%22" + payloadID + "%22," + Long.toString(starttime) + "]"); v.setEndKey("[%22" + payloadID + "%22," + Long.toString(timestampStop) + "]"); v.setWithDocs(true); v.setLimit(limit); System.out.println("DEBUG: DATABASE GOT QUERY"); TreeMap<Long, Telemetry_string> out = new TreeMap<Long, Telemetry_string>(); JsonFactory fac = new JsonFactory(); InputStream is = db.view_dont_parse(v); long lasttime = 0; if (is != null) { JsonParser jp = fac.createJsonParser(is); String str, str1; boolean gotkey = false; boolean keypt1 = false; TelemetryConfig tc = null; if (telem_configs.containsKey(callsign)) { tc = telem_configs.get(callsign); } while (jp.nextToken() != null)// || (jp.getCurrentLocation().getCharOffset() < body.length()-50)) && nullcount < 20) //100000 > out.size()) { //jp.nextToken(); str = jp.getCurrentName(); str1 = jp.getText(); if (str == "key" && str1 == "[") gotkey = true; else if (gotkey) { keypt1 = true; gotkey = false; } else if (keypt1) { keypt1 = false; try { lasttime = Long.parseLong(str1); } catch (NumberFormatException e) { System.out.println("ERROR PARSING - NUMBER FORMAT EXCEPTION!!!"); } } if (str != null && str1 != null) { if (str.equals("_sentence") && !str1.equals("_sentence")) { Telemetry_string ts = new Telemetry_string(str1, lasttime, tc); if (!ts.isZeroGPS() && ts.time != null) { if (out.size() > 0) { if (out.lastEntry().getValue().coords.alt_valid) { prevAltitude = out.lastEntry().getValue().coords.altitude; prevtime = out.lastEntry().getValue().time.getTime(); } } out.put(new Long(ts.time.getTime()), ts); if (ts.coords.alt_valid) maxAltitude = Math.max(ts.coords.altitude, maxAltitude); } } //nullcount = 0; } //else // nullcount++; } jp.close(); is.close(); } s.clearCouchResponse(); System.out.println("DEBUG: DATABASE PROCESSING DONE"); AscentRate as = new AscentRate(); if (out.size() >= 2 && prevAltitude > -9999) { as = new AscentRate(); as.addData(prevtime, prevAltitude); if (out.lastEntry().getValue().coords.alt_valid) { as.addData(out.lastEntry().getValue().time.getTime(), out.lastEntry().getValue().coords.altitude); } else as = new AscentRate(); } lasttime += 1000; if (lasttime >= timestampStart && lasttime <= timestampStop) fireDataReceived(out, true, callsign, timestampStart, lasttime, as, maxAltitude); else fireDataReceived(out, true, callsign, timestampStart, timestampStop, as, maxAltitude); return true; } catch (Exception e) { fireDataReceived(null, false, e.toString(), timestampStart, timestampStop, null, -99999999); return false; } }