Example usage for java.util Locale ENGLISH

List of usage examples for java.util Locale ENGLISH

Introduction

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

Prototype

Locale ENGLISH

To view the source code for java.util Locale ENGLISH.

Click Source Link

Document

Useful constant for language.

Usage

From source file:moefou4j.internal.util.Moefou4JInternalParseUtil.java

public static Date getDate(final String name, final String format) throws MoefouException {
    SimpleDateFormat sdf = formatMap.get().get(format);
    if (null == sdf) {
        sdf = new SimpleDateFormat(format, Locale.ENGLISH);
        sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
        formatMap.get().put(format, sdf);
    }//from w  w w. j  a  va2s .  c  o  m
    try {
        return sdf.parse(name);
    } catch (final ParseException pe) {
        throw new MoefouException("Unexpected date format(" + name + ") returned from twitter.com", pe);
    }
}

From source file:org.grails.plugins.elasticsearch.mapping.ElasticSearchMappingFactory.java

public static Map<String, Object> getElasticMapping(SearchableClassMapping scm) {
    Map<String, Object> elasticTypeMappingProperties = new LinkedHashMap<String, Object>();

    if (!scm.isAll()) {
        // "_all" : {"enabled" : true}
        elasticTypeMappingProperties.put("_all", Collections.singletonMap("enabled", false));
    }// w w  w .j av  a2s . co  m

    // Map each domain properties in supported format, or object for complex type
    for (SearchableClassPropertyMapping scpm : scm.getPropertiesMapping()) {
        // Does it have custom mapping?
        String propType = scpm.getGrailsProperty().getTypePropertyName();
        Map<String, Object> propOptions = new LinkedHashMap<String, Object>();
        // Add the custom mapping (searchable static property in domain model)
        propOptions.putAll(scpm.getAttributes());
        if (!(SUPPORTED_FORMAT.contains(scpm.getGrailsProperty().getTypePropertyName()))) {
            // Handle embedded persistent collections, ie List<String> listOfThings
            if (scpm.getGrailsProperty().isBasicCollectionType()) {
                String basicType = ClassUtils.getShortName(scpm.getGrailsProperty().getReferencedPropertyType())
                        .toLowerCase(Locale.ENGLISH);
                if (SUPPORTED_FORMAT.contains(basicType)) {
                    propType = basicType;
                }
                // Handle arrays
            } else if (scpm.getGrailsProperty().getReferencedPropertyType().isArray()) {
                String basicType = ClassUtils
                        .getShortName(scpm.getGrailsProperty().getReferencedPropertyType().getComponentType())
                        .toLowerCase(Locale.ENGLISH);
                if (SUPPORTED_FORMAT.contains(basicType)) {
                    propType = basicType;
                }
            } else if (isDateType(scpm.getGrailsProperty().getReferencedPropertyType())) {
                propType = "date";
            } else if (GrailsClassUtils.isJdk5Enum(scpm.getGrailsProperty().getReferencedPropertyType())) {
                propType = "string";
            } else if (scpm.getConverter() != null) {
                // Use 'string' type for properties with custom converter.
                // Arrays are automatically resolved by ElasticSearch, so no worries.
                propType = "string";
            } else {
                propType = "object";
            }

            if (scpm.getReference() != null) {
                propType = "object"; // fixme: think about composite ids.
            } else if (scpm.isComponent()) {
                // Proceed with nested mapping.
                // todo limit depth to avoid endless recursion?
                propType = "object";
                //noinspection unchecked
                propOptions.putAll((Map<String, Object>) (getElasticMapping(scpm.getComponentPropertyMapping())
                        .values().iterator().next()));

            }

            // Once it is an object, we need to add id & class mappings, otherwise
            // ES will fail with NullPointer.
            if (scpm.isComponent() || scpm.getReference() != null) {
                @SuppressWarnings({ "unchecked" })
                Map<String, Object> props = (Map<String, Object>) propOptions.get("properties");
                if (props == null) {
                    props = new LinkedHashMap<String, Object>();
                    propOptions.put("properties", props);
                }
                props.put("id", defaultDescriptor("long", "not_analyzed", true));
                props.put("class", defaultDescriptor("string", "no", true));
                props.put("ref", defaultDescriptor("string", "no", true));
            }
        }
        propOptions.put("type", propType);
        // See http://www.elasticsearch.com/docs/elasticsearch/mapping/all_field/
        if (!propType.equals("object") && scm.isAll()) {
            // does it make sense to include objects into _all?
            if (scpm.shouldExcludeFromAll()) {
                propOptions.put("include_in_all", false);
            } else {
                propOptions.put("include_in_all", true);
            }
        }
        // todo only enable this through configuration...
        if (propType.equals("string") && scpm.isAnalyzed()) {
            propOptions.put("term_vector", "with_positions_offsets");
        }
        elasticTypeMappingProperties.put(scpm.getPropertyName(), propOptions);
    }

    Map<String, Object> mapping = new LinkedHashMap<String, Object>();
    mapping.put(scm.getElasticTypeName(), Collections.singletonMap("properties", elasticTypeMappingProperties));

    return mapping;
}

