Package org.jivesoftware.openfire.roster

Examples of org.jivesoftware.openfire.roster.RosterItemProvider


  private List<String> importUsers(Document document, String previousDomain) {
    List<String> invalidUsers = new ArrayList<String>();

    UserManager userManager = UserManager.getInstance();
    RosterItemProvider rosterItemProvider = RosterItemProvider
        .getInstance();

    Element users = document.getRootElement();

    Iterator usersIter = users.elementIterator("User");
    while (usersIter.hasNext()) {
      Element user = (Element) usersIter.next();

      String userName = null;
      String password = null;
      String email = null;
      String name = null;
      List<RosterItem> rosterItems = new ArrayList<RosterItem>();

      Iterator userElements = user.elementIterator();
      while (userElements.hasNext()) {
        Element userElement = (Element) userElements.next();

        String nameElement = userElement.getName();
        if ("Username".equals(nameElement)) {
          userName = userElement.getText();
        } else if ("Password".equals(nameElement)) {
          password = userElement.getText();
        } else if ("Name".equals(nameElement)) {
          name = userElement.getText();
        } else if ("Email".equals(nameElement)) {
          email = userElement.getText();
        } else if ("Roster".equals(nameElement)) {
          Iterator rosterIter = userElement.elementIterator("Item");

          while (rosterIter.hasNext()) {
            Element rosterElement = (Element) rosterIter.next();

            String jid = rosterElement.attributeValue("jid");
            String askstatus = rosterElement
                .attributeValue("askstatus");
            String recvstatus = rosterElement
                .attributeValue("recvstatus");
            String substatus = rosterElement
                .attributeValue("substatus");
            String nickname = rosterElement.attributeValue("name");

            List<String> groups = new ArrayList<String>();
            Iterator groupIter = rosterElement
                .elementIterator("Group");
            while (groupIter.hasNext()) {
              Element group = (Element) groupIter.next();
              groups.add(group.getText());
            }

            // used for migration
            if (previousDomain != null) {
              jid = jid.replace(previousDomain, serverName);
            }

            rosterItems.add(new RosterItem(new JID(jid),
                RosterItem.SubType.getTypeFromInt(Integer
                    .parseInt(substatus)),
                RosterItem.AskType.getTypeFromInt(Integer
                    .parseInt(askstatus)),
                RosterItem.RecvType.getTypeFromInt(Integer
                    .parseInt(recvstatus)), nickname,
                groups));
          }
        }
      }

      if ((userName != null) && (password != null)) {
        try {
          userName = Stringprep.nodeprep(userName);

          if (!isUserProviderReadOnly()) {
            userManager.createUser(userName, password, name, email);
          }

          // Check to see user exists before adding their roster, this
          // is for read-only user providers.
          userManager.getUser(userName);
          for (RosterItem ri : rosterItems) {
            rosterItemProvider.createItem(userName, ri);
          }
        } catch (StringprepException se) {
          Log.info("Invalid username " + userName);
          invalidUsers.add(userName);
        } catch (UserAlreadyExistsException e) {
View Full Code Here


   
    private List<String> importUsers(Document document, String previousDomain) {
        List<String> invalidUsers = new ArrayList<String>();
       
        UserManager userManager = UserManager.getInstance();
        RosterItemProvider rosterItemProvider = RosterItemProvider.getInstance();
       
        Element users = document.getRootElement();
       
        Iterator<Element> usersIter = users.elementIterator("User");
        while (usersIter.hasNext()) {
            Element user = usersIter.next();
           
            String userName = null;
            String password = null;
            String email = null;
            String name = null;
            List<RosterItem> rosterItems = new ArrayList<RosterItem>();
           
            Iterator<Element> userElements = user.elementIterator();
            while (userElements.hasNext()) {
                Element userElement = userElements.next();
               
                String nameElement = userElement.getName();
                if ("Username".equals(nameElement)) {
                    userName = userElement.getText();
                }
                else if ("Password".equals(nameElement)) {
                    password = userElement.getText();
                }
                else if ("Name".equals(nameElement)) {
                    name = userElement.getText();
                }
                else if ("Email".equals(nameElement)) {
                    email = userElement.getText();
                }
                else if ("Roster".equals(nameElement)) {
                    Iterator<Element> rosterIter = userElement.elementIterator("Item");
                   
                    while (rosterIter.hasNext()) {
                        Element rosterElement = rosterIter.next();
                       
                        String jid = rosterElement.attributeValue("jid");
                        String askstatus = rosterElement.attributeValue("askstatus");
                        String recvstatus = rosterElement.attributeValue("recvstatus");
                        String substatus = rosterElement.attributeValue("substatus");
                        String nickname = rosterElement.attributeValue("name");
                       
                        List<String> groups = new ArrayList<String>();
                        Iterator<Element> groupIter = rosterElement.elementIterator("Group");
                        while (groupIter.hasNext()) {
                            Element group = groupIter.next();
                            String groupName = group.getText();
                            if (groupName != null && groupName.trim().length() > 0) {
                                groups.add(groupName);
                            }
                        }
                       
                        //used for migration
                        if (previousDomain != null) {
                            jid = jid.replace(previousDomain, serverName);
                        }
                       
                        rosterItems.add(new RosterItem(new JID(jid),
                                        RosterItem.SubType.getTypeFromInt(Integer.parseInt(substatus)),
                                        RosterItem.AskType.getTypeFromInt(Integer.parseInt(askstatus)),
                                        RosterItem.RecvType.getTypeFromInt(Integer.parseInt(recvstatus)),
                                        nickname,
                                        groups));
                    }
                }
            }
           
            if ((userName != null) && (password != null)) {
                try {
                    userName = Stringprep.nodeprep(userName);
                   
                    if (!isUserProviderReadOnly()) {
                       userManager.createUser(userName, password, name, email);
                    }
                   
                    //Check to see user exists before adding their roster, this is for read-only user providers.
                    userManager.getUser(userName);
                    for (RosterItem ri : rosterItems) {
                       rosterItemProvider.createItem(userName, ri);
                    }
                }
                catch (StringprepException se) {
                    Log.info("Invalid username " + userName);
                    invalidUsers.add(userName);
View Full Code Here

TOP

Related Classes of org.jivesoftware.openfire.roster.RosterItemProvider

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.