List of usage examples for org.apache.commons.lang3.text StrTokenizer StrTokenizer
public StrTokenizer(final char[] input)
From source file:mamo.vanillaVotifier.ShellCommandSender.java
@NotNull public Process sendCommand(@NotNull String command, @Nullable Map<String, String> environment) throws IOException { ProcessBuilder processBuilder = new ProcessBuilder(new StrTokenizer(command).getTokenArray()); if (environment != null) { processBuilder.environment().putAll(environment); }/*from w w w . j a v a 2s . c o m*/ return processBuilder.start(); }
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. * /*from w w w . ja v a 2 s.c om*/ * @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.ScopeBrowseServlet.java
/** * The doPost method of the servlet. <br> * //w ww. j av a 2 s .c om * 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.UserBrowseServlet.java
/** * The doPost method of the servlet. <br> * /*w w w . jav a 2 s .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"); 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.IdentifierBrowseServlet.java
/** * The doPost method of the servlet. <br> * /* w w w . j av 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 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:edu.lternet.pasta.portal.RevisionBrowseServlet.java
/** * The doPost method of the servlet. <br> * //www. j a v a 2 s. 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 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.PastaStatistics.java
/** * Iterates through the list of scopes and identifiers of site contributed * data packages to calculate the total number of site contributed data * packages in PASTA.//from w w w . j av a2s .c o m * * @return The number of site contributed data packages. */ public Integer getNumDataPackagesSites() { Integer numDataPackages = 0; String[] scopeList = { "knb-lter-and", "knb-lter-arc", "knb-lter-bes", "knb-lter-bnz", "knb-lter-cce", "knb-lter-cdr", "knb-lter-cap", "knb-lter-cwt", "knb-lter-fce", "knb-lter-gce", "knb-lter-hfr", "knb-lter-hbr", "knb-lter-jrn", "knb-lter-kbs", "knb-lter-knz", "knb-lter-luq", "knb-lter-mcm", "knb-lter-mcr", "knb-lter-nin", "knb-lter-nwt", "knb-lter-ntl", "knb-lter-pal", "knb-lter-pie", "knb-lter-sbc", "knb-lter-sev", "knb-lter-sgs", "knb-lter-vcr" }; for (String scope : scopeList) { 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:com.sos.CredentialStore.KeePass.pl.sind.keepass.kdb.v1.Entry.java
public String[] getNotesAsArray() { StrTokenizer objT = new StrTokenizer(notes.getText()); return objT.getTokenArray(); }
From source file:com.haulmont.cuba.web.testsupport.TestContainer.java
protected void initAppContext() { EclipseLinkCustomizer.initTransientCompatibleAnnotations(); String configProperty = AppContext.getProperty(AbstractAppContextLoader.SPRING_CONTEXT_CONFIG); StrTokenizer tokenizer = new StrTokenizer(configProperty); List<String> locations = tokenizer.getTokenList(); locations.add(getSpringConfig());//from ww w. ja va 2s .co m springAppContext = new CubaClassPathXmlApplicationContext(locations.toArray(new String[locations.size()])); AppContext.Internals.setApplicationContext(springAppContext); Events events = AppBeans.get(Events.NAME); events.publish(new AppContextInitializedEvent(springAppContext)); }
From source file:de.vandermeer.asciitable.AT_Renderer.java
/** * Renders an {@link AsciiTable}./*from ww w .j a v a 2 s . c o m*/ * @param rows table rows to render, cannot be null * @param colNumbers number of columns in the table * @param ctx context of the original table with relevant settings, cannot be null * @param width maximum line width, excluding any extra padding * @return collection of lines, each as a {@link StrBuilder} * @throws {@link NullPointerException} if rows or context where null */ default Collection<StrBuilder> renderAsCollection(LinkedList<AT_Row> rows, int colNumbers, AT_Context ctx, int width) { Validate.notNull(rows); Validate.notNull(ctx); ArrayList<Object> table = new ArrayList<>(); int[] colWidth = this.getCWC().calculateColumnWidths(rows, colNumbers, ctx.getTextWidth(width)); for (AT_Row row : rows) { int ruleset = 0; switch (row.getStyle()) { case NORMAL: ruleset = TA_GridConfig.RULESET_NORMAL; break; case STRONG: ruleset = TA_GridConfig.RULESET_STRONG; break; case LIGHT: ruleset = TA_GridConfig.RULESET_LIGHT; break; case HEAVY: ruleset = TA_GridConfig.RULESET_HEAVY; break; case UNKNOWN: throw new AsciiTableException("AT_Renderer: cannot render unknown row style", "table row style set to 'unknown'"); default: throw new AsciiTableException("AT_Renderer: cannot render unknown row style", "table row style not specified or type not processed"); } switch (row.getType()) { case RULE: table.add(ruleset); break; case CONTENT: String[][] cAr = new String[colNumbers][]; LinkedList<AT_Cell> cells = row.getCells(); if (cells == null) { throw new AsciiTableException("cannot render table", "row content (cells) was null"); } int length = 0; for (int i = 0; i < cells.size(); i++) { length += colWidth[i]; Object content = cells.get(i).getContent(); if (content == null) { length++; continue; } int realWidth = length; length -= cells.get(i).getContext().getPaddingLeft(); length -= cells.get(i).getContext().getPaddingRight(); if (content instanceof RendersToClusterWidth) { cAr[i] = ((RendersToClusterWidth) content).renderAsArray(length); } if (content instanceof DoesRenderToWidth) { cAr[i] = new StrTokenizer(((DoesRenderToWidth) content).render(length)) .setDelimiterChar('\n').setIgnoreEmptyTokens(false).getTokenArray(); } else { //create text from cell object String text = Object_To_StrBuilder.convert(content).toString().replaceAll("\\s+", " "); //check for translators, use what is available if (cells.get(i).getContext().getTargetTranslator() != null) { if (cells.get(i).getContext().getTargetTranslator().getCombinedTranslator() != null) { text = cells.get(i).getContext().getTargetTranslator().getCombinedTranslator() .translate(text); } } else if (cells.get(i).getContext().getHtmlElementTranslator() != null) { text = cells.get(i).getContext().getHtmlElementTranslator().translateHtmlElements(text); } else if (cells.get(i).getContext().getCharTranslator() != null) { text = cells.get(i).getContext().getCharTranslator().translateCharacters(text); } Collection<StrBuilder> csb = Text_To_FormattedText .create(length, cells.get(i).getContext().getTextAlignment().getMapping(), TextFormat.NONE.getMapping(), null, null, null, 0, 0, null, 0, 0, null) .transform(text); for (StrBuilder sb : csb) { sb.insert(0, new StrBuilder().appendPadding(cells.get(i).getContext().getPaddingLeft(), cells.get(i).getContext().getPaddingLeftChar())); sb.appendPadding(cells.get(i).getContext().getPaddingRight(), cells.get(i).getContext().getPaddingRightChar()); } for (int k = 0; k < cells.get(i).getContext().getPaddingTop(); k++) { ((ArrayList<StrBuilder>) csb).add(0, new StrBuilder().appendPadding(realWidth, cells.get(i).getContext().getPaddingTopChar())); } for (int k = 0; k < cells.get(i).getContext().getPaddingBottom(); k++) { ((ArrayList<StrBuilder>) csb).add(new StrBuilder().appendPadding(realWidth, cells.get(i).getContext().getPaddingBottomChar())); } cAr[i] = ClusterElementTransformer.create() .transform(csb, StrBuilder_To_String.create(), ArrayListStrategy.create()) .toArray(new String[0]); } length = 0; } cAr = Array2D_To_NormalizedArray.create(colNumbers).transform(cAr); cAr = Array2D_To_FlipArray.create().transform(cAr); table.add(Pair.of(ruleset, cAr)); break; case UNKNOWN: throw new AsciiTableException("AT_Renderer: cannot render unknown row type", "table row type set to 'unknown'"); default: throw new AsciiTableException("AT_Renderer: cannot render unknown row type", "table row type not specified or type not processed"); } } ArrayList<StrBuilder> ret = ctx.getGrid().addGrid(table, ctx.getGridTheme() | ctx.getGridThemeOptions()); int max = ret.get(0).length() + ctx.getFrameLeftMargin() + ctx.getFrameRightMargin(); for (StrBuilder sb : ret) { sb.insert(0, new StrBuilder().appendPadding(ctx.getFrameLeftMargin(), ctx.getFrameLeftChar())); sb.appendPadding(ctx.getFrameRightMargin(), ctx.getFrameRightChar()); } for (int k = 0; k < ctx.getFrameTopMargin(); k++) { ret.add(0, new StrBuilder().appendPadding(max, ctx.getFrameTopChar())); } for (int k = 0; k < ctx.getFrameBottomMargin(); k++) { ret.add(new StrBuilder().appendPadding(max, ctx.getFrameBottomChar())); } return ret; }