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.wisemapping.webmvc.MindmapController.java

private String showEditorPage(int id, @NotNull final Model model, boolean requiresLock)
        throws WiseMappingException {
    final MindMapBean mindmapBean = findMindmapBean(id);
    final Mindmap mindmap = mindmapBean.getDelegated();
    final User collaborator = Utils.getUser();
    final Locale locale = LocaleContextHolder.getLocale();

    // Is the mindmap locked ?.
    boolean isLocked = false;
    boolean readOnlyMode = !requiresLock || !mindmap.hasPermissions(collaborator, CollaborationRole.EDITOR);
    if (!readOnlyMode) {
        final LockManager lockManager = this.mindmapService.getLockManager();
        if (lockManager.isLocked(mindmap) && !lockManager.isLockedBy(mindmap, collaborator)) {
            readOnlyMode = true;//from w ww .  j  a v  a 2 s . c o  m
            isLocked = true;
        } else {
            model.addAttribute("lockTimestamp", mindmap.getLastModificationTime().getTimeInMillis());
            model.addAttribute(LOCK_SESSION_ATTRIBUTE, lockManager.generateSession());
        }
        model.addAttribute("lockInfo", lockManager.getLockInfo(mindmap));
    }
    // Set render attributes ...
    model.addAttribute("mindmap", mindmapBean);

    // Configure default locale for the editor ...
    model.addAttribute("locale", locale.toString().toLowerCase());
    model.addAttribute("principal", collaborator);
    model.addAttribute("readOnlyMode", readOnlyMode);
    model.addAttribute("memoryPersistence", false);
    model.addAttribute("mindmapLocked", isLocked);

    return "mindmapEditor";
}

From source file:org.alfresco.repo.search.impl.lucene.LuceneQueryParser.java

/**
 * @param field String//w ww  .j a  v a2s.c o m
 * @param part1 String
 * @param part2 String
 * @param includeLower boolean
 * @param includeUpper boolean
 * @param analysisMode AnalysisMode
 * @param fieldName String
 * @param propertyDef PropertyDefinition
 * @param tokenisationMode IndexTokenisationMode
 * @param booleanQuery BooleanQuery
 * @param mlAnalysisMode MLAnalysisMode
 * @param locale Locale
 * @throws ParseException
 */
protected void addTextRange(String field, String part1, String part2, boolean includeLower,
        boolean includeUpper, AnalysisMode analysisMode, String fieldName, PropertyDefinition propertyDef,
        IndexTokenisationMode tokenisationMode, BooleanQuery booleanQuery, MLAnalysisMode mlAnalysisMode,
        Locale locale) throws ParseException {
    String textFieldName = fieldName;

    if ((analysisMode == AnalysisMode.IDENTIFIER) || (analysisMode == AnalysisMode.LIKE)) {
        {
            // text and ml text need locale
            IndexTokenisationMode tm = propertyDef.getIndexTokenisationMode();
            if ((tm != null) && (tm == IndexTokenisationMode.BOTH)) {
                if (locale.toString().length() == 0) {
                    textFieldName = textFieldName + FIELD_NO_LOCALE_SUFFIX;
                } else {
                    textFieldName = textFieldName + "." + locale + FIELD_SORT_SUFFIX;
                }

            }

        }
    }
    switch (tokenisationMode) {
    case BOTH:
        switch (analysisMode) {
        case DEFAULT:
        case TOKENISE:
            addLocaleSpecificTokenisedTextRange(part1, part2, includeLower, includeUpper, analysisMode,
                    fieldName, booleanQuery, locale, textFieldName);
            break;
        case IDENTIFIER:
            addLocaleSpecificUntokenisedTextRange(field, part1, part2, includeLower, includeUpper, booleanQuery,
                    mlAnalysisMode, locale, textFieldName);
            break;
        case WILD:
        case LIKE:
        case PREFIX:
        case FUZZY:
        default:
            throw new UnsupportedOperationException();
        }
        break;
    case FALSE:
        addLocaleSpecificUntokenisedTextRange(field, part1, part2, includeLower, includeUpper, booleanQuery,
                mlAnalysisMode, locale, textFieldName);

        break;
    case TRUE:
        addLocaleSpecificTokenisedTextRange(part1, part2, includeLower, includeUpper, analysisMode, fieldName,
                booleanQuery, locale, textFieldName);
        break;
    default:
    }
}

