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.sakaiproject.emailtemplateservice.service.impl.EmailTemplateServiceImpl.java

private EmailTemplate getEmailTemplateNoDefault(String key, Locale locale) {
    log.debug("getEmailTemplateNoDefault( " + key + "," + locale);
    if (key == null || "".equals(key)) {
        throw new IllegalArgumentException("key cannot be null or empty");
    }//from  w w  w .j a  v a  2 s .  c om
    EmailTemplate et = null;
    if (locale != null) {
        Search search = new Search("key", key);
        search.addRestriction(new Restriction("locale", locale.toString()));
        et = dao.findOneBySearch(EmailTemplate.class, search);
    } else {
        Search search = new Search("key", key);
        search.addRestriction(new Restriction("locale", EmailTemplate.DEFAULT_LOCALE));
        et = dao.findOneBySearch(EmailTemplate.class, search);
    }
    return et;
}

From source file:com.bstek.dorado.view.resource.DefaultViewResourceBundleManager.java

protected Resource findResource(ViewConfigDefinition viewConfigDefinition, Locale locale) throws IOException {
    Resource viewResource = viewConfigDefinition.getResource();
    if (viewResource != null) {
        Resource resource;//  w w w  . j  a v  a  2  s .  co m
        String path = viewResource.getPath();
        if (StringUtils.isEmpty(path)) {
            return null;
        }

        int i = path.lastIndexOf(PathUtils.PATH_DELIM);
        if (i >= 0) {
            path = path.substring(i + 1);
        } else {
            i = path.lastIndexOf(':');
            if (i >= 0) {
                path = path.substring(i + 1);
            }
        }
        i = path.indexOf('.');
        if (i >= 0) {
            path = path.substring(0, i);
        }

        if (locale != null) {
            String localeSuffix = '.' + locale.toString();
            try {
                resource = viewResource.createRelative(path + localeSuffix + RESOURCE_FILE_SUFFIX);
                if (resource != null && resource.exists()) {
                    return resource;
                }
            } catch (Exception e) {
                // JBOSS 5.1snowdrop?VFS???
            }
        }

        try {
            resource = viewResource.createRelative(path + RESOURCE_FILE_SUFFIX);
            if (resource != null && resource.exists()) {
                return resource;
            }
        } catch (Exception e) {
            // JBOSS 5.1snowdrop?VFS???
        }
    }
    return null;
}

From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java

private void checkParse(final Locale locale, final SimpleDateFormat sdf, final DateParser fdf,
        final String formattedDate) throws ParseException {
    final Date expectedTime = sdf.parse(formattedDate);
    final Date actualTime = fdf.parse(formattedDate);
    assertEquals(locale.toString() + " " + formattedDate + "\n", expectedTime, actualTime);
}

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

private void addLocaleSpecificTokenisedTextRange(String part1, String part2, boolean includeLower,
        boolean includeUpper, AnalysisMode analysisMode, String fieldName, BooleanQuery booleanQuery,
        Locale locale, String textFieldName) throws ParseException {
    StringBuilder builder = new StringBuilder();
    builder.append("{").append(locale.toString()).append("}").append(part1);
    String first = getToken(fieldName, builder.toString(), analysisMode);

    builder = new StringBuilder();
    builder.append("{").append(locale.toString()).append("}").append(part2);
    String last = getToken(fieldName, builder.toString(), analysisMode);

    Query query = new ConstantScoreRangeQuery(textFieldName, first, last, includeLower, includeUpper);
    booleanQuery.add(query, Occur.SHOULD);
}

From source file:org.apache.felix.webconsole.internal.compendium.ConfigManager.java

