Java Code Examples for com.ibm.icu.util.StringTokenizer

The following examples show how to use com.ibm.icu.util.StringTokenizer. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public int compareTo(Version other) {
	try {
		StringTokenizer st1 = new StringTokenizer(getVersion().trim(), ".", false);
		StringTokenizer st2 = new StringTokenizer(other.getVersion().trim(), ".", false);

		Integer num1 = Integer.parseInt(st1.nextToken());
		Integer num2 = Integer.parseInt(st2.nextToken());

		if (num1.compareTo(num2) != 0)
			return num1.compareTo(num2);

		num1 = Integer.parseInt(st1.nextToken());
		num2 = Integer.parseInt(st2.nextToken());

		return num1.compareTo(num2);
	} catch (Throwable t) {
		if (this.getDate() != null && other.getDate() != null)
			return this.getDate().compareTo(other.getDate());
		else
			return -1;
	}
}
 
Example 2
Source Project: birt   Source File: AbstractPropertyDialog.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Looks up the node based on the path it is givean
 * 
 * @param path
 *            The complete path to the target node.
 * @return The Node object or null if it is not found.
 */
private final PropertyNode getNode( String path )
{
	PropertyNode currentNode = null;
	if ( path != null )
	{
		path = path.trim( );
		currentNode = rootNode;
		StringTokenizer tokenizer = new StringTokenizer( path, "/" ); //$NON-NLS-1$
		while ( tokenizer.hasMoreTokens( ) )
		{
			currentNode = currentNode.getSubNode( tokenizer.nextToken( ) );
			if ( currentNode == null )
			{
				return null;
			}
		}

	}
	return currentNode;
}
 
Example 3
Source Project: birt   Source File: ReportPlugin.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Convert the single string of preference into string array
 * 
 * @param preferenceValue
 *            The specified element name
 * @return String[] The array of strings
 */
public static String[] convert( String preferenceValue )
{

	String preferenceValueCopy = PREFERENCE_DELIMITER + preferenceValue;
	String replaceString = PREFERENCE_DELIMITER + PREFERENCE_DELIMITER;
	String regrex = PREFERENCE_DELIMITER + SPACE + PREFERENCE_DELIMITER;
	while ( preferenceValueCopy.indexOf( replaceString ) != -1 )
	{
		preferenceValueCopy = preferenceValueCopy.replaceFirst( replaceString,
				regrex );
	}

	StringTokenizer tokenizer = new StringTokenizer( preferenceValueCopy,
			PREFERENCE_DELIMITER );
	int tokenCount = tokenizer.countTokens( );
	String[] elements = new String[tokenCount];

	int i;
	for ( i = 0; i < tokenCount; i++ )
	{
		elements[i] = tokenizer.nextToken( ).trim( );
	}
	return elements;

}
 
Example 4
Source Project: birt   Source File: ReportLauncherUtils.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private static Integer getStartLevel( String text )
{
	StringTokenizer tok = new StringTokenizer( text, ":" ); //$NON-NLS-1$
	while ( tok.hasMoreTokens( ) )
	{
		String token = tok.nextToken( ).trim( );
		try
		{
			return new Integer( token );
		}
		catch ( NumberFormatException e )
		{
		}
	}
	return Integer.valueOf( -1 );
}
 
Example 5
Source Project: birt   Source File: ReportLauncherUtils.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public static TreeSet parseDeselectedWSIds( ILaunchConfiguration config )
		throws CoreException
{
	TreeSet deselected = new TreeSet( );
	String ids = config.getAttribute( IReportLauncherSettings.IMPORTPROJECT,
			(String) null );
	if ( ids != null && ids.length( ) > 0 )
	{
		StringTokenizer token = new StringTokenizer( ids, ";" ); //$NON-NLS-1$
		while ( token.hasMoreTokens( ) )
		{
			String str = token.nextToken( );
			int index = str.lastIndexOf( File.separator );
			if ( index > 0 )
			{
				str = str.substring( index + 1 );
			}
			deselected.add( str );
		}
	}
	return deselected;
}
 
