org.jivesoftware.smackx.vcardtemp.packet.VCard Java Examples

The following examples show how to use org.jivesoftware.smackx.vcardtemp.packet.VCard. 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() {
    final VCardManager vCardManager = SparkManager.getVCardManager();
    VCard vcard = vCardManager.getVCard();
    if (vcard == null) {
        return SparkManager.getSessionManager().getUsername();
    }
    else {
        String nickname = vcard.getNickName();
        if (ModelUtil.hasLength(nickname)) {
            return nickname;
        }
        else {
            String firstName = vcard.getFirstName();
            if (ModelUtil.hasLength(firstName)) {
                return firstName;
            }
        }
    }

    // Default to node if nothing.
    String username = SparkManager.getSessionManager().getUsername();
    username = XmppStringUtils.unescapeLocalpart(username);

    return username;
}
 
Example #2
Source File: SoftPhoneManager.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
 * Calls an individual user by their VCard information.
 *
 * @param jid the users JID.
 */
public void callByJID(String jid) {
    if (getStatus() == SipRegisterStatus.Registered) {
        final VCard vcard = SparkManager.getVCardManager().getVCard(XmppStringUtils.parseBareJid(jid));

        if (vcard != null) {
            String number = vcard.getPhoneWork("VOICE");
            if (!ModelUtil.hasLength(number)) {
                number = vcard.getPhoneHome("VOICE");
            }

            if (ModelUtil.hasLength(number)) {
                getDefaultGuiManager().dial(number);
            }
        }
    }
}
 
Example #3
Source File: VCardEditor.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
 * Builds the UI based on a VCard.
 * 
 * @param vcard
 *            the vcard used to build the UI.
 */
private void buildUI(VCard vcard) {

    fillUI(vcard);
    
    // Set Avatar
    byte[] bytes = vcard.getAvatar();
    if (bytes != null && bytes.length > 0) {
    	ImageIcon icon = new ImageIcon(bytes);
 
    	// See if we should remove the Avatar tab in profile dialog	    
    	if (!Default.getBoolean("DISABLE_AVATAR_TAB") && Enterprise.containsFeature(Enterprise.AVATAR_TAB_FEATURE)) {	    
    		avatarPanel.setAvatar(icon);
    		avatarPanel.setAvatarBytes(bytes);
    	}	    
 
    	if (avatarLabel != null) {
    		icon = GraphicUtils.scaleImageIcon(icon, 48, 48);
    		avatarLabel.setIcon(icon);
    	}
    }
}
 
Example #4
Source File: VCardManager.java    From Spark with Apache License 2.0 6 votes vote down vote up
public URL getAvatarURL(BareJid jid) {
    VCard vcard = getVCard(jid);
    if (vcard != null) {
        String hash = vcard.getAvatarHash();
        if (!ModelUtil.hasLength(hash)) {
            return null;
        }

        final File avatarFile = new File(contactsDir, hash);
        try {
            return avatarFile.toURI().toURL();
        }
        catch (MalformedURLException e) {
            Log.error(e);
        }
    }
    return null;
}
 
Example #5
Source File: VCardManager.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
 * Searches all vCards for a specified phone number.
 *
 * @param phoneNumber the phoneNumber.
 * @return the vCard which contains the phone number.
 */
public VCard searchPhoneNumber(String phoneNumber) {
    for (VCard vcard : vcards.values()) {
        String homePhone = getNumbersFromPhone(vcard.getPhoneHome("VOICE"));
        String workPhone = getNumbersFromPhone(vcard.getPhoneWork("VOICE"));
        String cellPhone = getNumbersFromPhone(vcard.getPhoneWork("CELL"));

        String query = getNumbersFromPhone(phoneNumber);
        if ((homePhone != null && homePhone.endsWith(query)) ||
            (workPhone != null && workPhone.endsWith(query)) ||
            (cellPhone != null && cellPhone.endsWith(query))) {
            return vcard;
        }
    }

    return null;
}
 
Example #6
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 #7
Source File: VCardTest.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Test
public void testPhoto() throws Throwable {

    // @formatter:off
    final String request =
                    "<iq id='v1' to='[email protected]/mobile' type='result'>"
                    + VCARD_XML
                    + "</iq>";
    // @formatter:on

    VCard vCard = PacketParserUtils.parseStanza(request);

    byte[] avatar = vCard.getAvatar();
    String mimeType = vCard.getAvatarMimeType();
    assertEquals(mimeType, MIME_TYPE);

    byte[] expectedAvatar = getAvatarBinary();
    assertTrue(Arrays.equals(avatar, expectedAvatar));
}
 
