com.ibm.icu.util.ULocale Java Examples

The following examples show how to use com.ibm.icu.util.ULocale. 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
Source File: BaseTestCase.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Opens design file providing the file name and the locale.
 * 
 * @param fileName
 *            the design file to be opened
 * @param locale
 *            the user locale
 * @param inSingleJarMode
 *            <code>true</code> if open the design that is in the single
 *            jar. Otherwise <code>false</code>.
 * @throws DesignFileException
 *             if any exception.
 */

protected void openDesign( String fileName, ULocale locale,
		boolean inSingleJarMode ) throws DesignFileException
{
	if ( inSingleJarMode )
		fileName = INPUT_FOLDER + fileName;

	if ( engine == null )
	{
		engine = new DesignEngine( new DesignConfig( ) );
		resetMetadata( );
	}
	sessionHandle = engine.newSessionHandle( locale );
	assertNotNull( sessionHandle );

	if ( inSingleJarMode )
		designHandle = sessionHandle.openDesign( getResource( fileName )
				.toString( ) );
	else
		designHandle = sessionHandle.openDesign( fileName );

	design = (ReportDesign) designHandle.getModule( );
}
 
Example #2
Source File: Messages.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public static ResourceBundle getResourceBundle( ULocale locale )
{
	if ( locale == null )
	{
		return RESOURCE_BUNDLE;
	}
	ResourceBundle bundle = hmLocalToBundle.get( locale );

	if ( bundle == null )
	{
		bundle = getMatchedResourceBundle( locale,
				ENGINE_EXTENSION,
				Messages.class );
		if ( bundle != null )
		{
			hmLocalToBundle.put( locale, bundle );
		}
	}

	return bundle;
}
 
Example #3
Source File: TableItemHandleTest.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Test suppressduplicate in table row
 * @throws Exception
 */
public void testSuppressDuplicatesProp( ) throws Exception
{
	SessionHandle session = DesignEngine.newSession( ULocale.ENGLISH );
	designHandle = session.createDesign( );
	design = (ReportDesign) designHandle.getModule( );

	RowHandle row = designHandle.getElementFactory( ).newTableRow( 3 );
	assertFalse( row.suppressDuplicates( ) );
	row.setSuppressDuplicates( true );
	assertTrue( row.suppressDuplicates( ) );
	designHandle.getCommandStack( ).undo( );
	assertFalse( row.suppressDuplicates( ) );
	designHandle.getCommandStack( ).redo( );
	assertTrue( row.suppressDuplicates( ) );

}
 
Example #4
Source File: FormatPercentNumPattern.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the default percent symbol position for given locale
 * 
 * @param locale
 * @return
 */
public static String getDefaultSymbolPosition( ULocale locale )
{
	if ( locale == null )
	{
		locale = ULocale.getDefault( );
	}

	NumberFormat formater = NumberFormat.getPercentInstance( locale );
	String result = formater.format( 1 );
	if ( result.endsWith( "%" ) ) //$NON-NLS-1$
	{
		return FormatNumberPattern.SYMBOL_POSITION_AFTER;
	}
	else
	{
		return FormatNumberPattern.SYMBOL_POSITION_BEFORE;
	}
}
 
Example #5
Source File: ArgumentInfo.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the display name for the property if the resource key of display
 * name is defined. Otherwise, return empty string.
 * 
 * @return the user-visible, localized display name for the property
 */

public String getDisplayName( )
{
	if ( displayNameKey != null )
	{
		String displayName = null;
		if ( messages == null )
		{
			displayName = ModelMessages.getMessage( this.displayNameKey );
		}
		else
		{
			ULocale locale = ThreadResources.getLocale( );
			displayName = messages.getMessage( displayNameKey, locale );
		}
		if ( displayName != null )
		{
			return displayName;
		}
	}
	return name;
}
 
Example #6
Source File: ReportDataServiceProvider.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private StyleHandle[] getAllStyleHandles( )
{
	List<StyleHandle> sLst = getReportDesignHandle( ).getAllStyles( );
	StyleHandle[] list = sLst.toArray( new StyleHandle[sLst.size( )] );
	Arrays.sort( list, new Comparator<StyleHandle>( ) {

		Collator collator = Collator.getInstance( ULocale.getDefault( ) );

		public int compare( StyleHandle s1, StyleHandle s2 )
		{
			return collator.compare( s1.getDisplayLabel( ),
					s2.getDisplayLabel( ) );
		}

	} );
	return list;
}
 