protected void doPost(HttpServletRequest comingrequest, HttpServletResponse response) throws IOException {
    // needed multiple times below
    String tempPid = comingrequest.getParameter(ConfigManager.SERVICE_PID);
    if (tempPid == null) {
        String pathInfo = comingrequest.getPathInfo();
        tempPid = pathInfo.substring(pathInfo.lastIndexOf('/') + STRING_FORWARD);
    }//from  ww w .  j a v a  2 s. c  om

    // the filter to select part of the configurations
    String pidFilterParam = comingrequest.getParameter(PID_FILTER);

    final ConfigurationAdmin currConfigAdmin = this.getConfigurationAdmin();

    // ignore this request if the pid and/or configuration admin is missing
    if (tempPid == null || currConfigAdmin == null) {
        // should log this here !!
        return;
    }

    // the configuration to operate on (to be created or "missing")
    Configuration tempConfig = null;

    // should actually apply the configuration before redirecting
    if (comingrequest.getParameter("create") != null) {
        tempConfig = new PlaceholderConfiguration(tempPid); // ca.createFactoryConfiguration(
        // pid, null );
        tempPid = tempConfig.getPid();
    } else if (comingrequest.getParameter("apply") != null) {
        String redirectAddr = applyConfiguration(comingrequest, currConfigAdmin, tempPid);
        if (redirectAddr != null) {
            if (pidFilterParam != null) {
                redirectAddr += "?" + PID_FILTER + "=" + pidFilterParam;
            }

            this.sendRedirectURL(comingrequest, response, redirectAddr);
        }

        return;
    }

    if (tempConfig == null) {
        tempConfig = getConfigurationWithPid(currConfigAdmin, tempPid);
    }

    // send the result
    response.setContentType("application/json");
    response.setCharacterEncoding("UTF-8");
    final Locale requestLocale = getLocale(comingrequest);
    final String localeInfo = (requestLocale != null) ? requestLocale.toString() : null;
    printJsonConfig(response.getWriter(), tempPid, tempConfig, pidFilterParam, localeInfo);
}

From source file:org.apache.felix.webconsole.internal.compendium.ConfigManager.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // let's check for a json request
    final String currInfo = request.getPathInfo();
    if (currInfo.endsWith(".json")) {
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");

        // after last slash and without extension
        String tempPid = currInfo.substring(currInfo.lastIndexOf('/') + 1, currInfo.length() - TAIL_LENGTH);
        // check whether the pid is actually a filter for the selection
        // of configurations to display
        String pidFilter = request.getParameter(PID_FILTER);
        if (pidFilter == null) {
            pidFilter = tempPid;//from  w w w. j  a v a2  s  . c o m
        }
        try {
            getBundleContext().createFilter(pidFilter);

            // if the pidFilter was set from the pid, clear the pid
            if (tempPid == pidFilter) {
                tempPid = null;
            }
        } catch (InvalidSyntaxException ex) {
            pidFilter = null;
        }

        final ConfigurationAdmin currConfigAdmin = this.getConfigurationAdmin();

        final Locale currLocale = getLocale(request);
        final String localeInfo = (currLocale != null) ? currLocale.toString() : null;

        final PrintWriter printWriter = response.getWriter();

        try {
            printWriter.write("[");
            final SortedMap tempServices = this.getServices(tempPid, pidFilter, localeInfo, false);
            final Iterator tempIter = tempServices.keySet().iterator();
            boolean moreConfig = false;
            while (tempIter.hasNext()) {
                final String servicePid = tempIter.next().toString();

                final Configuration config = this.getConfigurationWithPid(currConfigAdmin, servicePid);
                if (config != null) {
                    if (moreConfig) {
                        printWriter.print(',');
                    }
                    this.printJsonConfig(printWriter, servicePid, config, pidFilter, localeInfo);
                    moreConfig = true;
                }
            }
            printWriter.write("]");
        } catch (InvalidSyntaxException ex) {
            // this should not happend as we checked the filter before
        }
        // nothing more to do
        return;
    }

    super.doGet(request, response);
}

From source file:org.alfresco.repo.template.XSLTProcessor.java

