Package org.json.jdk5.simple

Examples of org.json.jdk5.simple.JSONObject


      sendJSONResponse(resp, rh.getJSON());
     
    }
    else
    {
      JSONObject jo = new JSONObject();
      jo.put("count",0);
      sendJSONResponse(resp, jo.toString());
    }
   
   
  }
View Full Code Here


    }
    else if(results!=null)
    {
      int i=0;
      for(QueryRow qr : results) {
        JSONObject jo = new JSONObject();
       
        String uriTmp = qr.getValue(results.getVariables().get(0)).toString();
       
        if(!filterOut.contains(uriTmp)&&!inserted.contains(uriTmp))
        {
          i++;
          jo.put("uri", uriTmp);
          inserted.add(uriTmp);
          jo.put("type", S3B_SSCF.Directory);
          jo.put("label", qr.getLiteralValue(results.getVariables().get(1)));
          try {
            jo.put("content", qr.getLiteralValue(results.getVariables().get(2)).toString());
          }
          catch (Exception e) {
            jo.put("content",null);
          }
          try {
            jo.put("creator", qr.getValue(results.getVariables().get(3)).toString());
          }
          catch (Exception e) {
            jo.put("creator",null);
          }
          if(areNew)
          {
            jo.put("group","others");
            if(newResults.get(uriTmp)!=null)
              newResults.remove(uriTmp);
          }
          resultJson.add(jo);
        }
      }
      //and now the groups
      if(i>0&&areNew)
      {
        JSONObject group = new JSONObject();
        group.put("uri", "others");
        group.put("name","others");
        //group.put("type");
        group.put("mean","Existing recommendations");
        group.put("count", i);
        groupsJson.add(group);
      }
     
    }
 
    //=== generate new results ===
    for(FilterResult fr:newResults.values())
    {
      if(!inJson)
        result.add(fr);
      else
      {
        JSONObject jo = new JSONObject();
        jo.put("uri", fr.getResourceUri());
        jo.put("type", fr.getResourceType());
        jo.put("label", fr.getLabel());
        jo.put("content", fr.getCreator());
        jo.put("creator", fr.getCreator());
        jo.put("group","new");
        resultJson.add(jo);
      }
    }
    if(newResults.size()>0&&inJson)
    {
      JSONObject group = new JSONObject();
      group.put("uri", "new");
      group.put("name","new");
      //group.put("type");
      group.put("mean","New recommendations");
      group.put("count", newResults.size());
      groupsJson.add(0,group);
    }
   
 
    Map<String,Object> finalResult = new HashMap<String,Object>();
View Full Code Here

  String content;
  String creator;
  String group;
 
  public JSONObject toJSONObject() {
    JSONObject jo = new JSONObject();
   
    jo.put("uri", getResourceUri());
    jo.put("type", getResourceType());
    jo.put("label", getLabel());
    jo.put("content", getContent());
    jo.put("creator", getCreator());
    jo.put("group", getGroup());
    return jo;
  }
View Full Code Here

    sb.append("\"");
  }
 
 
  public JSONObject toJSONObject(){
    JSONObject json = new JSONObject();
    json.put("label", label);
    json.put("id",id);
    if(!isStandalone())
      json.put("standalone",isStandalone());
    if(isSelected())
      json.put("selected", isSelected());
    json.put("level",getLevel());
   
    return json;
  }
View Full Code Here

        else if(results!=null)
        {
          int i=0;
          for(QueryRow qr:results) {
            i++;
            JSONObject jo = new JSONObject();

            jo.put("uri", qr.getValue(results.getVariables().get(0)).toString());
            jo.put("type",qr.getValue(results.getVariables().get(1)).toString());
            jo.put("label", qr.getLiteralValue(results.getVariables().get(2)));
            try {
              jo.put("content", qr.getLiteralValue(results.getVariables().get(3)));
            } catch(Exception e) {
              jo.put("content", null);
            }
            try {
              jo.put("creator", qr.getValue(results.getVariables().get(4)).toString());
            } catch (Exception e){
              jo.put("creator", null);
            }
            jo.put("group",resOne.getURI().toString());
           
            resultJson.add(jo);
          }
          //and now the wordnet
          if(i>0)
          {
            WordNetEntry wne = null;
            if(resOne.getContext().getLabel().equals("WordNet"))
            {
              wne = (WordNetEntry)resOne;
            }
            JSONObject wordNetConcept = new JSONObject();
            wordNetConcept.put("uri", resOne.getURI().toString());
            wordNetConcept.put("name", resOne.getLabel()); //it was getName()
            if(wne!=null)
            {
              WordSense word = new WordSense((WordNetContext)wne.getContext(),wne.getURI(),null);
              wordNetConcept.put("type",word.getPOS()!=null?word.getPOS():"");
            }
            else wordNetConcept.put("type","");
            wordNetConcept.put("mean", resOne.getDescription());
            wordNetConcept.put("count", i);
            groupsJson.add(wordNetConcept);
          }
        }
       
      }