From source file:org.Cherry.Modules.Web.MimeAndFileResourcesUtil.java

static public String supported(final HttpRequest request) throws MethodNotSupportedException {
    assert null != request;

    final RequestLine requestLine = request.getRequestLine();
    final String method = requestLine.getMethod().toUpperCase(Locale.ENGLISH);

    switch (method) {
    case "GET":
    case "HEAD":
    case "POST":
        return requestLine.getUri();
    }//from   w  ww  . ja va2 s.c  om

    throw new MethodNotSupportedException(method + " method not supported");
}

From source file:com.mycompany.projetsportmanager.filter.XHttpMethodOverrideFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {

    String headerValue = request.getHeader(this.headerParam);
    if ("POST".equals(request.getMethod()) && StringUtils.hasLength(headerValue)) {
        String method = headerValue.toUpperCase(Locale.ENGLISH);
        HttpServletRequest wrapper = new HttpMethodRequestWrapper(request, method);
        filterChain.doFilter(wrapper, response);
    } else {// w  ww .  j a  v a 2s .c  o m
        filterChain.doFilter(request, response);
    }
}

From source file:at.ac.univie.isc.asio.security.Role.java

private static String normalize(final String name) {
    if (name.startsWith(PREFIX)) {
        return name.substring(PREFIX.length()).toUpperCase(Locale.ENGLISH);
    } else {/*from   w  w w.  j a v  a 2s . c  o m*/
        return name.toUpperCase(Locale.ENGLISH);
    }
}

From source file:com.igormaznitsa.mvngolang.utils.UnpackUtils.java

