use of java.text.ChoiceFormat in project robovm by robovm.
the class OldMessageFormatTest method test_setFormatILjava_text_Format.
/**
* java.text.MessageFormat#setFormat(int, Format) Test of method
* java.text.MessageFormat#setFormat(int, Format). Case 1: Compare
* getFormats() results after calls to setFormat(). Case 2: Try to
* call setFormat() using incorrect index.
*/
public void test_setFormatILjava_text_Format() {
try {
// case 1: Compare getFormats() results after calls to setFormat()
MessageFormat f1 = (MessageFormat) format1.clone();
f1.setFormat(0, DateFormat.getTimeInstance());
f1.setFormat(1, DateFormat.getTimeInstance());
f1.setFormat(2, NumberFormat.getInstance());
f1.setFormat(3, new ChoiceFormat("0#off|1#on"));
f1.setFormat(4, new ChoiceFormat("1#few|2#ok|3#a lot"));
f1.setFormat(5, DateFormat.getTimeInstance());
Format[] formats = f1.getFormats();
formats = f1.getFormats();
Format[] correctFormats = new Format[] { DateFormat.getTimeInstance(), DateFormat.getTimeInstance(), NumberFormat.getInstance(), new ChoiceFormat("0#off|1#on"), new ChoiceFormat("1#few|2#ok|3#a lot"), DateFormat.getTimeInstance() };
assertEquals("Test1A:Returned wrong number of formats:", correctFormats.length, formats.length);
for (int i = 0; i < correctFormats.length; i++) {
assertEquals("Test1B:wrong format for pattern index " + i + ":", correctFormats[i], formats[i]);
}
// case 2: Try to setFormat using incorrect index
try {
f1.setFormat(-1, DateFormat.getDateInstance());
fail("Expected ArrayIndexOutOfBoundsException was not thrown");
f1.setFormat(f1.getFormats().length, DateFormat.getDateInstance());
fail("Expected ArrayIndexOutOfBoundsException was not thrown");
} catch (ArrayIndexOutOfBoundsException e) {
// expected
}
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
}
use of java.text.ChoiceFormat in project opennms by OpenNMS.
the class UpdateUserServlet method doPost.
/**
* {@inheritDoc}
*/
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession userSession = request.getSession(false);
if (userSession != null) {
User newUser = (User) userSession.getAttribute("user.modifyUser.jsp");
try {
UserFactory.init();
} catch (Throwable e) {
throw new ServletException("UpdateUserServlet:init Error initialising UserFactory " + e);
}
// get the rest of the user information from the form
newUser.setFullName(request.getParameter("fullName"));
newUser.setUserComments(request.getParameter("userComments"));
String password = request.getParameter("password");
if (password != null && !password.trim().equals("")) {
final Password pass = new Password();
pass.setEncryptedPassword(UserFactory.getInstance().encryptedPassword(password, true));
pass.setSalt(true);
newUser.setPassword(pass);
}
String tuiPin = request.getParameter("tuiPin");
if (tuiPin != null && !tuiPin.trim().equals("")) {
newUser.setTuiPin(tuiPin);
}
String email = request.getParameter(ContactType.email.toString());
String pagerEmail = request.getParameter("pemail");
String xmppAddress = request.getParameter(ContactType.xmppAddress.toString());
String microblog = request.getParameter(ContactType.microblog.toString());
String numericPage = request.getParameter("numericalService");
String numericPin = request.getParameter("numericalPin");
String textPage = request.getParameter("textService");
String textPin = request.getParameter("textPin");
String workPhone = request.getParameter(ContactType.workPhone.toString());
String mobilePhone = request.getParameter(ContactType.mobilePhone.toString());
String homePhone = request.getParameter(ContactType.homePhone.toString());
newUser.clearContacts();
Contact tmpContact = new Contact();
tmpContact.setInfo(email);
tmpContact.setType(ContactType.email.toString());
newUser.addContact(tmpContact);
tmpContact = new Contact();
tmpContact.setInfo(pagerEmail);
tmpContact.setType(ContactType.pagerEmail.toString());
newUser.addContact(tmpContact);
tmpContact = new Contact();
tmpContact.setInfo(xmppAddress);
tmpContact.setType(ContactType.xmppAddress.toString());
newUser.addContact(tmpContact);
tmpContact = new Contact();
tmpContact.setInfo(microblog);
tmpContact.setType(ContactType.microblog.toString());
newUser.addContact(tmpContact);
tmpContact = new Contact();
tmpContact.setInfo(numericPin);
tmpContact.setServiceProvider(numericPage);
tmpContact.setType(ContactType.numericPage.toString());
newUser.addContact(tmpContact);
tmpContact = new Contact();
tmpContact.setInfo(textPin);
tmpContact.setServiceProvider(textPage);
tmpContact.setType(ContactType.textPage.toString());
newUser.addContact(tmpContact);
tmpContact = new Contact();
tmpContact.setInfo(workPhone);
tmpContact.setType(ContactType.workPhone.toString());
newUser.addContact(tmpContact);
tmpContact = new Contact();
tmpContact.setInfo(mobilePhone);
tmpContact.setType(ContactType.mobilePhone.toString());
newUser.addContact(tmpContact);
tmpContact = new Contact();
tmpContact.setInfo(homePhone);
tmpContact.setType(ContactType.homePhone.toString());
newUser.addContact(tmpContact);
// build the duty schedule data structure
List<Boolean> newSchedule = new ArrayList<Boolean>(7);
ChoiceFormat days = new ChoiceFormat("0#Mo|1#Tu|2#We|3#Th|4#Fr|5#Sa|6#Su");
Collection<String> dutySchedules = getDutySchedulesForUser(newUser);
dutySchedules.clear();
int dutyCount = WebSecurityUtils.safeParseInt(request.getParameter("dutySchedules"));
for (int duties = 0; duties < dutyCount; duties++) {
newSchedule.clear();
String deleteFlag = request.getParameter("deleteDuty" + duties);
// don't save any duties that were marked for deletion
if (deleteFlag == null) {
for (int i = 0; i < 7; i++) {
String curDayFlag = request.getParameter("duty" + duties + days.format(i));
newSchedule.add(Boolean.valueOf(curDayFlag != null));
}
int startTime = WebSecurityUtils.safeParseInt(request.getParameter("duty" + duties + "Begin"));
int stopTime = WebSecurityUtils.safeParseInt(request.getParameter("duty" + duties + "End"));
DutySchedule newDuty = new DutySchedule(newSchedule, startTime, stopTime);
dutySchedules.add(newDuty.toString());
}
}
// The new list of roles will override the existing one.
// If the new list is empty or null, that means the user should not have roles, and the existing ones should be removed.
newUser.getRoles().clear();
String[] configuredRoles = request.getParameterValues("configuredRoles");
if (configuredRoles != null && configuredRoles.length > 0) {
newUser.getRoles().clear();
for (String role : configuredRoles) {
newUser.addRole(role);
}
}
userSession.setAttribute("user.modifyUser.jsp", newUser);
}
// forward the request for proper display
RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher(request.getParameter("redirect"));
dispatcher.forward(request, response);
}
use of java.text.ChoiceFormat in project opennms by OpenNMS.
the class GroupController method updateGroup.
private void updateGroup(HttpServletRequest request, WebGroup newGroup) {
String[] users = request.getParameterValues("selectedUsers");
List<String> userList = users == null ? Collections.<String>emptyList() : Arrays.asList(users);
newGroup.setUsers(new ArrayList<String>(userList));
String[] selectedCategories = request.getParameterValues("selectedCategories");
List<String> categoryList = selectedCategories == null ? Collections.<String>emptyList() : Arrays.asList(selectedCategories);
newGroup.setAuthorizedCategories(new ArrayList<String>(categoryList));
Vector<Object> newSchedule = new Vector<>();
ChoiceFormat days = new ChoiceFormat("0#Mo|1#Tu|2#We|3#Th|4#Fr|5#Sa|6#Su");
Collection<String> dutySchedules = newGroup.getDutySchedules();
dutySchedules.clear();
int dutyCount = WebSecurityUtils.safeParseInt(request.getParameter("dutySchedules"));
for (int duties = 0; duties < dutyCount; duties++) {
newSchedule.clear();
String deleteFlag = request.getParameter("deleteDuty" + duties);
// don't save any duties that were marked for deletion
if (deleteFlag == null) {
for (int i = 0; i < 7; i++) {
String curDayFlag = request.getParameter("duty" + duties + days.format(i));
if (curDayFlag != null) {
newSchedule.addElement(Boolean.TRUE);
} else {
newSchedule.addElement(Boolean.FALSE);
}
}
newSchedule.addElement(request.getParameter("duty" + duties + "Begin"));
newSchedule.addElement(request.getParameter("duty" + duties + "End"));
DutySchedule newDuty = new DutySchedule(newSchedule);
dutySchedules.add(newDuty.toString());
}
}
}
use of java.text.ChoiceFormat in project opennms by OpenNMS.
the class UpdateGroupController method handleRequestInternal.
/**
* {@inheritDoc}
*/
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
HttpSession userSession = request.getSession(false);
if (userSession != null) {
// group.modifyGroup.jsp
WebGroup newGroup = (WebGroup) userSession.getAttribute("group.modifyGroup.jsp");
// get the rest of the group information from the form
String[] users = request.getParameterValues("selectedUsers");
newGroup.setUsers(new ArrayList<String>(Arrays.asList(users)));
String[] selectedCategories = request.getParameterValues("selectedCategories");
newGroup.setAuthorizedCategories(new ArrayList<String>(Arrays.asList(selectedCategories)));
Vector<Object> newSchedule = new Vector<>();
ChoiceFormat days = new ChoiceFormat("0#Mo|1#Tu|2#We|3#Th|4#Fr|5#Sa|6#Su");
Collection<String> dutySchedules = newGroup.getDutySchedules();
dutySchedules.clear();
int dutyCount = WebSecurityUtils.safeParseInt(request.getParameter("dutySchedules"));
for (int duties = 0; duties < dutyCount; duties++) {
newSchedule.clear();
String deleteFlag = request.getParameter("deleteDuty" + duties);
// don't save any duties that were marked for deletion
if (deleteFlag == null) {
for (int i = 0; i < 7; i++) {
String curDayFlag = request.getParameter("duty" + duties + days.format(i));
if (curDayFlag != null) {
newSchedule.addElement(Boolean.TRUE);
} else {
newSchedule.addElement(Boolean.FALSE);
}
}
newSchedule.addElement(request.getParameter("duty" + duties + "Begin"));
newSchedule.addElement(request.getParameter("duty" + duties + "End"));
DutySchedule newDuty = new DutySchedule(newSchedule);
dutySchedules.add(newDuty.toString());
}
}
userSession.setAttribute("group.modifyGroup.jsp", newGroup);
}
return new ModelAndView(request.getParameter("redirect"));
}
use of java.text.ChoiceFormat in project ceylon-compiler by ceylon.
the class CeylonCompileMessages method msgCompilerErrors.
static String msgCompilerErrors(int numErrors) {
MessageFormat fmt = new MessageFormat("");
fmt.setLocale(Locale.getDefault());
double[] limits = { 1, 2 };
String[] keys = { RESOURCE_BUNDLE.getString("compile.errors.one"), RESOURCE_BUNDLE.getString("compile.errors.several") };
ChoiceFormat choice = new ChoiceFormat(limits, keys);
fmt.applyPattern(RESOURCE_BUNDLE.getString("compile.errors.pattern"));
Format[] formats = { choice, NumberFormat.getInstance() };
fmt.setFormats(formats);
return fmt.format(new Object[] { numErrors });
}
Aggregations