From source file:org.eclipse.jubula.client.archive.XmlExporter.java

/**
 * Write the information from the Object to its corresponding XML element.
 * /* ww w .j  a v a  2  s  .  c  o m*/
 * @param xml
 *            The XML element to be filled
 * @param po
 *            The persistent object which contains the information
 * @param includeTestResultSummaries 
 *                 Whether to save the Test Result Summaries as well.
 * 
 * @throws OperationCanceledException if the operation was canceled.
 */
public void fillProject(Project xml, IProjectPO po, boolean includeTestResultSummaries)
        throws ProjectDeletedException, PMException, OperationCanceledException {
    fillNode(xml, po);
    checkForCancel();
    IProjectPropertiesPO projectProperties = po.getProjectProperties();
    fillCheckConfiguration(xml, projectProperties.getCheckConfCont());
    // used toolkits
    fillUsedToolkits(xml, po);
    // All project toolkit info finished
    m_monitor.worked(1);
    fillComponentNames(xml, po);
    // aut toolkit
    final String autToolKit = po.getToolkit();
    xml.setAutToolKit(autToolKit);
    // AUT toolkit finished
    m_monitor.worked(1);
    // project languages
    xml.setDefaultLanguage(po.getDefaultLanguage().toString());
    for (Locale l : po.getLangHelper().getLanguageList()) {
        xml.addProjectLanguage(l.toString());
        // Project language finished
        m_monitor.worked(1);
    }
    // Test Data Cubes
    ITestDataCategoryPO testDataRootCategory = po.getTestDataCubeCont();
    for (ITestDataCategoryPO testDataCategory : testDataRootCategory.getCategoryChildren()) {
        TestDataCategory xmlTestDataCategory = xml.addNewTestDataCategory();
        fillTestDataCategory(xmlTestDataCategory, testDataCategory);
    }
    for (IParameterInterfacePO testDataCube : po.getTestDataCubeCont().getTestDataChildren()) {
        NamedTestData xmlTestDataCube = xml.addNewNamedTestData();
        fillNamedTestData(xmlTestDataCube, testDataCube);
    }
    // AUTs
    for (IAUTMainPO aut : getSortedAutList(po)) {
        Aut xmlAut = xml.addNewAut();
        fillAUT(xmlAut, aut);
        // AUT finished
        m_monitor.worked(1);
    }
    // test cases and categories (visible in test case view)
    handleSpecPersistables(xml, po);

    handleExecPersistables(xml, po);

    // reused projects
    handleReusedProjects(xml, po);
    checkForCancel();
    // testresult summaries
    if (includeTestResultSummaries) {
        fillTestResultSummary(xml, po);
    }
    checkForCancel();
    xml.setMetaDataVersion(po.getClientMetaDataVersion());
    xml.setMajorProjectVersion(po.getMajorProjectVersion());
    xml.setMinorProjectVersion(po.getMinorProjectVersion());
    xml.setIsReusable(po.getIsReusable());
    xml.setIsProtected(po.getIsProtected());
    xml.setTeststyleEnabled(projectProperties.getCheckConfCont().getEnabled());
    xml.setTestResultDetailsCleanupInterval(po.getTestResultCleanupInterval());
    xml.setAlmRepositoryName(projectProperties.getALMRepositoryName());
    xml.setIsReportOnSuccess(projectProperties.getIsReportOnSuccess());
    xml.setIsReportOnFailure(projectProperties.getIsReportOnFailure());
    xml.setDashboardURL(projectProperties.getDashboardURL());
    m_monitor.worked(1);
}

