// this action listener will be started whenever galaxy tries to "get data" from web cellhts22 public Object onQueryTool() { String galaxyURL = request.getParameter(PARAM_NAME); // the url of the galaxy webcellhts2 callback URL will be stored GLOBALLY so all // pages/components can access it galaxyURLState = galaxyURL; return cellHTS2Page; }
public void initializeWithUrlParameters( Request request, ReferenceService referenceService, Population population) { String originTitle = request.getParameter("origin"); String platformName = request.getParameter("platform"); String type = request.getParameter("type"); String publisherName = request.getParameter("publisher"); String userName = request.getParameter("user"); if (originTitle != null || platformName != null || type != null || publisherName != null) { clear(); } if (originTitle != null) { Origin origin = referenceService.findOriginByTitle(originTitle); if (origin != null) { filterByOrigin(origin); } } if (platformName != null) { Platform platform = referenceService.findPlatformByName(platformName); if (platform != null) { filterByPlatform(platform); } } if (publisherName != null) { Publisher publisher = referenceService.findPublisherByName(publisherName); if (publisher != null) { filterByPublisher(publisher); } } if (userName != null) { User user = population.findByLogin(userName); if (user != null) { filterByUser(user); } } if (type != null) { if ("hardwares".equals(type)) { filterByHardwares(); } else if ("accessories".equals(type)) { filterByAccessories(); } else { filterByGames(); } } }
private void updateClientTimeZone(String elementName) { if (timeZone != TimeZoneVisibility.SELECT) return; String id = request.getParameter(elementName + "$timezone"); TimeZone tz = TimeZone.getTimeZone(id); timeZoneTracker.setClientTimeZone(tz); }
Object onActivate() { String ret = ""; String serviceType = request.getParameter("serviceType"); String param = request.getParameter("optionValue"); String type = ""; try { if ("getCities".equalsIgnoreCase(serviceType)) { ret = getAddressUtils().getCitiesByProvince(param); type = messages.get("chooseCity"); } if ("getCounties".equalsIgnoreCase(serviceType)) { ret = getAddressUtils().getCountiesByCity(param); type = messages.get("chooseCounty"); } } catch (Exception e) { e.printStackTrace(); } return new TextStreamResponse("text/plain", getStringWithLabels(ret, type)); }
void onValidateCreditCardNumber() { String creditCardNumber = request.getParameter("param"); if (creditCardNumber == null) { creditCardMsg = "Value is required"; } else if (creditCardNumber.length() != 16) { creditCardMsg = "Credit card number must 16 digits long"; } else { creditCardMsg = ""; } if (request.isXHR()) { ajaxResponseRenderer.addRender("creditCardMsgZone", creditCardMsgZone); } }
void onValidateCreditCardName() { String creditCardName = request.getParameter("param"); if (creditCardName == null) { creditCardNameMsg = "Value is required"; } else if (creditCardName.length() < 3) { creditCardNameMsg = "Value is required"; } else { creditCardNameMsg = ""; } if (request.isXHR()) { ajaxResponseRenderer.addRender("creditCardNameMsgZone", creditCardNameMsgZone); } }
@OnEvent(value = "MyCustomEventName") JSONArray myEventHandler() { // check if this is a AJAX request if (request.isXHR()) { String queryParameter1 = request.getParameter("queryParameter1"); String queryParameter2 = request.getParameter("queryParameter2"); JSONArray object = new JSONArray(); object.put(1, "\n" + queryParameter1.toUpperCase()); object.put(2, "\n" + queryParameter2.toUpperCase()); object.put(3, getMessage()); // Make your real payload return object; } return null; }
// xmlshowevents/keywords=a+asdf+adf+asd void onActivate() { String keyWords = request.getParameter("keywords"); try { totalNumber = betService.getNumberOfEvents(keyWords, null); } catch (InstanceNotFoundException e) { // Never, category null return; } try { events = betService.findEvents(keyWords, null, 0, totalNumber); } catch (InstanceNotFoundException e) { // Never, category null } }
@Override protected void processSubmission(String elementName) { String value = request.getParameter(elementName); tracker.recordInput(this, value); updateClientTimeZone(elementName); Date parsedValue = null; try { if (InternalUtils.isNonBlank(value)) { // Regardless of the timeZone set on the DateFormat, the value is parsed in // the current default TimeZone. Use the calendar to adjust it out. Date inDefaultTimeZone = format.parse(value); parsedValue = convertDateToClientTimeZone(inDefaultTimeZone); } } catch (ParseException ex) { tracker.recordError(this, messages.format("tapx-date-value-not-parseable", value)); return; } try { fieldValidationSupport.validate(parsedValue, resources, validate); } catch (ValidationException ex) { tracker.recordError(this, ex.getMessage()); return; } if (min != null && parsedValue.before(min)) { tracker.recordError(this, messages.get("tapx-date-value-to-early")); return; } if (max != null && parsedValue.after(max)) { tracker.recordError(this, messages.get("tapx-date-value-too-late")); return; } this.value = parsedValue; }
@SuppressWarnings({"unchecked"}) @Override protected void processSubmission(String controlName) { String submittedValue = request.getParameter(controlName); tracker.recordInput(this, submittedValue); Object selectedValue = toValue(submittedValue); putPropertyNameIntoBeanValidationContext("value"); try { fieldValidationSupport.validate(selectedValue, resources, validate); value = selectedValue; } catch (ValidationException ex) { tracker.recordError(this, ex.getMessage()); } removePropertyNameFromBeanValidationContext(); }
private Double getDouble(String name) { String value = request.getParameter(name); return InternalUtils.isBlank(value) ? null : new Double(value); }
/** * Given the provided resource, test whether SSO should be 'aware' of this resource. 'Aware' * resources are valid return return points after SSO redirects, so the test should return false * on (for examples) static resources and utilities such as atom feeds. * * @param session : The session for this request * @param resource : The name of the resource being accessed * @param uri : The full URI of the resource if simple matches fail * @return boolean : True if SSO should be evaluated, False otherwise */ @Override public boolean testForSso(JsonSessionState session, String resource, String uri) { // The URL parameters can request forced SSO to this URL String ssoId = request.getParameter("ssoId"); if (ssoId != null) { return true; } // The URL parameters can contain a trust token String utoken = request.getParameter("token"); String stoken = (String) session.get("validToken"); if (utoken != null || stoken != null) { return true; } // Test for resources that start with unwanted values for (String test : excStarts) { if (resource.startsWith(test)) { return false; } } // Test for resources that end with unwanted values for (String test : excEnds) { if (resource.endsWith(test)) { return false; } } // Test for resources that equal unwanted values for (String test : excEquals) { if (resource.equals(test)) { return false; } } // Detail screen - specific payload target // This is an edge case, where the payload was a deep link, // it's not a subpage we can ignore String returnAddress = (String) session.get("returnAddress"); if (returnAddress != null && returnAddress.endsWith(uri)) { return true; } // The detail screen generates a lot of background calls to the server if (resource.equals("detail") || resource.equals("download") || resource.equals("preview")) { // Now check for the core page if (resource.equals("detail")) { if (detailPattern == null) { detailPattern = Pattern.compile("detail/\\w+/*$"); } Matcher matcher = detailPattern.matcher(uri); if (matcher.find()) { // This is actually the 'core' detail page return true; } } // This is just a subpage return false; } // Every other page return true; }
/** * Initialize the SSO Service, prepare a login if required * * @param session The server session data * @throws Exception if any errors occur */ @Override public String ssoInit(JsonSessionState session) throws Exception { // Keep track of the user switching portals for // link building in other methods String portalId = (String) session.get("portalId", defaultPortal); ssoLoginUrl = serverUrlBase + portalId + SSO_LOGIN_PAGE; // Find out what page we are on String path = request.getAttribute("RequestURI").toString(); String currentAddress = serverUrlBase + path; // Store the portal URL, might be required by implementers to build // an interface (images etc). session.set("ssoPortalUrl", serverUrlBase + portalId); // Makes sure all SSO plugins get initialised for (String ssoId : sso.keySet()) { sso.get(ssoId).ssoInit(session, rg.getHTTPServletRequest()); } // Are we logging in right now? String ssoId = request.getParameter("ssoId"); // If this isn't the login page... if (!currentAddress.contains(SSO_LOGIN_PAGE)) { // Store the current address for use later session.set("returnAddress", currentAddress); // We might still be logging in from a deep link if (ssoId == null) { // No we're not, finished now return null; } else { // Yes it's a deep link, store any extra query params // since they probably won't survive the round-trip // through SSO. for (String param : request.getParameterNames()) { if (!param.equals("ssoId")) { // Store all the other parameters session.set(SSO_STORAGE_PREFIX + param, request.getParameter(param)); } } } } // Get the last address to return the user to String returnAddress = (String) session.get("returnAddress"); if (returnAddress == null) { // Or use the home page returnAddress = serverUrlBase + portalId + "/home"; } // Which SSO provider did the user request? if (ssoId == null) { log.error("==== SSO: SSO ID not found!"); return null; } if (!sso.containsKey(ssoId)) { log.error("==== SSO: SSO ID invalid: '{}'!", ssoId); return null; } // The main event... finally sso.get(ssoId).ssoPrepareLogin(session, returnAddress, serverUrlBase); return ssoId; }
/** * Wrapper method for other SSO methods provided by the security manager. If desired, the security * manager can take care of the integration using the default usage pattern, rather then calling * them individually. * * @param session : The session of the current request * @param formData : FormData object for the current request * @return boolean : True if SSO has redirected, in which case no response should be sent by * Dispatch, otherwise False. */ @Override public boolean runSsoIntegration(JsonSessionState session, FormData formData) { this.formData = formData; // Used in integrating with thrid party systems. They can send us a // user, we will log them in via a SSO round-trip, then send them back // to the external system String returnUrl = request.getParameter("returnUrl"); if (returnUrl != null) { log.info("External redirect requested: '{}'", returnUrl); session.set("ssoReturnUrl", returnUrl); } // The URL parameters can contain a trust token String utoken = request.getParameter("token"); String stoken = (String) session.get("validToken"); String token = null; // Or an 'old' token still in the session if (stoken != null) { token = stoken; } // But give the URL priority if (utoken != null) { token = utoken; } if (token != null) { // Valid token if (this.testTrustToken(session, token)) { // Dispatch can continue return false; } // Invalid token // Given that trust tokens are designed for system integration // we are going to fail with a non-branded error message try { response.sendError(HttpServletResponse.SC_FORBIDDEN, "Invalid or expired security token!"); } catch (IOException ex) { log.error("Error sending 403 response to client!"); } // We don't want Dispatch to send a response return true; } // Single Sign-On integration try { // Instantiate with access to the session String ssoId = this.ssoInit(session); if (ssoId != null) { // We are logging in, so send them to the SSO portal String ssoUrl = this.ssoGetRemoteLogonURL(session, ssoId); if (ssoUrl != null) { response.sendRedirect(ssoUrl); return true; } } else { // Otherwise, check if we have user's details boolean valid = this.ssoCheckUserDetails(session); // If we validly logged in an SSO user, check for an // external redirect to third party systems if (valid) { returnUrl = (String) session.get("ssoReturnUrl"); if (returnUrl != null) { log.info("Redirect to external URL: '{}'", returnUrl); session.remove("ssoReturnUrl"); response.sendRedirect(returnUrl); return true; } } } } catch (Exception ex) { log.error("SSO Error!", ex); } return false; }
/** * Ajax event handler, form client side to get the data to display to parse it according to the * server-side format. see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data for * more details */ @OnEvent(value = "Data") JSONObject onData() { String page = request.getParameter(PAGE); int requestedPageNumber = Integer.parseInt(page); String search = request.getParameter(SEARCH); String searchField = request.getParameter(SEARCH_FIELD); String searchString = request.getParameter(SEARCH_STRING); String searchOper = request.getParameter(SEARCH_OPER); // searchField=tax&searchString=100&searchOper=gt if (search.equals("false")) source.resetFilter(); else if (searchField != null && searchOper != null && searchString != null) { SearchOperator op = SearchOperator.valueOf(searchOper); Class searchType = getDataModel().get(searchField).getConduit().getPropertyType(); Object searchValue = typeCoercer.coerce(searchString, searchType); SearchConstraint searchFor = new SearchConstraint( searchField, op, searchValue, getDataModel().get(searchField).getConduit()); List<SearchConstraint> lst = new ArrayList(); lst.add(searchFor); source.setFilter(lst); } String nd = request.getParameter(ND); String rowsSelected = request.getParameter(ROWS); int rowsPerPage = Integer.parseInt(rowsSelected); String sidx = request.getParameter(SIDX); String arrayString[] = sidx.split("\\s+"); // get only the start sidx = arrayString[0]; String sord = request.getParameter(SORD); JSONObject response = new JSONObject(); int records = source.getAvailableRows(); int nbPages = records / rowsPerPage; int modulo = records % rowsPerPage; if (modulo > 0) nbPages++; int startIndex = 0 + (requestedPageNumber - 1) * rowsPerPage; int endIndex = startIndex + rowsPerPage - 1; if (endIndex > records - 1) endIndex = records - 1; response.put("page", requestedPageNumber); response.put("total", nbPages); response.put("records", records); List<SortConstraint> sortConstraints = new ArrayList(); if (!sidx.isEmpty()) { GridSortModel sortModel = getSortModel(); ColumnSort colSort = sortModel.getColumnSort(sidx); if (sord.equals("asc")) setSortAscending(true); else setSortAscending(false); sortModel.updateSort(sidx); sortConstraints = sortModel.getSortConstraints(); } source.prepare(startIndex, endIndex, sortConstraints); JSONArray rows = new JSONArray(); for (int index = startIndex; index <= endIndex; index++) { JSONObject row = new JSONObject(); row.put("id", index); JSONArray cell = new JSONArray(); // Class c = dataSource.getRowType(); Object obj = source.getRowValue(index); List<String> names = getDataModel().getPropertyNames(); for (String name : names) { PropertyConduit conduit = getDataModel().get(name).getConduit(); Class type = conduit.getPropertyType(); // Block displayBlock = // defaultBeanBlockSource.getDisplayBlock(getDataModel().get(name).getDataType()); try { String cellValue; Object val = conduit.get(obj); // todo use BeanBlockSource or ... if (type.equals(Date.class)) { // mimic PropertyDisplayBlock Date cellDate = (Date) val; DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale); cellValue = dateFormat.format(cellDate); } else if (type.equals(Enum.class)) { cellValue = TapestryInternalUtils.getLabelForEnum(overrides.getOverrideMessages(), (Enum) val); } else { if (val == null) cellValue = "undefined " + name; else cellValue = typeCoercer.coerce(val, String.class); // ValueEncoder valueEncoder =encoderSource.getValueEncoder(type); // cellValue = valueEncoder.toClient(val); } cell.put(cellValue); } catch (NullPointerException ex) { cell.put("undefined " + name); } } row.put("cell", cell); rows.put(row); } response.put("rows", rows); // {"page":"1","total":2,"records":"13", // "rows":[{"id":"13","cell":["13","2007-10-06","Client 3","1000.00","0.00","1000.00",null]}, // {"id":"12","cell":["12","2007-10-06","Client 2","700.00","140.00","840.00",null]}, // {"id":"11","cell":["11","2007-10-06","Client 1","600.00","120.00","720.00",null]}, // {"id":"10","cell":["10","2007-10-06","Client 2","100.00","20.00","120.00",null]}, // {"id":"9","cell":["9","2007-10-06","Client 1","200.00","40.00","240.00",null]}, // {"id":"8","cell":["8","2007-10-06","Client 3","200.00","0.00","200.00",null]}, // {"id":"7","cell":["7","2007-10-05","Client 2","120.00","12.00","134.00",null]}, // {"id":"6","cell":["6","2007-10-05","Client 1","50.00","10.00","60.00",""]}, // {"id":"5","cell":["5","2007-10-05","Client 3","100.00","0.00","100.00","no tax at // all"]}, /// {"id":"4","cell":["4","2007-10-04","Client 3","150.00","0.00","150.00","no tax"]}], JSONObject userdata = new JSONObject(); response.put("userdata", userdata); // "userdata":{"amount":3220,"tax":342,"total":3564,"name":"Totals:"}} return response; }