📄 jwmacontactscontroller.java
字号:
ctdb.getContactGroup(id); //set name if not null, or empty string if (name != null && !name.equals("") && !name.equals(group.getName())) { group.setName(name); } group.setComments(comments); } } else { throw new JwmaException("group.action.invalidgroup", true); } session.redirect(JwmaKernel.CONTACTGROUP_VIEW); return; }//doUpdateGroup /** * Creates a group entry in the contact database. * * @param session a <tt>JwmaSession</tt> instance. * @param ctdb a <tt>JwmaContactsImpl</tt> instance. * * @throws JwmaException if it fails to execute properly. */ private void doCreateGroup(JwmaSession session, JwmaContactsImpl ctdb) throws JwmaException { //1. retrieve name and note String name = session.getRequestParameter("group.name"); String comments = session.getRequestParameter("group.comments"); log.debug("Creating group name=" + name + " " + " comments=" + comments); //check if groupname already exists if (ctdb.containsContactGroupName(name)) { throw new JwmaException("group.name.duplicate", true); } else { //check name if not null, or empty string if (name != null && !name.equals("")) { //create a new group in the users database JwmaContactGroupImpl group = ctdb.createContactGroup(name); group.setComments(comments); ctdb.addContactGroup(group); session.storeBean("jwma.contacts.group", group); } } JwmaKernel.getReference().getContactManagementPlugin() .saveContacts(ctdb); session.redirect(JwmaKernel.CONTACTGROUP_EDIT_VIEW); return; }//doCreateGroup /** * Deletes group entries from the contact database. * * @param session a <tt>JwmaSession</tt> instance. * @param ctdb a <tt>JwmaContactsImpl</tt> instance. * * @throws JwmaException if it fails to execute properly. */ private void doDeleteGroups(JwmaSession session, JwmaContactsImpl ctdb, String[] gids) throws JwmaException { log.debug("Deleting groups..."); for (int i = 0; i < gids.length; i++) { JwmaContactGroupImpl group = (JwmaContactGroupImpl) ctdb.getContactGroup(gids[i]); if (group != null) { log.debug("Deleting " + gids[i]); ctdb.removeContactGroup(group); } else { throw new JwmaException("group.action.invalidgroup", true); } } JwmaKernel.getReference().getContactManagementPlugin() .saveContacts(ctdb); session.redirect(JwmaKernel.CONTACTS_VIEW); return; }//doDeleteGroups /** * Adds contacts to a group entry in the contact database. * * @param session a <tt>JwmaSession</tt> instance. * @param ctdb a <tt>JwmaContactsImpl</tt> instance. * * @throws JwmaException if it fails to execute properly. */ private void doAddContacts(JwmaSession session, JwmaContactsImpl ctdb, String gid, String[] cids) throws JwmaException { //check if id exists if (ctdb.containsContactGroup(gid)) { //retrieve group JwmaContactGroupImpl group = (JwmaContactGroupImpl) ctdb.getContactGroup(gid); //add contacts for (int i = 0; i < cids.length; i++) { log.debug( "Trying to add #" + i + " is in database=" + ctdb.containsContact(cids[i]) + " with id=" + ctdb.getContact(cids[i]) ); if (ctdb.containsContact(cids[i])) { group.addContact((JwmaContactImpl) ctdb.getContact(cids[i])); } else { throw new JwmaException("contact.action.invalidcontact", true); } } } else { throw new JwmaException("group.action.invalidgroup", true); } session.redirect(JwmaKernel.CONTACTGROUP_EDIT_VIEW); return; }//doAddContacts /** * Removes contacts from a group entry in the contact database. * * @param session a <tt>JwmaSession</tt> instance. * @param ctdb a <tt>JwmaContactsImpl</tt> instance. * * @throws JwmaException if it fails to execute properly. */ private void doRemoveContacts(JwmaSession session, JwmaContactsImpl ctdb, String gid, String[] cids) throws JwmaException { //check if id exists if (ctdb.containsContactGroup(gid)) { //retrieve group JwmaContactGroupImpl group = (JwmaContactGroupImpl) ctdb.getContactGroup(gid); //add contacts for (int i = 0; i < cids.length; i++) { log.debug( "Trying to remove #" + i + " is in database=" + ctdb.containsContact(cids[i]) + " with id=" + cids[i]) ; if (ctdb.containsContact(cids[i]) && group.containsContact(cids[i])) { group.removeContact((JwmaContactImpl) ctdb.getContact(cids[i])); } else { throw new JwmaException("contact.action.invalidcontact"); } } } else { throw new JwmaException("group.action.invalidgroup", true); } session.redirect(JwmaKernel.CONTACTGROUP_EDIT_VIEW); return; }//doDeleteContacts /*** END group actions ************************************************************/ /*** BEGIN contact actions **********************************************************/ /** * Displays a contact entry from the contact database. * * @param session a <tt>JwmaSession</tt> instance. * @param ctdb a <tt>JwmaContactsImpl</tt> instance. * @param cid a contact identifier as <tt>String</tt>. * * @throws JwmaException if it fails to execute properly. */ private void doDisplayContact(JwmaSession session, JwmaContactsImpl ctdb, String cid) throws JwmaException { if (ctdb.containsContact(cid)) { session.storeBean( "jwma.contacts.contact", ctdb.getContact(cid) ); } else { throw new JwmaException("contact.action.invalidcontact", true); } session.redirect(JwmaKernel.CONTACT_VIEW); return; }//doDisplayContact /** * Displays a contact entry from the contact database for editing. * * @param session a <tt>JwmaSession</tt> instance. * @param ctdb a <tt>JwmaContactsImpl</tt> instance. * @param cid a contact identifier as <tt>String</tt>. * * @throws JwmaException if it fails to execute properly. */ private void doEditContact(JwmaSession session, JwmaContactsImpl ctdb, String cid) throws JwmaException { if (ctdb.containsContact(cid)) { session.storeBean( "jwma.contacts.contact", ctdb.getContact(cid) ); } else { throw new JwmaException("contact.action.invalidcontact", true); } session.redirect(JwmaKernel.CONTACT_EDIT_VIEW); return; }//doEditContact /** * Updates or creates a contact entry in the contact database. * * @param session a <tt>JwmaSession</tt> instance. * @param ctdb a <tt>JwmaContactsImpl</tt> instance. * @param cid a contact identifier as <tt>String</tt>. * * @throws JwmaException if it fails to execute properly. */ private void doUpdateContact(JwmaSession session, JwmaContactsImpl ctdb, String cid) throws JwmaException { JwmaContactImpl ct = null; boolean create = false; if (cid == null) { ct = ctdb.createContact(); log.debug("Created new contact=" + ct.getUID()); create = true; } else { if (ctdb.containsContact(cid)) { ct = (JwmaContactImpl) ctdb.getContact(cid); } else { throw new JwmaException("contact.action.invalidcontact"); } } String category = session.getRequestParameter("category"); String newcategory = session.getRequestParameter("_category"); if (category != null && category.length() > 0 && newcategory != null && !ctdb.existsContactCategory(category) && newcategory.length() > 0) { category = newcategory; ctdb.addContactCategory(newcategory); } String firstname = session.getRequestParameter("firstname"); String lastname = session.getRequestParameter("lastname"); String middlename = session.getRequestParameter("middlename"); String nickname = session.getRequestParameter("nickname"); String company = session.getRequestParameter("company"); String title = session.getRequestParameter("title"); String role = session.getRequestParameter("role"); //phone numbers String homenum = session.getRequestParameter("phone.home"); String worknum = session.getRequestParameter("phone.work"); String pagernum = session.getRequestParameter("phone.pager"); String faxnum = session.getRequestParameter("phone.fax"); String mobilenum = session.getRequestParameter("phone.mobile"); //primary location boolean primlocation = new Boolean( session.getRequestParameter("primary.location")).booleanValue(); //work String workstreet = session.getRequestParameter("work.street"); String workcity = session.getRequestParameter("work.city"); String workregion = session.getRequestParameter("work.region"); String workcountry = session.getRequestParameter("work.country"); String workzip = session.getRequestParameter("work.zip"); //home String homestreet = session.getRequestParameter("home.street"); String homecity = session.getRequestParameter("home.city"); String homeregion = session.getRequestParameter("home.region"); String homecountry = session.getRequestParameter("home.country"); String homezip = session.getRequestParameter("home.zip"); //internet String email = session.getRequestParameter("email.primary"); String altemail = session.getRequestParameter("email.alternate"); String url = session.getRequestParameter("personal.url"); String compurl = session.getRequestParameter("company.url"); //misc String birthday = session.getRequestParameter("birthdate"); String comments = session.getRequestParameter("comments"); boolean frequent = new Boolean( session.getRequestParameter("frequent")).booleanValue(); ct.setCategory(category); ct.setFirstname(firstname); ct.setLastname(lastname); ct.setMiddlename(middlename); if (nickname != null && nickname.length() > 0) { log.debug("after testing nick"); //Check if already existing nickname: JwmaContact ct_n = ctdb.getContactByNickname(nickname); if (ct_n != null && !ct_n.getUID().equals(ct.getUID())) { log.debug("contact=" + ct.getUID() + " nickct=" + ct_n.getUID()); throw new JwmaException("contact.update.duplicatenickname", true); } else { ct.setNickname(nickname); } } else { ct.setNickname(""); } ct.setCompany(company); ct.setTitle(title); ct.setRole(role); ct.setCompanyURL(compurl); ct.setHomePhoneNumber(homenum); ct.setWorkPhoneNumber(worknum); ct.setPagerNumber(pagernum); ct.setFaxNumber(faxnum); ct.setMobileNumber(mobilenum); ct.setPrimarilyWorkContact(primlocation); ct.setWorkStreet(workstreet); ct.setWorkCity(workcity); ct.setWorkRegion(workregion); ct.setWorkCountry(workcountry); ct.setWorkZIP(workzip); ct.setHomeStreet(homestreet); ct.setHomeCity(homecity); ct.setHomeRegion(homeregion); ct.setHomeCountry(homecountry); ct.setHomeZIP(homezip); ct.setEmail(email); ct.setAlternateEmail(altemail); ct.setURL(url); if (!ct.isFrequentRecipient() && frequent) { ctdb.addFrequentRecipient(ct); } if (ct.isFrequentRecipient() && !frequent) { ctdb.removeFrequentRecipient(ct); } ct.setFrequentRecipient(frequent); ct.setComments(comments); try { if (birthday != null && birthday.length() > 0) { ct.setBirthDate(session.getPreferences().getDateFormat().parse(birthday)); } } catch (Exception ex) { //ignore now throw new JwmaException(""); log.error("doUpdateContact()", ex); } if (create) { ctdb.addContact(ct); } saveContactDatabase(ctdb); session.storeBean("jwma.contacts.contact", ct); session.redirect(JwmaKernel.CONTACT_EDIT_VIEW); return; }//doUpdateContact /** * Deletes contact entries from the contact database. * * @param session a <tt>JwmaSession</tt> instance. * @param ctdb a <tt>JwmaContactsImpl</tt> instance. * @param cid a contact identifier as <tt>String</tt>. * * @throws JwmaException if it fails to execute properly. */ private void doDeleteContacts(JwmaSession session, JwmaContactsImpl ctdb, String[] cids) throws JwmaException { for (int i = 0; i < cids.length; i++) { if (ctdb.containsContact(cids[i])) { ctdb.removeContact( (JwmaContactImpl) ctdb.getContact(cids[i]) ); } else { throw new JwmaException("contact.action.invalidcontact", true); } } session.redirect(JwmaKernel.CONTACTS_VIEW); return; }//doDeleteContacts /** * Imports a contact buffered from a message. * * @param session a <tt>JwmaSession</tt> instance. * @param ctdb a <tt>JwmaContactsImpl</tt> instance. * @param ct a contact as <tt>JwmaContactImpl</tt>. * * @throws JwmaException if it fails to execute properly. */ private void doImportContact(JwmaSession session, JwmaContactsImpl ctdb, JwmaContactImpl ct) throws JwmaException { if (!ctdb.containsContact(ct.getUID())) { ctdb.addContact(ct); } else { throw new JwmaException("contact.action.invalidcontact", true); } session.storeBean("jwma.contacts.contact", ct); session.redirect(JwmaKernel.CONTACT_EDIT_VIEW); return; }//doDeleteContacts /*** END contact actions ************************************************************/ private final void saveContactDatabase(JwmaContactsImpl ctdb) throws JwmaException { JwmaKernel.getReference().getContactManagementPlugin() .saveContacts(ctdb); }//saveContactDatabase}//class JwmaContactsController
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -