public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { if (callbacks == null) throw new NullPointerException(); for (int i = 0; i < callbacks.length; i++) { if (callbacks[i] == null) continue; if (callbacks[i] instanceof ChoiceCallback) handleChoice((ChoiceCallback) callbacks[i]); else if (callbacks[i] instanceof ConfirmationCallback) handleConfirmation((ConfirmationCallback) callbacks[i]); else if (callbacks[i] instanceof LanguageCallback) handleLanguage((LanguageCallback) callbacks[i]); else if (callbacks[i] instanceof NameCallback) handleName((NameCallback) callbacks[i]); else if (callbacks[i] instanceof PasswordCallback) handlePassword((PasswordCallback) callbacks[i]); else if (callbacks[i] instanceof TextInputCallback) handleTextInput((TextInputCallback) callbacks[i]); else if (callbacks[i] instanceof TextOutputCallback) handleTextOutput((TextOutputCallback) callbacks[i]); else handleOther(callbacks[i]); } }
protected void handleLanguage(LanguageCallback c) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); out.print(messages.getString("callback.language")); String reply = null; reply = in.readLine(); if (reply == null) { c.setLocale(Locale.getDefault()); } else { c.setLocale(new Locale(reply.trim())); } }
/** * test of Ctor, method set/getLocale() */ public final void testLanguageCallback_01() { lc = new LanguageCallback(); Locale locale = Locale.US; lc.setLocale(locale); assertEquals("US", lc.getLocale().getCountry()); }
/** * locale is null */ public final void testLanguageCallback_02() { lc = new LanguageCallback(); assertNull(lc.getLocale()); try { lc.setLocale(null); } catch (NullPointerException e ){} }
@Test( expected = UnsupportedCallbackException.class ) public void testRoboconfCallbackHandler_failure() throws Exception { RoboconfCallbackHandler handler = new RoboconfCallbackHandler( "user", "password" ); handler.handle( new Callback[] { new NameCallback( "Username: " ), new PasswordCallback( "Password: ", false ), new LanguageCallback() }); }
protected synchronized void handleLanguage(LanguageCallback c) { Locale[] locales = Locale.getAvailableLocales(); String[] languages = new String[locales.length]; Locale def = Locale.getDefault(); int defind = 0; for (int i = 0; i < locales.length; i++) { CPStringBuilder lang = new CPStringBuilder(locales[i].getDisplayLanguage(locales[i])); String country = locales[i].getDisplayCountry(locales[i]); String variant = locales[i].getDisplayVariant(locales[i]); if (country.length() > 0 && variant.length() > 0) { lang.append(" ("); lang.append(country); lang.append(", "); lang.append(variant); lang.append(")"); } else if (country.length() > 0) { lang.append(" ("); lang.append(country); lang.append(")"); } else if (variant.length() > 0) { lang.append(" ("); lang.append(variant); lang.append(")"); } languages[i] = lang.toString(); if (locales[i].equals(def)) defind = i; } ChoiceCallback c2 = new ChoiceCallback(messages.getString("callback.language"), languages, defind, false); handleChoice(c2); c.setLocale(def); if (c2.getSelectedIndexes() != null && c2.getSelectedIndexes().length > 0) { int index = c2.getSelectedIndexes()[0]; if (index >= 0 && index < locales.length) c.setLocale(locales[index]); } }
protected void handleLanguage(LanguageCallback c) { c.setLocale(Locale.getDefault()); }
@Override protected Object[] getData() { LanguageCallback lc = new LanguageCallback(); lc.setLocale(Locale.UK); return new Object[] { lc }; }
public void assertDeserialized(Serializable golden, Serializable test) { assertTrue(test instanceof LanguageCallback); assertEquals(((LanguageCallback) golden).getLocale(), ((LanguageCallback) test).getLocale()); }
/** * Handles a {@link LanguageCallback}. * * @param callback The language callback. * @throws IOException If an I/O error occurs. */ protected abstract void handleLanguage(LanguageCallback callback) throws IOException;