@Override
public void process(String template, Object model, Writer out, Locale locale) {
    if (template.indexOf(StoreRef.URI_FILLER) != -1) {
        // If template is a node ref, ignore locale
        process(template, model, out);//from  w ww  .  jav a 2s .co  m
    } else {
        //Otherwise try and locate a locale specific resource.
        TemplateSource templateSource = null;
        int lastDot = template.lastIndexOf('.');
        String prefix = lastDot == -1 ? template : template.substring(0, lastDot);
        String suffix = lastDot == -1 ? "" : template.substring(lastDot);
        String localeName = LOCALE_SEPARATOR + locale.toString();
        StringBuffer buf = new StringBuffer(template.length() + localeName.length());
        buf.append(prefix);
        for (;;) {
            buf.setLength(prefix.length());
            String path = buf.append(localeName).append(suffix).toString();
            try {
                templateSource = (TemplateSource) templateLoader.findTemplateSource(path);
            } catch (IOException ex) {
                throw new TemplateException(MSG_UNABLE_TO_READ_TEMPLATE, new Object[] { ex.getMessage() }, ex);
            }
            if (templateSource != null) {
                break;
            }
            int lastUnderscore = localeName.lastIndexOf('_');
            if (lastUnderscore == -1) {
                break;
            }
            localeName = localeName.substring(0, lastUnderscore);
        }
        if (templateSource == null) {
            throw new TemplateException(MSG_ERROR_NO_TEMPLATE, new Object[] { template });
        }
        process(templateSource, model, out);
    }
}

From source file:com.alehuo.wepas2016projekti.controller.UploadController.java

/**
 * Kuvan latauksen ksittely//  ww  w.  j a  va2  s  . c  o m
 * @param a Autentikointi
 * @param m Malli
 * @param formData Lomakkeen data
 * @param bs BindingResult
 * @param l Locale
 * @return
 */
@RequestMapping(method = RequestMethod.POST)
public String processUpload(Authentication a, Model m, @Valid @ModelAttribute ImageUploadFormData formData,
        BindingResult bs, Locale l) {
    //Hae autentikointi
    UserAccount u = userService.getUserByUsername(a.getName());
    m.addAttribute("user", u);
    if (bs.hasErrors()) {
        LOG.log(Level.WARNING,
                "Kayttaja ''{0}'' yritti ladata kuvaa, mutta syotteita ei validoitu. Onko otsikko tyhja?",
                a.getName());
        return "upload";
    }
    MultipartFile file = formData.getFile();
    String description = formData.getDescription();

    //Tiedostomuodon tarkistus
    if (!(file.getContentType().equals("image/jpg") || file.getContentType().equals("image/png")
            || file.getContentType().equals("image/jpeg") || file.getContentType().equals("image/bmp")
            || file.getContentType().equals("image/gif"))) {
        if (l.toString().equals("fi")) {
            bs.rejectValue("file", "error.file", "Tiedostomuotoa ei sallita.");
        } else {
            bs.rejectValue("file", "error.file", "File type not permitted.");
        }

        if (bs.hasErrors()) {
            LOG.log(Level.WARNING,
                    "Kayttaja ''{0}'' yritti ladata kuvaa, mutta tiedostomuotoa ''{1}'' ei sallita.",
                    new Object[] { a.getName(), file.getContentType() });
            return "upload";
        }
    } else {
        //Tallenna kuva
        Image i;
        try {
            i = imageService.addImage(u, file.getBytes(), file.getContentType(), description);
            LOG.log(Level.INFO, "Kayttaja ''{0}'' latasi uuden kuvan palveluun. Kuvan tunniste: ''{1}''",
                    new Object[] { a.getName(), i.getUuid() });
        } catch (IOException ex) {
            LOG.log(Level.SEVERE, null, ex);
            LOG.log(Level.SEVERE,
                    "Kayttaja ''{0}'' yritti ladata kuvaa palveluun, mutta tapahtui palvelinvirhe.",
                    a.getName());
            if (l.toString().equals("fi")) {
                bs.rejectValue("file", "error.file", "Kuvan lhetys eponnistui.");
            } else {
                bs.rejectValue("file", "error.file", "Image upload failed.");
            }

            return "upload";
        }

    }

    return "redirect:/";
}

From source file:org.apache.felix.webconsole.internal.compendium.ConfigManager.java