Example #8
Source File: VCardTest.java    From Smack with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoWorkHomeSpecifier_ADDR() throws Throwable {

    // @formatter:off
    final String request =
                    "<iq id='v1' to='[email protected]/mobile' type='result'>"
                    + "<vCard xmlns='vcard-temp'><ADR><STREET>Some street</STREET><FF>ddss</FF></ADR></vCard>"
                    + "</iq>";
    // @formatter:on

    VCard vCard = PacketParserUtils.parseStanza(request);

    assertEquals("Some street", vCard.getAddressFieldWork("STREET"));
    assertEquals("ddss", vCard.getAddressFieldWork("FF"));

}
 
Example #9
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 #10
Source File: AvatarUtil.java    From xyTalk-pc with GNU Affero General Public License v3.0 5 votes vote down vote up
public static ImageIcon getAvatarIcon(VCard vcard,boolean isScale) {
    //avatar从vcard中来
    byte[] bytes = vcard.getAvatar();
    if (bytes != null && bytes.length > 0) {
        ImageIcon icon = new ImageIcon(bytes);
        if (isScale)
        	return GraphicUtils.scaleImageIcon(icon, 50, 50);
        else
        	return icon;
    }
    return null;
}
 
Example #11
Source File: ContactDialControl.java    From Spark with Apache License 2.0 5 votes vote down vote up
public Collection<Action> getPhoneActions(String jid) {
    if(!isVisible()){
        return Collections.emptyList();
    }
    
    final VCard vcard = SparkManager.getVCardManager().getVCardFromMemory(jid);

    final List<Action> actions = new ArrayList<Action>();
    final String workNumber = vcard.getPhoneWork("VOICE");
    final String homeNumber = vcard.getPhoneHome("VOICE");
    final String cellNumber = vcard.getPhoneWork("CELL");

    if (ModelUtil.hasLength(homeNumber)) {
        Action dialHomeAction = new CallAction(PhoneRes.getIString("phone.home")+":", homeNumber, PhoneRes.getImageIcon("HOME_IMAGE"));
        actions.add(dialHomeAction);
    }

    if (ModelUtil.hasLength(workNumber)) {
        final Action dialWorkAction = new CallAction(PhoneRes.getIString("phone.work")+":", workNumber, PhoneRes.getImageIcon("WORK_IMAGE"));
        actions.add(dialWorkAction);
    }

    if (ModelUtil.hasLength(cellNumber)) {
        final Action dialCellAction = new CallAction(PhoneRes.getIString("phone.cell")+":", cellNumber, PhoneRes.getImageIcon("MOBILE_IMAGE"));
        actions.add(dialCellAction);
    }

    return actions;
}
 
Example #12
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 #13
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 #14
Source File: VCardEditor.java    From Spark with Apache License 2.0 5 votes vote down vote up
private void fillUI(VCard vcard){
    personalPanel.setFirstName(vcard.getFirstName());
    personalPanel.setMiddleName(vcard.getMiddleName());
    personalPanel.setLastName(vcard.getLastName());
    personalPanel.setEmailAddress(vcard.getEmailHome());
    personalPanel.setNickname(vcard.getNickName());
    personalPanel.setJID(vcard.getJabberId());

    businessPanel.setCompany(vcard.getOrganization());
    businessPanel.setDepartment(vcard.getOrganizationUnit());
    businessPanel.setStreetAddress(vcard.getAddressFieldWork("STREET"));
    businessPanel.setCity(vcard.getAddressFieldWork("LOCALITY"));
    businessPanel.setState(vcard.getAddressFieldWork("REGION"));
    businessPanel.setZipCode(vcard.getAddressFieldWork("PCODE"));
    businessPanel.setCountry(vcard.getAddressFieldWork("CTRY"));
    businessPanel.setJobTitle(vcard.getField("TITLE"));
    businessPanel.setPhone(vcard.getPhoneWork("VOICE"));
    businessPanel.setFax(vcard.getPhoneWork("FAX"));
    businessPanel.setPager(vcard.getPhoneWork("PAGER"));
    businessPanel.setMobile(vcard.getPhoneWork("CELL"));
    businessPanel.setWebPage(vcard.getField("URL"));

    // Load Home Info
    homePanel.setStreetAddress(vcard.getAddressFieldHome("STREET"));
    homePanel.setCity(vcard.getAddressFieldHome("LOCALITY"));
    homePanel.setState(vcard.getAddressFieldHome("REGION"));
    homePanel.setZipCode(vcard.getAddressFieldHome("PCODE"));
    homePanel.setCountry(vcard.getAddressFieldHome("CTRY"));
    homePanel.setPhone(vcard.getPhoneHome("VOICE"));
    homePanel.setFax(vcard.getPhoneHome("FAX"));
    homePanel.setPager(vcard.getPhoneHome("PAGER"));
    homePanel.setMobile(vcard.getPhoneHome("CELL"));
}
 