Example 6
Source Project: birt   Source File: ReportLauncherUtils.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public static TreeSet parseDeselectedOpenFileNames(
		ILaunchConfiguration config ) throws CoreException
{
	TreeSet deselected = new TreeSet( );
	String ids = config.getAttribute( IReportLauncherSettings.OPENFILENAMES,
			(String) null );
	if ( ids != null && ids.length( ) > 0 )
	{
		StringTokenizer token = new StringTokenizer( ids, ";" ); //$NON-NLS-1$
		while ( token.hasMoreTokens( ) )
		{
			String str = token.nextToken( );
			int index = str.lastIndexOf( File.separator );
			if ( index > 0 )
			{
				str = str.substring( index + 1 );
			}
			deselected.add( str );
		}
	}
	return deselected;
}
 
Example 7
Source Project: birt   Source File: ReportLauncherUtils.java    License: Eclipse Public License 1.0 6 votes vote down vote up
public static TreeSet parseDeselectedClassIds( ILaunchConfiguration config )
		throws CoreException
{
	TreeSet deselected = new TreeSet( );
	String ids = config.getAttribute( IReportLauncherSettings.IMPORTPROJECTNAMES,
			(String) null );
	if ( ids != null && ids.length( ) > 0 )
	{
		StringTokenizer token = new StringTokenizer( ids, ";" ); //$NON-NLS-1$
		while ( token.hasMoreTokens( ) )
		{
			String str = token.nextToken( );
			int index = str.lastIndexOf( File.separator );
			if ( index > 0 )
			{
				str = str.substring( index + 1 );
			}
			deselected.add( str );
		}
	}
	return deselected;
}
 
Example 8
private void loadFromContent(MCRContent input) throws IOException {
    try (InputStream in = input.getInputStream()) {
        properties.load(in);
    }
    String include = properties.getProperty("MCR.Configuration.Include", null);

    if (include != null) {
        StringTokenizer st = new StringTokenizer(include, ", ");
        properties.remove("MCR.Configuration.Include");
        while (st.hasMoreTokens()) {
            loadFromFile(st.nextToken());
        }
    }
}
 
Example 9
Source Project: birt   Source File: ItemContentProvider.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Retrieve all the item names belonging to a specific category from dFile.
 * 
 * @param categoryName Category name
 */
private void parseItems( String categoryName )
{
	String sTmp = dFile.toString( );
	String startCategory = categoryName + ">"; //$NON-NLS-1$
	String endCategory = "/" + categoryName + ">"; //$NON-NLS-1$ //$NON-NLS-2$
	StringTokenizer tokens = new StringTokenizer( sTmp, "<" ); //$NON-NLS-1$
	boolean bThisCategory = false;
	iTypes = new ArrayList<String>( );
	while ( tokens.hasMoreTokens( ) )
	{
		String token = tokens.nextToken( );
		if ( startCategory.equals( token ) )
		{
			bThisCategory = true;
		}
		else if ( endCategory.equals( token ) )
		{
			break;
		}
		else if ( bThisCategory )
		{
			String sKey = token.substring( 0, token.indexOf( ">" ) ); //$NON-NLS-1$
			iTypes.add( sKey );
		}			
	}
}
 
Example 10
Source Project: birt   Source File: LineSeriesImpl.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private String getConvertedOrthogonalSampleDataRepresentation(
		String sOldRepresentation )
{
	StringTokenizer strtok = new StringTokenizer( sOldRepresentation, "," ); //$NON-NLS-1$
	StringBuffer sbNewRepresentation = new StringBuffer( "" ); //$NON-NLS-1$
	while ( strtok.hasMoreTokens( ) )
	{
		String sElement = strtok.nextToken( ).trim( );
		if ( sElement.startsWith( "H" ) ) //$NON-NLS-1$ // Orthogonal sample data is for a
		// stock chart (Orthogonal sample
		// data CANNOT
		// be text
		{
			StringTokenizer strStockTokenizer = new StringTokenizer( sElement );
			sbNewRepresentation.append( strStockTokenizer.nextToken( )
					.trim( )
					.substring( 1 ) );
		}
		else
		{
			sbNewRepresentation.append( sElement );
		}
		sbNewRepresentation.append( "," ); //$NON-NLS-1$
	}
	return sbNewRepresentation.toString( ).substring( 0,
			sbNewRepresentation.length( ) - 1 );
}
 