View Full Code Here

   * @return <tt>String</tt> JSON response as a string
   */
  private String toJSONResponse(String status, String sscfPerson, String[] nodes) {
    List<ResourceDifference> results = SynchronizationAction.getSynchronizationResults(sscfPerson);
//    List<ResourceDifference> results = createTestData();
    JSONObject jsonRes = new JSONObject();
    JSONArray jsonResults = new JSONArray();
    for (ResourceDifference res : results) {
      jsonResults.add(res.toJSONObject());
    }
    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm");
    Date date = SynchronizationAction.getLastSynchronizationDate(sscfPerson);
    String sDate = null;
    if(date != null){
      sDate = sdf.format(date);
    }
    jsonRes.put("status", status);
    jsonRes.put("lastSync", sDate);
    jsonRes.put("results", jsonResults);
    jsonRes.put("count", results.size());
    if(nodes != null && !"".equals(nodes))
      jsonRes.put("nodes", generateTreeNodes(sscfPerson, nodes));

    return jsonRes.toString();
  }
View Full Code Here

  public void setType(String _type) {
    this.type = _type;
  }
 
  public JSONObject toJSONObject(){
    JSONObject json = new JSONObject();
    json.put("content", content.toJSONObject());
    json.put("type", type);
    json.put("dyn", dyn);
    return json;
  }
View Full Code Here

   * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      String serverAddress = req.getScheme()+"://"+req.getServerName()+((req.getServerPort() != 80)?":"+req.getServerPort():"")+req.getContextPath()+"/";

      JSONObject obj=new JSONObject();

      this.setStaticContent(obj);
     
      JSONArray items = new JSONArray();
      obj.put("items", items);
     
      ServletCallBean callBean = (ServletCallBean)req.getAttribute("callBean");
     
    try {
      Map<String, Map<String, Collection<String>>> triples = callBean.getGraphStats().getTriples();
      for(String resource : callBean.getGraphStats().getResults()){
        String type = MbbTypes.detectType(triples, resource);
       
        if("book".equals(type))
          items.add(this.jsonBook(triples, resource, serverAddress));
        else if("person".equals(type))
          items.add(this.jsonPerson(triples, resource, serverAddress));
        else
          items.add(this.jsonOther(triples, resource, serverAddress));
      }
    } catch (AccessDeniedException e) {
      e.printStackTrace();
    }
     
     
     
      String result = obj.toString();
      //resp.setContentType("application/x-json");
      resp.setContentType("text/html; charset=UTF-8");
      resp.setHeader("Cache-Control","no-cache"); //HTTP 1.1
      resp.setHeader("Pragma","no-cache"); //HTTP 1.0
      resp.setDateHeader ("Expires", 0);
View Full Code Here

 

  protected JSONObject jsonBook(Map<String, Map<String, Collection<String>>> triples, String resource, String serverAddress){
    Map<String, Collection<String>> value = triples.get(resource);
    Book book = MbbTypes.getBook(value, triples);
    JSONObject object = new JSONObject();
    object.put("type", "Book");
    object.put("id", resource);
    object.put("uri", resource);

    if(book != null){
      object.put("bookType", book.getBookType());
      object.put("label", book.getTitle());
      object.put("abstract", book.getAbstr());
     
      JSONArray authors = new JSONArray();
      if(book.getAuthors() != null)
        for(Person author : book.getAuthors())
          authors.add(author.getName());
     
      object.put("creator", authors);
     
      JSONArray keywords = new JSONArray();
      if(book.getKeywords() != null)
        keywords.addAll(book.getKeywords());
     
      object.put("keywords", keywords);
     
      this.addProperties(object, book.getOtherProperties());

      String coverFile = (book.getCover() != null)?book.getCover():"image/def_cover_page.jpg";
      object.put("cover", serverAddress+"servlet/showImage?from=cover&file="+coverFile+"&type="+((book.getCoverMime()!=null)?book.getCoverMime():"image/jpg")+"&w=50");
     
    }
   
   
    return object;
View Full Code Here

    </c:forEach>
    uri: "${person.email}"
  },
   */
  protected JSONObject jsonPerson(Map<String, Map<String, Collection<String>>> triples, String resource, String serverAddress){
    JSONObject object = new JSONObject();
    Map<String, Collection<String>> value = triples.get(resource);
    Person person = MbbTypes.getPerson(value);
   
    object.put("type", "Person");
    object.put("label", person.getName());
    object.put("homepage", person.getHomepage());
    object.put("bio", person.getBio());
   
    JSONArray emails = new JSONArray();
    if(person.getEmails() != null)
      emails.addAll(person.getEmails());
   
    object.put("email", emails);
   
    JSONArray knows = new JSONArray();
    if(person.getKnows() != null)
      knows.addAll(person.getKnows());
   
    object.put("knows", knows);
   
    JSONArray phones = new JSONArray();
    if(person.getPhones() != null)
      phones.addAll(person.getPhones());
   
    object.put("phones", phones);
   
    JSONArray interests = new JSONArray();
    if(person.getInterests() != null)
      interests.addAll(person.getInterests());
   
    object.put("interests", interests);
   
    this.addProperties(object, person.getOtherProperties());

    return object;
  }
View Full Code Here

TOP

Related Classes of org.json.jdk5.simple.JSONObject

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.