Package net.solosky.maplefetion.store

Examples of net.solosky.maplefetion.store.FetionStore



    @Override
    protected ActionEvent doActionOK(SipcResponse response) throws FetionException
    {
      FetionStore store = this.context.getFetionStore();
    if(response.getBody()!=null){
        Element root = XMLHelper.build(response.getBody().toSendString());
      List groupList = XMLHelper.findAll(root, "/results/groups/*group");
      Iterator it = groupList.iterator();
      while(it.hasNext()) {
        Element e = (Element) it.next();
        Group group = store.getGroup(e.getAttributeValue("uri"));
        if(group!=null) {
                BeanHelper.toBean(Group.class, group, e);
          logger.debug("Got a group:"+group);
        }
      }
View Full Code Here


      throws FetionException
  {
    Element root = XMLHelper.build(response.getBody().toSendString());
    List sclist = XMLHelper.findAll(root, "/results/schedule-sms-list/*schedule-sms");
    Iterator it = sclist.iterator();
    FetionStore store = this.context.getFetionStore();
   
    synchronized (store) {
      while(it.hasNext()){
        Element e = (Element) it.next();
        //这里的 定时短信只有ID,如果需要定时短信的详细信息还需要发出另外的请求
        //真搞不懂为什么不把定时短信的详细直接返回,非得要发另外一个请求,很无语。。
        ScheduleSMS sc = new ScheduleSMS(Integer.parseInt(e.getAttributeValue("id")), null, null, null);
        store.addScheduleSMS(sc);
      }
        }
   
    return super.doActionOK(response);
  }
View Full Code Here

      throws FetionException
  {
    Element root = XMLHelper.build(response.getBody().toSendString());
    List sclist = XMLHelper.findAll(root, "/results/schedule-sms-list/*schedule-sms");
    Iterator it = sclist.iterator();
    FetionStore store = this.context.getFetionStore();
    SimpleDateFormat df = new SimpleDateFormat("yyyy-M-d H:m:s");
    df.setTimeZone(TimeZone.getTimeZone("GMT 0"));
    while(it.hasNext()){
      Element e = (Element) it.next();
      int scId = Integer.parseInt(e.getAttributeValue("id"));
      ScheduleSMS sc = store.getScheduleSMS(scId);
      if(sc!=null){
        try {
          BeanHelper.setValue(sc, "sendDate", df.parse(e.getAttributeValue("send-time")))//发送时间
        } catch (ParseException e1) {
          throw new net.solosky.maplefetion.util.ParseException("Parse scheduleSMS send-time failed. "+e.getAttributeValue("sendTime"));
        }
       
        BeanHelper.setValue(sc, "message", new Message(e.getChild("message").getText()))//消息内容
       
        ArrayList<Buddy> recieverList = new ArrayList<Buddy>();
        List recvList = XMLHelper.findAll(e, "/schedule-sms/receivers/*receiver");    //接收者
        Iterator rit =recvList.iterator();
        while(rit.hasNext()){
          Element el = (Element) rit.next();
          String uri = el.getAttributeValue("uri");
          Buddy buddy = store.getBuddyByUri(uri);
          if(buddy!=null){
            recieverList.add(buddy);
          }else if(context.getFetionUser().getUri().equals(uri)){    //可能是用户自己
            recieverList.add(context.getFetionUser());
          }else{
            buddy = UriHelper.createBuddy(uri);
            BeanHelper.setValue(buddy, "relation", Relation.STRANGER);
            recieverList.add(buddy);
            store.addBuddy(buddy);
          }
        }
        BeanHelper.setValue(sc, "receiverList", recieverList);
       
      }
View Full Code Here

      throws FetionException
  {
 
    Element root = XMLHelper.build(response.getBody().toSendString());
   
    FetionStore store = this.context.getFetionStore();
   
    //解析个人信息,飞信真有意思,这里却不简写,map.xml里面全是简写的,所以这里只能手动注入了。
    Element personal = XMLHelper.find(root, "/results/user-info/personal");
    User user = this.context.getFetionUser();
    user.setEmail(personal.getAttributeValue("register-email"));

    int personalVersion = Integer.parseInt(personal.getAttributeValue("version"));
    Element contactList = XMLHelper.find(root, "/results/user-info/contact-list");
    int contactVersion = Integer.parseInt(contactList.getAttributeValue("version"));
   
    //联系人和个人信息版本信息
    store.getStoreVersion().setPersonalVersion(personalVersion);
    store.getStoreVersion().setContactVersion(contactVersion);
    user.getStoreVersion().setPersonalVersion(personalVersion);
    user.getStoreVersion().setContactVersion(contactVersion);
   
    //个人信息
    BeanHelper.toBean(User.class, user, personal);
   
   
    //一定要对飞信列表加锁,防止其他飞信操作获取到空的数据
    synchronized (store) {

      //解析分组列表
      List list = XMLHelper.findAll(root, "/results/user-info/contact-list/buddy-lists/*buddy-list");
      Iterator it = list.iterator();
      while(it.hasNext()) {
        Element e = (Element) it.next();
        store.addCord(new Cord(Integer.parseInt(e.getAttributeValue("id")), e.getAttributeValue("name")));
      }
     
      //解析好友列表
      list = XMLHelper.findAll(root, "/results/user-info/contact-list/buddies/*b");
      it = list.iterator();
      while(it.hasNext()) {
        Element e = (Element) it.next();
        String uri = e.getAttributeValue("u");
       
        Buddy b = UriHelper.createBuddy(uri);
        b.setUserId(Integer.parseInt(e.getAttributeValue("i")));
        b.setLocalName(e.getAttributeValue("n"));
        b.setUri(e.getAttributeValue("u"));
        b.setCordId(e.getAttributeValue("l"));
        b.setRelation(Relation.valueOf(Integer.parseInt(e.getAttributeValue("r"))));
       
        store.addBuddy(b);
      }
     
      //处理 chat-friend..
        //这个chat-friend具体是什么含义我也没搞得太清楚,目前猜测里面的名单可能和用户是陌生人关系
      list = XMLHelper.findAll(root, "/results/user-info/contact-list/chat-friends/*c");
      it = list.iterator();
        while(it.hasNext()){
          Element e = (Element) it.next();
          Buddy b = UriHelper.createBuddy(e.getAttributeValue("u"));
        b.setUserId(Integer.parseInt(e.getAttributeValue("i")));
        b.setUri(e.getAttributeValue("u"));
            b.setRelation(Relation.STRANGER);
            store.addBuddy(b);
        }
       
        //处理Blacklist
        list = XMLHelper.findAll(root, "/results/user-info/contact-list/blacklist/*k");
      it = list.iterator();
        while(it.hasNext()){
          Element e = (Element) it.next();
          String uri = e.getAttributeValue("u");
          Buddy b = store.getBuddyByUri(uri);
          if(b!=null) {
            b.setRelation(Relation.BANNED);
          }
        }
       
       
        //处理Crendeticals
        Element credentialList = XMLHelper.find(root, "/results/credentials");
       
        user.setSsiCredential(this.decryptCredential(credentialList.getAttributeValue("kernel")));
       
        list = XMLHelper.findAll(root, "/results/credentials/*credential");
        it = list.iterator();
        while(it.hasNext()) {
          Element e = (Element) it.next();
          String domain = e.getAttributeValue("domain");
          Credential c = store.getCredential(domain);
          if(c==null) {
            c = new Credential(domain, null);
            store.addCredential(c);
          }
          c.setCredential(this.decryptCredential(e.getAttributeValue("c")));
        }
        }
   
View Full Code Here

  {
    //用户已经开通飞信,返回了用户的真实的uri,建立一个好友对象,并加入到好友列表中

    Element root = XMLHelper.build(response.getBody().toSendString());
    Element element = XMLHelper.find(root, "/results/contacts/buddies/buddy");
    FetionStore store = this.context.getFetionStore();
   
    //如果被拒绝后,用户还可以发起添加对方的请求,这样用户可能发起了多次加好友请求
    //所以这里做个判断,如果原来的好友存在,直接删除掉
    int statusCode = Integer.parseInt(element.getAttributeValue("status-code"));
    switch(statusCode) {
    case 200:
      int userId = Integer.parseInt(element.getAttributeValue("user-id"));
      Buddy buddy = store.getBuddyByUserId(userId);
      if(buddy!=null){
        store.deleteBuddy(buddy);
      }
      buddy = new Buddy();
      BeanHelper.toBean(Buddy.class, buddy, element);
     
      store.addBuddy(buddy);
     
      //更新联系人版本信息
      Element contacts = XMLHelper.find(root,"/results/contacts");
        String version = contacts.getAttributeValue("version");
        if(version!=null){
          int v = Integer.parseInt(version);
          store.getStoreVersion().setContactVersion(v);
          context.getFetionUser().getStoreVersion().setContactVersion(v);
        }
       
      return new AddBuddySuccessEvent(buddy);
     
View Full Code Here

    @Override
    protected ActionEvent doActionOK(SipcResponse response)
            throws FetionException
    {
      Element root = XMLHelper.build(response.getBody().toSendString());
      FetionStore store = this.context.getFetionStore();
      synchronized (store) {
       
          List list = XMLHelper.findAll(root, "/results/contacts/blacklist/*blocked");
          Iterator it = list.iterator();
         
        while(it.hasNext()) {
            Element e = (Element) it.next();
            String uri = e.getAttributeValue("uri");
            Buddy buddy = store.getBuddyByUri(uri);
            if(buddy!=null) {
              BeanHelper.setValue(buddy, "relation", Relation.BANNED);
              context.getFetionStore().flushBuddy(buddy);
            }
          }
       
        Element el =  XMLHelper.find(root, "/results/contacts");
        String version = el.getAttributeValue("version");
        if(version!=null) {
          store.getStoreVersion().setContactVersion(Integer.parseInt(version));
        }
        }
     
      return super.doActionOK(response);
    }
View Full Code Here

  @Override
  protected ActionEvent doActionOK(SipcResponse response)
      throws FetionException {
    Element root = XMLHelper.build(response.getBody().toSendString());
    Element element = XMLHelper.find(root, "/results/contacts/buddies/buddy");
    FetionStore store = this.context.getFetionStore();
    if(element!=null && element.getAttributeValue("user-id")!=null) {
      Buddy buddy = store.getBuddyByUserId(Integer.parseInt(element.getAttributeValue("user-id")));
      if(buddy!=null)
        store.deleteBuddy(buddy);
    }
   
    Element contacts = XMLHelper.find(root, "/results/contacts");
    if(contacts!=null && contacts.getAttributeValue("version")!=null){
      int version = Integer.parseInt(contacts.getAttributeValue("version"));
View Full Code Here

    if(this.context.getFetionStore().getStoreVersion().getGroupVersion()!=groupVersion){
      //解析群列表
      this.context.getFetionStore().clearGroupList();
      List groupList = XMLHelper.findAll(root, "/results/group-list/*group");
      Iterator it = groupList.iterator();
      FetionStore store = this.context.getFetionStore();
      while(it.hasNext()) {
        Element e = (Element) it.next();
        Group group = new Group();
        BeanHelper.setValue(group, "uri", e.getAttributeValue("uri"));
        //group.setIdentity( Integer.parseInt(e.getAttributeValue("identity")));
        store.addGroup(group);
      }
    }
    return super.doActionOK(response);
  }
View Full Code Here

    {
      Element root = XMLHelper.build(response.getBody().toSendString());
      Element credentialList = XMLHelper.find(root, "/results/credentials");
    List list = XMLHelper.findAll(root, "/results/credentials/*credential");
    Iterator it = list.iterator();
    FetionStore store = this.context.getFetionStore();
    User user = this.context.getFetionUser();
   
    user.setSsiCredential(this.decryptCredential(credentialList.getAttributeValue("kernel")));
   
    while(it.hasNext()) {
      Element e = (Element) it.next();
      String domain = e.getAttributeValue("domain");
      Credential c = store.getCredential(domain);
      if(c==null) {
        c = new Credential(domain, null);
        store.addCredential(c);
      }
      c.setCredential(this.decryptCredential(e.getAttributeValue("c")));
    }
     
      return super.doActionOK(response);
View Full Code Here

  @Override
  protected ActionEvent doActionOK(SipcResponse response)
      throws FetionException
  {
    //解析群成员信息
      FetionStore store = this.context.getFetionStore();
    Element root = XMLHelper.build(response.getBody().toSendString());
    List groupList = XMLHelper.findAll(root, "/results/groups/*group");
    Iterator it = groupList.iterator();
    while(it.hasNext()) {
      Element g = (Element) it.next();
      Group group = store.getGroup(g.getAttributeValue("uri"));
      //群下面的成员迭代
      List memberList = XMLHelper.findAll(g, "/group/*member");
      Iterator mit = memberList.iterator();
      while(mit.hasNext()) {
        Element e = (Element) mit.next();
        Member member = new Member();
        member.setUri(e.getAttributeValue("uri"));
        member.setNickName(e.getAttributeValue("nickname"));
        member.setIicNickName(e.getAttributeValue("iicnickname"));
        //member.setUserId(Integer.parseInt(e.getAttributeValue("user-id")));
        member.setT6svcid(Integer.parseInt(e.getAttributeValue("t6svcid")));
        member.setIdentity(Integer.parseInt(e.getAttributeValue("identity")));
       
        //BeanHelper.toBean(Member.class, member, e);
       
        store.addGroupMember(group, member);
      }
    }
    return super.doActionOK(response);
  }
View Full Code Here

TOP

Related Classes of net.solosky.maplefetion.store.FetionStore

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.