Example #15
Source File: XMPP.java    From XMPPSample_Studio with Apache License 2.0 5 votes vote down vote up
public void login(String user, String pass, StatusItem status, String username)
            throws XMPPException, SmackException, IOException, InterruptedException {
        Log.i(TAG, "inside XMPP getlogin Method");
        long l = System.currentTimeMillis();
        XMPPTCPConnection connect = connect();
        if (connect.isAuthenticated()) {
            Log.i(TAG, "User already logged in");
            return;
        }

        Log.i(TAG, "Time taken to connect: " + (System.currentTimeMillis() - l));

        l = System.currentTimeMillis();
        connect.login(user, pass);
        Log.i(TAG, "Time taken to login: " + (System.currentTimeMillis() - l));

        Log.i(TAG, "login step passed");

        Presence p = new Presence(Presence.Type.available);
        p.setMode(Presence.Mode.available);
        p.setPriority(24);
        p.setFrom(connect.getUser());
        if (status != null) {
            p.setStatus(status.toJSON());
        } else {
            p.setStatus(new StatusItem().toJSON());
        }
//        p.setTo("");
        VCard ownVCard = new VCard();
        ownVCard.load(connect);
        ownVCard.setNickName(username);
        ownVCard.save(connect);

        PingManager pingManager = PingManager.getInstanceFor(connect);
        pingManager.setPingInterval(150000);
        connect.sendPacket(p);


    }
 
Example #16
Source File: XMPPManager.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
public VCard getUserVCard(String jid) {
    //ProviderManager.getInstance().addIQProvider("vCard", "vcard-temp", new VCardProvider());

    VCard vCard = new VCard();

    try {
        vCard.load(XMPPManager.getInstance().getConnection(), JidCreate.entityBareFrom(jid/*+DOMAIN*/));
        VCardProvider vCardProvider = new VCardProvider();

    } catch (Exception e) {
        e.printStackTrace();
    }
    return vCard;
}
 
Example #17
Source File: VCardManager.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a new vCard to the cache.
 *
 * @param jid   the jid of the user.
 * @param vcard the users vcard to cache.
 */
public void addVCard(BareJid jid, VCard vcard) {
    if (vcard == null)
    	return; 
    vcard.setJabberId(jid.toString());
    if (vcards.containsKey(jid) && vcards.get(jid).getError() == null && vcard.getError()!= null)
    {
    	return;
    	
    }
    vcards.put(jid, vcard);
}
 
Example #18
Source File: VCardManager.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the Avatar in the form of an <code>ImageIcon</code>.
 *
 * @param vcard the vCard containing the avatar.
 * @return the ImageIcon or null if no avatar was present.
 */
public static ImageIcon getAvatarIcon(VCard vcard) {
    // Set avatar
    byte[] bytes = vcard.getAvatar();
    if (bytes != null && bytes.length > 0) {
        ImageIcon icon = new ImageIcon(bytes);
        return GraphicUtils.scaleImageIcon(icon, 40, 40);
    }
    return null;
}
 
Example #19
Source File: VCardManager.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the VCard for this Spark user. This information will be cached after loading.
 *
 * @return this users VCard.
 */
public VCard getVCard() {
    if (!vcardLoaded) {
    	reloadPersonalVCard();
        vcardLoaded = true;
    }
    return personalVCard;
}
 
