List of usage examples for org.apache.commons.lang3.text StrTokenizer hasNext
@Override public boolean hasNext()
From source file:me.ineson.demo.service.utils.RestUtils.java
/** * @param where/* w ww .j av a2 s. c o m*/ * @param root * @param query * @param builder * @param translations * @return */ public static Predicate parseWhereClause(String where, Root<?> root, CriteriaQuery<?> query, CriteriaBuilder builder, Map<String, String> translations) { List<Predicate> predicates = new ArrayList<Predicate>(); for (String singleCriteria : new StrTokenizer(where, ",").getTokenList()) { if (StringUtils.isNotBlank(singleCriteria)) { int equalsIndex = singleCriteria.indexOf("="); if (equalsIndex > 0) { String fieldPath = singleCriteria.substring(0, equalsIndex); String value = singleCriteria.substring(equalsIndex + 1); if (translations != null && translations.containsKey(fieldPath)) { String newFieldPath = translations.get(fieldPath); log.debug("replacing field {} with {} ", fieldPath, newFieldPath); fieldPath = newFieldPath; } StrTokenizer tokenizer = new StrTokenizer(fieldPath, "."); javax.persistence.criteria.Path<?> expression = null; while (tokenizer.hasNext()) { String field = tokenizer.next(); if (tokenizer.hasNext()) { if (expression == null) { expression = root.join(field); } else { // expression = expression.join( field); throw new IllegalArgumentException( "Paths to joins of greater than a depth of 1 are not implemented yet"); } } else { if (expression == null) { log.info("expression0 {}", expression); expression = root.get(field); log.info("expression1 {}", expression); } else { expression = expression.get(field); } } } Object realValue = value; if ("bodyType".equals(fieldPath)) { me.ineson.demo.service.SolarBodyType solarBodyType = me.ineson.demo.service.SolarBodyType .valueOf(value); switch (solarBodyType) { case PLANET: realValue = SolarBodyType.Planet; break; case SUN: realValue = SolarBodyType.Sun; break; case DWARF_PLANET: realValue = SolarBodyType.DwarfPlanet; break; default: realValue = solarBodyType; } log.info("enum bodyType before {} after {}", value, realValue); } log.info("expression9 {}", expression); predicates.add(builder.equal(expression, realValue)); } } } log.debug("predictes "); if (predicates.size() == 0) { return null; } if (predicates.size() == 1) { return predicates.get(0); } return builder.and(predicates.toArray(new Predicate[predicates.size()])); }
From source file:edu.lternet.pasta.portal.PastaStatistics.java
/** * Iterates through the list of scopes and identifiers to calculate * the number of data packages in PASTA. * /* w ww . ja va 2 s . c o m*/ * @return The number of data packages. */ public Integer getNumDataPackages() { Integer numDataPackages = 0; String scopeList = null; try { scopeList = this.dpmClient.listDataPackageScopes(); } catch (Exception e) { logger.error("PastaStatistics: " + e.getMessage()); e.printStackTrace(); } StrTokenizer scopes = new StrTokenizer(scopeList); while (scopes.hasNext()) { String scope = scopes.nextToken(); String idList = null; try { idList = this.dpmClient.listDataPackageIdentifiers(scope); } catch (Exception e) { logger.error("PastaStatistics: " + e.getMessage()); e.printStackTrace(); } StrTokenizer identifiers = new StrTokenizer(idList); numDataPackages += identifiers.size(); } return numDataPackages; }
From source file:edu.lternet.pasta.portal.RevisionBrowseServlet.java
/** * The doPost method of the servlet. <br> * /*from ww w . j av a 2 s . c o m*/ * This method is called when a form has its tag value method equals to post. * * @param request * the request send by the client to the server * @param response * the response send by the server to the client * @throws ServletException * if an error occurred * @throws IOException * if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession httpSession = request.getSession(); String uid = (String) httpSession.getAttribute("uid"); if (uid == null || uid.isEmpty()) uid = "public"; String scope = request.getParameter("scope"); String identifier = request.getParameter("identifier"); Integer id = Integer.valueOf(identifier); String text = null; String html = null; Integer count = 0; try { if (scope != null && !(scope.isEmpty()) && identifier != null && !(identifier.isEmpty())) { DataPackageManagerClient dpmClient = new DataPackageManagerClient(uid); text = dpmClient.listDataPackageRevisions(scope, id, null); StrTokenizer tokens = new StrTokenizer(text); html = "<ol>\n"; while (tokens.hasNext()) { String revision = tokens.nextToken(); html += "<li><a class=\"searchsubcat\" href=\"./mapbrowse?scope=" + scope + "&identifier=" + identifier + "&revision=" + revision + "\">" + scope + "." + identifier + "." + revision + "</a></li>\n"; count++; } html += "</ol>\n"; } else { String msg = "The 'scope', 'identifier', or 'revision' field of the packageId is empty."; throw new UserErrorException(msg); } } catch (Exception e) { handleDataPortalError(logger, e); } request.setAttribute("browsemessage", browseMessage); request.setAttribute("html", html); request.setAttribute("count", count.toString()); RequestDispatcher requestDispatcher = request.getRequestDispatcher(forward); requestDispatcher.forward(request, response); }
From source file:edu.lternet.pasta.portal.UserBrowseServlet.java
/** * The doPost method of the servlet. <br> * /*from w w w . j a v a2 s . c o m*/ * This method is called when a form has its tag value method equals to post. * * @param request * the request send by the client to the server * @param response * the response send by the server to the client * @throws ServletException * if an error occurred * @throws IOException * if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession httpSession = request.getSession(); String uid = (String) httpSession.getAttribute("uid"); String distinguishedName = (String) httpSession.getAttribute("uid"); String forward = null; String browseMessage = "View a data package you have uploaded."; if (uid == null || uid.isEmpty() || uid.equals("public") || distinguishedName == null || distinguishedName.isEmpty()) { String message = LOGIN_WARNING; forward = "./login.jsp"; request.setAttribute("message", message); request.setAttribute("from", "userBrowseServlet"); } else { forward = "./dataPackageBrowser.jsp"; String text = null; String html = null; Integer count = 0; try { DataPackageManagerClient dpmClient = new DataPackageManagerClient(uid); text = dpmClient.listUserDataPackages(distinguishedName); StrTokenizer tokens = new StrTokenizer(text); html = "<ol>\n"; EmlPackageIdFormat epif = new EmlPackageIdFormat(); while (tokens.hasNext()) { String packageId = tokens.nextToken(); EmlPackageId epid = epif.parse(packageId); String scope = epid.getScope(); Integer identifier = epid.getIdentifier(); Integer revision = epid.getRevision(); html += String.format( "<li><a class=\"searchsubcat\" href=\"./mapbrowse?scope=%s&identifier=%d&revision=%d\">%s</a></li>\n", scope, identifier, revision, packageId); count++; } html += "</ol>\n"; request.setAttribute("html", html); request.setAttribute("count", count.toString()); if (count < 1) { browseMessage = String.format("No data packages have been uploaded by user '%s'.", distinguishedName); } request.setAttribute("browsemessage", browseMessage); } catch (Exception e) { handleDataPortalError(logger, e); } } RequestDispatcher requestDispatcher = request.getRequestDispatcher(forward); requestDispatcher.forward(request, response); }
From source file:edu.lternet.pasta.portal.ScopeBrowseServlet.java
/** * The doPost method of the servlet. <br> * //w w w. jav a 2s .c o m * This method is called when a form has its tag value method equals to post. * * @param request * the request send by the client to the server * @param response * the response send by the server to the client * @throws ServletException * if an error occurred * @throws IOException * if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession httpSession = request.getSession(); String uid = (String) httpSession.getAttribute("uid"); if (uid == null || uid.isEmpty()) uid = "public"; String text = null; String html = null; Integer count = 0; try { DataPackageManagerClient dpmClient = new DataPackageManagerClient(uid); text = dpmClient.listDataPackageScopes(); StrTokenizer tokens = new StrTokenizer(text); html = "<ol>\n"; ArrayList<String> arrayList = new ArrayList<String>(); // Add scope values to a sorted set while (tokens.hasNext()) { String token = tokens.nextToken(); arrayList.add(token); count++; } // Output sorted set of scope values for (String scope : arrayList) { html += "<li><a class=\"searchsubcat\" href=\"./identifierbrowse?scope=" + scope + "\">" + scope + "</a></li>\n"; } html += "</ol>\n"; } catch (Exception e) { handleDataPortalError(logger, e); } request.setAttribute("browsemessage", browseMessage); request.setAttribute("html", html); request.setAttribute("count", count.toString()); RequestDispatcher requestDispatcher = request.getRequestDispatcher(forward); requestDispatcher.forward(request, response); }
From source file:edu.lternet.pasta.portal.IdentifierBrowseServlet.java
/** * The doPost method of the servlet. <br> * /*from w ww. j ava 2s . co m*/ * This method is called when a form has its tag value method equals to post. * * @param request * the request send by the client to the server * @param response * the response send by the server to the client * @throws ServletException * if an error occurred * @throws IOException * if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession httpSession = request.getSession(); String uid = (String) httpSession.getAttribute("uid"); if (uid == null || uid.isEmpty()) uid = "public"; String scope = request.getParameter("scope"); String text = null; String html = null; Integer count = 0; if (scope != null && !(scope.isEmpty())) { try { DataPackageManagerClient dpmClient = new DataPackageManagerClient(uid); text = dpmClient.listDataPackageIdentifiers(scope); StrTokenizer tokens = new StrTokenizer(text); html = "<ol>\n"; ArrayList<String> arrayList = new ArrayList<String>(); // Add scope/identifier values to a sorted set while (tokens.hasNext()) { arrayList.add(tokens.nextToken()); count++; } // Output sorted set of scope/identifier values for (String identifier : arrayList) { html += "<li><a class=\"searchsubcat\" href=\"./mapbrowse?scope=" + scope + "&identifier=" + identifier + "\">" + scope + "." + identifier + "</a></li>\n"; } html += "</ol>\n"; } catch (Exception e) { handleDataPortalError(logger, e); } } else { html = "<p class=\"warning\"> Error: \"scope\" field empty</p>\n"; } request.setAttribute("browsemessage", browseMessage); request.setAttribute("html", html); request.setAttribute("count", count.toString()); RequestDispatcher requestDispatcher = request.getRequestDispatcher(forward); requestDispatcher.forward(request, response); }
From source file:org.labkey.npod.DonorToolsSettings.java
public void setIncludedDatasetNames(String includedDatasetIds) { if (null != includedDatasetIds) { _includedDatasetIds = new ArrayList<>(); StrTokenizer tokenizer = StrTokenizer.getCSVInstance(includedDatasetIds); while (tokenizer.hasNext()) { _includedDatasetIds.add(Integer.valueOf(tokenizer.next())); }/*from www. j a v a 2s .c o m*/ } else { _includedDatasetIds = new ArrayList<>(); } }
From source file:org.labkey.npod.DonorToolsSettings.java
public void setPrioritySampleTypes(String prioritySampleTypes) { if (null == prioritySampleTypes) { _prioritySampleTypeIds = new ArrayList<>(); } else {/*from w w w. j a v a 2s . c om*/ _prioritySampleTypeIds = new ArrayList<>(); StrTokenizer tokenizer = StrTokenizer.getCSVInstance(prioritySampleTypes); while (tokenizer.hasNext()) { _prioritySampleTypeIds.add(Integer.valueOf(tokenizer.next())); } } }
From source file:org.lenskit.data.dao.file.DelimitedColumnEntityFormat.java
@Override public LineEntityParser makeParser(List<String> header) { assert header.size() == getHeaderLines(); if (usesHeader() && labeledColumns != null) { assert header.size() == 1; List<TypedName<?>> cols = new ArrayList<>(); StrTokenizer tok = new StrTokenizer(header.get(0), delimiter); while (tok.hasNext()) { String label = tok.next(); cols.add(labeledColumns.get(label)); }//from w w w .j a va 2 s . co m return new OrderedParser(cols, tok); } else { return new OrderedParser(columns, new StrTokenizer("", delimiter)); } }