Example #7
Source File: CalendarUtil.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a calendar type for the given locale.
 * When the given locale has calendar keyword, the
 * value of calendar keyword is returned.  Otherwise,
 * the default calendar type for the locale is returned.
 * @param loc The locale
 * @return Calendar type string, such as "gregorian"
 */
public static String getCalendarType(ULocale loc) {
    String calType = loc.getKeywordValue(CALKEY);
    if (calType != null) {
        return calType;
    }

    // Canonicalize, so grandfathered variant will be transformed to keywords
    ULocale canonical = ULocale.createCanonical(loc.toString());
    calType = canonical.getKeywordValue(CALKEY);
    if (calType != null) {
        return calType;
    }

    // When calendar keyword is not available, use the locale's
    // region to get the default calendar type
    String region = ULocale.getRegionForSupplementalData(canonical, true);
    return CalendarPreferences.INSTANCE.getCalendarTypeForRegion(region);
}
 
Example #8
Source File: SeriesNameFormat.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param unitType
 */
public SeriesNameDateFormat( GroupingUnitType unitType, ULocale loc,
		boolean keepHierarchy )
{
	this.unitType = unitType;
	dfWrapper = DateFormatWrapperFactory.getPreferredDateFormat( GroupingUtil.groupingUnit2CDateUnit( unitType ),
			loc,
			keepHierarchy );
}
 
Example #9
Source File: BreakIteratorFactory.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
@Override
public BreakIterator createBreakIterator(ULocale locale, int kind) {
// TODO: convert to ULocale when service switches over
    if (service.isDefault()) {
        return createBreakInstance(locale, kind);
    }
    ULocale[] actualLoc = new ULocale[1];
    BreakIterator iter = (BreakIterator)service.get(locale, kind, actualLoc);
    iter.setLocale(actualLoc[0], actualLoc[0]); // services make no distinction between actual & valid
    return iter;
}
 
Example #10
Source File: CustomColorHandleTest.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @throws DesignFileException
 */
public void testSemanticErrors( ) throws DesignFileException
{
	openDesign( SEMANTIC_CHECK_FILE_NAME, ULocale.ENGLISH ); 
	List errors = design.getErrorList( );

	assertEquals( 2, errors.size( ) );
}
 
Example #11
Source File: Regression_245931.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void test_regression_245931() throws SemanticException {
	DesignEngine engine = new DesignEngine(new DesignConfig());
	SessionHandle session = engine.newSessionHandle(ULocale.ENGLISH);
	LibraryHandle libraryHandle = session.createLibrary();

	AutoTextHandle autoTextHandle = libraryHandle.getElementFactory()
			.newAutoText("autotext1");
	autoTextHandle
			.setAutoTextType(DesignChoiceConstants.AUTO_TEXT_PAGE_NUMBER);

	assertEquals("Page Number", autoTextHandle.getDisplayLabel());

}
 
Example #12
Source File: ChartReportStyleProcessor.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * The constructor. Default not using cache.
 * 
 * @param handle
 * @param useCache
 *            specify if use cache.
 * @param uLocale
 * @param style
 */
public ChartReportStyleProcessor( DesignElementHandle handle,
		boolean useCache,
		org.eclipse.birt.report.engine.content.IStyle dstyle, int dpi, ULocale uLocale )
{
	this.handle = handle;
	this.useCache = useCache;
	this.dstyle = dstyle;
	this.dpi = dpi;
	this.uLocale = uLocale;
	// Set concrete style processor proxy according to current context.
	this.setStyleProcessorProxy( ChartReportStyleProcessor.getChartStyleProcessorProxy( this ) );
}
 
Example #13
Source File: CoreTestUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gets the session locale.
 * 
 * @param session
 * @return the session locale
 */

public static ULocale getSessionLocale( DesignSession session )
{
	if ( session == null )
		return ULocale.getDefault( );
	return session.locale;
}
 
Example #14
Source File: ListFormatter.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
public ListFormatter get(ULocale locale, String style) {
    String key = String.format("%s:%s", locale.toString(), style);
    ListFormatter result = cache.get(key);
    if (result == null) {
        result = load(locale, style);
        cache.put(key, result);
    }
    return result;
}
 
Example #15
Source File: LibraryHandleTest.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Test cases:
 * 
 * A new element from factory of library handle can be added into the
 * library directly.
 * 
 * @throws Exception
 *             no exception thrown
 */

