Search in sources :

Example 91 with Locale

use of java.util.Locale in project sonarqube by SonarSource.

the class TestHtmlTag method testInvalidLanguage.

/**
     * Test an invalid "language"
     */
public void testInvalidLanguage() {
    // switch to render "lang" attribute
    htmlTag.setLang(true);
    // make sure HtmlTag is setup to render "lang" using a valid value
    request.setLocale(Locale.US);
    assertEquals("check valid", "<html lang=\"en-US\">", htmlTag.renderHtmlStartElement());
    // Test script injection
    request.setLocale(new Locale("/><script>alert()</script>", "", ""));
    assertEquals("invalid <script>", "<html>", htmlTag.renderHtmlStartElement());
    // Test <
    request.setLocale(new Locale("abc<def", "", ""));
    assertEquals("invalid LT", "<html>", htmlTag.renderHtmlStartElement());
    // Test >
    request.setLocale(new Locale("abc>def", "", ""));
    assertEquals("invalid GT", "<html>", htmlTag.renderHtmlStartElement());
    // Test /
    request.setLocale(new Locale("abc/def", "", ""));
    assertEquals("invalid SLASH", "<html>", htmlTag.renderHtmlStartElement());
    // Test &
    request.setLocale(new Locale("abc&def", "", ""));
    assertEquals("invalid AMP", "<html>", htmlTag.renderHtmlStartElement());
}
Also used : Locale(java.util.Locale)

Example 92 with Locale

use of java.util.Locale in project buck by facebook.

the class DiagnosticPrettyPrinterTest method createDiagnostic.

/**
   * Create a {@link Diagnostic} for use in tests.
   *
   * @param message The compilation error message.
   * @param row The row within the source, 1-indexed because the compiler does that.
   * @param column The column within {@code row}, also 1-indexed.
   */
private Diagnostic<? extends JavaFileObject> createDiagnostic(final String message, String pathToSource, String sourceContents, final long row, final long column) throws Exception {
    final JavaFileObject fileObject = new StringJavaFileObject(pathToSource, sourceContents);
    // Calculate the position, because we're all bad at counting things
    int pos = -1;
    if (row != -1) {
        pos = -1;
        int rowCount = 1;
        while (rowCount <= row) {
            pos++;
            if (sourceContents.charAt(pos) == '\n') {
                rowCount++;
            }
        }
        // And now just add the row, which is 1 indexed, so we then subtract 1.
        pos += row - 1;
    }
    final int position = pos;
    return new Diagnostic<JavaFileObject>() {

        @Override
        public Kind getKind() {
            return Kind.ERROR;
        }

        @Override
        public JavaFileObject getSource() {
            return fileObject;
        }

        @Override
        public long getPosition() {
            return position;
        }

        @Override
        public long getStartPosition() {
            return position;
        }

        @Override
        public long getEndPosition() {
            return position;
        }

        @Override
        public long getLineNumber() {
            return row;
        }

        @Override
        public long getColumnNumber() {
            return column;
        }

        @Override
        @Nullable
        public String getCode() {
            return null;
        }

        @Override
        public String getMessage(Locale locale) {
            return message;
        }
    };
}
Also used : Locale(java.util.Locale) JavaFileObject(javax.tools.JavaFileObject) SimpleJavaFileObject(javax.tools.SimpleJavaFileObject) Diagnostic(javax.tools.Diagnostic)

Example 93 with Locale

use of java.util.Locale in project android_frameworks_base by ParanoidAndroid.

the class DateView method updateClock.

protected void updateClock() {
    final String weekdayFormat = getContext().getString(R.string.system_ui_weekday_pattern);
    final String dateFormat = getContext().getString(R.string.system_ui_date_pattern);
    final Locale l = Locale.getDefault();
    final Date now = new Date();
    String weekdayFmt = ICU.getBestDateTimePattern(weekdayFormat, l.toString());
    String dateFmt = ICU.getBestDateTimePattern(dateFormat, l.toString());
    StringBuilder builder = new StringBuilder();
    builder.append(new SimpleDateFormat(weekdayFmt, l).format(now));
    builder.append("\n");
    builder.append(new SimpleDateFormat(dateFmt, l).format(now));
    setText(builder.toString());
}
Also used : Locale(java.util.Locale) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 94 with Locale

use of java.util.Locale in project android_frameworks_base by ParanoidAndroid.

the class AppWidgetServiceImpl method onConfigurationChanged.

void onConfigurationChanged() {
    if (DBG)
        log("Got onConfigurationChanged()");
    Locale revised = Locale.getDefault();
    if (revised == null || mLocale == null || !(revised.equals(mLocale))) {
        mLocale = revised;
        synchronized (mAppWidgetIds) {
            ensureStateLoadedLocked();
            // Note: updateProvidersForPackageLocked() may remove providers, so we must copy the
            // list of installed providers and skip providers that we don't need to update.
            // Also note that remove the provider does not clear the Provider component data.
            ArrayList<Provider> installedProviders = new ArrayList<Provider>(mInstalledProviders);
            HashSet<ComponentName> removedProviders = new HashSet<ComponentName>();
            int N = installedProviders.size();
            for (int i = N - 1; i >= 0; i--) {
                Provider p = installedProviders.get(i);
                ComponentName cn = p.info.provider;
                if (!removedProviders.contains(cn)) {
                    updateProvidersForPackageLocked(cn.getPackageName(), removedProviders);
                }
            }
            saveStateAsync();
        }
    }
}
Also used : Locale(java.util.Locale) ArrayList(java.util.ArrayList) ComponentName(android.content.ComponentName) Point(android.graphics.Point) HashSet(java.util.HashSet)

Example 95 with Locale

use of java.util.Locale in project android_frameworks_base by ParanoidAndroid.

the class TextToSpeechTests method testGetLanguage_invalidReturnValues.

public void testGetLanguage_invalidReturnValues() {
    IDelegate delegate = LittleMock.mock(IDelegate.class);
    MockableTextToSpeechService.setMocker(delegate);
    // Test1: Simple end to end test. Ensure that bad return values
    // are dealt with appropriately.
    LittleMock.doReturn(null).when(delegate).onGetLanguage();
    Locale returnVal = mTts.getLanguage();
    assertNull(returnVal);
    // Bad value 2. An array of length < 3.
    LittleMock.doReturn(new String[] { "eng", "usa" }).when(delegate).onGetLanguage();
    returnVal = mTts.getLanguage();
    assertNull(returnVal);
}
Also used : Locale(java.util.Locale) IDelegate(com.android.speech.tts.MockableTextToSpeechService.IDelegate)

Aggregations

Locale (java.util.Locale)5854 Test (org.junit.Test)902 HashMap (java.util.HashMap)548 GenericValue (org.apache.ofbiz.entity.GenericValue)504 ArrayList (java.util.ArrayList)486 Delegator (org.apache.ofbiz.entity.Delegator)484 GenericEntityException (org.apache.ofbiz.entity.GenericEntityException)398 IOException (java.io.IOException)313 LocalDispatcher (org.apache.ofbiz.service.LocalDispatcher)296 Date (java.util.Date)273 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)271 Map (java.util.Map)244 BigDecimal (java.math.BigDecimal)214 SimpleDateFormat (java.text.SimpleDateFormat)198 ResourceBundle (java.util.ResourceBundle)197 File (java.io.File)166 LinkedList (java.util.LinkedList)158 ULocale (android.icu.util.ULocale)156 List (java.util.List)147 Test (org.junit.jupiter.api.Test)132