コード例 #1
0
  public OAuthUser parseInfos(String body) {
    OAuthUser infos = new OAuthUser();
    try {
      DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
      Document doc = dBuilder.parse(new InputSource(new StringReader(body)));

      NodeList nodes = doc.getElementsByTagName("person");
      for (int i = 0; i < nodes.getLength(); i++) {
        Element element = (Element) nodes.item(i);
        for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling()) {
          String localName = node.getNodeName();
          if ("first-name".equals(localName)) {
            infos.setFirstName(getCharacterDataFromElement(node));
          } else if ("last-name".equals(localName)) {
            infos.setLastName(getCharacterDataFromElement(node));
          } else if ("email-address".equals(localName)) {
            infos.setEmail(getCharacterDataFromElement(node));
          } else if ("id".equals(localName)) {
            infos.setId(getCharacterDataFromElement(node));
          }
        }
      }
    } catch (ParserConfigurationException | SAXException | IOException e) {
      log.error("", e);
    }
    return infos;
  }
コード例 #2
0
ファイル: TwitterProvider.java プロジェクト: klemens/openolat
  public OAuthUser parseInfos(String body) {
    OAuthUser user = new OAuthUser();

    try {
      JSONObject obj = new JSONObject(body);
      user.setId(getValue(obj, "id_str"));

      String name = getValue(obj, "name");
      if (name != null) {
        name = name.trim();
        int lastSpaceIndex = name.lastIndexOf(' ');
        if (lastSpaceIndex > 0) {
          user.setFirstName(name.substring(0, lastSpaceIndex));
          user.setLastName(name.substring(lastSpaceIndex + 1));
        } else {
          user.setLastName(name);
        }
      }

      user.setLang(getValue(obj, "lang"));
    } catch (JSONException e) {
      log.error("", e);
    }

    return user;
  }