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:org.gitana.platform.client.node.NodeImpl.java

@Override
public Node createTranslation(String edition, Locale locale, ObjectNode object) {
    String uri = getResourceUri() + "/i18n?edition=" + edition + "&locale=" + locale.toString();
    Response r1 = getRemote().post(uri, object);
    String nodeId = r1.getId();/*from w  w  w  .  j  av a 2s  .c o  m*/

    Response r2 = getRemote()
            .get("/repositories/" + getRepositoryId() + "/branches/" + getBranchId() + "/nodes/" + nodeId);
    return (Node) getFactory().node(getBranch(), r2);
}

From source file:com.octo.captcha.engine.bufferedengine.BufferedEngineContainer.java

/**
 * Method launch by a scheduler to feed the disk buffer with captcha. The ratio of feeding for each locale is
 * defined in the configuration component.
 *//*from  ww w  .j  a v  a 2s .c om*/
public void feedPersistentBuffer() {

    log.debug("entering feedPersistentBuffer()");
    //evaluate the total feed size
    int freePersistentBufferSize = config.getMaxPersistentMemorySize().intValue() - persistentBuffer.size();
    freePersistentBufferSize = freePersistentBufferSize > 0 ? freePersistentBufferSize : 0;
    int totalFeedsize = freePersistentBufferSize > config.getFeedSize().intValue()
            ? config.getFeedSize().intValue()
            : freePersistentBufferSize;

    log.info("Starting feed. Total feed size = " + totalFeedsize);

    //feed the buffer for each locale
    MapIterator it = config.getLocaleRatio().mapIterator();
    while (it.hasNext() && !shutdownCalled) {
        Locale locale = (Locale) it.next();
        double ratio = ((Double) it.getValue()).doubleValue();
        int ratioCount = (int) Math.round(totalFeedsize * ratio);

        if (log.isDebugEnabled()) {
            log.debug("construct " + ratioCount + " captchas for locale " + locale.toString());
        }
        //batch build and store captchas
        int toBuild = ratioCount;
        while (toBuild > 0 && !shutdownCalled) {
            int batch = toBuild > config.getFeedBatchSize().intValue() ? config.getFeedBatchSize().intValue()
                    : toBuild;
            ArrayList captchas = new ArrayList(batch);
            //build captchas, batch sized
            int builded = 0;
            for (int i = 0; i < batch; i++) {
                try {
                    captchas.add(engine.getNextCaptcha(locale));
                    builded++;
                } catch (CaptchaException e) {
                    log.warn("Error during captcha construction, skip this one : ", e);
                }
            }
            //persist
            persistentBuffer.putAllCaptcha(captchas, locale);
            if (log.isInfoEnabled()) {
                log.info("feeded persistent buffer with  " + builded + " captchas for locale " + locale);
            }
            toBuild -= builded;
        }

    }
    log.info("Stopping feed : feeded persitentBuffer with : " + totalFeedsize + " captchas");
    log.info("Stopping feed : resulting persitentBuffer size : " + persistentBuffer.size());
    persistentFeedings++;
}

From source file:org.auraframework.http.resource.InlineJs.java

private void appendLocaleDataJavascripts(PrintWriter out) {
    AuraLocale auraLocale = localizationAdapter.getAuraLocale();

    // Refer to the locale in LocaleValueProvider
    Locale langLocale = auraLocale.getLanguageLocale();
    Locale userLocale = auraLocale.getLocale();

    // This is for backward compatibility. At this moment, there are three locales
    // in Locale Value Provider. Keep them all available for now to avoid breaking consumers.
    String langMomentLocale = this.getMomentLocale(langLocale.toString());
    String userMomentLocale = this.getMomentLocale(userLocale.toString());
    String ltngMomentLocale = this.getMomentLocale(langLocale.getLanguage() + "_" + userLocale.getCountry());

    StringBuilder defineLocaleJs = new StringBuilder();
    // "en" data has been included in moment lib, no need to load locale data
    if (!"en".equals(langMomentLocale)) {
        String content = this.localeData.get(langMomentLocale);
        defineLocaleJs.append(content).append("\n");
    }/*from  www  .  j  a  v  a  2  s  . c om*/

    // if user locale is same as language locale, not need to load again
    if (!"en".equals(userMomentLocale) && userMomentLocale != null
            && !userMomentLocale.equals(langMomentLocale)) {
        String content = this.localeData.get(userMomentLocale);
        defineLocaleJs.append(content);
    }

    if (!"en".equals(ltngMomentLocale) && ltngMomentLocale != null && !ltngMomentLocale.equals(langMomentLocale)
            && !ltngMomentLocale.equals(userMomentLocale)) {
        String content = this.localeData.get(ltngMomentLocale);
        defineLocaleJs.append(content);
    }

    if (defineLocaleJs.length() > 0) {
        String loadLocaleDataJs = String.format("\n(function(){\n" + "    function loadLocaleData(){\n%s}\n"
                + "    window.moment? loadLocaleData() : (window.Aura || (window.Aura = {}), window.Aura.loadLocaleData=loadLocaleData);\n"
                + "})();\n", defineLocaleJs.toString());

        out.append(loadLocaleDataJs);
    }
}

