public String processListCommand() { String result = new String(); StringBuffer stb = new StringBuffer(); stb.append("<surveys>\n"); try { ArrayList<SurveyVO> listOfSurveys = (ArrayList<SurveyVO>) mb.listSurveysByImeiDB(imei, TransactionLogVO.STATUS_AVAILABLE); for (Iterator iterator = listOfSurveys.iterator(); iterator.hasNext(); ) { SurveyVO surveyVO = (SurveyVO) iterator.next(); String linha = "<survey id=\"" + surveyVO.getIdSurvey() + "\"" + " title=\"" + surveyVO.getTitle() + "\"/>"; stb.append(linha + "\n"); } stb.append("</surveys>"); result = stb.toString(); } catch (MSMApplicationException e) { e.printStackTrace(); } catch (MSMSystemException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return result; }
public String processDownloadCommand() { StringBuffer result = new StringBuffer(); try { for (Iterator iterator = mb.listSurveysByImeiDB(imei, TransactionLogVO.STATUS_AVAILABLE).iterator(); iterator.hasNext(); ) { NdgUser userlogged = mb.getUserByImei(imei); if (userlogged != null) { SurveyVO surveyVO = (SurveyVO) iterator.next(); StringBuffer currentResult = new StringBuffer(surveyVO.getSurvey()); // we need to remove last '\n' if (currentResult.charAt(currentResult.toString().length() - 1) == '\n') { currentResult.deleteCharAt(currentResult.toString().length() - 1); } result.append(currentResult); } else { new UserNotFoundException(); } } } catch (MSMApplicationException e) { e.printStackTrace(); } catch (MSMSystemException e) { e.printStackTrace(); } return new String(result); }