Example usage for java.util Locale toString

List of usage examples for java.util Locale toString

Introduction

In this page you can find the example usage for java.util Locale toString.

Prototype

@Override
public final String toString() 

Source Link

Document

Returns a string representation of this Locale object, consisting of language, country, variant, script, and extensions as below:
language + "_" + country + "_" + (variant + "_#" | "#") + script + "_" + extensions
Language is always lower case, country is always upper case, script is always title case, and extensions are always lower case.

Usage

From source file:com.aurel.track.admin.user.person.PersonBL.java

/**
 *    The following method creates a client user, based on name, and email address.
 * The password will be set by accessing an URL by newly created client user.
 * @param name/*  w  w w . j av  a 2s  .  c o  m*/
 * @param emailAddress
 * @return
 */
public static TPersonBean saveAnonymousUserAsClientFromEmail(String name, String emailAddress, Locale locale) {
    TPersonBean person = new TPersonBean();
    if (name != null && !"".equals(name)) {
        String nameparts[] = name.split("\\s+");
        String firstName = "";
        String lastName = "";
        for (int i = 0; i < nameparts.length - 1; ++i) {
            firstName = firstName + " " + nameparts[i];
        }
        firstName = firstName.trim();
        person.setFirstName(firstName);
        firstName = firstName.toLowerCase();

        lastName = nameparts[nameparts.length - 1];
        person.setLastName(lastName);
        lastName = lastName.toLowerCase();

        String loginName = firstName + "." + lastName;
        TPersonBean checkedPerson = PersonBL.loadByLoginName(loginName);
        if (checkedPerson != null) {
            String tmpLoginName = loginName;
            int index = 1;
            while (checkedPerson != null) {
                tmpLoginName = loginName + Integer.toString(index);
                checkedPerson = PersonBL.loadByLoginName(tmpLoginName);
                index++;
            }
            loginName = tmpLoginName;
        }
        person.setUserLevel(TPersonBean.USERLEVEL.CLIENT);
        person.setLoginName(loginName);
        person.setEmail(emailAddress);
        person.setPrefEmailType("HTML");
        person.setHomePage("cockpit");
        if (locale != null) {
            person.setPrefLocale(locale.toString());
        }
        Integer id = save(person);
        person = PersonBL.loadByPrimaryKey(id);
        LOGGER.debug("New client user has been created from sent mail userName: " + person.getUsername()
                + " firstname: " + person.getFirstName() + " lastname: " + person.getLastName() + " e-mail: "
                + person.getEmail());
        ProfileBL.addNewClientToGroups(id);
        return person;
    }
    LOGGER.debug("Creating new client user from sent mail failed!");
    return null;
}

From source file:com.alkacon.opencms.formgenerator.CmsSelectWidgetXmlcontentType.java

/**
 * Resolves xpath macros of the form <code>"%(xpath.XPATHEXPRESSION)"</code> by the field value of the XML content
 * denoted by the given resource. <p>
 * /*from   www  .ja v a  2s  .co m*/
 * File loading and unmarshalling is only done if the given String contains xpath macros.
 * <p>
 * 
 * @param cms to access values in the cmsobject.
 * 
 * @param resource the resource pointing to an xmlcontent containing the macro values to resolve.
 * 
 * @param value the unresolved macro string.
 * 
 * @return a String with resolved xpath macros that have been read from the xmlcontent.
 * 
 * @throws CmsException if something goes wrong
 */