public static int unpackFileToFolder(@Nonnull final Log logger, @Nullable final String folder,
        @Nonnull final File archiveFile, @Nonnull final File destinationFolder, final boolean makeAllExecutable)
        throws IOException {
    final String normalizedName = archiveFile.getName().toLowerCase(Locale.ENGLISH);

    final ArchEntryGetter entryGetter;

    boolean modeZipFile = false;

    final ZipFile theZipFile;
    final ArchiveInputStream archInputStream;
    if (normalizedName.endsWith(".zip")) {
        logger.debug("Detected ZIP archive");

        modeZipFile = true;/*from  www .  j a v a  2 s  .co m*/

        theZipFile = new ZipFile(archiveFile);
        archInputStream = null;
        entryGetter = new ArchEntryGetter() {
            private final Enumeration<ZipArchiveEntry> iterator = theZipFile.getEntries();

            @Override
            @Nullable
            public ArchiveEntry getNextEntry() throws IOException {
                ArchiveEntry result = null;
                if (this.iterator.hasMoreElements()) {
                    result = this.iterator.nextElement();
                }
                return result;
            }
        };
    } else {
        theZipFile = null;
        final InputStream in = new BufferedInputStream(new FileInputStream(archiveFile));
        try {
            if (normalizedName.endsWith(".tar.gz")) {
                logger.debug("Detected TAR.GZ archive");
                archInputStream = new TarArchiveInputStream(new GZIPInputStream(in));

                entryGetter = new ArchEntryGetter() {
                    @Override
                    @Nullable
                    public ArchiveEntry getNextEntry() throws IOException {
                        return ((TarArchiveInputStream) archInputStream).getNextTarEntry();
                    }
                };

            } else {
                logger.debug("Detected OTHER archive");
                archInputStream = ARCHIVE_STREAM_FACTORY.createArchiveInputStream(in);
                logger.debug("Created archive stream : " + archInputStream.getClass().getName());

                entryGetter = new ArchEntryGetter() {
                    @Override
                    @Nullable
                    public ArchiveEntry getNextEntry() throws IOException {
                        return archInputStream.getNextEntry();
                    }
                };
            }

        } catch (ArchiveException ex) {
            IOUtils.closeQuietly(in);
            throw new IOException("Can't recognize or read archive file : " + archiveFile, ex);
        } catch (CantReadArchiveEntryException ex) {
            IOUtils.closeQuietly(in);
            throw new IOException("Can't read entry from archive file : " + archiveFile, ex);
        }
    }

    try {

        final String normalizedFolder = folder == null ? null : FilenameUtils.normalize(folder, true) + '/';

        int unpackedFilesCounter = 0;
        while (true) {
            final ArchiveEntry entry = entryGetter.getNextEntry();
            if (entry == null) {
                break;
            }
            final String normalizedPath = FilenameUtils.normalize(entry.getName(), true);

            logger.debug("Detected archive entry : " + normalizedPath);

            if (normalizedFolder == null || normalizedPath.startsWith(normalizedFolder)) {
                final File targetFile = new File(destinationFolder, normalizedFolder == null ? normalizedPath
                        : normalizedPath.substring(normalizedFolder.length()));
                if (entry.isDirectory()) {
                    logger.debug("Folder : " + normalizedPath);
                    if (!targetFile.exists() && !targetFile.mkdirs()) {
                        throw new IOException("Can't create folder " + targetFile);
                    }
                } else {
                    final File parent = targetFile.getParentFile();

                    if (parent != null && !parent.isDirectory() && !parent.mkdirs()) {
                        throw new IOException("Can't create folder : " + parent);
                    }

                    final FileOutputStream fos = new FileOutputStream(targetFile);

                    try {
                        if (modeZipFile) {
                            logger.debug("Unpacking ZIP entry : " + normalizedPath);

                            final InputStream zipEntryInStream = theZipFile
                                    .getInputStream((ZipArchiveEntry) entry);
                            try {
                                if (IOUtils.copy(zipEntryInStream, fos) != entry.getSize()) {
                                    throw new IOException(
                                            "Can't unpack file, illegal unpacked length : " + entry.getName());
                                }
                            } finally {
                                IOUtils.closeQuietly(zipEntryInStream);
                            }
                        } else {
                            logger.debug("Unpacking archive entry : " + normalizedPath);

                            if (!archInputStream.canReadEntryData(entry)) {
                                throw new IOException("Can't read archive entry data : " + normalizedPath);
                            }
                            if (IOUtils.copy(archInputStream, fos) != entry.getSize()) {
                                throw new IOException(
                                        "Can't unpack file, illegal unpacked length : " + entry.getName());
                            }
                        }
                    } finally {
                        fos.close();
                    }

                    if (makeAllExecutable) {
                        try {
                            targetFile.setExecutable(true, true);
                        } catch (SecurityException ex) {
                            throw new IOException("Can't make file executable : " + targetFile, ex);
                        }
                    }
                    unpackedFilesCounter++;
                }
            } else {
                logger.debug("Archive entry " + normalizedPath + " ignored");
            }
        }
        return unpackedFilesCounter;
    } finally {
        IOUtils.closeQuietly(theZipFile);
        IOUtils.closeQuietly(archInputStream);
    }
}