From source file:com.aurel.track.screen.dashboard.action.DashboardAJAXAction.java

@Override
public String execute() throws Exception {
    try {/*from   www  .  j  a  v  a 2s  . co m*/
        Locale locale = (Locale) session.get(Constants.LOCALE_KEY);
        TDashboardFieldBean dashboardItem = (TDashboardFieldBean) DashboardFieldRuntimeBL.getInstance()
                .loadField(dashboardID);
        IPluginDashboard plugin = DashboardUtil.getPlugin(dashboardItem);
        Map<String, String> configParamsMap = dashboardItem.getParametres();
        if (locale != null) {
            configParamsMap.put(BasePluginDashboardView.CONFIGURATION_PARAMS.LOCALE_STRING, locale.toString());
        }
        String jsonData = plugin.createJsonData(dashboardID, session, configParamsMap, projectID, releaseID,
                params);
        try {
            JSONUtility.prepareServletResponseJSON(ServletActionContext.getResponse());
            PrintWriter out = ServletActionContext.getResponse().getWriter();
            StringBuilder sb = new StringBuilder();
            sb.append("{");
            JSONUtility.appendBooleanValue(sb, JSONUtility.JSON_FIELDS.SUCCESS, true);
            JSONUtility.appendJSONValue(sb, "data", jsonData, true);
            sb.append("}");
            out.println(sb);
        } catch (IOException e) {
            LOGGER.error(ExceptionUtils.getStackTrace(e));
        }
    } catch (Exception e) {
        LOGGER.error(ExceptionUtils.getStackTrace(e));
        JSONUtility.encodeJSONFailure(ServletActionContext.getResponse(), e.getMessage(), 1);
    }

    return null;
}

From source file:com.bstek.dorado.view.resolver.PackageFileResolver.java

protected final Resource getI18NResource(DoradoContext context, String resourcePrefix, String fileName,
        String resourceSuffix, Locale locale) throws Exception {
    if (locale == null) {
        locale = defaultLocale;//  www.j a va2 s.  c o  m
    }

    String localeSuffix = "";
    if (locale != null) {
        String localeString = locale.toString();
        if (StringUtils.isNotEmpty(localeString)) {
            localeSuffix = '.' + localeString;
        }
    }

    return doGetI18NResource(context, resourcePrefix, fileName, localeSuffix);
}

From source file:org.eclipse.jubula.client.core.businessprocess.importfilter.ExcelImportFilter.java

/**
 * parses a file and returns the data as DataTable structure
 * /*from   w w  w  .  j a v a2s . co  m*/
 * @param dataDir
 *      directory for data files
 * @param file
 *      data source File
 * @param locale
 *      data source locale
 * @return
 *      filled TestDataManager with new data
 * @throws IOException
 *      error occured while reading data source
 * @throws NoSupportForLocaleException
 *      no support for selected locale
 */