Example #20
Source File: VCardManager.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
  * Displays the full profile for a particular JID.
  *
  * @param jid    the jid of the user to display.
  * @param parent the parent component to use for displaying dialog.
  */
 public void viewFullProfile(final BareJid jid, final JComponent parent) {
     final SwingWorker vcardThread = new SwingWorker() {
         VCard vcard = new VCard();

         @Override
public Object construct() {
             vcard = getVCard(jid);
             return vcard;
         }

         @Override
public void finished() {
             if (vcard.getError() != null || vcard == null) {
                 // Show vcard not found
             	UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
                 JOptionPane.showMessageDialog(parent, Res.getString("message.unable.to.load.profile", jid), Res.getString("title.profile.not.found"), JOptionPane.ERROR_MESSAGE);
             }
             else {
                 editor.viewFullProfile(vcard, parent);
             }
         }
     };

     vcardThread.start();

 }
 
Example #21
Source File: VCardManager.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
  * Displays <code>VCardViewer</code> for a particular JID.
  *
  * @param jid    the jid of the user to display.
  * @param parent the parent component to use for displaying dialog.
  */
 public void viewProfile(final BareJid jid, final JComponent parent) {
     final SwingWorker vcardThread = new SwingWorker() {
         VCard vcard = new VCard();

         @Override
public Object construct() {
             vcard = getVCard(jid);
             return vcard;
         }

         @Override
public void finished() {
             if (vcard == null) {
                 // Show vcard not found
             	UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
                 JOptionPane.showMessageDialog(parent, Res.getString("message.unable.to.load.profile", jid), Res.getString("title.profile.not.found"), JOptionPane.ERROR_MESSAGE);
             }
             else {
                 editor.displayProfile(jid, vcard, parent);
             }
         }
     };

     vcardThread.start();

 }
 