From source file:com.balero.models.StaticPagesDAO.java

@Transactional
public void make(Locale locale) {
    Session session = sessionFactory.getCurrentSession();
    StaticPages staticPages = new StaticPages();
    staticPages.setId(1);//from  w w  w . ja v a 2  s . c  o  m
    staticPages.setPagename("Example");
    staticPages.setPagebody("\n"
            + "<p>Lorem Ipsum is text that is commonly used in graphic design typefaces demonstrations or draft design to test the visual design before inserting the final text.</p>\n"
            + "\n"
            + "<p>Although currently has no sources to justify tesis hip, professor of classical philology Richard McClintock says its use dates back to the early printers XVI.1 century Its use in some text editors well known in today has given the new popularity lorem ipsum.</p>\n"
            + "\n"
            + "<p>The text itself no sense, although it is not completely random, but derives from a text by Cicero in Latin language, whose words have been removed them syllables or letters. The meaning of the text does not matter, since it is just a test demostracino,</p>\n");
    staticPages.setPageslug("example-page");
    staticPages.setPagelocale(locale.toString());
    session.save(staticPages);
    session.flush();
}

From source file:com.balero.models.BlogDAO.java

@Transactional
public void make(Locale locale) {
    Session session = sessionFactory.getCurrentSession();
    Blog Blog = new Blog();
    Blog.setId(1);/*  w  w w . j  av a  2 s  .c  o m*/
    Blog.setPosttitle("<h3>Lorem ipsum</h3>\n" + "\n"
            + "<p>Lorem Ipsum is text that is commonly used in graphic design typefaces demonstrations or draft design to test the visual design before inserting the final text.</p>\n"
            + "\n"
            + "<p>Although currently has no sources to justify tesis hip, professor of classical philology Richard McClintock says its use dates back to the early printers XVI.1 century Its use in some text editors well known in today has given the new popularity lorem ipsum.</p>\n"
            + "\n"
            + "<p>The text itself no sense, although it is not completely random, but derives from a text by Cicero in Latin language, whose words have been removed them syllables or letters. The meaning of the text does not matter, since it is just a test demostracino,</p>\n");
    Blog.setPostbody("Read more content...");
    Blog.setPostslug("welcome-test-post");
    Blog.setPostlocale(locale.toString());
    Blog.setPostauthor("admin");
    Blog.setPoststatus("published");
    session.save(Blog);
    session.flush();
}

From source file:org.jahia.ajax.gwt.helper.LanguageHelper.java

/**
 * Get available languages for the current site.
 *
 * When the site object is a jnt:module (mainly in studio mode) or if the passed site has no languages configured,
 * then we retrieve the languages of the system site.
 *
 * If the currentLocale parameter is empty or does not match any of the language of the site, none of the languages
 * will be flagged as current./*from   ww w .  j a  v a2 s . c  o m*/
 *
 * @param site
 * @param currentLocale
 * @return
 */
public List<GWTJahiaLanguage> getLanguages(@NotNull JCRSiteNode site, Locale currentLocale) {
    List<GWTJahiaLanguage> items = new ArrayList<GWTJahiaLanguage>();
    try {
        JCRSiteNode siteToCheck = site;
        if (site.isNodeType("jnt:module") || CollectionUtils.isEmpty(site.getLanguages())) {
            siteToCheck = (JCRSiteNode) ServicesRegistry.getInstance().getJahiaSitesService()
                    .getSiteByKey(JahiaSitesService.SYSTEM_SITE_KEY);
        }
        final Set<String> mandatoryLanguages = siteToCheck.getMandatoryLanguages();
        final Set<String> activeLanguages = siteToCheck.getActiveLiveLanguages();
        final TreeSet<String> orderedLanguages = new TreeSet<String>(siteToCheck.getLanguages());
        for (String langCode : orderedLanguages) {
            GWTJahiaLanguage item = new GWTJahiaLanguage();
            item.setLanguage(langCode);
            item.setDisplayName(getDisplayName(langCode));
            item.setImage(
                    getLangIcon(Jahia.getContextPath(), LanguageCodeConverters.languageCodeToLocale(langCode)));
            item.setCurrent(currentLocale != null && langCode.equalsIgnoreCase(currentLocale.toString()));
            item.setActive(activeLanguages.contains(langCode));
            item.setMandatory(mandatoryLanguages.contains(langCode));
            items.add(item);
        }
    } catch (Exception e) {
        logger.error("Error while retrieving languages for site/module: " + site.getPath(), e);
    }
    return items;
}

