List of usage examples for java.util Locale equals
@Override public boolean equals(Object obj)
From source file:info.magnolia.cms.i18n.AbstractI18nContentSupport.java
/** * Uses {@link #getNextLocale(Locale)} to find the next locale. If the returned locale is in the * checkedLocales set it falls back to the fall-back locale. If the fall-back locale itself is * passed to the method, the method returns null to signal the end of the chain. */// w ww . j a va 2 s.c om protected Locale getNextContentLocale(Locale locale, Set<Locale> checkedLocales) { if (locale.equals(getFallbackLocale())) { return null; } Locale candidate = getNextLocale(locale); if (!checkedLocales.contains(candidate)) { return candidate; } return getFallbackLocale(); }
From source file:org.opencms.ade.containerpage.inherited.CmsContainerConfigurationWriter.java
/** * Saves a list of container element beans to a file in the VFS.<p> * * @param cms the current CMS context/* w w w . j a va 2 s. c o m*/ * @param name the name of the configuration to save * @param newOrdering true if a new ordering needs to be saved * @param pageResource a container page or folder * @param elements the elements whose data should be saved * * @throws CmsException if something goes wrong */ public void save(CmsObject cms, String name, boolean newOrdering, CmsResource pageResource, List<CmsContainerElementBean> elements) throws CmsException { cms = OpenCms.initCmsObject(cms); cms.getRequestContext().setSiteRoot(""); String configPath; if (pageResource.isFolder()) { configPath = CmsStringUtil.joinPaths(pageResource.getRootPath(), CmsContainerConfigurationCache.INHERITANCE_CONFIG_FILE_NAME); } else { configPath = CmsStringUtil.joinPaths(CmsResource.getParentFolder(pageResource.getRootPath()), CmsContainerConfigurationCache.INHERITANCE_CONFIG_FILE_NAME); } CmsInheritedContainerState state = OpenCms.getADEManager().getInheritedContainerState(cms, CmsResource.getParentFolder(CmsResource.getParentFolder(configPath)), name); Set<String> keys = state.getNewElementKeys(); CmsResource configRes = null; boolean needToUnlock = false; if (!cms.existsResource(configPath)) { // create it configRes = cms.createResource(configPath, OpenCms.getResourceManager() .getResourceType(CmsResourceTypeXmlContainerPage.INHERIT_CONTAINER_CONFIG_TYPE_NAME)); needToUnlock = true; } if (configRes == null) { configRes = cms.readResource(configPath); } CmsFile configFile = cms.readFile(configRes); // make sure the internal flag is set configFile.setFlags(configFile.getFlags() | CmsResource.FLAG_INTERNAL); CmsXmlContent content = CmsXmlContentFactory.unmarshal(cms, configFile); for (Locale localeToRemoveEntryFrom : content.getLocales()) { removeExistingEntry(cms, content, localeToRemoveEntryFrom, name); } CmsContainerConfiguration configuration = createConfigurationBean(newOrdering, elements, keys); Locale saveLocale = Locale.ENGLISH; for (Locale locale : content.getLocales()) { if (!saveLocale.equals(locale)) { content.removeLocale(locale); } } if (!content.hasLocale(saveLocale)) { content.addLocale(cms, saveLocale); } Element parentElement = content.getLocaleNode(saveLocale); serializeSingleConfiguration(cms, name, configuration, parentElement); byte[] contentBytes = content.marshal(); configFile.setContents(contentBytes); CmsLock prevLock = cms.getLock(configRes); boolean alreadyLocked = prevLock.isOwnedBy(cms.getRequestContext().getCurrentUser()); if (!alreadyLocked) { cms.lockResourceTemporary(configRes); needToUnlock = true; } try { cms.writeFile(configFile); } finally { if (needToUnlock) { cms.unlockResource(configRes); } } }
From source file:org.eclipse.smarthome.core.internal.i18n.I18nProviderImpl.java
private void setLocale(@Nullable String language, @Nullable String script, @Nullable String region, @Nullable String variant) { Locale oldLocale = this.locale; if (StringUtils.isEmpty(language)) { // at least the language must be defined otherwise the system default locale is used logger.debug("No language set, setting locale to 'null'."); locale = null;//from w w w.ja v a2s . c o m if (oldLocale != null) { logger.info("Locale is not set, falling back to the default locale"); } return; } final Locale.Builder builder = new Locale.Builder(); try { builder.setLanguage(language); } catch (final RuntimeException ex) { logger.warn("Language ({}) is invalid. Cannot create locale, keep old one.", language, ex); return; } try { builder.setScript(script); } catch (final RuntimeException ex) { logger.warn("Script ({}) is invalid. Skip it.", script, ex); return; } try { builder.setRegion(region); } catch (final RuntimeException ex) { logger.warn("Region ({}) is invalid. Skip it.", region, ex); return; } try { builder.setVariant(variant); } catch (final RuntimeException ex) { logger.warn("Variant ({}) is invalid. Skip it.", variant, ex); return; } final Locale newLocale = builder.build(); locale = newLocale; if (!newLocale.equals(oldLocale)) { logger.info("Locale set to '{}'.", newLocale); } }
From source file:org.opencms.i18n.CmsLocaleGroup.java
/** * Returns true if this is a potential group head, i.e. the locale of the primary resource is the main translation locale configured for the site * in which it is located.<p>/*ww w . j av a 2 s .co m*/ * * @return true if this is a potential group head */ public boolean isPotentialGroupHead() { CmsSite site = OpenCms.getSiteManager().getSiteForRootPath(m_primaryResource.getRootPath()); if (site == null) { return false; } Locale mainLocale = site.getMainTranslationLocale(null); if (mainLocale == null) { return false; } Locale primaryLocale = getMainLocale(); return mainLocale.equals(primaryLocale); }
From source file:org.apache.jmeter.util.JMeterUtils.java
/** * Changes the current locale: re-reads resource strings and notifies * listeners.//from w w w .j av a 2 s . c o m * * @param loc - * new locale */ public static void setLocale(Locale loc) { log.info("Setting Locale to " + loc.toString()); /* * See bug 29920. getBundle() defaults to the property file for the * default Locale before it defaults to the base property file, so we * need to change the default Locale to ensure the base property file is * found. */ Locale def = null; boolean isDefault = false; // Are we the default language? if (loc.getLanguage().equals(ENGLISH_LANGUAGE)) { isDefault = true; def = Locale.getDefault(); // Don't change locale from en_GB to en if (!def.getLanguage().equals(ENGLISH_LANGUAGE)) { Locale.setDefault(Locale.ENGLISH); } else { def = null; // no need to reset Locale } } if (loc.toString().equals("ignoreResources")) { // $NON-NLS-1$ log.warn("Resource bundles will be ignored"); ignoreResorces = true; // Keep existing settings } else { ignoreResorces = false; ResourceBundle resBund = ResourceBundle.getBundle("org.apache.jmeter.resources.messages", loc); // $NON-NLS-1$ resources = resBund; locale = loc; final Locale resBundLocale = resBund.getLocale(); if (isDefault || resBundLocale.equals(loc)) {// language change worked // Check if we at least found the correct language: } else if (resBundLocale.getLanguage().equals(loc.getLanguage())) { log.info("Could not find resources for '" + loc.toString() + "', using '" + resBundLocale.toString() + "'"); } else { log.error("Could not find resources for '" + loc.toString() + "'"); } } notifyLocaleChangeListeners(); /* * Reset Locale if necessary so other locales are properly handled */ if (def != null) { Locale.setDefault(def); } }
From source file:ch.silviowangler.dox.TranslationServiceImpl.java
@Override @Transactional(readOnly = true, propagation = SUPPORTS) public String findTranslation(String key, Locale locale) throws NoTranslationFoundException { logger.debug("Trying to find message for key '{}' and locale '{}'", key, locale.getDisplayName()); Translation translation = translationRepository.findByKeyAndLocale(key, locale); if (translation == null) { final Locale fallbackLocale = new Locale(locale.getLanguage()); logger.debug("No translation found for key '{}' and locale '{}'. Falling back to locale '{}'", new Object[] { key, locale.getDisplayName(), fallbackLocale.getDisplayName() }); translation = translationRepository.findByKeyAndLocale(key, fallbackLocale); if (translation == null && !fallbackLocale.equals(GERMAN)) { translation = translationRepository.findByKeyAndLocale(key, GERMAN); if (translation == null) { logger.warn("No translation found for key '{}' and locale '{}'", key, locale); throw new NoTranslationFoundException(key, locale); }//from w ww.j a v a 2 s .c o m return translation.getLanguageSpecificTranslation(); } else { logger.debug("Found translation of key '{}' using fallback locale '{}'", key, fallbackLocale.getDisplayName()); if (translation == null) throw new NoTranslationFoundException(key, locale); return translation.getLanguageSpecificTranslation(); } } else { logger.debug("Found translation of key '{}' on first attempt using locale '{}'", key, locale.getDisplayName()); return translation.getLanguageSpecificTranslation(); } }
From source file:org.xwiki.wikistream.instance.internal.AbstractInstanceWikiStreamTest.java
@Before public void before() throws Exception { this.xmlInputWikiStreamFactory = this.oldcore.getMocker().getInstance(InputWikiStreamFactory.class, WikiStreamType.WIKI_XML.serialize()); this.outputWikiStreamFactory = this.oldcore.getMocker().getInstance(OutputWikiStreamFactory.class, WikiStreamType.XWIKI_INSTANCE.serialize()); this.oldcore.getXWikiContext().setDatabase("wiki"); // XWiki/*from w w w.j a va 2 s . c o m*/ Mockito.when(this.oldcore.getMockXWiki().getDocument(Mockito.any(DocumentReference.class), Mockito.any(XWikiContext.class))).then(new Answer<XWikiDocument>() { @Override public XWikiDocument answer(InvocationOnMock invocation) throws Throwable { DocumentReference target = (DocumentReference) invocation.getArguments()[0]; if (target.getLocale() == null) { target = new DocumentReference(target, Locale.ROOT); } XWikiDocument document = documents.get(target); if (document == null) { document = new XWikiDocument(target); } return document; } }); Mockito.doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { XWikiDocument document = (XWikiDocument) invocation.getArguments()[0]; String comment = (String) invocation.getArguments()[1]; boolean minorEdit = (Boolean) invocation.getArguments()[2]; document.setComment(StringUtils.defaultString(comment)); document.setMinorEdit(minorEdit); if (document.isContentDirty() || document.isMetaDataDirty()) { document.setDate(new Date()); if (document.isContentDirty()) { document.setContentUpdateDate(new Date()); document.setContentAuthorReference(document.getAuthorReference()); } document.incrementVersion(); document.setContentDirty(false); document.setMetaDataDirty(false); } document.setNew(false); document.setStore(oldcore.getMockStore()); XWikiDocument previousDocument = documents.get(document.getDocumentReferenceWithLocale()); if (previousDocument != document) { for (XWikiAttachment attachment : document.getAttachmentList()) { if (!attachment.isContentDirty()) { attachment.setAttachment_content(previousDocument .getAttachment(attachment.getFilename()).getAttachment_content()); } } } documents.put(document.getDocumentReferenceWithLocale(), document.clone()); return null; } }).when(this.oldcore.getMockXWiki()).saveDocument(Mockito.any(XWikiDocument.class), Mockito.any(String.class), Mockito.anyBoolean(), Mockito.any(XWikiContext.class)); Mockito.doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { oldcore.getMockXWiki().saveDocument((XWikiDocument) invocation.getArguments()[0], (String) invocation.getArguments()[1], false, (XWikiContext) invocation.getArguments()[2]); return null; } }).when(this.oldcore.getMockXWiki()).saveDocument(Mockito.any(XWikiDocument.class), Mockito.any(String.class), Mockito.any(XWikiContext.class)); Mockito.doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { XWikiDocument document = (XWikiDocument) invocation.getArguments()[0]; documents.remove(document.getDocumentReferenceWithLocale()); return null; } }).when(this.oldcore.getMockXWiki()).deleteDocument(Mockito.any(XWikiDocument.class), Mockito.any(XWikiContext.class)); Mockito.when(this.oldcore.getMockXWiki().getXClass(Mockito.any(DocumentReference.class), Mockito.any(XWikiContext.class))).then(new Answer<BaseClass>() { @Override public BaseClass answer(InvocationOnMock invocation) throws Throwable { return oldcore.getMockXWiki().getDocument((DocumentReference) invocation.getArguments()[0], (XWikiContext) invocation.getArguments()[1]).getXClass(); } }); Mockito.when(this.oldcore.getMockXWiki().hasAttachmentRecycleBin(Mockito.any(XWikiContext.class))) .thenReturn(true); // XWikiStoreInterface Mockito.when(this.oldcore.getMockStore().getTranslationList(Mockito.any(XWikiDocument.class), Mockito.any(XWikiContext.class))).then(new Answer<List<String>>() { @Override public List<String> answer(InvocationOnMock invocation) throws Throwable { XWikiDocument document = (XWikiDocument) invocation.getArguments()[0]; List<String> translations = new ArrayList<String>(); for (XWikiDocument storedDocument : documents.values()) { Locale storedLocale = storedDocument.getLocale(); if (!storedLocale.equals(Locale.ROOT) && storedDocument.getDocumentReference() .equals(document.getDocumentReference())) { translations.add(storedLocale.toString()); } } return translations; } }); // Users Mockito.when(this.oldcore.getMockXWiki().getUserClass(Mockito.any(XWikiContext.class))) .then(new Answer<BaseClass>() { @Override public BaseClass answer(InvocationOnMock invocation) throws Throwable { XWikiContext xcontext = (XWikiContext) invocation.getArguments()[0]; XWikiDocument userDocument = oldcore.getMockXWiki().getDocument( new DocumentReference(USER_CLASS, new WikiReference(xcontext.getDatabase())), xcontext); final BaseClass userClass = userDocument.getXClass(); if (userDocument.isNew()) { userClass.addTextField("first_name", "First Name", 30); userClass.addTextField("last_name", "Last Name", 30); userClass.addEmailField("email", "e-Mail", 30); userClass.addPasswordField("password", "Password", 10); userClass.addBooleanField("active", "Active", "active"); userClass.addTextAreaField("comment", "Comment", 40, 5); userClass.addTextField("avatar", "Avatar", 30); userClass.addTextField("phone", "Phone", 30); userClass.addTextAreaField("address", "Address", 40, 3); oldcore.getMockXWiki().saveDocument(userDocument, xcontext); } return userClass; } }); Mockito.when(this.oldcore.getMockXWiki().getGroupClass(Mockito.any(XWikiContext.class))) .then(new Answer<BaseClass>() { @Override public BaseClass answer(InvocationOnMock invocation) throws Throwable { XWikiContext xcontext = (XWikiContext) invocation.getArguments()[0]; XWikiDocument groupDocument = oldcore.getMockXWiki().getDocument( new DocumentReference(GROUP_CLASS, new WikiReference(xcontext.getDatabase())), xcontext); final BaseClass groupClass = groupDocument.getXClass(); if (groupDocument.isNew()) { groupClass.addTextField("member", "Member", 30); oldcore.getMockXWiki().saveDocument(groupDocument, xcontext); } return groupClass; } }); }
From source file:org.itracker.core.resources.ITrackerResources.java
public static String getLocaleFullDN(Locale locale, Locale displayLocale) { if (null == locale) { locale = new Locale(""); }/*w w w .jav a 2s . c o m*/ String fullName = StringUtils.trimToNull(getLocaleNativeName(locale)); if (null == displayLocale || locale.getLanguage().equals(displayLocale.getLanguage())) { return fullName; } if (StringUtils.equals(fullName, String.valueOf(locale))) { fullName = getLocaleDN(locale, displayLocale); return fullName; } else { String localizedName = StringUtils.trimToNull(getLocaleDN(locale, displayLocale)); if (null != fullName && !StringUtils.equals(fullName, localizedName)) { return fullName.trim() + " (" + localizedName.trim() + ")"; } else if (null != localizedName) { return localizedName.trim(); } else if (null != fullName) { return fullName.trim(); } } return locale.getDisplayName() + (!locale.equals(displayLocale) ? " (" + locale.getDisplayLanguage(locale) + ")" : ""); }
From source file:edu.ku.brc.specify.prefs.SystemPrefs.java
@Override public void savePrefs() { if (form.getValidator() == null || form.getValidator().hasChanged()) { super.savePrefs(); ValCheckBox chk = form.getCompById("2"); localPrefs.putBoolean(VERSION_CHECK, (Boolean) chk.getValue()); chk = form.getCompById("3"); remotePrefs.putBoolean(SEND_STATS, (Boolean) chk.getValue()); chk = form.getCompById("9"); remotePrefs.putBoolean(SEND_ISA_STATS, (Boolean) chk.getValue()); /* remove if worldwind is broken*/chk = form.getCompById(USE_WORLDWIND); /* remove if worldwind is broken*/localPrefs.putBoolean(USE_WORLDWIND, (Boolean) chk.getValue()); // /* remove if worldwind is broken*/chk = form.getCompById(SYSTEM_HasOpenGL); /* remove if worldwind is broken*/localPrefs.putBoolean(SYSTEM_HasOpenGL, (Boolean) chk.getValue()); // /* remove if worldwind is broken*/chk = form.getCompById(USE_WORLDWIND); /* remove if worldwind is broken*/localPrefs.putBoolean(USE_WORLDWIND, (Boolean) chk.getValue()); //chk = form.getCompById(ALWAYS_ASK_COLL); //localPrefs.putBoolean(ALWAYS_ASK_COLL, (Boolean)chk.getValue()); ValComboBox localeCBX = form.getCompById("5"); Locale item = (Locale) localeCBX.getComboBox().getSelectedItem(); if (item != null) { if (item.equals(UIRegistry.getPlatformLocale())) { localPrefs.remove("locale.lang"); localPrefs.remove("locale.country"); localPrefs.remove("locale.var"); //System.out.println("["+localPrefs.get("locale.lang", null)+"]"); Locale.setDefault(UIRegistry.getPlatformLocale()); } else { if (item.getLanguage() == null) { localPrefs.remove("locale.lang"); } else { localPrefs.put("locale.lang", item.getLanguage()); }/* w w w. j a v a2 s. co m*/ if (item.getCountry() == null) { localPrefs.remove("locale.country"); } else { localPrefs.put("locale.country", item.getCountry()); } if (item.getVariant() == null) { localPrefs.remove("locale.var"); } else { localPrefs.put("locale.var", item.getVariant()); } } ValBrowseBtnPanel browse = form.getCompById("7"); if (browse != null) { String newSplashPath = browse.getValue().toString(); if (newSplashPath != null && (oldSplashPath == null || !oldSplashPath.equals(newSplashPath))) { if (newSplashPath.isEmpty()) { resetSplashImage(); localPrefs.remove(SPECIFY_BG_IMG_PATH); } else { localPrefs.put(SPECIFY_BG_IMG_PATH, newSplashPath); changeSplashImage(); } } } File cp = JasperReportsCache.getImagePath(); try { localPrefs.flush(); } catch (BackingStoreException ex) { } } } }
From source file:com.massivekinetics.ow.ui.views.timepicker.TimePicker.java
/** * Sets the current locale.//from ww w.j a v a 2 s .c o m * * @param locale The current locale. */ private void setCurrentLocale(Locale locale) { if (locale.equals(mCurrentLocale)) { return; } mCurrentLocale = locale; mTempCalendar = Calendar.getInstance(locale); }