Example 11
Source Project: birt   Source File: BarSeriesImpl.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private String getConvertedOrthogonalSampleDataRepresentation(
		String sOldRepresentation )
{
	StringTokenizer strtok = new StringTokenizer( sOldRepresentation, "," ); //$NON-NLS-1$
	StringBuffer sbNewRepresentation = new StringBuffer( "" ); //$NON-NLS-1$
	while ( strtok.hasMoreTokens( ) )
	{
		String sElement = strtok.nextToken( ).trim( );
		if ( sElement.startsWith( "H" ) ) //$NON-NLS-1$ // Orthogonal sample data is for a
		// stock chart (Orthogonal sample
		// data CANNOT
		// be text
		{
			StringTokenizer strStockTokenizer = new StringTokenizer( sElement );
			sbNewRepresentation.append( strStockTokenizer.nextToken( )
					.trim( )
					.substring( 1 ) );
		}
		else
		{
			sbNewRepresentation.append( sElement );
		}
		sbNewRepresentation.append( "," ); //$NON-NLS-1$
	}
	return sbNewRepresentation.toString( ).substring( 0,
			sbNewRepresentation.length( ) - 1 );
}
 
Example 12
Source Project: birt   Source File: ColorBuilder.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Parses the input string to a GRB object.
 * 
 * @param string
 *            The input string.
 * @return The RGB object represented the string.
 */
protected RGB parseString( String string )
{
	int colors[] = ColorUtil.getRGBs( string );
	if ( colors != null )
		return new RGB( colors[0], colors[1], colors[2] );

	StringTokenizer st = new StringTokenizer( string, " ,()" );//$NON-NLS-1$
	if ( !st.hasMoreTokens( ) )
		return null;
	int[] rgb = new int[]{
			0, 0, 0
	};
	int index = 0;
	while ( st.hasMoreTokens( ) )
	{
		try
		{
			rgb[index] = Integer.decode( st.nextToken( ) ).intValue( );
			if ( rgb[index] < 0 || rgb[index] > 255 )
				return null;
			index++;
		}
		catch ( Exception e )
		{
			return null;
		}
	}
	return new RGB( rgb[0], rgb[1], rgb[2] );
}
 
Example 13
Source Project: birt   Source File: WorkspaceClassPathFinder.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public String getClassPath( String projects )
{
	if ( projects == null || projects.length( ) == 0 )
	{
		return null;
	}

	StringBuffer wbuf = new StringBuffer( );

	StringTokenizer token = new StringTokenizer( projects,
			PROPERTYSEPARATOR );
	boolean hasHeader = false;
	while ( token.hasMoreTokens( ) )
	{
		String projectName = token.nextToken( );
		List paths = getProjectPaths( projectName );
		for ( int i = 0; i < paths.size( ); i++ )
		{
			String url = (String) paths.get( i );
			if ( url != null && url.length( ) != 0 )
				if ( i == 0 && !hasHeader )
				{
					wbuf.append( url );
					hasHeader = true;
				}
				else
				{
					wbuf.append( PROPERTYSEPARATOR + url );
				}
		}

	}

	return wbuf.toString( );
}
 
Example 14
Source Project: birt   Source File: ColorBuilder.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Parses the input string to a GRB object.
 * 
 * @param string
 *            The input string.
 * @return The RGB object represented the string.
 */