From source file:org.jahia.bin.JahiaAdministration.java

/**
 * This method is used like a dispatcher for user requests.
 *
 * @param request  Servlet request./*  w  w w  . j ava2 s.  c om*/
 * @param response Servlet response.
 * @param session  Servlet session for the current user.
 */
private void userRequestDispatcher(final HttpServletRequest request, final HttpServletResponse response,
        final HttpSession session) throws JahiaException, IOException, ServletException {
    String op = request.getParameter("do");
    if (op == null)
        op = "";
    final String operation = op;

    ParamBean jParams = initAdminJahiaData(request, response, session);
    final JahiaUser user = jParams.getUser();
    final JahiaSite site = jParams.getSite();

    try {
        Boolean accessGranted = (Boolean) session.getAttribute(CLASS_NAME + "accessGranted");
        if (accessGranted == null) {
            accessGranted = Boolean.FALSE;
        }

        if (accessGranted) {
            Locale uiLocale = (Locale) request.getSession().getAttribute(ProcessingContext.SESSION_UI_LOCALE);
            if (request.getParameter("switchUiLocale") != null) {
                uiLocale = LanguageCodeConverters.languageCodeToLocale(request.getParameter("switchUiLocale"));
                request.getSession().setAttribute(ProcessingContext.SESSION_UI_LOCALE, uiLocale);
                user.setProperty("preferredLanguage", uiLocale.toString());
            }

            Config.set(request, Config.FMT_LOCALIZATION_CONTEXT, new LocalizationContext(
                    new JahiaResourceBundle(uiLocale, site.getTemplatePackageName()), uiLocale));

            AdministrationModulesRegistry modulesRegistry = (AdministrationModulesRegistry) SpringContextSingleton
                    .getInstance().getContext().getBean("administrationModulesRegistry");
            AdministrationModule currentModule = modulesRegistry.getServerAdministrationModule(operation);
            if (currentModule != null) {
                if (hasSitePermission(currentModule.getPermissionName(), site.getSiteKey())
                        || hasServerPermission(currentModule.getPermissionName())) {
                    session.setAttribute(CLASS_NAME + "configJahia", Boolean.TRUE);
                    /** todo clean up this hardcoded mess. Is it even used anymore ? */
                    if ("sharecomponents".equals(operation) && user.isRoot()) {
                        request.setAttribute("showAllComponents", Boolean.TRUE);
                    }

                    currentModule.service(request, response);
                } else if ("sites".equals(operation)
                        && (session.getAttribute(JahiaAdministration.CLASS_NAME + "redirectToJahia") != null)) {
                    session.setAttribute(CLASS_NAME + "configJahia", Boolean.TRUE);
                    currentModule.service(request, response);
                }
            } else {
                currentModule = modulesRegistry.getSiteAdministrationModule(operation);
                if (currentModule != null) {
                    if (hasSitePermission(currentModule.getPermissionName(), site.getSiteKey())) {
                        session.setAttribute(CLASS_NAME + "configJahia", Boolean.FALSE);
                        if ("search".equals(operation)) {
                            // Use response wrapper to ensure correct handling of Application fields output to the response
                            // @todo is this still necessary with Pluto wrapper in effect ?
                            currentModule.service(new ServletIncludeRequestWrapper(request),
                                    new ServletIncludeResponseWrapper(response, true,
                                            SettingsBean.getInstance().getCharacterEncoding()));
                        } else {
                            currentModule.service(request, response);
                        }
                    }
                }
            }

            if ("switch".equals(operation)) {
                // operation : switch management mode (server, sites)
                switchModeAction(request, response, session);
            } else if ("change".equals(operation)) {
                // operation : change site id to manage
                session.setAttribute(CLASS_NAME + "configJahia", Boolean.FALSE);
                changeSite(request, response, session);
            } else {
                if (currentModule == null) {
                    displayMenu(request, response, session);
                }
            }

            // the user don't currently have a granted access...
        } else if (isValidLoginSession(session)) {
            displayMenu(request, response, session);
        } else {
            logger.debug("session login not valid.");
            if (JahiaUserManagerService
                    .isGuest((JahiaUser) session.getAttribute(ProcessingContext.SESSION_USER))) {
                displayLogin(request, response, session);
            } else {
                throw new JahiaForbiddenAccessException();
            }
        }
    } catch (Exception e) {
        if (e instanceof JahiaForbiddenAccessException) {
            throw (JahiaForbiddenAccessException) e;
        }
        logger.error("Error during " + operation + " operation", e);
        if (isValidLoginSession(session)) {
            displayMenu(request, response, session);
        } else {
            if (JahiaUserManagerService
                    .isGuest((JahiaUser) session.getAttribute(ProcessingContext.SESSION_USER))) {
                displayLogin(request, response, session);
            } else {
                throw new JahiaForbiddenAccessException();
            }
        }
    }
}