public DataTable parse(File dataDir, String file, Locale locale)
        throws IOException, NoSupportForLocaleException, DataReadException {

    DataTable filledDataTable;
    final FileInputStream inStream = findDataFile(dataDir, file);
    try {
        POIFSFileSystem fs = new POIFSFileSystem(inStream);
        HSSFWorkbook wb = new HSSFWorkbook(fs);
        // first data sheet is the only supported so far
        final int index = wb.getSheetIndex(locale.toString());
        if (index == -1) {
            throw new NoSupportForLocaleException();
        }
        HSSFSheet sheet = wb.getSheetAt(index);
        final int lastRowNum = sheet.getLastRowNum();
        final int firstRowNum = sheet.getFirstRowNum();
        // iterate over rows
        if (sheet.getRow(firstRowNum) == null) {
            return new DataTable(0, 0);
        }
        final int height = lastRowNum - firstRowNum + 1;
        final int width = sheet.getRow(firstRowNum).getLastCellNum()
                - sheet.getRow(firstRowNum).getFirstCellNum();
        filledDataTable = new DataTable(height, width);
        for (int rowNum = firstRowNum; rowNum <= lastRowNum; rowNum++) {
            HSSFRow row = sheet.getRow(rowNum);
            final short lastCellNum = row.getLastCellNum();
            final short firstCellNum = row.getFirstCellNum();
            for (int cellNr = firstCellNum; cellNr < lastCellNum; cellNr++) {

                HSSFCell cell = row.getCell(cellNr);
                String cellString = getExcelCellString(cell);
                filledDataTable.updateDataEntry(rowNum, cellNr, cellString);
            }
        }
    } catch (IOException e) {
        throw e; // just pass on, don't fall through to Throwable
    } catch (Throwable t) {
        throw new DataReadException(t);
    } finally {
        inStream.close();
    }

    /* fix issues with documents saved via open office 
     * if the document has been saved via open office it contains one ore many
     * "null" columns at the end of the data table; these columns are truncated 
     */
    while ((filledDataTable.getColumnCount() > 0)
            && (StringUtils.isBlank(filledDataTable.getData(0, filledDataTable.getColumnCount() - 1)))) {
        int newHeight = filledDataTable.getRowCount();
        int newWidth = filledDataTable.getColumnCount() - 1;
        DataTable cleanedFilledDataTable = new DataTable(newHeight, newWidth);
        for (int i = 0; i < newHeight; i++) {
            for (int j = 0; j < newWidth; j++) {
                cleanedFilledDataTable.updateDataEntry(i, j, filledDataTable.getData(i, j));
            }
        }
        filledDataTable = cleanedFilledDataTable;
    }

    return filledDataTable;
}

From source file:org.jboss.dashboard.displayer.table.TableDisplayerXMLFormat.java