public void testMakeUniqueName( ) throws Exception
{
	libraryHandle = createLibrary( ULocale.ENGLISH );
	ElementFactory libFactory = libraryHandle.getElementFactory( );

	TableHandle tableHandle = libFactory.newTableItem( null );
	assertEquals( "NewTable", tableHandle.getName( ) ); //$NON-NLS-1$

	tableHandle = libFactory.newTableItem( null );
	assertEquals( "NewTable1", tableHandle.getName( ) ); //$NON-NLS-1$

	tableHandle = libFactory.newTableItem( "NewTable2" ); //$NON-NLS-1$
	libraryHandle.getComponents( ).add( tableHandle );

	tableHandle = libFactory.newTableItem( "NewTable2" ); //$NON-NLS-1$
	assertEquals( "NewTable21", tableHandle.getName( ) ); //$NON-NLS-1$

	libraryHandle.getComponents( ).add( tableHandle );

	tableHandle = libraryHandle.getElementFactory( ).newTableItem( null );
	tableHandle.setName( null );

	assertNull( tableHandle.getName( ) );

	libraryHandle.rename( tableHandle );
	assertEquals( "NewTable", tableHandle.getName( ) ); //$NON-NLS-1$
}
 
Example #16
Source File: Regression_118361.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @throws ContentException
 * @throws NameException
 */

public void test_regression_118361( ) throws ContentException, NameException
{
	DesignEngine engine = new DesignEngine( new DesignConfig( ) );
	SessionHandle session = engine.newSessionHandle( ULocale.ENGLISH );
	ReportDesignHandle designHandle = session.createDesign( );

	ElementFactory factory = designHandle.getElementFactory( );
	SimpleMasterPageHandle page = factory.newSimpleMasterPage( "oldName" ); //$NON-NLS-1$

	designHandle.getMasterPages( ).add( page );

	MasterPageHandle pageHandle = designHandle.findMasterPage( "oldName" ); //$NON-NLS-1$
	try
	{
		pageHandle.setName( "newName" ); //$NON-NLS-1$

		//makeOutputDir( );
		//designHandle.saveAs( this.getFullQualifiedClassName( ) + "/" + OUTPUT_FOLDER
		//		+ "/" + "regression_118361.out" ); //$NON-NLS-1$
		String TempFile=this.genOutputFile(outFileName);
		designHandle.saveAs( TempFile );
	}
	catch ( Exception e )
	{
		// if rename failed, the case failed.

		fail( );
	}

}
 
Example #17
Source File: BaseTestCase.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Opens design file as resource with the given locale.
 * 
 * @param fileName
 *            the file name without path
 * @param locale
 *            the given locale
 * @throws DesignFileException
 *             if any exception.
 */

protected void openDesignAsResource(Class theClass, String fileName,
		ULocale locale) throws DesignFileException {
	fileName = PLUGIN_PATH + this.getFullQualifiedClassName()
			+ INPUT_FOLDER + fileName;
	sessionHandle = new DesignEngine(new DesignConfig())
			.newSessionHandle(ULocale.ENGLISH);
	assertNotNull(sessionHandle);

	InputStream stream = theClass.getResourceAsStream(fileName);
	designHandle = sessionHandle.openDesign(fileName, stream);
	design = (ReportDesign) designHandle.getModule();
}
 
Example #18
Source File: Messages.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param key
 * @param oa
 * @param lcl
 */
public static String getString( String key, Object[] oa, ULocale lcl )
{
	try
	{
		return SecurityUtil.formatMessage( getResourceBundle( lcl ).getString( key ),
				oa );
	}
	catch ( MissingResourceException e )
	{
		e.printStackTrace( );
		return '!' + key + '!';
	}
}
 