From source file:org.eclipse.jubula.client.archive.XmlExporter.java

/**
 * Write the information from the Object to its corresponding XML element.
 * /* w  w w  .  jav  a 2s. c om*/
 * @param xml
 *            The XML element to be filled
 * @param po
 *            The persistent object which contains the information
 */
private void fillTestData(TestData xml, ITDManager po) {

    for (String uniqueId : po.getUniqueIds()) {
        xml.addUniqueIds(uniqueId);
    }

    int rowCnt = 1;
    for (IDataSetPO row : po.getDataSets()) {
        TestDataRow xmlRow = xml.addNewRow();
        xmlRow.setRowCount(rowCnt++);
        int colCnt = 1;
        for (ITestDataPO td : row.getList()) {
            TestDataCell xmlCell = xmlRow.addNewData();
            xmlCell.setColumnCount(colCnt++);
            List<Locale> sortedLanguageList = new ArrayList<Locale>(td.getLanguages());
            Collections.sort(sortedLanguageList, LANG_CODE_ALPHA_COMPARATOR);
            for (Locale lang : sortedLanguageList) {
                String val = td.getValue(lang);
                I18NString xmlI18n = xmlCell.addNewData();
                xmlI18n.setLanguage(lang.toString());
                xmlI18n.setValue(val);
            }
        }
    }
}

From source file:org.alfresco.repo.search.impl.solr.SolrQueryHTTPClient.java

protected String buildStatsUrl(StatsParameters searchParameters, String baseUrl, Locale locale,
        SolrStoreMappingWrapper mapping) throws UnsupportedEncodingException {
    URLCodec encoder = new URLCodec();
    StringBuilder url = new StringBuilder();
    String languageUrlFragment = extractLanguageFragment(searchParameters.getLanguage());

    url.append(baseUrl);/*from  w w w. ja  v  a2  s.  co  m*/
    url.append("/").append(languageUrlFragment);
    url.append("?wt=").append(encoder.encode("json", "UTF-8"));
    url.append("&locale=").append(encoder.encode(locale.toString(), "UTF-8"));

    url.append(buildSortParameters(searchParameters, encoder));

    url.append("&stats=true");
    url.append("&rows=0");
    if (!StringUtils.isBlank(searchParameters.getFilterQuery())) {
        url.append("?fq=").append(encoder.encode(searchParameters.getFilterQuery(), "UTF-8"));
    }

    for (Entry<String, String> entry : searchParameters.getStatsParameters().entrySet()) {
        url.append("&stats.").append(entry.getKey()).append("=")
                .append(encoder.encode(entry.getValue(), "UTF-8"));
    }

    if ((mapping != null) && ((searchParameters.getStores().size() > 1) || (mapping.isSharded()))) {
        boolean requiresSeparator = false;
        url.append("&shards=");
        for (StoreRef storeRef : searchParameters.getStores()) {
            SolrStoreMappingWrapper storeMapping = extractMapping(storeRef);

            if (requiresSeparator) {
                url.append(',');
            } else {
                requiresSeparator = true;
            }

            url.append(storeMapping.getShards());

        }
    }

    return url.toString();
}