protected void formatDisplayer(DataDisplayer displayer, PrintWriter out, int indent) throws Exception {
    TableDisplayer tableDisplayer = (TableDisplayer) displayer;
    DataSetTable table = tableDisplayer.getTable();

    printIndent(out, indent);//from   w  ww . j  av a 2 s.  c om
    out.print("<rowsperpage>");
    out.print(table.getMaxRowsPerPage());
    out.println("</rowsperpage>");

    if (table.getHeaderPosition() != null) {
        printIndent(out, indent);
        out.print("<headerposition>");
        out.print(table.getHeaderPosition());
        out.println("</headerposition>");
    }

    if (table.getHtmlStyle() != null) {
        printIndent(out, indent);
        out.print("<htmlstyle>");
        out.print(StringEscapeUtils.escapeXml(table.getHtmlStyle()));
        out.println("</htmlstyle>");
    }

    if (table.getRowEvenStyle() != null) {
        printIndent(out, indent);
        out.print("<rowevenstyle>");
        out.print(StringEscapeUtils.escapeXml(table.getRowEvenStyle()));
        out.println("</rowevenstyle>");
    }

    if (table.getRowOddStyle() != null) {
        printIndent(out, indent);
        out.print("<rowoddstyle>");
        out.print(StringEscapeUtils.escapeXml(table.getRowOddStyle()));
        out.println("</rowoddstyle>");
    }

    if (table.getRowHoverStyle() != null) {
        printIndent(out, indent);
        out.print("<rowhoverstyle>");
        out.print(StringEscapeUtils.escapeXml(table.getRowHoverStyle()));
        out.println("</rowhoverstyle>");
    }

    if (table.getHtmlClass() != null) {
        printIndent(out, indent);
        out.print("<htmlclass>");
        out.print(StringEscapeUtils.escapeXml(table.getHtmlClass()));
        out.println("</htmlclass>");
    }

    if (table.getRowEventClass() != null) {
        printIndent(out, indent);
        out.print("<rowevenclass>");
        out.print(StringEscapeUtils.escapeXml(table.getRowEventClass()));
        out.println("</rowevenclass>");
    }

    if (table.getRowOddClass() != null) {
        printIndent(out, indent);
        out.print("<rowoddclass>");
        out.print(StringEscapeUtils.escapeXml(table.getRowOddClass()));
        out.println("</rowoddclass>");
    }

    if (table.getRowHoverClass() != null) {
        printIndent(out, indent);
        out.print("<rowhoverclass>");
        out.print(StringEscapeUtils.escapeXml(table.getRowHoverClass()));
        out.println("</rowhoverclass>");
    }
    // Group by configuration (optional).
    DataProperty groupByProperty = table.getGroupByProperty();
    if (groupByProperty != null) {
        printIndent(out, indent++);
        out.println("<groupby>");
        DomainConfiguration domainConfig = new DomainConfiguration(groupByProperty);
        table.setGroupByConfiguration(domainConfig);
        formatDomain(domainConfig, out, indent);

        printIndent(out, indent);
        out.print("<showtotals>");
        out.print(table.showGroupByTotals());
        out.println("</showtotals>");

        printIndent(out, indent);
        out.print("<totalshtmlstyle>");
        out.print(table.getGroupByTotalsHtmlStyle());
        out.println("</totalshtmlstyle>");

        printIndent(out, --indent);
        out.println("</groupby>");
    }

    // Columns to display.
    for (int columnIndex = 0; columnIndex < table.getColumnCount(); columnIndex++) {
        DataProperty columnProperty = table.getOriginalDataProperty(columnIndex);
        if (columnProperty == null)
            continue;

        TableColumn column = table.getColumn(columnIndex);
        printIndent(out, indent++);
        out.println("<column>");

        printIndent(out, indent);
        out.print("<modelproperty>");
        out.print(column.getPropertyId());
        out.println("</modelproperty>");

        printIndent(out, indent);
        out.print("<viewindex>");
        out.print(columnIndex);
        out.println("</viewindex>");

        Map<Locale, String> columnName = column.getNameI18nMap();
        for (Locale l : columnName.keySet()) {
            printIndent(out, indent);
            out.print("<name language");
            out.print("=\"" + StringEscapeUtils.escapeXml(l.toString()) + "\">");
            out.print(StringEscapeUtils.escapeXml(columnName.get(l)));
            out.println("</name>");
        }

        Map<Locale, String> columnHint = column.getHintI18nMap();
        for (Locale l : columnHint.keySet()) {
            printIndent(out, indent);
            out.print("<hint language");
            out.print("=\"" + StringEscapeUtils.escapeXml(l.toString()) + "\">");
            out.print(StringEscapeUtils.escapeXml(columnHint.get(l)));
            out.println("</hint>");
        }

        if (column.getHeaderHtmlStyle() != null) {
            printIndent(out, indent);
            out.print("<headerhtmlstyle>");
            out.print(StringEscapeUtils.escapeXml(column.getHeaderHtmlStyle()));
            out.println("</headerhtmlstyle>");
        }

        if (column.getCellHtmlStyle() != null) {
            printIndent(out, indent);
            out.print("<cellhtmlstyle>");
            out.print(StringEscapeUtils.escapeXml(column.getCellHtmlStyle()));
            out.println("</cellhtmlstyle>");
        }

        if (column.getHtmlValue() != null) {
            printIndent(out, indent);
            out.print("<htmlvalue>");
            out.print(StringEscapeUtils.escapeXml(column.getHtmlValue()));
            out.println("</htmlvalue>");
        }

        String selectable = "false";
        if (column.isSelectable())
            selectable = "true";
        printIndent(out, indent);
        out.print("<selectable>");
        out.print(selectable);
        out.println("</selectable>");

        String sortable = "false";
        if (column.isSortable())
            sortable = "true";
        printIndent(out, indent);
        out.print("<sortable>");
        out.print(sortable);
        out.println("</sortable>");

        // Group by configuration (optional).
        if (groupByProperty != null) {
            String functionCode = table.getGroupByFunctionCode(columnIndex);
            if (functionCode != null && !groupByProperty.equals(columnProperty)) {
                printIndent(out, indent);
                out.print("<groupbyfunction>");
                out.print(functionCode);
                out.println("</groupbyfunction>");
            }
        }
        printIndent(out, --indent);
        out.println("</column>");
    }
}

