List of usage examples for java.util StringTokenizer countTokens
public int countTokens()
From source file:edu.ku.brc.ui.UIHelper.java
/** * Parse comma separated r,g,b string//from w ww .j av a 2 s . c om * @param rgb the string with comma separated color values * @return the Color object */ public static Color parseRGB(final String rgb) { StringTokenizer st = new StringTokenizer(rgb, ","); if (st.countTokens() == 3) { String r = st.nextToken().trim(); String g = st.nextToken().trim(); String b = st.nextToken().trim(); return new Color(Integer.parseInt(r), Integer.parseInt(g), Integer.parseInt(b)); } throw new ConfigurationException("R,G,B value is bad [" + rgb + "]"); }
From source file:jp.terasoluna.fw.validation.FieldChecks.java
/** * ?????//from www . j a va2s . c o m * * @param va Validator????ValidatorAction * @return ? */ @SuppressWarnings("rawtypes") protected Class[] getParamClass(ValidatorAction va) { StringTokenizer st = new StringTokenizer(va.getMethodParams(), ","); Class[] paramClass = new Class[st.countTokens()]; for (int i = 0; st.hasMoreTokens(); i++) { try { String key = st.nextToken().trim(); paramClass[i] = ClassUtils.getClass(key); } catch (ClassNotFoundException e) { return null; } } return paramClass; }
From source file:com.izforge.izpack.compiler.CompilerConfig.java
private String[] getFilesetIncludedFiles(IXMLElement fileSetElement) throws CompilerException { List<String> includedFiles = new ArrayList<String>(); String dir_attr = xmlCompilerHelper.requireAttribute(fileSetElement, "dir"); File dir = new File(dir_attr); if (!dir.isAbsolute()) { dir = new File(compilerData.getBasedir(), dir_attr); }// w ww . j a va 2 s . c o m if (!dir.isDirectory()) // also tests '.exists()' { assertionHelper.parseError(fileSetElement, "Invalid directory 'dir': " + dir_attr); } boolean casesensitive = xmlCompilerHelper.validateYesNoAttribute(fileSetElement, "casesensitive", YES); boolean defexcludes = xmlCompilerHelper.validateYesNoAttribute(fileSetElement, "defaultexcludes", YES); // get includes and excludes List<IXMLElement> xcludesList; String[] includes = null; xcludesList = fileSetElement.getChildrenNamed("include"); if (!xcludesList.isEmpty()) { includes = new String[xcludesList.size()]; for (int j = 0; j < xcludesList.size(); j++) { IXMLElement xclude = xcludesList.get(j); includes[j] = xmlCompilerHelper.requireAttribute(xclude, "name"); } } String[] excludes = null; xcludesList = fileSetElement.getChildrenNamed("exclude"); if (!xcludesList.isEmpty()) { excludes = new String[xcludesList.size()]; for (int j = 0; j < xcludesList.size(); j++) { IXMLElement xclude = xcludesList.get(j); excludes[j] = xmlCompilerHelper.requireAttribute(xclude, "name"); } } // parse additional fileset attributes "includes" and "excludes" String[] toDo = new String[] { "includes", "excludes" }; // use the existing containers filled from include and exclude // and add the includes and excludes to it String[][] containers = new String[][] { includes, excludes }; for (int j = 0; j < toDo.length; ++j) { String inex = fileSetElement.getAttribute(toDo[j]); if (inex != null && inex.length() > 0) { // This is the same "splitting" as ant PatternSet do ... StringTokenizer tokenizer = new StringTokenizer(inex, ", ", false); int newSize = tokenizer.countTokens(); String[] nCont = null; if (containers[j] != null && containers[j].length > 0) { // old container exist; create a new which can hold // all values // and copy the old stuff to the front newSize += containers[j].length; nCont = new String[newSize]; System.arraycopy(containers[j], 0, nCont, 0, containers[j].length); } if (nCont == null) // No container for old values created, create a new one. { nCont = new String[newSize]; } for (int k = 0; k < newSize; ++k) // Fill the new one or expand the existent container { nCont[k] = tokenizer.nextToken(); } containers[j] = nCont; } } includes = containers[0]; // push the new includes to the // local var excludes = containers[1]; // push the new excludes to the // local var // scan and add fileset DirectoryScanner directoryScanner = new DirectoryScanner(); directoryScanner.setIncludes(includes); directoryScanner.setExcludes(excludes); if (defexcludes) { directoryScanner.addDefaultExcludes(); } directoryScanner.setBasedir(dir); directoryScanner.setCaseSensitive(casesensitive); try { directoryScanner.scan(); String[] files = directoryScanner.getIncludedFiles(); String[] dirs = directoryScanner.getIncludedDirectories(); // Directory scanner has done recursion, add files and // directories Collections.addAll(includedFiles, files); Collections.addAll(includedFiles, dirs); } catch (Exception e) { throw new CompilerException(e.getMessage()); } return includedFiles.toArray(new String[includedFiles.size()]); }
From source file:cms.service.template.TemplateUtility.java
public String[] getString2TokenArray(String data, String seperator) { String[] retStr;//ww w.j a va 2s. com int count = 0; if (data != null && !data.equals("")) { StringTokenizer st = new StringTokenizer(data, seperator); int length = st.countTokens(); retStr = new String[length]; while (st.hasMoreTokens()) { //logger.info("token="+st.nextToken()); retStr[count] = st.nextToken().trim(); count++; } return (retStr); } return (null); }
From source file:cms.service.template.TemplateUtility.java
public boolean isDate(String s) { boolean isfirst = true; boolean backslas = false; boolean dash = false; String delimitor = ""; String retStr = ""; if (s != null && !s.equals("")) { if (s.indexOf("/") > 0) { backslas = true;//from w w w . j a va2s.c o m delimitor = "/"; } if (s.indexOf("-") > 0) { dash = true; delimitor = "-"; } StringTokenizer st = new StringTokenizer(s, delimitor); while (st.hasMoreTokens() && st.countTokens() >= 2) { try { int j = Integer.parseInt(st.nextToken()); } catch (NumberFormatException ne) { return (false); } } } return (true); }
From source file:cms.service.template.TemplateUtility.java
public String[] getGridDataArray(String data, String rowseperator, String columnSeperator) { Vector rowData = getGridRowData(data, rowseperator); String[] retStr = new String[1]; int count = 0; for (int i = 0; i < rowData.size(); i++) { StringTokenizer st = new StringTokenizer((String) rowData.elementAt(i), columnSeperator); int length = st.countTokens() * rowData.size(); retStr = new String[length]; while (st.hasMoreTokens()) { //logger.info("Col value="+st.nextToken()); retStr[count] = st.nextToken(); count++;//from w w w. j a v a 2s. c om } if (count == 0) retStr[count] = (String) rowData.elementAt(i); } return (retStr); }
From source file:fs.MainWindow.java
public int[] ExtractIndices(StringTokenizer strfeatures) { int nrfeatures = strfeatures.countTokens(); int[] features = new int[nrfeatures]; for (int n = 0; n < nrfeatures; n++) { features[n] = Integer.valueOf(strfeatures.nextToken()); }// w ww .java2 s . co m return (features); }
From source file:com.silverpeas.workflowdesigner.control.WorkflowDesignerSessionController.java
/** * Returns the item type codes as configured in the properties * * @param fNone if <code>true</code> the 'None' option shall be included * @return an array of codes/*from w w w.j ava2 s . c o m*/ */ public String[] retrieveItemTypeCodes(boolean fNone) { StringTokenizer strtok = new StringTokenizer(getSettings().getString("itemTypes"), ","); List<String> list = new ArrayList<String>(strtok.countTokens() + 1); if (fNone) { list.add(""); } while (strtok.hasMoreTokens()) { list.add(strtok.nextToken()); } return list.toArray(new String[list.size()]); }
From source file:com.silverpeas.workflowdesigner.control.WorkflowDesignerSessionController.java
/** * Returns the action kind codes as configured in the properties retrieve * * @return an array of codes//from w w w .java2s. c om */ public String[] retrieveActionKindCodes() { StringTokenizer strtok = new StringTokenizer(getSettings().getString("actionKinds"), ","); List<String> list = new ArrayList<String>(strtok.countTokens()); while (strtok.hasMoreTokens()) { list.add(strtok.nextToken()); } return list.toArray(new String[list.size()]); }
From source file:com.silverpeas.workflowdesigner.control.WorkflowDesignerSessionController.java
/** * Returns the language codes as configured in the properties * * @param fDefault if <code>true</code> the 'default' option shall be included * @return an array of language codes/*from w w w . j a v a 2s . c o m*/ */ public String[] retrieveLanguageCodes(boolean fDefault) { StringTokenizer strtok = new StringTokenizer(getSettings().getString("languages"), ","); List<String> list = new ArrayList<String>(strtok.countTokens() + 1); if (fDefault) { list.add("default"); } while (strtok.hasMoreTokens()) { list.add(strtok.nextToken()); } return list.toArray(new String[list.size()]); }