/** * Returns the same value as the <code>nextToken</code> method, except that its declared return value is * <code>Object</code> rather than <code>String</code>. It exists so that this class can implement the * <code>Enumeration</code> interface. * * @return the next token in the string. * @throws NoSuchElementException if there are no more tokens in this tokenizer's string. * @see Enumeration * @see CSVTokenizer#nextToken() */ public Object nextElement() { return nextToken(); }
/** * Returns the next token in this string tokenizer's string. First, the set of characters considered to be separator * by this <tt>CSVTokenizer</tt> object is changed to be the characters in the string <tt>separator</tt>. Then the * next token in the string after the current position is returned. The current position is advanced beyond the * recognized token. The new delimiter set remains the default after this call. * * @param theSeparator the new separator. * @return the next token, after switching to the new delimiter set. * @throws NoSuchElementException if there are no more tokens in this tokenizer's string. */ public String nextToken( final String theSeparator ) { separator = theSeparator; return nextToken(); }
/** * Returns the same value as the <code>nextToken</code> method, except that its declared return value is * <code>Object</code> rather than <code>String</code>. It exists so that this class can implement the * <code>Enumeration</code> interface. * * @return the next token in the string. * @throws NoSuchElementException if there are no more tokens in this tokenizer's string. * @see Enumeration * @see CSVTokenizer#nextToken() */ public Object nextElement() { return nextToken(); }
/** * Returns the next token in this string tokenizer's string. First, the set of characters considered to be separator * by this <tt>CSVTokenizer</tt> object is changed to be the characters in the string <tt>separator</tt>. Then the * next token in the string after the current position is returned. The current position is advanced beyond the * recognized token. The new delimiter set remains the default after this call. * * @param theSeparator the new separator. * @return the next token, after switching to the new delimiter set. * @throws NoSuchElementException if there are no more tokens in this tokenizer's string. */ public String nextToken(final String theSeparator) { separator = theSeparator; return nextToken(); }
public String[] toArray() { final ArrayList<String> retval = new ArrayList<String>( 20 ); while ( hasMoreElements() ) { retval.add( nextToken() ); } return (String[]) retval.toArray(); } }
private Object parseDoubleDefaultParam( String defaultValue, CSVTokenizer csvt ) { if ( csvt.countTokens() == 1 ) { return Double.parseDouble( csvt.nextToken() ); } else { ArrayList<Double> vals = new ArrayList<Double>(); while ( csvt.hasMoreTokens() ) { String token = csvt.nextToken(); vals.add( Double.parseDouble( token ) ); } return vals.toArray( new Double[0] ); } }
private Object parseBooleanDefaultParam( String defaultValue, CSVTokenizer csvt ) { if ( csvt.countTokens() == 1 ) { return Boolean.parseBoolean( csvt.nextToken() ); } else { ArrayList<Boolean> vals = new ArrayList<Boolean>(); while ( csvt.hasMoreTokens() ) { String token = csvt.nextToken(); vals.add( Boolean.parseBoolean( token ) ); } return vals.toArray( new Boolean[0] ); } }
public String[] toArray() { final ArrayList<String> retval = new ArrayList<String>(20); while (hasMoreElements()) { retval.add(nextToken()); } return (String[]) retval.toArray(); } }
private Object parseStringDefaultParam( String defaultValue, CSVTokenizer csvt ) { if ( csvt.countTokens() == 1 ) { return csvt.nextToken(); } else { ArrayList<String> vals = new ArrayList<String>(); while ( csvt.hasMoreTokens() ) { String token = csvt.nextToken(); vals.add( token ); } return vals.toArray( new String[0] ); } }
/** * Calculates the number of times that this tokenizer's <code>nextToken</code> method can be called before it * generates an exception. The current position is not advanced. * * @return the number of tokens remaining in the string using the current delimiter set. * @see CSVTokenizer#nextToken() */ public int countTokens() { int count = 0; final int preserve = this.currentIndex; final boolean preserveStart = this.beforeStart; while ( this.hasMoreTokens() ) { this.nextToken(); count++; } this.currentIndex = preserve; this.beforeStart = preserveStart; return count; }
/** * Calculates the number of times that this tokenizer's <code>nextToken</code> method can be called before it * generates an exception. The current position is not advanced. * * @return the number of tokens remaining in the string using the current delimiter set. * @see CSVTokenizer#nextToken() */ public int countTokens() { int count = 0; final int preserve = this.currentIndex; final boolean preserveStart = this.beforeStart; while (this.hasMoreTokens()) { this.nextToken(); count++; } this.currentIndex = preserve; this.beforeStart = preserveStart; return count; }
/** * Looks up the property with the given name. This replaces the name with the current index position. * * @param name * the name of the property to look up. * @return the translated value. */ protected String lookupVariable( final String name ) { final CSVTokenizer tokenizer = new CSVTokenizer( name, false ); if ( tokenizer.hasMoreTokens() == false ) { return null; } final String varName = tokenizer.nextToken(); final StringBuilder b = new StringBuilder( name.length() ); b.append( '{' ); b.append( String.valueOf( fields.size() ) ); while ( tokenizer.hasMoreTokens() ) { b.append( ',' ); b.append( tokenizer.nextToken() ); } b.append( '}' ); final String formatString = b.toString(); fields.add( varName ); return formatString; }
/** * Returns the schema portion of the serialized ResourceKey string. If the string is invalid, <code>null</code> will * be returned. * * @param data the String serialized version of a <code>ResourceKey</code> * @return the schema object. */ public static Object readSchemaFromString( final String data ) { if ( data == null ) { return null; } final CSVTokenizer tokenizer = new CSVTokenizer( data, DELIMITER, "\"", false ); if ( tokenizer.hasMoreElements() == false ) { return null; } final String tempData = tokenizer.nextToken(); if ( tempData.startsWith( SERIALIZATION_PREFIX ) ) { return tempData.substring( SERIALIZATION_PREFIX.length() ); } return null; }
public List<List<String>> parseSampleContents() { String delim = getDelimiter(); if ( contents == null ) { throw new IllegalStateException( "Sample Contents is null, nothing to parse" ); //$NON-NLS-1$ } else if ( delim == null || "".equals( delim ) ) { //$NON-NLS-1$ // use a random delimiter that will result in an un-parsed list delim = "~!@#$%"; } List<List<String>> sample = new ArrayList<List<String>>(); CSVTokenizer csvTokenizer; String enclosure = null; if ( !"".equals( getEnclosure() ) ) { enclosure = getEnclosure(); } for ( String line : contents ) { csvTokenizer = new CSVTokenizer( line, delim, enclosure ); List<String> rowData = new ArrayList<String>(); while ( csvTokenizer.hasMoreTokens() ) { // get next token and store it in the list rowData.add( csvTokenizer.nextToken() ); } sample.add( rowData ); } return sample; }
private static String continueLookupVariable( final CSVTokenizer tokenizer, final Object parent ) throws BeanException { if ( tokenizer.hasMoreTokens() ) { final String name = tokenizer.nextToken(); final Object base = ConverterRegistry.toPropertyValue( name, parent.getClass() ); if ( tokenizer.hasMoreTokens() ) { return continueLookupVariable( tokenizer, base ); } else { return ConverterRegistry.toAttributeValue( base ); } } return null; }
/** * Splits a given string at the given separator string. Duplicate separators will result in empty strings thus * preserving the number of fields specified in the original string. * * @param string the text to be split. * @param separator the separator chacters used for the split. * @param quate the quoting character. * @return the splitted array. */ public static String[] splitCSV( final String string, final String separator, final String quate ) { final CSVTokenizer strtok = new CSVTokenizer( string, separator, quate, false ); final String[] tokens = new String[ strtok.countTokens() ]; int i = 0; while ( strtok.hasMoreTokens() ) { final String token = strtok.nextToken(); tokens[ i ] = ( token ); i += 1; } return tokens; }
/** * Splits a given string at the given separator string. Duplicate separators will result in empty strings thus * preserving the number of fields specified in the original string. * * @param string the text to be split. * @param separator the separator chacters used for the split. * @param quate the quoting character. * @return the splitted array. */ public static String[] splitCSV(final String string, final String separator, final String quate) { final CSVTokenizer strtok = new CSVTokenizer(string, separator, quate, false); final String[] tokens = new String[strtok.countTokens()]; int i = 0; while (strtok.hasMoreTokens()) { final String token = strtok.nextToken(); tokens[i] = (token); i += 1; } return tokens; }
/** * Boots modules, which have been spcified in the "org.pentaho.reporting.engine.classic.core.boot.Modules" * configuration parameter. */ private void bootAdditionalModules() { try { final String bootModules = getGlobalConfig().getConfigProperty( "org.pentaho.reporting.engine.classic.core.boot.Modules" ); // NON-NLS if ( bootModules != null ) { final CSVTokenizer csvToken = new CSVTokenizer( bootModules, "," ); while ( csvToken.hasMoreTokens() ) { final String token = csvToken.nextToken(); getPackageManager().load( token ); } } } catch ( SecurityException se ) { // we'll ignore any Security exception .. ClassicEngineBoot.logger.info( "Security settings forbid to check the system properties for extension modules." ); // NON-NLS } catch ( Exception se ) { ClassicEngineBoot.logger.error( "An error occured while checking the system properties for extension modules.", // NON-NLS se ); } }
protected String lookupVariable( final String entity ) { // first, split the entity into separate strings (separator is '.'). final CSVTokenizer tokenizer = new CSVTokenizer( entity, "." ); if ( tokenizer.hasMoreTokens() ) { final String name = tokenizer.nextToken(); final Object base = performInitialLookup( name ); try { if ( tokenizer.hasMoreTokens() ) { return BeanPropertyLookupParser.continueLookupVariable( tokenizer, base ); } else { return ConverterRegistry.toAttributeValue( base ); } } catch ( BeanException e ) { return entity; } } return entity; }
public void testCSVTokenizer() { final String example = "\"Test\""; final CSVTokenizer tokenizer = new CSVTokenizer( example, false ); assertTrue( "Tokenizer has at least one element", tokenizer.hasMoreTokens() ); assertEquals( tokenizer.nextToken(), "Test" ); }