/**
 * @see org.apache.felix.webconsole.AbstractWebConsolePluginServlet#renderServletRequest(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse)
 *//* w  ww . j a  v a 2  s  . c  o  m*/
public void renderServletRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {

    // extract the configuration pid from the request path
    String tempPid = request.getPathInfo().substring(this.getServletLabel().length() + 1);
    if (tempPid.length() == 0) {
        tempPid = null;
    } else {
        tempPid = tempPid.substring(tempPid.lastIndexOf('/') + STRING_FORWARD);
    }
    // same procedure in doGet
    String currPidFilter = request.getParameter(PID_FILTER);
    if (currPidFilter == null) {
        currPidFilter = tempPid;
    }
    if (currPidFilter != null) {
        try {
            getBundleContext().createFilter(currPidFilter);

            // if the pidFilter was set from the pid, clear the pid
            if (tempPid == currPidFilter) {
                tempPid = null;
            }
        } catch (InvalidSyntaxException ex) {
            // its ok, if the pid is just a single PID
            currPidFilter = null;
        }
    }

    final ConfigurationAdmin currConfigAdmin = this.getConfigurationAdmin();

    final Locale tempLocale = getLocale(request);
    final String localeInfo = (tempLocale != null) ? tempLocale.toString() : null;

    final PrintWriter printWriter = response.getWriter();

    final String attrAppRoot = (String) request.getAttribute(OsgiManager.OSGI_APP_ROOT);
    printWriter.println(
            "<script src='" + attrAppRoot + "/res/ui/configmanager.js' language='JavaScript'></script>");

    printWriter.println("<table class='content' cellpadding='0' cellspacing='0' width='100%'>");

    if (currConfigAdmin == null) {
        printWriter.println("<tr class='content' id='configField'>");
        printWriter.println("<td class='content'>&nbsp;</th>");
        printWriter.println("<td class='content'>");
        printWriter.print("Configuration Admin Service not available");
    } else {
        printWriter.println("<tr class='content' id='configField'>");
        printWriter.println("<td class='content'>Configurations</th>");
        printWriter.println("<td class='content'>");
        this.listConfigurations(printWriter, currConfigAdmin, currPidFilter, localeInfo);
        printWriter.println("</td>");
        printWriter.println("</tr>");

        printWriter.println("<tr class='content' id='factoryField'>");
        printWriter.println("<td class='content'>Factory Configurations</th>");
        printWriter.println("<td class='content'>");
        this.listFactoryConfigurations(printWriter, currConfigAdmin, currPidFilter, localeInfo);

    }
    printWriter.println("</td>");
    printWriter.println("</tr>");
    printWriter.println("</table>");

    // if a configuration is addressed, display it immediately
    final Configuration currConfig;
    if (request.getParameter("create") != null && tempPid != null) {
        currConfig = new PlaceholderConfiguration(tempPid);
        tempPid = currConfig.getPid();
    } else {
        currConfig = getConfigurationWithPid(currConfigAdmin, tempPid);
    }

    if (tempPid != null) {
        Util.startScript(printWriter);

        printWriter.println("var configuration=");
        printJsonConfig(printWriter, tempPid, currConfig, currPidFilter, localeInfo);

        printWriter.println(";");
        printWriter.println("displayConfigForm(configuration);");
        Util.endScript(printWriter);
    }
}

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

private void addLocaleSpecificTokenisedMLOrTextAttribute(String queryText, SubQuery subQueryBuilder,
        AnalysisMode analysisMode, LuceneFunction luceneFunction, BooleanQuery booleanQuery, Locale locale,
        String actualField) throws ParseException {
    StringBuilder builder = new StringBuilder(queryText.length() + 10);
    builder.append("{").append(locale.toString()).append("}").append(queryText);
    Query subQuery = subQueryBuilder.getQuery(actualField, builder.toString(), analysisMode, luceneFunction);
    if (subQuery != null) {
        booleanQuery.add(subQuery, Occur.SHOULD);
    }/*from www.  j  a v  a  2  s.c o  m*/
}