List of usage examples for java.util Locale equals
@Override public boolean equals(Object obj)
From source file:org.opencms.widgets.CmsCategoryWidget.java
/** * Returns the right resource, depending on the locale.<p> * //from w w w .j a v a 2 s . c o m * @param cms the cms context * @param param the widget parameter * * @return the resource to get/set the categories for */ protected CmsResource getResource(CmsObject cms, I_CmsWidgetParameter param) { I_CmsXmlContentValue value = (I_CmsXmlContentValue) param; CmsFile file = value.getDocument().getFile(); String resourceName = cms.getSitePath(file); if (CmsWorkplace.isTemporaryFile(file)) { StringBuffer result = new StringBuffer(resourceName.length() + 2); result.append(CmsResource.getFolderPath(resourceName)); result.append(CmsResource.getName(resourceName).substring(1)); resourceName = result.toString(); } try { List<CmsResource> listsib = cms.readSiblings(resourceName, CmsResourceFilter.ALL); for (int i = 0; i < listsib.size(); i++) { CmsResource resource = listsib.get(i); // get the default locale of the resource Locale locale = getDefaultLocale(cms, cms.getSitePath(resource)); if (locale.equals(value.getLocale())) { // get the property for the right locale return resource; } } } catch (CmsVfsResourceNotFoundException e) { // may hapen if editing a new resource if (LOG.isDebugEnabled()) { LOG.debug(e.getLocalizedMessage(), e); } } catch (CmsException e) { if (LOG.isErrorEnabled()) { LOG.error(e.getLocalizedMessage(), e); } } return file; }
From source file:nonjsp.application.XulViewHandlerImpl.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.// www .j ava 2 s .com */ 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; } } } return result; }
From source file:org.vaadin.webinars.springandvaadin.i18n.ui.Servlet.java
@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final Locale locale = localeResolver.resolveLocale(request); LocaleContextHolder.setLocale(locale); ServletRequestAttributes requestAttributes = new ServletRequestAttributes(request); RequestContextHolder.setRequestAttributes(requestAttributes); try {//from www .j a va 2s . com super.service(new HttpServletRequestWrapper(request) { @Override public Locale getLocale() { return locale; } }, response); } finally { if (!locale.equals(LocaleContextHolder.getLocale())) { localeResolver.setLocale(request, response, LocaleContextHolder.getLocale()); } LocaleContextHolder.resetLocaleContext(); RequestContextHolder.resetRequestAttributes(); } }
From source file:org.opencms.ui.sitemap.CmsSitemapTreeDataProvider.java
/** * Gets the node data for children of a given node.<p> * * @param nodeData the node whose children to get * @return the children/*from w w w . j a va 2 s . co m*/ */ public List<CmsSitemapTreeNodeData> getChildren(CmsSitemapTreeNodeData nodeData) { CmsClientSitemapEntry entry = nodeData.getClientEntry(); List<CmsSitemapTreeNodeData> result = Lists.newArrayList(); try { CmsVfsSitemapService svc = getSitemapService(); CmsClientSitemapEntry ent = svc.getChildren(m_root.getRootPath(), entry.getId(), 1); for (CmsClientSitemapEntry subEnt : ent.getSubEntries()) { if (subEnt.isInNavigation() && ((subEnt.getDefaultFileId() != null) || subEnt.isNavigationLevelType())) { try { CmsUUID idToRead = subEnt.getId(); if (subEnt.getDefaultFileId() != null) { idToRead = subEnt.getDefaultFileId(); } Locale l1 = OpenCms.getLocaleManager().getDefaultLocale(svc.getCmsObject(), svc.getCmsObject().readResource(idToRead)); Locale l2 = OpenCms.getLocaleManager().getDefaultLocale(svc.getCmsObject(), svc.getCmsObject().readResource(ent.getId(), CmsResourceFilter.IGNORE_EXPIRATION)); if (!l1.equals(l2)) { continue; } } catch (Exception e) { LOG.error(e.getLocalizedMessage(), e); } CmsSitemapTreeNodeData data = new CmsSitemapTreeNodeData(m_localeContext.getRootLocale(), m_localeContext.getComparisonLocale()); if (m_foldersWithNoChildFolders.contains(subEnt.getId())) { data.setHasNoChildren(true); } data.setClientEntry(subEnt); try { data.initialize(m_cms); result.add(data); } catch (Exception e) { LOG.error(e.getLocalizedMessage()); } } } } catch (CmsException e) { LOG.error(e.getLocalizedMessage(), e); } catch (CmsRpcException e) { LOG.error(e.getLocalizedMessage(), e); } return result; }
From source file:de.austinpadernale.holidays.Holiday.java
public String getName(Locale locale) { String result;//from w w w. j ava 2 s . c om if (names == null || names.isEmpty()) { result = createName(); } else if (locale == null || locale.equals(Locale.ROOT)) { HolidayName hn = null; for (HolidayName n : names) { if (n.getLanguage() == null || n.getLanguage().equals(Locale.ROOT)) { hn = n; break; } } result = holidayNameToName(hn); } else { HolidayName rn = null; HolidayName ln2 = null; HolidayName ln = null; HolidayName cn = null; for (HolidayName n : names) { Locale l = n.getLanguage(); if (l == null || l.equals(Locale.ROOT)) { if (rn == null) { rn = n; } continue; } if (equals(l.getLanguage(), locale.getLanguage()) && StringUtils.isEmpty(l.getCountry())) { if (ln == null) { ln = n; } continue; } if (equals(l.getLanguage(), locale.getLanguage()) && !StringUtils.isEmpty(l.getCountry())) { if (ln2 == null) { ln2 = n; } continue; } if (equals(l.getLanguage(), locale.getLanguage()) && equals(l.getCountry(), locale.getCountry())) { if (cn == null) { cn = n; } } } if (cn != null) { result = holidayNameToName(cn); } else if (ln != null) { result = holidayNameToName(ln); } else if (ln2 != null) { result = holidayNameToName(ln2); } else if (rn != null) { result = holidayNameToName(rn); } else { result = createName(); } } return result; }
From source file:org.xwiki.store.filesystem.internal.FilesystemStoreTools.java
/** * Get the directory associated with this document. This is a path obtained from the owner document reference, where * each reference segment (wiki, spaces, document name) contributes to the final path. For a document called * xwiki:Main.WebHome, the directory will be: <code>(storageDir)/xwiki/Main/WebHome/~this/</code> * * @param documentReference the DocumentReference for the document to get the directory for. * @return a file path corresponding to the attachment location; each segment in the path is URL-encoded in order to * be safe./* ww w .j a va 2s . c o m*/ */ private File getDocumentContentDir(final DocumentReference documentReference) { final File documentDir = new File(this.storageDir, this.fileEntitySerializer.serialize(documentReference, true)); File documentContentDir = new File(documentDir, DOCUMENT_DIR_NAME); // Add the locale Locale documentLocale = documentReference.getLocale(); if (documentLocale != null) { final File documentLocalesDir = new File(documentContentDir, DOCUMENT_LOCALES_DIR_NAME); final File documentLocaleDir = new File(documentLocalesDir, documentLocale.equals(Locale.ROOT) ? DOCUMENT_LOCALES_ROOT_NAME : documentLocale.toString()); documentContentDir = new File(documentLocaleDir, DOCUMENTLOCALE_DIR_NAME); } return documentContentDir; }
From source file:com.octo.captcha.service.AbstractCaptchaService.java
/** * Method to retrive the question corresponding to the given ticket. * * @param ID ticket//from www. j a va2 s. c o m * @param locale the desired localized capthca * @return the localized question * @throws CaptchaServiceException if the ticket is invalid */ public String getQuestionForID(String ID, Locale locale) throws CaptchaServiceException { Captcha captcha; //check if has capthca if (!this.store.hasCaptcha(ID)) { //if not generate it captcha = generateAndStoreCaptcha(locale, ID); } else { captcha = this.store.getCaptcha(ID); if (captcha == null) { captcha = generateAndStoreCaptcha(locale, ID); } else if (locale != null) { Locale storedlocale = this.store.getLocale(ID); if (!locale.equals(storedlocale)) { captcha = generateAndStoreCaptcha(locale, ID); } } } return captcha.getQuestion(); }
From source file:org.opencms.search.solr.CmsSolrDocumentXmlContent.java
/** * @see org.opencms.search.documents.CmsDocumentXmlContent#extractContent(org.opencms.file.CmsObject, org.opencms.file.CmsResource, org.opencms.search.CmsSearchIndex) *///from w ww. j av a 2 s.c o m @Override public I_CmsExtractionResult extractContent(CmsObject cms, CmsResource resource, CmsSearchIndex index) throws CmsException { logContentExtraction(resource, index); try { I_CmsExtractionResult result = null; List<I_CmsExtractionResult> ex = new ArrayList<I_CmsExtractionResult>(); for (CmsResource detailContainers : CmsJspTagContainer.getDetailOnlyResources(cms, resource)) { CmsSolrDocumentContainerPage containerpageExtractor = new CmsSolrDocumentContainerPage(""); String localeTemp = detailContainers.getRootPath(); localeTemp = CmsResource.getParentFolder(localeTemp); localeTemp = CmsResource.getName(localeTemp); localeTemp = localeTemp.substring(0, localeTemp.length() - 1); Locale locale = CmsLocaleManager.getLocale(localeTemp); if (CmsJspTagContainer.useSingleLocaleDetailContainers( OpenCms.getSiteManager().getSiteRoot(resource.getRootPath())) && locale.equals(CmsLocaleManager.getDefaultLocale())) { // in case of single locale detail containers do not force the locale locale = null; } I_CmsExtractionResult containersExtractionResult = containerpageExtractor.extractContent(cms, detailContainers, index, locale); // only use the locales of the resource itself, not the ones of the detail containers page containersExtractionResult.getContentItems().remove(CmsSearchField.FIELD_RESOURCE_LOCALES); ex.add(containersExtractionResult); } result = extractXmlContent(cms, resource, index); result = result.merge(ex); return result; } catch (Throwable t) { throw new CmsIndexException(Messages.get().container(Messages.ERR_TEXT_EXTRACTION_1, resource), t); } }
From source file:com.evolveum.midpoint.web.component.menu.top.LocalePanel.java
private LocaleDescriptor getSelectedLocaleDescriptor() { Locale locale = getSession().getLocale(); if (locale == null) { return null; }//from w w w. j a v a2s . c o m // The second condition is a fix attempt for issue MID-2075, where firefox // returns 'sk' as a locale from session, while other browsers return 'sk_SK'. // This is the reason, why in firefox selected locale is ignored (the commented // condition is not met) so we are adding second condition to overcome this issue. for (LocaleDescriptor desc : AVAILABLE_LOCALES) { // if (locale.equals(desc.getLocale()) if (locale.equals(desc.getLocale()) || locale.getLanguage().equals(desc.getLocale().getLanguage())) { return desc; } } return null; }
From source file:de.sub.goobi.forms.SpracheForm.java
/** * The function getSupportedLocales() returns a list of maps, each * representing one locale configured in the faces-config.xml file. Each of * the maps will contain the fields. id the locales ID String, e.g. fr? * or en_GB? displayLanguageSelf the name of the language in the language * itself, e.g. English?, Deutsch?, franais?, espaol?, ???, * ?, /*from w ww . j a v a 2s.c o m*/ * * <p> * Its a good practice to identify a language in its own spelling, since * this will be most likely what a speaker of that language will recognize. * See also: http://www.cs.tut.fi/~jkorpela/flags.html Note that * capitalisation is subject to the respective language. If the language is * unknown, the id will be returned. displayLanguageTranslated the name of * the language in the currently selected language, e.g., if the current * language is English: English?, German?, French?, * </p> * * <p> * This is just a nice feature because the language names are provided by * Java; and its used in the mouse-over titles, so you can find out what * e.g. ? means, even if you dont have a clue of the glyphs used. If * no translations are available, this will fall back to English. selected * whether this is the current language * </p> * * <p> * This can be used for a sophisticated layout. * </p> * * @return a list of maps, each with the fields id?, displayName? and * selected? */ public List<Map<String, Object>> getSupportedLocales() { List<Map<String, Object>> result = new ArrayList<>(); Locale currentDisplayLanguage = FacesContext.getCurrentInstance().getViewRoot().getLocale(); @SuppressWarnings("unchecked") // It seems we have an old Faces API, Faces 2.1s getSupportedLocales() // returns Iterator<Locale> // TODO: Update JSF API Iterator<Locale> localesIterator = FacesContext.getCurrentInstance().getApplication().getSupportedLocales(); while (localesIterator.hasNext()) { Locale supportedLocale = localesIterator.next(); if (supportedLocale.getLanguage().length() > 0) { Map<String, Object> translation = new HashMap<>(); translation.put("id", supportedLocale.toString()); translation.put("displayLanguageSelf", supportedLocale.getDisplayLanguage(supportedLocale)); translation.put("displayLanguageTranslated", supportedLocale.getDisplayLanguage(currentDisplayLanguage)); translation.put("selected", Boolean.valueOf(supportedLocale.equals(currentDisplayLanguage))); result.add(translation); } } return result; }