Example #19
Source File: AutoDataBindingViewer.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void paintControl( PaintEvent e )
{
	idr.setProperty( IDeviceRenderer.GRAPHICS_CONTEXT, e.gc );
	Composite co = (Composite) e.getSource( );
	Rectangle re = co.getClientArea( );
	Bounds bo = BoundsImpl.create( 0, 0, re.width, re.height );
	bo.scale( 72d / idr.getDisplayServer( ).getDpiResolution( ) );
	
	RunTimeContext context = new RunTimeContext( );
	context.setULocale( ULocale.getDefault( ) );
	
	String[] set = {
			"Items", "Amounts"};//$NON-NLS-1$ //$NON-NLS-2$
	Object[][] data = {
			{
					"A", "B", "C"//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
			}, {
					Integer.valueOf( 7 ), Integer.valueOf( 2 ), Integer.valueOf( 5 )
			}
	};
	dree = new SimpleDataRowExpressionEvaluator( set, data );
	Generator gr = Generator.instance( );
	try
	{
		gr.bindData( dree, cm, context );
		gr.render( idr, gr.build( idr.getDisplayServer( ),
				cm,
				bo,
				null,
				context,
				null ) );
	}
	catch ( ChartException ce )
	{
		ce.printStackTrace( );
	}
}
 
Example #20
Source File: AlphabeticIndex.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Add more index characters (aside from what are in the locale)
 * @param additions additional characters to add to the index, such as those in Swedish.
 * @return this, for chaining
 * @stable ICU 4.8
 */
public AlphabeticIndex<V> addLabels(ULocale... additions) {
    for (ULocale addition : additions) {
        addIndexExemplars(addition);
    }
    buckets = null;
    return this;
}
 
Example #21
Source File: FormatBuilder.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void setInputFormat( String formatCategroy, String formatPattern,
		ULocale formatLocale )
{
	assert !StringUtil.isBlank( formatCategroy );
	this.formatCategory = formatCategroy;
	this.formatPattern = formatPattern;
	this.formatLocale = formatLocale;
}
 
Example #22
Source File: ModuleOption.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Sets the locale.
 * 
 * @param locale
 *            the locale
 */

public void setLocale( ULocale locale )
{
	if ( locale != null )
		options.put( LOCALE_KEY, locale );
}
 
Example #23
Source File: ULocalePropertyType.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public String toString( Module module, PropertyDefn defn, Object value )
{
	if ( value == null )
		return null;

	if ( value instanceof String )
		return (String) value;

	return ( (ULocale) value ).toString( );

}
 
Example #24
Source File: Regression_130271.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @throws Exception
 * @throws Exception
 */

public void test_regression_130271( ) throws Exception
{
	
	openLibrary( LIBRARY );
	DataSourceHandle datasource = libraryHandle
			.findDataSource( "Data Source" );//$NON-NLS-1$
	DataSetHandle dataset = libraryHandle.findDataSet( "Data Set" );//$NON-NLS-1$

	sessionHandle = new DesignEngine( new DesignConfig( ) )
			.newSessionHandle( ULocale.ENGLISH );
	designHandle = sessionHandle.createDesign( );

	openDesign( INPUT );
	
//	String filename = this.getClassFolder() + "/" + INPUT_FOLDER + "/" + INPUT;
//	designHandle.setFileName( filename );

	designHandle.includeLibrary( LIBRARY, "lib" );//$NON-NLS-1$
	DataSourceHandle dsource = (DataSourceHandle) designHandle
			.getElementFactory( ).newElementFrom( datasource, "dsource" );//$NON-NLS-1$
	DataSetHandle dset = (DataSetHandle) designHandle.getElementFactory( )
			.newElementFrom( dataset, "dset" );//$NON-NLS-1$

	designHandle.getDataSources( ).add( dsource );
	designHandle.getDataSets( ).add( dset );

	String TempFile=this.genOutputFile(OUTPUT);
	designHandle.saveAs( TempFile );
	assertTrue( super.compareTextFile( GOLDEN, OUTPUT ) );
}
 
Example #25
Source File: DateFormatterTest.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
@Test
   public void testGetPattern( )
{
	Locale locale = new Locale( "en", "us" );
	DateFormatter sample = new DateFormatter( "MM/dd/yyyy hh:mm:ss a",
			ULocale.forLocale(locale) );
	assertEquals( "MM/dd/yyyy hh:mm:ss a", sample.getPattern( ) );
}
 
Example #26
Source File: LibraryCompoundElementTest.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Tests writing the properties.
 * 
 * @throws Exception
 *             if any error found.
 */

