List of usage examples for org.apache.commons.lang.text StrTokenizer StrTokenizer
public StrTokenizer(char[] input, StrMatcher delim)
From source file:com.akrema.stringeval.utils.ExprUtils.java
/** * extract arguments from the input string * and specify if we have integer or string arguments * * @param inputstring the parameters in the expression * @return map contain number of argument+value *///ww w . j a v a 2s.co m public static HashMap<Integer, Object> extractArguments(String inputstring) throws InputStringException { HashMap<Integer, Object> args = new HashMap<Integer, Object>(); StrTokenizer tokenizer = new StrTokenizer(inputstring, StringCONST.DELM); if (tokenizer.size() > 3) { throw new InputStringException(" the arguments list must be 3 "); } int index = 1; while (tokenizer.hasNext()) { String ch = tokenizer.nextToken(); if (ch.matches("\\d+")) { args.put(index, Integer.parseInt(ch)); index++; } else { args.put(index, ch); index++; } } return args; }
From source file:com.processpuzzle.fundamental_types.domain.ParameterValueList.java
public static ParameterValueList parse(String parameters) throws ClassNotFoundException, InstantiationException, IllegalAccessException { ParameterValueList valueList = new ParameterValueList(); StrMatcher delimiters = StrMatcher.charSetMatcher(LIST_DELIMITERS.toCharArray()); StrTokenizer tokenizer = new StrTokenizer(parameters, delimiters); while (tokenizer.hasNext()) { ParameterValue parameterValue = ParameterValue.parse(tokenizer.nextToken()); valueList.add(parameterValue);//w ww. j a va 2 s .c om } return valueList; }
From source file:com.inkubator.hrm.util.IpUtil.java
public static String getIpFromRequest(HttpServletRequest request) { String ip;//from ww w .j a v a 2 s.c o m boolean found = false; if ((ip = request.getHeader("x-forwarded-for")) != null) { LOGGER.info("IP Number " + ip); StrTokenizer tokenizer = new StrTokenizer(ip, ","); while (tokenizer.hasNext()) { ip = tokenizer.nextToken().trim(); if (isIPv4Valid(ip) && !isIPv4Private(ip)) { found = true; break; } } } if (!found) { LOGGER.info("IP Number " + ip); ip = request.getRemoteAddr(); } return ip; }
From source file:au.org.ala.delta.intkey.directives.DefineNamesDirective.java
@Override protected BasicIntkeyDirectiveInvocation doProcess(IntkeyContext context, String data) throws Exception { String keyword = null;/*from www . j a v a2 s . c om*/ List<String> names = new ArrayList<String>(); // Need to prompt if data starts with a wildcard - don't bother // tokenizing if (!data.toUpperCase().startsWith(IntkeyDirectiveArgument.DEFAULT_DIALOG_WILDCARD)) { // Taxon names are separated by newlines or by commas List<String> tokens = new StrTokenizer(data, StrMatcher.charSetMatcher(new char[] { '\n', '\r', ',' })) .getTokenList(); if (!tokens.isEmpty()) { String firstToken = tokens.get(0); // The keyword (which may quoted) and first taxon name may be // separated by a space List<String> splitFirstToken = new StrTokenizer(firstToken, StrMatcher.charSetMatcher(new char[] { ' ' }), StrMatcher.quoteMatcher()).getTokenList(); keyword = splitFirstToken.get(0); if (splitFirstToken.size() > 1) { names.add(StringUtils.join(splitFirstToken.subList(1, splitFirstToken.size()), " ")); } for (int i = 1; i < tokens.size(); i++) { names.add(tokens.get(i).trim()); } //If first name begins with a wildcard, we need to prompt for names. Clear out the names list if this is the case. if (!names.isEmpty()) { if (names.get(0).toUpperCase().startsWith(IntkeyDirectiveArgument.DEFAULT_DIALOG_WILDCARD)) { names.clear(); } } } } List<Item> taxa = new ArrayList<Item>(); for (String taxonName : names) { Item taxon = context.getDataset().getTaxonByName(taxonName); if (taxon == null) { throw new IntkeyDirectiveParseException( UIUtils.getResourceString("InvalidTaxonName.error", taxonName)); } else { taxa.add(taxon); } } String directiveName = StringUtils.join(getControlWords(), " ").toUpperCase(); if (StringUtils.isEmpty(keyword)) { keyword = context.getDirectivePopulator() .promptForString(UIUtils.getResourceString("EnterKeyword.caption"), null, directiveName); if (keyword == null) { // cancelled return null; } } if (taxa.isEmpty()) { List<String> selectedKeywords = new ArrayList<String>(); // Not // used, // but // required // as an // argument taxa = context.getDirectivePopulator().promptForTaxaByList(directiveName, false, false, false, false, null, selectedKeywords); if (taxa == null || taxa.isEmpty()) { // cancelled return null; } // extract taxon names for use in building string representation of // command for (Item taxon : taxa) { names.add(_taxonFormatter.formatItemDescription(taxon)); } } DefineNamesDirectiveInvocation invoc = new DefineNamesDirectiveInvocation(keyword, taxa); invoc.setStringRepresentation( String.format("%s \"%s\" %s", getControlWordsAsString(), keyword, StringUtils.join(names, ", "))); return invoc; }
From source file:de.unigoettingen.sub.commons.contentlib.servlet.controller.GetPdfAction.java
/************************************************************************************ * exectute all simple pdf actions and send pdf back to output stream of the servlet, after setting correct mime type * //from ww w . j a va 2 s. co m * @param request {@link HttpServletRequest} of ServletRequest * @param response {@link HttpServletResponse} for writing to response output stream * @throws IOException * @throws URISyntaxException * @throws ContentLibException ************************************************************************************/ @Override public void run(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response) throws IOException, URISyntaxException, ContentLibException { super.run(servletContext, request, response); Watermark myWatermark = null; /* * get central configuration and retrieve source image from url */ ContentServerConfiguration config = ContentServerConfiguration.getInstance(); /* * parse images and get all image paths into HashMap */ HashMap<Integer, UrlImage> urlMap = new HashMap<Integer, UrlImage>(); String images = request.getParameter("images"); StrTokenizer imagetokenizer = new StrTokenizer(images, "$"); int i = 1; for (String image : imagetokenizer.getTokenArray()) { URL imagePath = new URL(config.getRepositoryPathImages() + image); PDFPage page = new PDFPage(); page.setURL(imagePath); urlMap.put(i++, page); } /* * parse image names and get all into HashMap */ HashMap<Integer, String> nameMap = new HashMap<Integer, String>(); if (request.getParameter("imageNames") != null) { String allnames = request.getParameter("imageNames"); StrTokenizer imageNametokenizer = new StrTokenizer(allnames, "$"); i = 1; for (String name : imageNametokenizer.getTokenArray()) { nameMap.put(i++, name.trim()); } } /* * parse bookmarks and get all into HashMap */ HashMap<String, PDFBookmark> allBookmarks = new HashMap<String, PDFBookmark>(); LinkedList<PDFBookmark> topBookmarks = new LinkedList<PDFBookmark>(); /* run through all bookmark defnition */ StrTokenizer bookmarkDefTokenizer = new StrTokenizer(request.getParameter("bookmarks"), "$"); for (String bookmarkDef : bookmarkDefTokenizer.getTokenArray()) { /* get all bookmark definition values as strings from tokenizer */ StrTokenizer bookmarkDefValues = new StrTokenizer(bookmarkDef, ","); String defID = bookmarkDefValues.getTokenArray()[0].trim(); String defParentID = bookmarkDefValues.getTokenArray()[1].trim(); String defImageNumber = bookmarkDefValues.getTokenArray()[2].trim(); String defTitle = bookmarkDefValues.getTokenArray()[3].trim(); /* create bookmark and add it to HashMap */ PDFBookmark bm = new PDFBookmark(Integer.parseInt(defImageNumber) + 1, defTitle); if (defParentID.equals("0")) { topBookmarks.add(bm); } else { allBookmarks.get(defParentID).addChildBookmark(bm); } allBookmarks.put(defID, bm); } /* * create new PDFManager to create the PDF files */ PDFManager pdfmanager = new PDFManager(urlMap); /* add bookmarks */ pdfmanager.setStructureList(topBookmarks); /* add image names if present */ if (request.getParameter("imageNames") != null) { pdfmanager.setImageNames(nameMap); } if (config.getWatermarkUse()) { File watermarkfile = new File(new URI(config.getWatermarkConfigFilePath())); myWatermark = Watermark.generateWatermark(request, watermarkfile); } /* * define conversion parameters from request or from configuration -------------------------------- */ /* alwaysUseRenderedImage */ if (request.getParameter("alwaysUseRenderedImage") != null) { pdfmanager.setAlwaysUseRenderedImage( Boolean.parseBoolean(request.getParameter("alwaysUseRenderedImage"))); } else { pdfmanager.setAlwaysUseRenderedImage(config.getPdfDefaultAlwaysUseRenderedImage()); } /* alwaysCompressToJPEG */ if (request.getParameter("alwaysCompressToJPEG") != null) { pdfmanager.setAlwaysCompressToJPEG(Boolean.parseBoolean(request.getParameter("alwaysCompressToJPEG"))); } else { pdfmanager.setAlwaysCompressToJPEG(config.getPdfDefaultAlwaysCompressToJPEG()); } /* * set pdf metadata -------------------------------- */ /* author */ if (request.getParameter("metadataAuthor") != null) { pdfmanager.setAuthor(request.getParameter("metadataAuthor").trim()); } /* creator */ if (request.getParameter("metadataCreator") != null) { pdfmanager.setCreator(request.getParameter("metadataCreator").trim()); } /* title */ if (request.getParameter("metadataTitle") != null) { pdfmanager.setTitle(request.getParameter("metadataTitle").trim()); } /* subject */ if (request.getParameter("metadataSubject") != null) { pdfmanager.setSubject(request.getParameter("metadataSubject").trim()); } /* keyword */ if (request.getParameter("metadataKeyword") != null) { pdfmanager.setKeyword(request.getParameter("metadataKeyword").trim()); } /* * set file name and attachment header from parameter or from configuration */ StringBuilder targetFileName = new StringBuilder(); if (config.getSendPdfAsAttachment()) { targetFileName.append("attachment; "); } targetFileName.append("filename="); if (request.getParameter("targetFileName") != null) { targetFileName.append(request.getParameter("targetFileName")); } else { String filename = ContentLibUtil.getCustomizedFileName(config.getDefaultFileNamePdf(), ".pdf"); targetFileName.append(filename); } response.setHeader("Content-Disposition", targetFileName.toString()); response.setContentType("application/pdf"); /* * write pdf to response stream */ try { pdfmanager.createPDF(response.getOutputStream(), PdfPageSize.ORIGINAL, myWatermark); } catch (URISyntaxException e) { throw new ContentLibPdfException("error while creating pdf file", e); } finally { if (response.getOutputStream() != null) { response.getOutputStream().flush(); response.getOutputStream().close(); } } }
From source file:com.odiago.flumebase.io.CharBufferUtils.java
/** * Parses a CharSequence into a list of values, all of some other type. *///from w w w . j av a 2 s. c om public static List<Object> parseList(CharBuffer chars, Type listItemType, String nullStr, String listDelim) throws ColumnParseException { StrTokenizer tokenizer = new StrTokenizer(chars.toString(), listDelim.charAt(0)); List<Object> out = new ArrayList<Object>(); while (tokenizer.hasNext()) { String part = (String) tokenizer.next(); out.add(parseType(CharBuffer.wrap(part), listItemType, nullStr, listDelim)); } return Collections.unmodifiableList(out); }
From source file:com.haulmont.cuba.core.app.NumberIdWorker.java
protected Object executeScript(String entityName, String sqlScript) { EntityManager em = persistence.getEntityManager(getDataStore(entityName)); StrTokenizer tokenizer = new StrTokenizer(sqlScript, SequenceSupport.SQL_DELIMITER); Object value = null;/*from w ww.j a v a 2s . co m*/ Connection connection = em.getConnection(); while (tokenizer.hasNext()) { String sql = tokenizer.nextToken(); try { PreparedStatement statement = connection.prepareStatement(sql); try { if (statement.execute()) { ResultSet rs = statement.getResultSet(); if (rs.next()) value = rs.getLong(1); } } finally { DbUtils.closeQuietly(statement); } } catch (SQLException e) { throw new IllegalStateException("Error executing SQL for getting next number", e); } } return value; }
From source file:com.haulmont.cuba.core.app.UniqueNumbers.java
protected Object executeScript(String domain, String sqlScript) { EntityManager em = persistence.getEntityManager(getDataStore(domain)); StrTokenizer tokenizer = new StrTokenizer(sqlScript, SequenceSupport.SQL_DELIMITER); Object value = null;//from w ww . j a v a 2 s .com Connection connection = em.getConnection(); while (tokenizer.hasNext()) { String sql = tokenizer.nextToken(); try { PreparedStatement statement = connection.prepareStatement(sql); try { if (statement.execute()) { ResultSet rs = statement.getResultSet(); if (rs.next()) value = rs.getLong(1); } } finally { DbUtils.closeQuietly(statement); } } catch (SQLException e) { throw new IllegalStateException("Error executing SQL for getting next number", e); } } return value; }
From source file:com.zimbra.cs.servlet.ContextPathBasedThreadPoolBalancerFilter.java
protected void parse(String input) throws ServletException { rulesByContextPath.clear();/* w w w . j ava2s.co m*/ for (String str : new StrTokenizer(input, ",").getTokenArray()) { String[] array = str.split(":"); if (array.length != 2) { throw new ServletException("Malformed rules: " + input); } String key = StringUtils.trimToNull(array[0]); String value = StringUtils.trimToNull(array[1]); if (key == null || value == null) { throw new ServletException("Malformed rules: " + input); } Rules rules = Rules.parse(value); rulesByContextPath.put(key, rules); } }
From source file:com.evanmclean.evlib.text.FuzzyCompare.java
/** * Construct a lexicon of all the good words in the string. * // w ww. j av a 2 s . c o m * @param str * The string to process. * @return A new lexicon. */ @SuppressWarnings("DM_CONVERT_CASE") public FuzzyLexicon makeLexicon(final String str) { if (tokenizer == null) tokenizer = new StrTokenizer(str, WORD_DELIM_MATCH); else tokenizer.reset(str); final HashSet<String> lexicon = new HashSet<String>(); while (tokenizer.hasNext()) { final String word = tokenizer.nextToken().toLowerCase(); if (goodWord(word)) lexicon.add(trim(word)); } return new FuzzyLexicon(str, lexicon, this); }