private String resolveXpathMacros(CmsObject cms, CmsResource resource, final String value) throws CmsException {

    String work = value;
    StringBuffer result = new StringBuffer();

    String startMacro = new StringBuffer(I_CmsMacroResolver.MACRO_DELIMITER + "")
            .append(I_CmsMacroResolver.MACRO_START).append("xpath.").toString();

    int startmacroIndex = work.indexOf(startMacro);
    int stopmacro = 0;
    String xpath;
    if (startmacroIndex != -1) {

        // for the option value we have to unmarshal...
        CmsXmlContent xmlcontent = CmsXmlContentFactory.unmarshal(cms, cms.readFile(resource));
        // we read the locale node of the xmlcontent instance matching the resources
        // locale property (or top level locale).
        Locale locale = CmsLocaleManager.getLocale(
                cms.readPropertyObject(xmlcontent.getFile(), CmsPropertyDefinition.PROPERTY_LOCALE, true)
                        .getValue());

        while (startmacroIndex != -1) {
            stopmacro = work.indexOf(I_CmsMacroResolver.MACRO_END);
            if (stopmacro == 0) {
                // TODO: complain about missing closing macro bracket!
            }

            // first cut the prefix of the macro to put it to the result:
            result.append(work.substring(0, startmacroIndex));
            // now replace the macro:
            xpath = work.substring(startmacroIndex + 8, stopmacro);

            try {
                result.append(xmlcontent.getValue(xpath, locale).getPlainText(cms));
            } catch (Exception ex) {
                if (LOG.isErrorEnabled()) {
                    LOG.error(Messages.get().getBundle().key(Messages.LOG_ERR_SELECTWIDGET_XPATH_INVALID_4,
                            new Object[] { xpath, locale.toString(), xmlcontent.getFile().getRootPath(),
                                    ex.getLocalizedMessage() }));
                }
            }
            // skip over the consumed String of value:
            work = work.substring(stopmacro + 1);

            // take a new start for macro:
            startmacroIndex = work.indexOf(startMacro);
        }
    }
    // append trailing value
    result.append(work);
    return result.toString();

}

From source file:it.cnr.icar.eric.client.ui.thin.RegistryObjectBean.java

public String getNameContentLocale() {
    String contentLocaleStr = null;
    try {/*  www .ja  va2  s .c  om*/
        Locale contentLocale = RegistryBrowser.getInstance().getUserPreferencesBean().getContentLocale();
        InternationalStringImpl iString = ((InternationalStringImpl) registryObject.getName());
        LocalizedString lString = null;
        if (iString != null) {
            lString = iString.getClosestLocalizedString(contentLocale, null);
        }
        if (lString == null) {
            contentLocaleStr = contentLocale.toString();
        } else {
            Locale locale = lString.getLocale();
            if (locale == null) {
                locale = Locale.getDefault();
            }
            contentLocaleStr = locale.toString();
        }
    } catch (Exception e) {
        log.error(WebUIResourceBundle.getInstance().getString("message.ErrorInGettingNameContent"), e);
    } finally {
        if (contentLocaleStr == null) {
            contentLocaleStr = Locale.getDefault().toString();
        }
    }
    return contentLocaleStr;
}

From source file:it.cnr.icar.eric.client.ui.thin.RegistryObjectBean.java

public String getDescriptionContentLocale() {
    String contentLocaleStr = null;
    try {/*from   w  ww  .  j a  va  2s. c  om*/
        Locale contentLocale = RegistryBrowser.getInstance().getUserPreferencesBean().getContentLocale();
        InternationalStringImpl iString = ((InternationalStringImpl) registryObject.getName());
        LocalizedString lString = null;
        if (iString != null) {
            lString = iString.getClosestLocalizedString(contentLocale, null);
        }
        if (lString == null) {
            contentLocaleStr = contentLocale.toString();
        } else {
            Locale locale = lString.getLocale();
            if (locale == null) {
                locale = Locale.getDefault();
            }
            contentLocaleStr = locale.toString();
        }
    } catch (Exception e) {
        log.error(WebUIResourceBundle.getInstance().getString("message.ErrorInGettingDescriptionContent"), e);
    } finally {
        if (contentLocaleStr == null) {
            contentLocaleStr = Locale.getDefault().toString();
        }
    }
    return contentLocaleStr;
}

From source file:org.hoteia.qalingo.core.web.util.RequestUtil.java

public void updateCurrentLocalization(HttpServletRequest request, AbstractEngineSession session,
        Localization localization) throws Exception {
    final Locale locale = localization.getLocale();
    setLocaleSpringContext(request, locale.toString());
    setSessionMarketAreaLocalization(session, localization);
}

From source file:org.de.jmg.learn._MainActivity.java