protected RGB parseString( String string )
{
	int colors[] = ColorUtil.getRGBs( string );
	if ( colors != null )
		return new RGB( colors[0], colors[1], colors[2] );

	StringTokenizer st = new StringTokenizer( string, " ,()" );//$NON-NLS-1$
	if ( !st.hasMoreTokens( ) )
		return null;
	int[] rgb = new int[]{
			0, 0, 0
	};
	int index = 0;
	while ( st.hasMoreTokens( ) )
	{
		try
		{
			rgb[index] = Integer.decode( st.nextToken( ) ).intValue( );
			if ( rgb[index] < 0 || rgb[index] > 255 )
				return null;
			index++;
		}
		catch ( Exception e )
		{
			return null;
		}
	}
	return new RGB( rgb[0], rgb[1], rgb[2] );
}
 
Example 15
Source Project: birt   Source File: NavTree.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Adds nodes with full path and display name.
 * 
 * @param nodePath
 *            Full path is used to search. Every section of path is stored
 *            in item's data.
 * @param displayName
 *            Name is used to display only. If null or blank, use current
 *            path instead.
 */
public boolean addNode( String nodePath, String displayName )
{
	StringTokenizer stk = new StringTokenizer( nodePath, SEPARATOR );
	TreeItem currentItem = null;
	while ( stk.hasMoreTokens( ) )
	{
		String str = stk.nextToken( );
		currentItem = findAndAdd( str, currentItem, displayName );
	}
	return true;
}
 
Example 16
Source Project: birt   Source File: NavTree.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Finds tree item according to full path.
 * 
 * @param nodePath
 *            Full path with <code>NavTree.SEPARATOR</code>.
 * @return TreeItem or null if not found
 */
public TreeItem findTreeItem( String nodePath )
{
	if ( nodePath == null )
	{
		return null;
	}
	StringTokenizer tokens = new StringTokenizer( nodePath,
			NavTree.SEPARATOR );
	TreeItem item = null;
	TreeItem[] children = getItems( );
	while ( tokens.hasMoreTokens( ) )
	{
		String nodeText = tokens.nextToken( );
		if ( children.length == 0 )
		{
			return item;
		}

		boolean isFound = false;
		for ( int i = 0; i < children.length; i++ )
		{
			if ( children[i].getData( ).equals( nodeText ) )
			{
				isFound = true;
				item = children[i];
				children = item.getItems( );
				break;
			}
		}
		if ( !isFound )
		{
			return null;
		}
	}
	return item;
}
 
Example 17
public static Comparator<AbstractDocument> getComparator(String sort) {
	StringTokenizer st = new StringTokenizer(sort, ",", false);
	List<DocumentComparator> comparators = new ArrayList<DocumentComparator>();

	while (st.hasMoreTokens()) {
		String token = st.nextToken().trim();
		String field = token.substring(0, token.indexOf(' '));
		boolean asc = "asc".equals(token.substring(token.indexOf(' ') + 1));

		DocumentComparator comp = null;
		if ("filename".equals(field))
			comp = FILENAME_SORT;
		else if ("id".equals(field))
			comp = ID_SORT;
		else if ("fileSize".equals(field))
			comp = FILESIZE_SORT;
		else if ("version".equals(field))
			comp = VERSION_SORT;
		else if ("fileVersion".equals(field))
			comp = FILEVERSION_SORT;
		else if ("lastModified".equals(field))
			comp = LASTMODIFIED_SORT;
		else if ("published".equals(field))
			comp = PUBLISHED_SORT;
		else if ("created".equals(field))
			comp = CREATED_SORT;
		else if ("created".equals(field))
			comp = CUSTOMID_SORT;
		else if ("type".equals(field))
			comp = TYPE_SORT;
		else if ("comment".equals(field))
			comp = COMMENT_SORT;
		else if ("workflowStatus".equals(field))
			comp = WFSTATUS_SORT;
		else if ("startPublishing".equals(field))
			comp = STARTPUB_SORT;
		else if ("stopPublishing".equals(field))
			comp = STOPPUB_SORT;
		else if ("publishedStatus".equals(field))
			comp = PUBSTATUS_SORT;
		else if (field.startsWith("ext_"))
			comp = newComparatorForExtendedAttribute(field.substring(field.indexOf('_') + 1));

		if (comp != null && asc)
			comparators.add(comp);
		else if (comp != null && !asc)
			comparators.add(descending(comp));
	}

	return getComparator(comparators);
}
 
