List of usage examples for java.util Locale getLanguage
public String getLanguage()
From source file:de.xwic.appkit.webbase.table.DefaultColumnLabelProvider.java
@Override public void initialize(TimeZone timeZone, Locale locale, String dateFormat, String timeFormat, Column col) { this.locale = locale; this.column = col.getListColumn(); this.entityClass = col.getEntityClass(); this.customProperty = column.getPropertyId().startsWith("#"); final Property finalProperty = column.getFinalProperty(); if (customProperty && null == finalProperty) { return;/*from w w w . j av a 2 s . c om*/ } if (finalProperty.isEntity() && finalProperty.getEntityType().equals(IPicklistEntry.class.getName())) { isPicklistEntry = true; } switch (finalProperty.getDateType()) { case Property.DATETYPE_DATETIME: if (dateFormat != null && timeFormat != null) { dateFormatter = new SimpleDateFormat(dateFormat + " " + timeFormat); } else if (Locale.GERMAN.getLanguage().equals(locale.getLanguage())) { dateFormatter = new SimpleDateFormat("dd.MM.yyyy HH:mm"); } else { dateFormatter = new SimpleDateFormat("dd-MMM-yyyy hh:mm a", locale); } dateFormatter.setTimeZone(timeZone); break; case Property.DATETYPE_TIME: if (timeFormat != null) { dateFormatter = new SimpleDateFormat(timeFormat); } else if (Locale.GERMAN.getLanguage().equals(locale.getLanguage())) { dateFormatter = new SimpleDateFormat("HH:mm"); } else { dateFormatter = new SimpleDateFormat("hh:mm a"); } dateFormatter.setTimeZone(timeZone); break; default: if (dateFormat != null) { dateFormatter = new SimpleDateFormat(dateFormat); } else if (Locale.GERMAN.getLanguage().equals(locale.getLanguage())) { dateFormatter = new SimpleDateFormat("dd.MM.yyyy"); } else { dateFormatter = new SimpleDateFormat("dd-MMM-yyyy", locale); } break; } }
From source file:com.frameworkset.platform.cms.driver.i18n.CmsLocaleManager.java
/** * Returns the first matching locale (eventually simplified) from the available locales.<p> * //w ww.j a v a 2 s .c om * @param locales must be an ascending sorted list of locales in order of preference * @param available the available locales to find a match in * * @return the first precise or simplified match */ public Locale getFirstMatchingLocale(List locales, Collection available) { Iterator i; // first try a precise match i = locales.iterator(); while (i.hasNext()) { Locale locale = (Locale) i.next(); if (available.contains(locale)) { // precise match return locale; } } // now try a match only with language and country i = locales.iterator(); while (i.hasNext()) { Locale locale = (Locale) i.next(); if (locale.getVariant().length() > 0) { // the locale has a variant, try to match without the variant locale = new Locale(locale.getLanguage(), locale.getCountry(), ""); if (available.contains(locale)) { // match return locale; } } } // finally try a match only with language i = locales.iterator(); while (i.hasNext()) { Locale locale = (Locale) i.next(); if (locale.getCountry().length() > 0) { // the locale has a country, try to match without the country locale = new Locale(locale.getLanguage(), "", ""); if (available.contains(locale)) { // match return locale; } } } // no match return null; }
From source file:om.edu.squ.squportal.portlet.dps.role.db.RoleDbImpl.java
/** * /*from ww w.j ava 2 s. c om*/ * method name : getRoles * @param formName * @return * RoleDbImpl * return type : List<RoleNameValue> * * purpose : Get list of Roles for a particular form * * Date : Jul 16, 2017 3:24:28 PM */ public List<RoleNameValue> getRoles(String formName, Locale locale) { String PROP_SQL_ROLE_LIST_FORM = queryPropsCommonRole.getProperty(Constants.CONST_PROP_SQL_ROLE_LIST_FORM); RowMapper<RoleNameValue> mapper = new RowMapper<RoleNameValue>() { @Override public RoleNameValue mapRow(ResultSet rs, int rowNum) throws SQLException { RoleNameValue roleNameValue = new RoleNameValue(rs.getInt(Constants.CONST_COLMN_APPROVAL_SEQUENCE), rs.getString(Constants.CONST_COLMN_APPROVER_ROLE_CODE), rs.getString(Constants.CONST_COLMN_APPROVER_ROLE_NAME)); return roleNameValue; } }; Map<String, String> mapParamsRole = new HashMap<String, String>(); mapParamsRole.put("paramFormName", formName); mapParamsRole.put("paramLocale", locale.getLanguage()); return nPJdbcTemplDps.query(PROP_SQL_ROLE_LIST_FORM, mapParamsRole, mapper); }
From source file:de.ingrid.portal.interfaces.impl.WMSInterfaceImpl.java
/** * @see de.ingrid.portal.interfaces.WMSInterface#getWMSSearchURL(java.lang.String) *///from w ww . ja v a 2 s .co m public String getWMSSearchURL(String sessionId, boolean jsEnabled, Locale language) { String searchURL = ""; if (jsEnabled || !mapBenderVersion.equals(MAPBENDER_VERSION_2_1)) { searchURL = config.getString("display_search_url", "http://localhost/mapbender/frames/WMS_Search.php"); } else { // this URL only exists for MapBender 2.1 based Map Viewer searchURL = config.getString("nojs_display_search_url", "http://localhost/mapbender/frames/wms_search_nojs.php"); } if (searchURL.indexOf("?") > 0) { searchURL = searchURL.concat("&PHPSESSID=" + sessionId); } else { searchURL = searchURL.concat("?PHPSESSID=" + sessionId); } if (language != null) { searchURL = searchURL.concat("&" + LANGUAGE_PARAM + "=" + language.getLanguage()); } return searchURL; }
From source file:org.jahia.modules.rolesmanager.RolesAndPermissionsHandler.java
private RoleBean createRoleBean(JCRNodeWrapper role, boolean getPermissions, boolean getSubRoles) throws RepositoryException { RoleBean roleBean = new RoleBean(); JCRNodeWrapper parentRole = JCRContentUtils.getParentOfType(role, "jnt:role"); final String uuid = role.getIdentifier(); roleBean.setUuid(uuid);//from w ww .java2 s.c o m roleBean.setParentUuid(parentRole != null ? parentRole.getIdentifier() : null); roleBean.setName(role.getName()); roleBean.setPath(role.getPath()); roleBean.setDepth(role.getDepth()); JCRNodeWrapper n; Map<String, I18nRoleProperties> i18nRoleProperties = new TreeMap<String, I18nRoleProperties>(); for (Locale l : role.getExistingLocales()) { n = getSession(l).getNodeByIdentifier(uuid); if (!n.hasProperty(Constants.JCR_TITLE) && !n.hasProperty(Constants.JCR_DESCRIPTION)) { i18nRoleProperties.put(l.getLanguage(), null); continue; } I18nRoleProperties properties = new I18nRoleProperties(); properties.setLanguage(l.getDisplayName(LocaleContextHolder.getLocale())); if (n.hasProperty(Constants.JCR_TITLE)) { properties.setTitle(n.getProperty(Constants.JCR_TITLE).getString()); } if (n.hasProperty(Constants.JCR_DESCRIPTION)) { properties.setDescription(n.getProperty(Constants.JCR_DESCRIPTION).getString()); } i18nRoleProperties.put(l.getLanguage(), properties); } roleBean.setI18nProperties(i18nRoleProperties); if (role.hasProperty("j:hidden")) { roleBean.setHidden(role.getProperty("j:hidden").getBoolean()); } String roleGroup = "edit-role"; if (role.hasProperty("j:roleGroup")) { roleGroup = role.getProperty("j:roleGroup").getString(); } RoleType roleType = roleTypes.get(roleGroup); roleBean.setRoleType(roleType); if (getPermissions) { List<String> tabs = new ArrayList<String>(roleBean.getRoleType().getScopes()); Map<String, List<String>> permIdsMap = new HashMap<String, List<String>>(); fillPermIds(role, tabs, permIdsMap, false); Map<String, List<String>> inheritedPermIdsMap = new HashMap<String, List<String>>(); fillPermIds(role.getParent(), tabs, inheritedPermIdsMap, true); Map<String, Map<String, Map<String, PermissionBean>>> permsForRole = new LinkedHashMap<String, Map<String, Map<String, PermissionBean>>>(); roleBean.setPermissions(permsForRole); for (String tab : tabs) { addPermissionsForScope(roleBean, tab, permIdsMap, inheritedPermIdsMap); } if (roleType.getAvailableNodeTypes() != null) { List<String> nodeTypesOnRole = new ArrayList<String>(); if (role.hasProperty("j:nodeTypes")) { for (Value value : role.getProperty("j:nodeTypes").getValues()) { nodeTypesOnRole.add(value.getString()); } } SortedSet<NodeType> nodeTypes = new TreeSet<NodeType>(); for (String s : roleType.getAvailableNodeTypes()) { boolean includeSubtypes = false; if (s.endsWith("/*")) { s = StringUtils.substringBeforeLast(s, "/*"); includeSubtypes = true; } ExtendedNodeType t = NodeTypeRegistry.getInstance().getNodeType(s); nodeTypes.add(new NodeType(t.getName(), t.getLabel(LocaleContextHolder.getLocale()), nodeTypesOnRole.contains(t.getName()))); if (includeSubtypes) { for (ExtendedNodeType sub : t.getSubtypesAsList()) { nodeTypes.add(new NodeType(sub.getName(), sub.getLabel(LocaleContextHolder.getLocale()), nodeTypesOnRole.contains(sub.getName()))); } } } roleBean.setNodeTypes(nodeTypes); } } // sub-roles if (getSubRoles) { final List<JCRNodeWrapper> subRoles = JCRContentUtils.getNodes(role, "jnt:role"); final List<RoleBean> subRoleBeans = new ArrayList<RoleBean>(subRoles.size()); for (JCRNodeWrapper subRole : subRoles) { subRoleBeans.add(createRoleBean(subRole, false, false)); } roleBean.setSubRoles(subRoleBeans); } return roleBean; }
From source file:com.scoreflex.Scoreflex.java
/** * Gets the current language. If language was specified using {@link * Scoreflex.setLang(String)}, this value is returned. Otherwise it is * guessed from the system./*ww w. j a va2 s . co m*/ * * @return The locale in use. */ public static String getLang() { if (null != sLang) return sLang; Locale locale = Locale.getDefault(); if (null == locale) return DEFAULT_LANGUAGE_CODE; String language = locale.getLanguage(); String country = locale.getCountry(); String localeString = String.format("%s_%s", language != null ? language.toLowerCase(Locale.ENGLISH) : "", country != null ? country.toUpperCase(Locale.ENGLISH) : ""); // 1. if no language is specified, return the default language if (null == language) return DEFAULT_LANGUAGE_CODE; // 2. try to match the language or the entire locale string among the // list of available language codes String matchedLanguageCode = null; for (int i = 0; i < VALID_LANGUAGE_CODES.length; i++) { if (VALID_LANGUAGE_CODES[i].equals(localeString)) { // return here as this is the most precise match we can get return localeString; } if (VALID_LANGUAGE_CODES[i].equals(language)) { // set the matched language code, and continue iterating as we // may match the localeString in a later iteration. matchedLanguageCode = language; } } if (null != matchedLanguageCode) return matchedLanguageCode; return DEFAULT_LANGUAGE_CODE; }
From source file:de.ingrid.portal.interfaces.impl.WMSInterfaceImpl.java
/** * @see de.ingrid.portal.interfaces.WMSInterface#getWMSURL(java.lang.String) *///from ww w . j ava2 s . c o m public String getWMSViewerURL(String sessionId, boolean jsEnabled, Locale language) { String viewerURL = ""; if (jsEnabled || !mapBenderVersion.equals(MAPBENDER_VERSION_2_1)) { viewerURL = config.getString("display_viewer_url", "http://localhost/mapbender/frames/WMS_Viewer.php"); } else { // this URL only exists for MapBender 2.1 based Map Viewer viewerURL = config.getString("nojs_display_viewer_url", "http://localhost/mapbender/frames/wms_viewer_nojs.php"); } if (viewerURL.indexOf("?") > 0) { viewerURL = viewerURL.concat("&PHPSESSID=" + sessionId); } else { viewerURL = viewerURL.concat("?PHPSESSID=" + sessionId); } if (language != null) { viewerURL = viewerURL.concat("&" + LANGUAGE_PARAM + "=" + language.getLanguage()); } return viewerURL; }
From source file:com.haulmont.cuba.web.LoginWindow.java
protected Locale resolveLocale(App app) { if (globalConfig.getLocaleSelectVisible()) { String lastLocale = app.getCookieValue(COOKIE_LOCALE); if (lastLocale != null) { for (Locale locale : locales.values()) { if (locale.toLanguageTag().equals(lastLocale)) { return locale; }//from w w w. j a v a 2s .c o m } } } for (Locale locale : locales.values()) { if (locale.equals(app.getLocale())) { return locale; } } // if not found and application locale contains country, try to match by language only if (!StringUtils.isEmpty(app.getLocale().getCountry())) { Locale appLocale = Locale.forLanguageTag(app.getLocale().getLanguage()); for (Locale locale : locales.values()) { if (Locale.forLanguageTag(locale.getLanguage()).equals(appLocale)) { return locale; } } } // return first locale set in the cuba.availableLocales app property return locales.values().iterator().next(); }
From source file:edu.ku.brc.specify.config.SpecifySchemaI18NService.java
@Override public void loadWithLocale(final Byte schemaType, final int disciplineId, final DBTableIdMgr mgr, final Locale locale) { // First do Just Hidden in case a table is missing a title or desc String sql = String.format( "SELECT Name, IsHidden FROM splocalecontainer WHERE SchemaType = %d AND DisciplineID = %d", schemaType, disciplineId);//from w w w .j a va 2 s.c om Vector<Object[]> rows = BasicSQLUtils.query(sql); for (Object[] row : rows) { DBTableInfo ti = mgr.getInfoByTableName(row[0].toString()); if (ti != null) { Boolean isHidden = (Boolean) row[1]; ti.setHidden(isHidden != null ? isHidden : false); } else { log.error("Couldn't find table [" + row[0] + "]"); } } sql = "SELECT cn.Name, Text, cn.Aggregator, cn.IsUIFormatter, cn.Format FROM splocalecontainer cn INNER JOIN splocaleitemstr ON " + "cn.SpLocaleContainerID = splocaleitemstr.SpLocaleContainerNameID where Language = '" + locale.getLanguage() + "' AND " + "cn.SchemaType = " + schemaType + " AND cn.DisciplineID = " + disciplineId; rows = BasicSQLUtils.query(sql); for (Object[] row : rows) { DBTableInfo ti = mgr.getInfoByTableName(row[0].toString()); if (ti != null) { ti.setTitle(row[1].toString()); ti.setAggregatorName(row[2] != null ? row[2].toString() : null); if (row[4] != null) { if (row[3] != null && ((Boolean) row[3])) { ti.setUiFormatter(row[4].toString()); } else { ti.setDataObjFormatter(row[4].toString()); } } } else { log.error("Couldn't find table [" + row[0] + "]"); } } sql = "SELECT cn.Name,Text FROM splocalecontainer cn INNER JOIN splocaleitemstr ON " + "cn.SpLocaleContainerID = splocaleitemstr.SpLocaleContainerDescID where Language = '" + locale.getLanguage() + "' AND " + "cn.SchemaType = " + schemaType + " AND cn.DisciplineID = " + disciplineId; rows = BasicSQLUtils.query(sql); for (Object[] row : rows) { DBTableInfo ti = mgr.getInfoByTableName(row[0].toString()); if (ti != null) { ti.setDescription(StringEscapeUtils.unescapeXml(row[1] != null ? row[1].toString() : null)); } else { log.error("Couldn't find table [" + row[0] + "]"); } } sql = "SELECT cn.Name,splocalecontaineritem.Name,splocalecontaineritem.Format, " + "splocalecontaineritem.IsUIFormatter, splocalecontaineritem.PickListName, splocaleitemstr.Text, " + "splocalecontaineritem.IsHidden, splocalecontaineritem.WebLinkName , splocalecontaineritem.IsRequired " + "FROM splocalecontainer cn INNER JOIN splocalecontaineritem ON cn.SpLocaleContainerID = splocalecontaineritem.SpLocaleContainerID " + "INNER JOIN splocaleitemstr ON splocalecontaineritem.SpLocaleContainerItemID = splocaleitemstr.SpLocaleContainerItemNameID " + " where splocaleitemstr.Language = '" + locale.getLanguage() + "' AND " + "cn.SchemaType = " + schemaType + " AND cn.DisciplineID = " + disciplineId + " order by cn.Name"; log.debug(sql); String name = ""; DBTableInfo ti = null; rows = BasicSQLUtils.query(sql); for (Object[] row : rows) { String nm = row[0].toString(); if (!name.equals(nm)) { ti = mgr.getInfoByTableName(nm); name = nm; } if (ti != null) { DBTableChildIFace tblChild = ti.getItemByName(row[1].toString()); if (tblChild != null) { tblChild.setTitle(row[5] != null ? row[5].toString() : null); Boolean isHidden = (Boolean) row[6]; tblChild.setHidden(isHidden != null ? isHidden : false); } else { log.error("Couldn't find field[" + row[1] + "] for table [" + row[0] + "]"); } if (tblChild instanceof DBFieldInfo) { String format = row[2] == null ? null : row[2].toString(); boolean isUIFmt = row[3] == null ? false : (Boolean) row[3]; String pickListName = row[4] == null ? null : row[4].toString(); String webLinkName = row[7] == null ? null : row[7].toString(); boolean isRequired = row[8] == null ? false : (Boolean) row[8]; DBFieldInfo fieldInfo = (DBFieldInfo) tblChild; fieldInfo.setPickListName(pickListName); fieldInfo.setWebLinkName(webLinkName); fieldInfo.setRequired( fieldInfo.isRequiredInSchema()/*i.e. is required in DB schema*/ || isRequired); if (isUIFmt) { UIFieldFormatterIFace formatter = UIFieldFormatterMgr.getInstance().getFormatter(format); if (formatter != null) { fieldInfo.setFormatter(formatter); } else { log.error("Couldn't find UIFieldFormatter with name [" + format + "]"); } } else if (StringUtils.isNotEmpty(format)) { fieldInfo.setFormatStr(format); } } } else { log.error("Couldn't find table [" + row[0] + "]"); } } Institution inst = AppContextMgr.getInstance().getClassObject(Institution.class); Collection collection = AppContextMgr.getInstance().getClassObject(Collection.class); SpecifyAppContextMgr.setUpCatNumAccessionFormatters(inst, collection); sql = "SELECT cn.Name, splocalecontaineritem.Name, splocaleitemstr.Text, splocalecontaineritem.IsHidden " + "FROM splocalecontainer cn INNER JOIN splocalecontaineritem ON cn.SpLocaleContainerID = splocalecontaineritem.SpLocaleContainerID " + "INNER JOIN splocaleitemstr ON splocalecontaineritem.SpLocaleContainerItemID = splocaleitemstr.SpLocaleContainerItemDescID " + " where splocaleitemstr.Language = '" + locale.getLanguage() + "' AND " + "cn.SchemaType = " + schemaType + " AND cn.DisciplineID = " + disciplineId + " order by cn.Name"; name = ""; ti = null; rows = BasicSQLUtils.query(sql); for (Object[] row : rows) { String nm = row[0].toString(); if (!name.equals(nm)) { ti = mgr.getInfoByTableName(nm); name = nm; } if (ti != null) { DBTableChildIFace tblChild = ti.getItemByName(row[1].toString()); if (tblChild != null) { tblChild.setDescription(row[2] != null ? row[2].toString() : null); Boolean isHidden = (Boolean) row[3]; tblChild.setHidden(isHidden != null ? isHidden : false); } else { log.error("Couldn't find field[" + row[1] + "] for table [" + nm + "]"); } } else { log.error("Couldn't find table [" + nm + "]"); } } }
From source file:com.sun.faces.application.ViewHandlerImpl.java
/** * Attempts to find a matching locale based on <code>perf</code> and * list of supported locales, using the matching algorithm * as described in JSTL 8.3.2./*from ww w . j a v a 2 s . co m*/ */ protected Locale findMatch(FacesContext context, Locale perf) { Locale result = null; Iterator it = context.getApplication().getSupportedLocales(); while (it.hasNext()) { Locale supportedLocale = (Locale) it.next(); if (perf.equals(supportedLocale)) { // exact match result = supportedLocale; break; } else { // Make sure the preferred locale doesn't have country // set, when doing a language match, For ex., if the // preferred locale is "en-US", if one of supported // locales is "en-UK", even though its language matches // that of the preferred locale, we must ignore it. if (perf.getLanguage().equals(supportedLocale.getLanguage()) && supportedLocale.getCountry().equals("")) { result = supportedLocale; } } } // if it's not in the supported locales, if (null == result) { Locale defaultLocale = context.getApplication().getDefaultLocale(); if (defaultLocale != null) { if (perf.equals(defaultLocale)) { // exact match result = defaultLocale; } else { // Make sure the preferred locale doesn't have country // set, when doing a language match, For ex., if the // preferred locale is "en-US", if one of supported // locales is "en-UK", even though its language matches // that of the preferred locale, we must ignore it. if (perf.getLanguage().equals(defaultLocale.getLanguage()) && defaultLocale.getCountry().equals("")) { result = defaultLocale; } } } } return result; }