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());
}
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;
}
};
}
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());
}
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();
}
}
}
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);
}
Aggregations