From source file:org.alfresco.repo.search.impl.lucene.LuceneQueryParser.java

protected void addMLTextAttributeQuery(String field, String queryText, SubQuery subQueryBuilder,
        AnalysisMode analysisMode, LuceneFunction luceneFunction, String expandedFieldName,
        PropertyDefinition propertyDef, IndexTokenisationMode tokenisationMode, BooleanQuery booleanQuery,
        MLAnalysisMode mlAnalysisMode, Locale locale) throws ParseException {
    String mlFieldName = expandedFieldName;

    if ((tokenisationMode == IndexTokenisationMode.BOTH)
            && ((analysisMode == AnalysisMode.IDENTIFIER) || (analysisMode == AnalysisMode.LIKE))) {
        {/*from   w ww  . j a  va2 s  .c  o m*/
            // text and ml text need locale
            IndexTokenisationMode tm = propertyDef.getIndexTokenisationMode();
            if ((tm != null) && (tm == IndexTokenisationMode.BOTH)) {
                if (locale.toString().length() == 0) {
                    mlFieldName = mlFieldName + FIELD_NO_LOCALE_SUFFIX;
                } else {
                    mlFieldName = mlFieldName + "." + locale + FIELD_SORT_SUFFIX;
                }
            }

        }
    }

    boolean lowercaseExpandedTerms = getLowercaseExpandedTerms();
    try {
        switch (tokenisationMode) {
        case BOTH:
            switch (analysisMode) {
            default:
            case DEFAULT:
            case TOKENISE:
                addLocaleSpecificTokenisedMLOrTextAttribute(queryText, subQueryBuilder, analysisMode,
                        luceneFunction, booleanQuery, locale, expandedFieldName);
                break;
            case IDENTIFIER:
            case FUZZY:
            case PREFIX:
            case WILD:
            case LIKE:
                setLowercaseExpandedTerms(false);
                addLocaleSpecificUntokenisedMLOrTextAttribute(field, queryText, subQueryBuilder, analysisMode,
                        luceneFunction, booleanQuery, mlAnalysisMode, locale, mlFieldName);

                break;
            }
            break;
        case FALSE:
            setLowercaseExpandedTerms(false);
            addLocaleSpecificUntokenisedMLOrTextAttribute(field, queryText, subQueryBuilder, analysisMode,
                    luceneFunction, booleanQuery, mlAnalysisMode, locale, mlFieldName);
            break;
        case TRUE:
        default:
            switch (analysisMode) {
            default:
            case DEFAULT:
            case TOKENISE:
            case IDENTIFIER:
                addLocaleSpecificTokenisedMLOrTextAttribute(queryText, subQueryBuilder, analysisMode,
                        luceneFunction, booleanQuery, locale, expandedFieldName);
                break;
            case FUZZY:
            case PREFIX:
            case WILD:
            case LIKE:
                addLocaleSpecificUntokenisedMLOrTextAttribute(field, queryText, subQueryBuilder, analysisMode,
                        luceneFunction, booleanQuery, mlAnalysisMode, locale, mlFieldName);
                break;
            }
        }
    } finally {
        setLowercaseExpandedTerms(lowercaseExpandedTerms);
    }
}