From source file:com.redhat.rhn.common.localization.LocalizationService.java

/**
 * Determines if locale is supported/*w w  w. jav a  2s. co  m*/
 * @param locale user's locale
 * @return result
 */
public boolean isLocaleSupported(Locale locale) {
    return this.supportedLocales.get(locale.toString()) != null;
}

From source file:net.wastl.webmail.storage.FileStorage.java

protected void initLanguages() {
    log.info("Initializing available languages ... ");
    File f = new File(parent.getProperty("webmail.template.path") + System.getProperty("file.separator"));
    String[] flist = f.list(new FilenameFilter() {
        public boolean accept(File myf, String s) {
            if (myf.isDirectory() && s.equals(s.toLowerCase()) && (s.length() == 2 || s.equals("default"))) {
                return true;
            } else {
                return false;
            }//from www.j  a v a  2s.com
        }
    });

    File cached = new File(
            parent.getProperty("webmail.data.path") + System.getProperty("file.separator") + "locales.cache");
    Locale[] available1 = null;

    /* Now we try to cache the Locale list since it takes really long to gather it! */
    boolean exists = cached.exists();
    if (exists) {
        try {
            ObjectInputStream in = new ObjectInputStream(new FileInputStream(cached));
            available1 = (Locale[]) in.readObject();
            in.close();
            log.info("Using disk cache for langs... ");
        } catch (Exception ex) {
            exists = false;
        }
    }
    if (!exists) {
        // We should cache this on disk since it is so slow!
        available1 = Collator.getAvailableLocales();
        ObjectOutputStream os = null;
        try {
            os = new ObjectOutputStream(new FileOutputStream(cached));
            os.writeObject(available1);
        } catch (IOException ioe) {
            log.error("Failed to write to storage", ioe);
        } finally {
            try {
                os.close();
            } catch (IOException ioe) {
                log.error("Failed to close stream", ioe);
            }
        }
    }

    // Do this manually, as it is not JDK 1.1 compatible ...
    //Vector available=new Vector(Arrays.asList(available1));
    Vector<Locale> available = new Vector<Locale>(available1.length);
    for (int i = 0; i < available1.length; i++) {
        available.addElement(available1[i]);
    }
    String s = "";
    int count = 0;
    for (int i = 0; i < flist.length; i++) {
        String cur_lang = flist[i];
        Locale loc = new Locale(cur_lang, "", "");
        Enumeration<Locale> enumVar = available.elements();
        boolean added = false;
        while (enumVar.hasMoreElements()) {
            Locale l = (Locale) enumVar.nextElement();
            if (l.getLanguage().equals(loc.getLanguage())) {
                s += l.toString() + " ";
                count++;
                added = true;
            }
        }
        if (!added) {
            s += loc.toString() + " ";
            count++;
        }
    }
    log.info(count + " languages initialized.");
    cs.configRegisterStringKey(this, "LANGUAGES", s, "Languages available in WebMail");
    setConfig("LANGUAGES", s);

    /*
      Setup list of themes for each language
    */
    for (int j = 0; j < flist.length; j++) {
        File themes = new File(parent.getProperty("webmail.template.path")
                + System.getProperty("file.separator") + flist[j] + System.getProperty("file.separator"));
        String[] themelist = themes.list(new FilenameFilter() {
            public boolean accept(File myf, String s3) {
                if (myf.isDirectory() && !s3.equals("CVS")) {
                    return true;
                } else {
                    return false;
                }
            }
        });
        String s2 = "";
        for (int k = 0; k < themelist.length; k++) {
            s2 += themelist[k] + " ";
        }
        cs.configRegisterStringKey(this, "THEMES_" + flist[j].toUpperCase(), s2,
                "Themes for language " + flist[j]);
        setConfig("THEMES_" + flist[j].toUpperCase(), s2);
    }
}

From source file:org.olat.core.gui.render.velocity.VelocityRenderDecorator.java

/**
 * @return current language code as found in (current)Locale.toString() method
 *///from  www  .  j av  a  2 s  . com
public String getLanguageCode() {
    Locale currentLocale = I18nManager.getInstance().getCurrentThreadLocale();
    return currentLocale.toString();
}