Example 18
Source Project: birt   Source File: StockSeriesImpl.java    License: Eclipse Public License 1.0 4 votes vote down vote up
private String getConvertedOrthogonalSampleDataRepresentation(
		String sOldRepresentation )
{
	StringTokenizer strtok = new StringTokenizer( sOldRepresentation, "," ); //$NON-NLS-1$
	NumberFormat nf = NumberFormat.getNumberInstance( );
	StringBuffer sbNewRepresentation = new StringBuffer( "" ); //$NON-NLS-1$
	int iValueCount = 0;
	while ( strtok.hasMoreTokens( ) )
	{
		String sElement = strtok.nextToken( ).trim( );
		try
		{
			if ( nf.parse( sElement ).doubleValue( ) < 0 )
			{
				// If the value is negative, use an arbitrary positive value
				sElement = String.valueOf( 4.0 + iValueCount );
				iValueCount++;
			}
		}
		catch ( ParseException e )
		{
			sElement = String.valueOf( 4.0 + iValueCount );
			iValueCount++;
		}
		sbNewRepresentation.append( "H" ); //$NON-NLS-1$
		sbNewRepresentation.append( sElement );
		sbNewRepresentation.append( " " ); //$NON-NLS-1$

		sbNewRepresentation.append( " L" ); //$NON-NLS-1$
		sbNewRepresentation.append( sElement );
		sbNewRepresentation.append( " " ); //$NON-NLS-1$

		sbNewRepresentation.append( " O" ); //$NON-NLS-1$
		sbNewRepresentation.append( sElement );
		sbNewRepresentation.append( " " ); //$NON-NLS-1$

		sbNewRepresentation.append( " C" ); //$NON-NLS-1$
		sbNewRepresentation.append( sElement );
		sbNewRepresentation.append( "," ); //$NON-NLS-1$
	}
	return sbNewRepresentation.toString( ).substring( 0,
			sbNewRepresentation.length( ) - 1 );
}
 
Example 19
Source Project: birt   Source File: ReportLocationListener.java    License: Eclipse Public License 1.0 4 votes vote down vote up
public void changing( LocationEvent event )
{
	if ( event.location.startsWith( "birt://" ) ) //$NON-NLS-1$
	{
		try
		{
			String urlstr = URLDecoder.decode( event.location, "UTF-8" ); //$NON-NLS-1$
			urlstr = urlstr.substring( urlstr.indexOf( "?" ) + 1 ); //$NON-NLS-1$
			StringTokenizer st = new StringTokenizer( urlstr, "&" ); //$NON-NLS-1$

			final Map options = new HashMap( );
			while ( st.hasMoreTokens( ) )
			{
				String option = st.nextToken( );
				int index = option.indexOf( "=" ); //$NON-NLS-1$
				if ( index > 0 )
				{
					options.put( option.substring( 0, index ),
							URLDecoder.decode( option.substring( index + 1,
									option.length( ) ), "UTF-8" ) ); //$NON-NLS-1$
				}
				else
				{
					options.put( option, "" ); //$NON-NLS-1$
				}
			}
			event.doit = false;
			Display.getCurrent( ).asyncExec( new Runnable( ) {

				public void run( )
				{
					viewer.setReportDesignFile( (String) options.get( "__report" ) ); //$NON-NLS-1$
					viewer.setParamValues( options );
					viewer.setCurrentPage( 1 );
					viewer.render( );
				}
			} );
		}
		catch ( UnsupportedEncodingException e )
		{
		}
	}

}
 
Example 20
Source Project: birt   Source File: ColorHelper.java    License: Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Extracts the foreground (RGB String), background (RGB String), bold
 * (boolean String) from the given preference string.
 * 
 * @param preference
 *            should be in the form of Foreground RGB String | Background
 *            RGB String | Bold true/false | Italic true/false |
 *            Strikethrough true/false | Underline true/false
 * @return String[] where String[0] = Foreground RGB String, String[1] =
 *         Background RGB String, String[2] = Bold true/false, 3 = Italic
 *         true/false, 4 = Strikethrough true/false, 5 = Underline
 *         true/false; indexes 2-4 may be null if we ran into problems
 *         extracting
 */
