Java Code Examples for org.jivesoftware.smackx.vcardtemp.packet.VCard#getLastName()

The following examples show how to use org.jivesoftware.smackx.vcardtemp.packet.VCard#getLastName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserManager.java    From Spark with Apache License 2.0 6 votes vote down vote up
public String getNickname(BareJid jid) {
	String vcardNickname = null;
    VCard vCard = SparkManager.getVCardManager().getVCard(jid);
    if (vCard != null && vCard.getError() == null) {
        String firstName = vCard.getFirstName();
        String lastName = vCard.getLastName();
        String nickname = vCard.getNickName();
        if (ModelUtil.hasLength(nickname)) {
            vcardNickname = nickname;
        }
        else if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) {
            vcardNickname = firstName + " " + lastName;
        }
        else if (ModelUtil.hasLength(firstName)) {
            vcardNickname = firstName;
        }
    }
    
    return vcardNickname;
}
 
Example 2
Source File: Workspace.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new room based on an anonymous user.
 *
 * @param bareJID the bareJID of the anonymous user.
 * @param message the message from the anonymous user.
 */
private void createOneToOneRoom(EntityBareJid bareJID, Message message) {
    ContactItem contact = contactList.getContactItemByJID(bareJID);
    Localpart localpart = bareJID.getLocalpartOrNull();
    String nickname = null;
    if (localpart != null) {
        nickname = localpart.toString();
    }
    if (contact != null) {
        nickname = contact.getDisplayName();
    }
    else {
        // Attempt to load VCard from users who we are not subscribed to.
        VCard vCard = SparkManager.getVCardManager().getVCard(bareJID);
        if (vCard != null && vCard.getError() == null) {
            String firstName = vCard.getFirstName();
            String lastName = vCard.getLastName();
            String userNickname = vCard.getNickName();
            if (ModelUtil.hasLength(userNickname)) {
                nickname = userNickname;
            }
            else if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) {
                nickname = firstName + " " + lastName;
            }
            else if (ModelUtil.hasLength(firstName)) {
                nickname = firstName;
            }
        }
    }

    SparkManager.getChatManager().createChatRoom(bareJID, nickname, nickname);
    try {
        insertMessage(bareJID, message);
    }
    catch (ChatRoomNotFoundException e) {
        Log.error("Could not find chat room.", e);
    }
}
 
Example 3
Source File: MissedCalls.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Called whenever the user misses a call. The information will be displayed in the Spark Toaster until the user
 * explicitly closes the window.
 *
 * @param callerID the callerID
 * @param number   the number the user dialed from.
 */
public void addMissedCall(String callerID, final String number) {
  callID = callerID;
    VCard vcard = SparkManager.getVCardManager().searchPhoneNumber(number);
    if (vcard != null) {
        String firstName = vcard.getFirstName();
        String lastName = vcard.getLastName();
        if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) {
        	callID = firstName + " " + lastName;
        }
        else if (ModelUtil.hasLength(firstName)) {
        	callID = firstName;
        }
    }

    try {
  	  EventQueue.invokeAndWait(new Runnable(){
  		  public void run()
  		  {
  			  final MissedCall missedCall = new MissedCall(callID, new Date(), number);
  	        model.insertElementAt(missedCall, 0);
  	        
  	        if (toaster == null || !list.isShowing()) {
  	      	  toaster = new SparkToaster();
  	      	  toaster.setToasterHeight(230);
  	      	  toaster.setToasterWidth(300);
  	      	  toaster.setDisplayTime(500000000);
  	      	  toaster.showToaster(PhoneRes.getIString("phone.missedcalls"), gui);
  	        }
  		  }
  	  });
    }
    catch(Exception e) {
  	  Log.error(e);
    }
}
 