From source file:com.intouch.action.EventProcessor.java

@Override
public JSONObject processRequest(Map<String, String[]> params) throws ServerQueryException {
    DataHelper dataHelper = DataHelper.getInstance();
    User user = dataHelper.getUserByToken(params.get("token")[0]);
    JSONObject response;/*  w ww  . ja  v a  2 s.  c om*/
    response = new JSONObject();
    try {
        isParameterExist(params, "name");
        isParameterExist(params, "description");
        isParameterExist(params, "gps");
        isParameterExist(params, "id");
        isParameterExist(params, "date_time");
        isParameterExist(params, "address");
        isParameterExist(params, "token");
        isApiKeyValid(params.get("api_key")[0]);
    } catch (ServerQueryException ex) {
        response.put("result", "error");
        response.put("error_type", ex.getMessage());
        return response;
    }

    Event event = null;
    Date date_time = null;
    try {
        date_time = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH).parse(params.get("date_time")[0]);
    } catch (ParseException ex) {
        Logger.getLogger(EventProcessor.class.getName()).log(Level.SEVERE, null, ex);
        date_time = new Date();
    }

    event = new Event(user, params.get("name")[0], params.get("gps")[0], date_time, params.get("address")[0],
            new Date());

    event.setDescription(params.get("description")[0]);

    dataHelper.createNewEvent(event);

    Gson gson = new Gson();
    response.put("result", "success");
    response.put("event", gson.toJson(event, Event.class));
    return response;
}

From source file:eu.trentorise.smartcampus.ac.provider.managers.SocialEngineManager.java

private SCWebApiClient getClient() throws SocialEngineException {
    if (client == null) {
        client = SCWebApiClient.getInstance(Locale.ENGLISH, socialEngineHost, socialEnginePort);
        if (!client.ping())
            throw new SocialEngineException("Social engine not available");
    }//from  ww w  .  j a va2  s  .  c  o m
    return client;
}

From source file:com.webbfontaine.valuewebb.report.PDInformationForAnalysisReport.java

public PDInformationForAnalysisReport() {
    format = "xls";

    fromYearAndMonth = new ReportParameter("FROM_DATE", null, "FROM_DATE");
    toYearAndMonth = new ReportParameter("TO_DATE", null, "TO_DATE");
    statuses = new ReportParameter("STATUSES",
            Arrays.asList("Sent Ok", "GW Passed", "GW Locked", "Petition Query"), null);
    reportLocale = new ReportParameter("REPORT_LOCALE", Locale.ENGLISH, "Report locale");
    appCountry = new ReportParameter("APP_COUNTRY", "CI", "Application country");
}

From source file:ca.nines.ise.cmd.Validate.java

/**
 * {@inheritDoc}//from ww w .  ja  v  a  2  s .  c  om
 */
@ErrorCode(code = { "dom.errors" })
@Override
public void execute(CommandLine cmd) throws Exception {
    File[] files;

    Log log = Log.getInstance();
    Locale.setDefault(Locale.ENGLISH);
    Schema schema = Schema.defaultSchema();
    DOMValidator dv = new DOMValidator();
    NestingValidator nv = new NestingValidator(schema);
    PrintStream out = new PrintStream(System.out, true, "UTF-8");

    if (cmd.hasOption("l")) {
        out = new PrintStream(new FileOutputStream(cmd.getOptionValue("l")), true, "UTF-8");
    }

    files = getFilePaths(cmd);
    if (files != null) {
        out.println("Found " + files.length + " files to check.");
        for (File in : files) {
            DOM dom = new DOMBuilder(in).build();
            if (dom.getStatus() != DOM.DOMStatus.ERROR) {
                dv.validate(dom, schema);
                nv.validate(dom);
            } else {
                Message m = Message.builder("dom.errors").setSource(dom.getSource()).build();
                log.add(m);
            }
            if (log.count() > 0) {
                out.println(log);
            }
            log.clear();
        }
    }
}