Example #22
Source File: XMPPManager.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
public void changeImage(final File file) {
    xmppQueue.postRunnable(new Runnable() {
        @Override
        public void run() {
            try {
                VCard vcard = new VCard();
                vcard.load(connection);

                byte[] bytes;

                bytes = getFileBytes(file);
                if (file == null) {
                    vcard.removeAvatar();
                } else {
                    vcard.setAvatar(bytes);
                }
                // FileLog.e("yahala", "changeImage "+vcard.getFirstName());
                vcard.save(connection);
                UserConfig.clientUserPhoto = file.getAbsolutePath();
                UserConfig.saveConfig(false);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

}
 
Example #23
Source File: VCardTest.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Test
public void testFN() throws Throwable {

    // @formatter:off
    final String request =
                    "<iq id='v1' to='[email protected]/mobile' type='result'>"
                    + "<vCard xmlns='vcard-temp'><FN>kir max</FN></vCard>"
                    + "</iq>";
    // @formatter:on

    VCard vCard = PacketParserUtils.parseStanza(request);

    assertEquals("kir max", vCard.getField("FN"));
}
 
Example #24
Source File: VCardManager.java    From Smack with Apache License 2.0 5 votes vote down vote up
/**
 * Save this vCard for the user connected by 'connection'. XMPPConnection should be authenticated
 * and not anonymous.
 *
 * @param vcard VCard.
 *
 * @throws XMPPErrorException thrown if there was an issue setting the VCard in the server.
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
// TODO: Split VCard into VCardIq and VCardData, then create saveVCard(VCardData) and deprecate this method.
@SuppressWarnings("deprecation")
public void saveVCard(VCard vcard) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    // XEP-54 § 3.2 "A user may publish or update his or her vCard by sending an IQ of type "set" with no 'to' address…"
    vcard.setTo((Jid) null);
    vcard.setType(IQ.Type.set);
    // Also make sure to generate a new stanza id (the given vcard could be a vcard result), in which case we don't
    // want to use the same stanza id again (although it wouldn't break if we did)
    vcard.setStanzaId();
    connection().createStanzaCollectorAndSend(vcard).nextResultOrThrow();
}
 
Example #25
Source File: VCardTest.java    From Smack with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnknownAddressElementNotAdded() throws Throwable {

    // @formatter:off
    final String request =
                    "<iq id='v1' to='[email protected]/mobile' type='result'>"
                    + "<vCard xmlns='vcard-temp'><ADR><UNKNOWN>1234</UNKNOWN></ADR></vCard>"
                    + "</iq>";
    // @formatter:on

    VCard vCard = PacketParserUtils.parseStanza(request);
    assertEquals(null, vCard.getField("UNKNOWN"));
}
 
Example #26
Source File: VCardProvider.java    From Smack with Apache License 2.0 5 votes vote down vote up
private static void parseAddress(XmlPullParser parser, VCard vCard) throws XmlPullParserException, IOException {
    final int initialDepth = parser.getDepth();
    boolean isWork = true;
    outerloop: while (true) {
        XmlPullParser.Event eventType = parser.next();
        switch (eventType) {
        case START_ELEMENT:
            String name = parser.getName();
            if ("HOME".equals(name)) {
                isWork = false;
            }
            else {
                for (String adr : ADR) {
                    if (adr.equals(name)) {
                        if (isWork) {
                            vCard.setAddressFieldWork(name, parser.nextText());
                        }
                        else {
                            vCard.setAddressFieldHome(name, parser.nextText());
                        }
                    }
                }
            }
            break;
        case END_ELEMENT:
            if (parser.getDepth() == initialDepth) {
                break outerloop;
            }
            break;
        default:
            break;
        }
    }
}
 
Example #27
Source File: VCardProvider.java    From Smack with Apache License 2.0 5 votes vote down vote up
private static void parseOrg(XmlPullParser parser, VCard vCard) throws XmlPullParserException, IOException {
    final int initialDepth = parser.getDepth();

    outerloop: while (true) {
        XmlPullParser.Event eventType = parser.next();
        switch (eventType) {
        case START_ELEMENT:
            String name = parser.getName();
            switch (name) {
            case "ORGNAME":
                vCard.setOrganization(parser.nextText());
                break;
            case "ORGUNIT":
                vCard.setOrganizationUnit(parser.nextText());
                break;
            default:
                break;
            }
            break;
        case END_ELEMENT:
            if (parser.getDepth() == initialDepth) {
                break outerloop;
            }
            break;
        default:
            break;
        }
    }
}
 
Example #28
Source File: VCardProvider.java    From Smack with Apache License 2.0 5 votes vote down vote up
private static void parseEmail(XmlPullParser parser, VCard vCard) throws XmlPullParserException, IOException {
    final int initialDepth = parser.getDepth();
    boolean isWork = false;

    outerloop: while (true) {
        XmlPullParser.Event eventType = parser.next();
        switch (eventType) {
        case START_ELEMENT:
            String name = parser.getName();
            switch (name) {
            case "WORK":
                isWork = true;
                break;
            case "USERID":
                if (isWork) {
                    vCard.setEmailWork(parser.nextText());
                }
                else {
                    vCard.setEmailHome(parser.nextText());
                }
                break;
            default:
                break;
            }
            break;
        case END_ELEMENT:
            if (parser.getDepth() == initialDepth) {
                break outerloop;
            }
            break;
        default:
            break;
        }
    }
}
 
Example #29
Source File: VCardProvider.java    From Smack with Apache License 2.0 5 votes vote down vote up
private static void parseName(XmlPullParser parser, VCard vCard) throws XmlPullParserException, IOException {
    final int initialDepth = parser.getDepth();

    outerloop: while (true) {
        XmlPullParser.Event eventType = parser.next();
        switch (eventType) {
        case START_ELEMENT:
            String name = parser.getName();
            switch (name) {
            case "FAMILY":
                vCard.setLastName(parser.nextText());
                break;
            case "GIVEN":
                vCard.setFirstName(parser.nextText());
                break;
            case "MIDDLE":
                vCard.setMiddleName(parser.nextText());
                break;
            case "PREFIX":
                vCard.setPrefix(parser.nextText());
                break;
            case "SUFFIX":
                vCard.setSuffix(parser.nextText());
                break;
            default:
                break;
            }
            break;
        case END_ELEMENT:
            if (parser.getDepth() == initialDepth) {
                break outerloop;
            }
            break;
        default:
            break;

        }
    }
}
 
Example #30
Source File: VCardProvider.java    From Smack with Apache License 2.0 5 votes vote down vote up
private static void parsePhoto(XmlPullParser parser, VCard vCard) throws XmlPullParserException, IOException {
    final int initialDepth = parser.getDepth();
    String binval = null;
    String mimetype = null;

    outerloop: while (true) {
        XmlPullParser.Event eventType = parser.next();
        switch (eventType) {
        case START_ELEMENT:
            String name = parser.getName();
            switch (name) {
            case "BINVAL":
                binval = parser.nextText();
                break;
            case "TYPE":
                mimetype = parser.nextText();
                break;
            default:
                break;
            }
            break;
        case END_ELEMENT:
            if (parser.getDepth() == initialDepth) {
                break outerloop;
            }
            break;
        default:
            break;
        }
    }

    if (binval == null || mimetype == null) {
        return;
    }

    vCard.setAvatar(binval, mimetype);
}