public void testWriter( ) throws Exception
{
	openDesign( INPUT1, ULocale.ENGLISH );

	// verify the overridden color in the design.

	TableHandle bodyTable = (TableHandle) designHandle
			.findElement( "table1" ); //$NON-NLS-1$
	assertEquals( "New Design Table", bodyTable.getCaption( ) ); //$NON-NLS-1$

	RowHandle bodyRow = (RowHandle) bodyTable.getDetail( ).get( 1 );
	bodyRow.getPrivateStyle( ).getColor( ).setStringValue(
			ColorPropertyType.FUCHSIA );
	bodyRow.getHeight( ).setAbsolute( 1.1 );
	bodyRow.setBookmark( "http://www.eclipse.org/birt" ); //$NON-NLS-1$

	CellHandle bodyCell = (CellHandle) bodyRow.getCells( ).get( 0 );
	bodyCell.getPrivateStyle( ).getColor( ).setStringValue(
			ColorPropertyType.RED );

	TableHandle bodyInnerTable = (TableHandle) bodyCell.getContent( ).get(
			0 );
	bodyInnerTable.setName( "New Table" ); //$NON-NLS-1$
	bodyInnerTable.setStyleName( "new_style" ); //$NON-NLS-1$
	RowHandle bodyInnerRow = (RowHandle) bodyInnerTable.getHeader( )
			.get( 0 );
	CellHandle bodyInnerCell = (CellHandle) bodyInnerRow.getCells( )
			.get( 0 );

	bodyInnerCell.getPrivateStyle( ).getColor( ).setStringValue(
			ColorPropertyType.NAVY );

	// ensure that style and name is written out.

	save( );
	assertTrue( compareFile( GOLDEN_FILE ) );
}
 
Example #27
Source File: Messages.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param key
 * @param oa
 * @param lcl
 */
public static String getString( String key, Object[] oa, ULocale lcl )
{
	try
	{
		return SecurityUtil.formatMessage( getResourceBundle( lcl ).getString( key ),
				oa );
	}
	catch ( MissingResourceException e )
	{
		e.printStackTrace( );
		return '!' + key + '!';
	}
}
 
Example #28
Source File: Messages.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param key
 * @param lcl
 */
public static String getString( String key, ULocale lcl )
{
	try
	{
		return getResourceBundle( lcl ).getString( key );
	}
	catch ( MissingResourceException e )
	{
		return '!' + key + '!';
	}
}
 
Example #29
Source File: ReportDesignHandleTest.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 
 * @throws Exception
 */
public void testEmbeddedImage( ) throws Exception
{
	openDesign( "EmbeddedImageTest.xml", ULocale.ENGLISH ); //$NON-NLS-1$
	PropertyHandle images = designHandle
			.getPropertyHandle( ReportDesign.IMAGES_PROP );
	assertNotNull( images );

	// get the embedded images

	EmbeddedImageHandle image1 = (EmbeddedImageHandle) images.getAt( 0 );
	EmbeddedImageHandle image2 = (EmbeddedImageHandle) images.getAt( 1 );
	String image1Name = image1.getName( );
	String image2Name = image2.getName( );
	ArrayList imageList = new ArrayList( );
	imageList.add( image1 );
	imageList.add( image2 );
	designHandle.dropImage( imageList );

	// undo and test again
	design.getActivityStack( ).undo( );
	image1 = (EmbeddedImageHandle) images.getAt( 0 );
	image2 = (EmbeddedImageHandle) images.getAt( 1 );

	design.getActivityStack( ).redo( );
	assertNull( images.getListValue( ) );
	try
	{
		designHandle.dropImage( image1Name );
		designHandle.dropImage( image2Name );
		fail( );
	}
	catch ( PropertyValueException e )
	{
		assertEquals(
				PropertyValueException.DESIGN_EXCEPTION_ITEM_NOT_FOUND, e
						.getErrorCode( ) );
	}
}
 
Example #30
Source File: MessageFormat.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the locale to be used for creating argument Format objects.
 * This affects subsequent calls to the {@link #applyPattern applyPattern}
 * method as well as to the <code>format</code> and
 * {@link #formatToCharacterIterator formatToCharacterIterator} methods.
 *
 * @param locale the locale to be used when creating or comparing subformats
 * @stable ICU 3.2
 */
public void setLocale(ULocale locale) {
    /* Save the pattern, and then reapply so that */
    /* we pick up any changes in locale specific */
    /* elements */
    String existingPattern = toPattern();                       /*ibm.3550*/
    this.ulocale = locale;
    // Invalidate all stock formatters. They are no longer valid since
    // the locale has changed.
    stockDateFormatter = null;
    stockNumberFormatter = null;
    pluralProvider = null;
    ordinalProvider = null;
    applyPattern(existingPattern);                              /*ibm.3550*/
}