public static String[] unpackStylePreferences( String preference )
{
	String[] stylePrefs = new String[6];
	if ( preference != null )
	{
		StringTokenizer st = new StringTokenizer( preference,
				STYLE_SEPARATOR );
		if ( st.hasMoreTokens( ) )
		{
			String foreground = st.nextToken( ).trim( );
			stylePrefs[0] = foreground;
		}
		else
		{
			stylePrefs[0] = NULL;
		}
		if ( st.hasMoreTokens( ) )
		{
			String background = st.nextToken( ).trim( );
			stylePrefs[1] = background;
		}
		else
		{
			stylePrefs[1] = NULL;
		}

		if ( st.hasMoreTokens( ) )
		{
			String bold = st.nextToken( ).trim( );
			stylePrefs[2] = Boolean.valueOf( bold ).toString( );
		}
		else
		{
			stylePrefs[2] = Boolean.FALSE.toString( );
		}
		if ( st.hasMoreTokens( ) )
		{
			String italic = st.nextToken( ).trim( );
			stylePrefs[3] = Boolean.valueOf( italic ).toString( );
		}
		else
		{
			stylePrefs[3] = Boolean.FALSE.toString( );
		}
		if ( st.hasMoreTokens( ) )
		{
			String strikethrough = st.nextToken( ).trim( );
			stylePrefs[4] = Boolean.valueOf( strikethrough ).toString( );
		}
		else
		{
			stylePrefs[4] = Boolean.FALSE.toString( );
		}
		if ( st.hasMoreTokens( ) )
		{
			String underline = st.nextToken( ).trim( );
			stylePrefs[5] = Boolean.valueOf( underline ).toString( );
		}
		else
		{
			stylePrefs[5] = Boolean.FALSE.toString( );
		}
	}

	return stylePrefs;
}
 
Example 21
Source Project: birt   Source File: ReportLauncherUtils.java    License: Eclipse Public License 1.0 4 votes vote down vote up
public static HashMap getAutoStartPlugins( boolean useDefault,
		String customAutoStart )
{
	HashMap list = new HashMap( );
	if ( true )
	// !PDECore.getDefault( ).getModelManager( ).isOSGiRuntime( ) )
	{
		list.put( "org.eclipse.core.boot", Integer.valueOf( 0 ) ); //$NON-NLS-1$
	}
	else
	{
		String bundles = null;
		if ( useDefault )
		{
			Properties prop = getConfigIniProperties( getEclipseHome( ).toOSString( ),
					"configuration/config.ini" ); //$NON-NLS-1$
			if ( prop != null )
				bundles = prop.getProperty( "osgi.bundles" ); //$NON-NLS-1$
			if ( prop == null || bundles == null )
			{
				String path = getOSGiPath( );
				if ( path != null )
					prop = getConfigIniProperties( path,
							"eclipse.properties" ); //$NON-NLS-1$
				if ( prop != null )
					bundles = prop.getProperty( "osgi.bundles" ); //$NON-NLS-1$
			}
		}
		else
		{
			bundles = customAutoStart;
		}
		if ( bundles != null )
		{
			StringTokenizer tokenizer = new StringTokenizer( bundles, "," ); //$NON-NLS-1$
			while ( tokenizer.hasMoreTokens( ) )
			{
				String token = tokenizer.nextToken( ).trim( );
				int index = token.indexOf( '@' );
				if ( index == -1 || index == token.length( ) - 1 )
					continue;
				String start = token.substring( index + 1 );
				if ( start.indexOf( "start" ) != -1 || !useDefault ) { //$NON-NLS-1$
					Integer level = index != -1 ? getStartLevel( start )
							: new Integer( -1 );
					list.put( index != -1 ? token.substring( 0,
							token.indexOf( '@' ) ) : token, level );
				}
			}
		}
	}
	return list;
}