public void speak(String t, Locale l, String ID, boolean blnFlush) {
    try {//from w  w w.ja  v  a  2s  . com
        if (!_main.blnTextToSpeech || l.toString().equalsIgnoreCase("_off"))
            return;
        String ts[] = (" " + t + " ").split(getString(R.string.cloze));
        if (!t.equalsIgnoreCase(getString(R.string.cloze)) && ts.length > 1) {
            for (int i = 0; i < ts.length; i++) {
                String s = ts[i];
                speak(s, l, ID, (i == 0) ? blnFlush : false);
                if (i < ts.length - 1) {
                    if (Build.VERSION.SDK_INT < 21) {
                        HashMap<String, String> h = new HashMap<>();
                        h.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "cloze");
                        //noinspection deprecation
                        _main.tts.playSilence(2500, TextToSpeech.QUEUE_ADD, h);
                    } else {
                        _main.tts.playSilentUtterance(2500, TextToSpeech.QUEUE_ADD, "cloze");
                    }
                    //speak(getString(R.string.cloze), Locale.getDefault(), ID, false);
                }
            }
        } else {
            int res = _main.tts.setLanguage(l);
            if (res < 0) {
                if (_main.tts.setLanguage(Locale.US) < 0)
                    return;
            }
            int flags;
            if (blnFlush) {
                flags = TextToSpeech.QUEUE_FLUSH;
            } else {
                flags = TextToSpeech.QUEUE_ADD;
            }
            if (Build.VERSION.SDK_INT < 21) {
                HashMap<String, String> h = new HashMap<>();
                h.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, ID);

                //noinspection deprecation
                _main.tts.speak(t, flags, h);
            } else {
                _main.tts.speak(t, flags, null, ID);
            }
        }
    } catch (Exception ex) {
        lib.setgstatus("speak: " + t + " " + l.toString());
        lib.ShowException(_main, ex);
    }
}

From source file:com.mobiletin.inputmethod.indic.LatinIME.java

private void resetSuggest() {
    final Locale switcherSubtypeLocale = mSubtypeSwitcher.getCurrentSubtypeLocale();
    final String switcherLocaleStr = switcherSubtypeLocale.toString();
    final Locale subtypeLocale;
    if (TextUtils.isEmpty(switcherLocaleStr)) {
        // This happens in very rare corner cases - for example, immediately after a switch
        // to LatinIME has been requested, about a frame later another switch happens. In this
        // case, we are about to go down but we still don't know it, however the system tells
        // us there is no current subtype so the locale is the empty string. Take the best
        // possible guess instead -- it's bound to have no consequences, and we have no way
        // of knowing anyway.
        Log.e(TAG, "System is reporting no current subtype.");
        subtypeLocale = getResources().getConfiguration().locale;
    } else {//from   w  w  w .j  ava 2  s  . c  o m
        subtypeLocale = switcherSubtypeLocale;
    }
    resetSuggestForLocale(subtypeLocale);
}

From source file:org.alfresco.repo.model.ml.MultilingualContentServiceImpl.java

/**
 * {@inheritDoc}/*from w  ww .  ja  va  2  s.  c o  m*/
 */