Example 4
Source File: ContactDetailsPanel.java    From Spark with Apache License 2.0 5 votes vote down vote up
private void displayVCard(VCard vCard) {
    if (vCard.getError() != null) {
        return;
    }
    String firstName = vCard.getFirstName();
    String lastName = vCard.getLastName();
    if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) {
        contactNameLabel.setText(firstName + " " + lastName);
    }
    else if (ModelUtil.hasLength(firstName)) {
        contactNameLabel.setText(firstName);
    }
    else {
        contactNameLabel.setText(PhoneRes.getIString("phone.unknown"));
    }

    String jobTitle = vCard.getField("TITLE");
    if (jobTitle != null) {
        jobTitleLabel.setText(jobTitle);
    }

    String email = vCard.getEmailWork();
    if (email == null) {
        email = vCard.getEmailHome();
    }

    if (email != null) {
        emailLabel.setText(email);
    }

    invalidate();
    validate();
    repaint();

    viewProfileLabel.setVisible(true);
}
 
Example 5
Source File: WorkgroupManager.java    From Spark with Apache License 2.0 4 votes vote down vote up
private void showWorkgroup(final ContactItem contactItem) throws Exception {
     VCard vcard = SparkManager.getVCardManager().getVCard();

     final Map<String, String> variables = new HashMap<String, String>();
     String firstName = vcard.getFirstName();
     String lastName = vcard.getLastName();

     if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) {
         variables.put("username", firstName + " " + lastName);
     }
     else if (ModelUtil.hasLength(firstName)) {
         variables.put("username", firstName);
     }
     else if (ModelUtil.hasLength(lastName)) {
         variables.put("username", lastName);
     }

     String email = vcard.getEmailHome();
     String emailWork = vcard.getEmailWork();

     if (ModelUtil.hasLength(emailWork)) {
         email = emailWork;
     }

     if (ModelUtil.hasLength(email)) {
         variables.put("email", email);
     }


     EntityBareJid workgroupJID = contactItem.getJid().asEntityBareJidOrThrow();
     Localpart nameOfWorkgroup = workgroupJID.getLocalpart();
     final JDialog workgroupDialog = new JDialog(SparkManager.getMainWindow(), "Contact " + nameOfWorkgroup + " Workgroup");
     Workgroup workgroup = new Workgroup(workgroupJID, SparkManager.getConnection());

     final Form workgroupForm = workgroup.getWorkgroupForm();
     String welcomeText = FormText.getWelcomeText(workgroupJID.toString());
     String startButton = FormText.getStartButton(workgroupJID.toString());

     final WorkgroupDataForm formUI = new WorkgroupDataForm(workgroupForm, variables);
     formUI.setBackground(Color.white);

     final JPanel titlePane = new LiveTitlePane("Contact Workgroup", FastpathRes.getImageIcon(FastpathRes.FASTPATH_IMAGE_24x24)) {
private static final long serialVersionUID = -4484940286068835770L;

public Dimension getPreferredSize() {
             final Dimension size = super.getPreferredSize();
             size.width = 400;
             return size;
         }
     };


     formUI.add(titlePane, new GridBagConstraints(0, 0, 3, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));

     final JButton submitButton = new JButton("Start Chat!");
     submitButton.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
             if (validateForm(workgroupDialog, workgroupForm, formUI.getFilledForm())) {
                 enterQueue(contactItem.getJid().asEntityBareJidOrThrow(), formUI.getFilledForm());
                 workgroupDialog.dispose();
             }
         }
     });


     formUI.setEnterListener(new WorkgroupDataForm.EnterListener() {
         public void enterPressed() {
             if (validateForm(workgroupDialog, workgroupForm, formUI.getFilledForm())) {
                 enterQueue(contactItem.getJid().asEntityBareJidOrThrow(), formUI.getFilledForm());
                 workgroupDialog.dispose();
             }
         }
     });


     formUI.add(submitButton, new GridBagConstraints(1, 100, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));


     workgroupDialog.getContentPane().setLayout(new BorderLayout());
     workgroupDialog.getContentPane().add(formUI, BorderLayout.CENTER);

     workgroupDialog.pack();
     GraphicUtils.centerWindowOnScreen(workgroupDialog);
     workgroupDialog.setVisible(true);
 }