public NodeRef addEmptyTranslation(NodeRef translationOfNodeRef, String name, Locale locale) {
    boolean hasMLAspect = nodeService.hasAspect(translationOfNodeRef,
            ContentModel.ASPECT_MULTILINGUAL_DOCUMENT);
    boolean isMLContainer = nodeService.getType(translationOfNodeRef)
            .equals(ContentModel.TYPE_MULTILINGUAL_CONTAINER);

    if (hasMLAspect || isMLContainer) {
        // Get the pivot translation
        NodeRef pivotTranslationNodeRef = getPivotTranslation(translationOfNodeRef);
        if (pivotTranslationNodeRef != null) {
            // We found a pivot translation, so use it
            translationOfNodeRef = pivotTranslationNodeRef;
        } else {
            // We use the given translation
        }
    } else {
        throw new IllegalArgumentException("Node must have aspect " + ContentModel.ASPECT_MULTILINGUAL_DOCUMENT
                + ": \n" + "   Translation: " + translationOfNodeRef + "\n" + "   Locale:      " + locale);
    }

    FileInfo translationOfFileInfo = fileFolderService.getFileInfo(translationOfNodeRef);
    String translationOfName = translationOfFileInfo.getName();
    // If name is null, supply one
    if (name == null) {
        name = translationOfName;
    }
    // If there is a name clash, add the locale to the main portion of the filename
    if (name.equalsIgnoreCase(translationOfName)) {
        String localeStr = locale.toString();
        if (localeStr.endsWith("_")) {
            localeStr = localeStr.substring(0, localeStr.length() - 1);
        }
        String rawName;
        String extension;
        int index = name.lastIndexOf('.');
        if (index > 0) {
            rawName = name.substring(0, index);
            extension = "." + name.substring(index + 1);
        } else {
            rawName = name;
            extension = ""; // No extension
        }
        name = rawName + "_" + localeStr + extension;
    }

    // Create the document in the space of the node of reference
    NodeRef parentNodeRef = nodeService.getPrimaryParent(translationOfNodeRef).getParentRef();

    // Create the empty translation.
    // ALF-2200: Create the translation as the same type as the pivot
    QName newTranslationType = nodeService.getType(translationOfNodeRef);
    NodeRef newTranslationNodeRef = fileFolderService.create(parentNodeRef, name, newTranslationType)
            .getNodeRef();

    // add the translation to the container
    addTranslation(newTranslationNodeRef, translationOfNodeRef, locale);

    // Although the content is spoofed from the pivot translation, it isn't done for all services
    // TODO: Fix http://issues.alfresco.com/browse/AR-1487
    ContentData translationOfContentData = (ContentData) nodeService.getProperty(translationOfNodeRef,
            ContentModel.PROP_CONTENT);
    if (translationOfContentData != null) {
        ContentData newTranslationContentData = new ContentData(null, translationOfContentData.getMimetype(),
                translationOfContentData.getSize(), translationOfContentData.getEncoding(),
                translationOfContentData.getLocale());
        nodeService.setProperty(newTranslationNodeRef, ContentModel.PROP_CONTENT, newTranslationContentData);
    }

    // set it empty
    nodeService.addAspect(newTranslationNodeRef, ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION, null);
    // Initially, the file should be temporary.  This will be changed as soon as some content is added.
    nodeService.addAspect(newTranslationNodeRef, ContentModel.ASPECT_TEMPORARY, null);

    if (logger.isDebugEnabled()) {
        logger.debug("Added an empty translation: \n" + "   Translation of:  " + translationOfNodeRef + "\n"
                + "   New translation: " + newTranslationNodeRef + "\n" + "   Locale:          " + locale);
    }

    return newTranslationNodeRef;
}

From source file:org.alfresco.repo.model.ml.MultilingualContentServiceImpl2.java

/**
 * {@inheritDoc}/*  w ww.jav  a 2s .c  o m*/
 */
public NodeRef addEmptyTranslation(NodeRef translationOfNodeRef, String name, Locale locale) {
    boolean hasMLAspect = nodeService.hasAspect(translationOfNodeRef,
            ContentModel.ASPECT_MULTILINGUAL_DOCUMENT);
    boolean isMLContainer = nodeService.getType(translationOfNodeRef)
            .equals(ContentModel.TYPE_MULTILINGUAL_CONTAINER);

    if (hasMLAspect || isMLContainer) {
        // Get the pivot translation
        NodeRef pivotTranslationNodeRef = getPivotTranslation(translationOfNodeRef);
        if (pivotTranslationNodeRef != null) {
            // We found a pivot translation, so use it
            translationOfNodeRef = pivotTranslationNodeRef;
        } else {
            // We use the given translation
        }
    } else {
        throw new IllegalArgumentException("Node must have aspect " + ContentModel.ASPECT_MULTILINGUAL_DOCUMENT
                + ": \n" + "   Translation: " + translationOfNodeRef + "\n" + "   Locale:      " + locale);
    }

    FileInfo translationOfFileInfo = fileFolderService.getFileInfo(translationOfNodeRef);
    String translationOfName = translationOfFileInfo.getName();
    // If name is null, supply one
    if (name == null) {
        name = translationOfName;
    }
    // If there is a name clash, add the locale to the main portion of the
    // filename
    if (name.equalsIgnoreCase(translationOfName)) {
        String localeStr = locale.toString();
        if (localeStr.endsWith("_")) {
            localeStr = localeStr.substring(0, localeStr.length() - 1);
        }
        String rawName;
        String extension;
        int index = name.lastIndexOf('.');
        if (index > 0) {
            rawName = name.substring(0, index);
            extension = "." + name.substring(index + 1);
        } else {
            rawName = name;
            extension = ""; // No extension
        }
        name = rawName + "_" + localeStr + extension;
    }

    // Create the document in the space of the node of reference
    NodeRef parentNodeRef = nodeService.getPrimaryParent(translationOfNodeRef).getParentRef();

    // Create the empty translation.
    // ALF-2200: Create the translation as the same type as the pivot
    QName newTranslationType = nodeService.getType(translationOfNodeRef);
    NodeRef newTranslationNodeRef = fileFolderService.create(parentNodeRef, name, newTranslationType)
            .getNodeRef();

    // add the translation to the container
    addTranslation(newTranslationNodeRef, translationOfNodeRef, locale);

    // Although the content is spoofed from the pivot translation, it isn't
    // done for all services
    // TODO: Fix http://issues.alfresco.com/browse/AR-1487
    ContentData translationOfContentData = (ContentData) nodeService.getProperty(translationOfNodeRef,
            ContentModel.PROP_CONTENT);
    if (translationOfContentData != null) {
        ContentData newTranslationContentData = new ContentData(null, translationOfContentData.getMimetype(),
                translationOfContentData.getSize(), translationOfContentData.getEncoding(),
                translationOfContentData.getLocale());
        nodeService.setProperty(newTranslationNodeRef, ContentModel.PROP_CONTENT, newTranslationContentData);
    }

    // set it empty
    nodeService.addAspect(newTranslationNodeRef, ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION, null);
    // Initially, the file should be temporary. This will be changed as soon
    // as some content is added.
    nodeService.addAspect(newTranslationNodeRef, ContentModel.ASPECT_TEMPORARY, null);

    if (logger.isDebugEnabled()) {
        logger.debug("Added an empty translation: \n" + "   Translation of:  " + translationOfNodeRef + "\n"
                + "   New translation: " + newTranslationNodeRef + "\n" + "   Locale:          " + locale);
    }

    return newTranslationNodeRef;
}

From source file:com.octo.captcha.engine.bufferedengine.buffer.DiskCaptchaBuffer.java

/**
 * Puts items into the store.//from  w  ww.  java2s. c  o m
 */
protected synchronized void store(Object element, Locale locale) throws IOException {
    if (!isInitalized)
        return;
    // Serialise the entry
    final ByteArrayOutputStream outstr = new ByteArrayOutputStream();
    final ObjectOutputStream objstr = new ObjectOutputStream(outstr);
    objstr.writeObject(element);
    objstr.close();
    final byte[] buffer = outstr.toByteArray();

    //check if there is space
    //        if (diskElements.size() >= maxDataSize)
    //        {
    //            return false;
    //        }

    // Check for a free block
    DiskElement diskElement = findFreeBlock(buffer.length);
    if (diskElement == null) {
        diskElement = new DiskElement();
        diskElement.position = randomAccessFile.length();
        diskElement.blockSize = buffer.length;
    }

    // TODO - cleanup block on failure
    // Write the record
    randomAccessFile.seek(diskElement.position);

    //TODO the free block algorithm will gradually leak disk space, due to
    //payload size being less than block size
    //this will be a problem for the persistent cache
    randomAccessFile.write(buffer);

    // Add to index, update stats
    diskElement.payloadSize = buffer.length;
    totalSize += buffer.length;

    //create the localized buffer
    if (!diskElements.containsKey(locale)) {

        diskElements.put(locale, new LinkedList());
    }
    ((LinkedList) diskElements.get(locale)).addLast(diskElement);

    if (log.isDebugEnabled()) {
        long menUsed = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
        log.debug("Store " + locale.toString() + " on object, total size : " + size()
                + " Total unsed elements : " + freeSpace.size() + " memory used " + menUsed);
    }
}