Package org.json.jdk5.simple

Examples of org.json.jdk5.simple.JSONArray


    SscfInbox si = new SscfInbox();
    return si.getJSONInboxContent(request, mbox);
  }
 
  public static String getThesauri() {
    JSONArray ja = new JSONArray();
   
    for(ThesaurusContext context:Thesauri.getInstance().getContexts())
    {
      JSONObject jo = new JSONObject();
      jo.put("label", context.getLabel());
      jo.put("uri", context.getUri().toString());
     
      ja.add(jo);
    }
   
    return ja.toString();
  }
View Full Code Here


  public JSONObject toJSONObject(){
    JSONObject json = new JSONObject();
    json.put("differenceType", synchronizationState.getMessage());
    if(storedPost != null){
      json.put("storedPostURI", storedPost.getHref());
      JSONArray tags = new JSONArray();
      for(String tag : storedPost.getTags()){
        tags.add(tag);
      }
      json.put("storedPostTags", tags);
      json.put("storedPostDesc", storedPost.getDescription());
    }else{
      json.put("storedPostURI",null);
    }
    if(importedPost != null){
      json.put("importedPostURI", importedPost.getHref());
      JSONArray tags = new JSONArray();
      for(String tag : importedPost.getTags()){
        tags.add(tag);
      }
      json.put("importedPostTags", tags);
      json.put("importedPostDesc", importedPost.getDescription());
    }else{
      json.put("importedPostURI", null);
View Full Code Here

   * @return json representation of the result
   */
  public String getJSON()
  {
    Map<String,? extends Object> results = processFilter(true);
    JSONArray result = new JSONArray();
   
    JSONObject jomain = new JSONObject();
   
    if(results!=null)
    {
      result = (JSONArray)results.get("result");
     
      if(result!=null&&result.size()>0)
      {
        jomain.put("count",result.size());
        jomain.put("results", result);
        jomain.put("groups", results.get("groups"));
      }
      else
        jomain.put("count",0);
View Full Code Here

  public Map<String,? extends Object> processFilter(boolean inJson)
  {
    String[] keywords = FilterHelper.fetchKeywords(this.filterString);
   
    List<FilterResult> result = new ArrayList<FilterResult>();
    JSONArray resultJson = new JSONArray();
    List<String> avoidDuplicates = new ArrayList<String>();
   
    if(keywords.length > 0)
    {
      for(String keyword:keywords)
      {
        //Introduced because of low performance of UNION query
        int numberOfQueryParts = 2;
       
        for(int i=1;i<=numberOfQueryParts;i++)
        {
          StringBuilder query = new StringBuilder(FilterModes.ModeSimple.getQuery(this.searchType, this.person, keyword,i));
          query.delete(query.length()-1, query.length())
         
          //add type restrictions.
          StringBuilder sb = new StringBuilder();
          sb.append(" FILTER (");
          for(String type:allowedTypes)
          {
            sb.append(SscfRdfQuery.RDF_FILTER_TYPE_RESTRICTION.toString(type));
            sb.append(" || ");
          }
          sb.delete(sb.length()-3, sb.length());
          sb.append(") }");
          sb.append(" LIMIT 100");
         
          query.append(sb);
         
          System.out.println("final qyery"+query);
         
          QueryResultTable results = null;
          try
          {
            results = DbFace.getModel().querySelect(query.toString(),"SPARQL");
          }
          catch (Exception e1)
          {
            // TODO Auto-generated catch block
            e1.printStackTrace();
          }
       
       
          if(results!=null&&!inJson)
          {
            for(QueryRow qr : results) {
           
              String uri =  qr.getValue(results.getVariables().get(0)).toString();
              if(!avoidDuplicates.contains(uri))
              {
                FilterResult fr = new FilterResult();
                fr.setResourceUri(qr.getValue(results.getVariables().get(0)).toString());
                fr.setResourceType(qr.getValue(results.getVariables().get(1)).toString());
                fr.setLabel(qr.getLiteralValue(results.getVariables().get(2)));
                try {
                  fr.setContent(qr.getLiteralValue(results.getVariables().get(3)));
                }
                catch (Exception e)
                {
                  fr.setContent(null);
                }
                try
                {
                  fr.setCreator(qr.getLiteralValue(results.getVariables().get(4)));
                }
                catch (Exception e)
                {
                  fr.setCreator(null);
                }
               
                result.add(fr);
                avoidDuplicates.add(uri);
              }
            }
          }
          else if(results!=null)
          {
            for(QueryRow qr : results) {
             
              String uri =  qr.getValue(results.getVariables().get(0)).toString();
              if(!avoidDuplicates.contains(uri))
              {
                JSONObject jo = new JSONObject();
                jo.put("uri", qr.getValue(results.getVariables().get(0)).toString().toString());
                jo.put("type", qr.getValue(results.getVariables().get(1)).toString().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.getLiteralValue(results.getVariables().get(4)));
                }
                catch (Exception e)
                {
                  jo.put("creator", null);
                }
               
                resultJson.add(jo);
                avoidDuplicates.add(uri);
              }
            }
          }
        }
View Full Code Here

  public Map<String, ? extends Object> processFilter(boolean inJson)
  {
    Collection<TaxonomyContext<TaxonomyEntry>> taxonomies = Taxonomies.getInstance().getContexts();
   
    List<FilterResult> result = new ArrayList<FilterResult>();
    JSONArray resultJson = new JSONArray();
   
    //groups containers
    JSONArray groupsJson = new JSONArray();
   
    //TODO: in case of taxonomies lets use whole phrase, may be changed.
    String filter = this.filterString;
   
    List<TaxonomyEntry> entries = new ArrayList<TaxonomyEntry>();
   
    for(TaxonomyContext<TaxonomyEntry> tc : taxonomies)
    {
      if(filter==null||!(filter.startsWith("\"")&&filter.endsWith("\"")))
        filter+="*";
       
      Collection<TaxonomyEntry> tmpentries = tc.listMatchingByLabelAndContext(filter)
      entries.addAll(tmpentries);
    }
   
    if(entries.size()>0)
    {
      for(TaxonomyEntry entry:entries)
      {
        String query = FilterModes.ModeTax.getQuery(this.searchType, this.person, entry.getURI().toString(),0);         
          //this.searchType.getTaxonomyQuery(this.person,entry.getURI());
        QueryResultTable results=null;
        try
        {
          results = DbFace.getModel().querySelect(query,"SPARQL");
        }
        catch (Exception e1)
        {
          //
        }
       
        if(results!=null&&!inJson)
        {
          for(QueryRow qr:results) {
           
            FilterResult fr = new FilterResult();
            fr.setResourceUri(qr.getValue(results.getVariables().get(0)).toString());
            fr.setResourceType(qr.getValue(results.getVariables().get(1)).toString());
            fr.setLabel(qr.getLiteralValue(results.getVariables().get(2)));
            try {
              fr.setContent(qr.getLiteralValue(results.getVariables().get(3)));
            } catch(Exception e) {
              fr.setContent(null);
            }
            try {
              fr.setCreator(qr.getValue(results.getVariables().get(4)).toString());
            }
            catch (Exception e) {
              fr.setCreator(null);
            }
            fr.setGroup(entry.getURI().toString());
           
            result.add(fr);
          }
        }
        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",entry.getURI().toString());
           
            resultJson.add(jo);
          }
          //and now the taxonomies
          if(i>0)
          {
            JSONObject concept = new JSONObject();
            concept.put("uri", entry.getURI().toString());
            concept.put("name", entry.getLabel());
            concept.put("type", entry.getContext().getLabel());//taxonomy
            List<TaxonomyEntry> path = entry.getPathFromRoot();
            path.remove(entry);
            StringBuilder sb = new StringBuilder();
            for(TaxonomyEntry te:path) {
              sb.append(te.getLabel());
              sb.append(" > ");
            }
            if(sb.length()>=3) {
              sb.insert(0, "Parents: ")//TODO: i18n or move to js.
              sb.delete(sb.length()-2, sb.length());
            }
            concept.put("mean", sb.toString());
            concept.put("count", i);
            groupsJson.add(concept);
          }
        }
      }
      //3. present results
     
View Full Code Here

   */
  @Override
  public Map<String, ? extends Object> processFilter(boolean inJson)
  {
    List<FilterResult> result = new ArrayList<FilterResult>();
    JSONArray resultJson = new JSONArray();
    boolean areNew = false;
    //groups containers
    JSONArray groupsJson = new JSONArray();
    Map<String,FilterResult> newResults = new HashMap<String, FilterResult>();
    
    String query = SscfRdfQuery.RDF_GET_RECOM_BY_PERSON.toString(this.person);
    String queryFilterOut = SscfRdfQuery.RDF_GET_RECOM_BY_PERSON_FILTEROUT.toString(this.person);
    //this.searchType.getWordNetQuery(this.person,wncOne.getURI());
 
    System.out.println(query);
   
    QueryResultTable results = null;
    QueryResultTable resTmp = null;
   
    List<String> filterOut = new ArrayList<String>();
    List<String> inserted = new ArrayList<String>();
    try
    {
      results = DbFace.getModel().querySelect(query,"SPARQL");
      resTmp = DbFace.getModel().querySelect(queryFilterOut,"SPARQL");   
     
      for(QueryRow qr:resTmp)
        filterOut.add(qr.getValue(resTmp.getVariables().get(0)).toString());
    }
    catch (Exception e1)
    {
      //do nothing
    }
   
    if(getNew)
    {
      String prolog,trustPolicies;
      //properties set by the SSCFTrustSampleServlet
      prolog = System.getProperty("RealTrust.XSBEnginePath");
      trustPolicies = System.getProperty("sscftrust.policies");
     
      SSCFTrustEngineExecuter stee = new SSCFTrustEngineExecuter(prolog,trustPolicies,null);
     
      stee.execute(person);
     
      //QueryResultsTable resultsAfter = SesameDbFace.getDbFace().performTableQuery(query);
      QueryResultTable resultsAfter=null;
      try
      {
        resultsAfter = DbFace.getModel().querySelect(query,"SPARQL");
      }
      catch (Exception e1)
      {
        //
      }
     
      if(resultsAfter!=null&&(results==null || getIteratorLength(resultsAfter.iterator())!=getIteratorLength(results.iterator())))
      {
        for(QueryRow qr : resultsAfter) {
         
          FilterResult fr = new FilterResult();
         
          String uriTmp = qr.getValue(resultsAfter.getVariables().get(0)).toString();
         
          if(!filterOut.contains(uriTmp)&&!inserted.contains(uriTmp))
          {
            fr.setResourceUri(uriTmp);
            inserted.add(uriTmp);
            fr.setResourceType(S3B_SSCF.Directory);
            fr.setLabel(qr.getLiteralValue(resultsAfter.getVariables().get(1)));
            try {
              fr.setContent(qr.getLiteralValue(resultsAfter.getVariables().get(2)));
            } catch (Exception e) {
              fr.setContent(null);
            }
            try  {
              fr.setCreator(qr.getValue(resultsAfter.getVariables().get(3)).toString());
            } catch (Exception e) {
              fr.setCreator(null);
            }
            newResults.put(fr.getResourceUri(),fr);
          }
        }
        areNew = true;
      }
      else
        results = null;
    }
    inserted.clear();
    //=== generate normal results ===
    if(results!=null&&!inJson)
    {
      for(QueryRow qr : results) {

        FilterResult fr = new FilterResult();
        String uriTmp = qr.getValue(results.getVariables().get(0)).toString();
       
        if(!filterOut.contains(uriTmp)&&!inserted.contains(uriTmp))
        {
          fr.setResourceUri(uriTmp);
          inserted.add(uriTmp);
          fr.setResourceType(S3B_SSCF.Directory);
          fr.setLabel(qr.getLiteralValue(results.getVariables().get(1)));
          try {
            fr.setContent(qr.getLiteralValue(results.getVariables().get(2)));
          }
          catch (Exception e) {
            fr.setContent(null);
          }
          try {
            fr.setCreator(qr.getValue(results.getVariables().get(3)).toString());
          }
          catch (Exception e) {
            fr.setCreator(null);
          }
          if(areNew)
          {
            fr.setGroup("others");
            if(newResults.get(fr.getResourceUri())!=null)
              newResults.remove(fr.getResourceUri());
          }
          result.add(fr);
        }
      }
    }
    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>();
    if(!inJson)
View Full Code Here

   */
  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){
View Full Code Here

  public Map<String,? extends Object> processFilter(boolean inJson)
  {
    String[] keywords = FilterHelper.fetchKeywords(this.filterString);
   
    List<FilterResult> result = new ArrayList<FilterResult>();
    JSONArray resultJson = new JSONArray();
   
    //groups containers
    JSONArray groupsJson = new JSONArray();
   
    if(keywords.length > 0)
    {
      List<KOSEntryProxy> res = new ArrayList<KOSEntryProxy>()
     
      for(String keyword:keywords)
      {
        if(keyword.contains(" "))
          keyword = keyword.replaceAll(" ", " AND ");
        //1. get wordnet conepts
        for(ThesaurusContext context : Thesauri.getInstance().getContexts()) {
           Map<KOSEntry,Float> tmpres = ThesaurusStorage.getInstance().search(context, keyword+" AND (type:synset)",new Float(0.85F));
          
           for(KOSEntry entry:tmpres.keySet()) {
             if(!res.contains(entry))
               res.add((KOSEntryProxy)entry);
           }
           break; //use only one context - it looks like it will always get all the results
        }
        //wnc.addAll(WordNetClassification.getWordNetClassifications(keyword));
      }
     
      //2. check for each concepts if there is some resource
      //annotated with it
      for(KOSEntry resOne: res)
      {
        String query = FilterModes.ModeWordnet.getQuery(this.searchType, person, resOne.getURI().toString(),0);
          //this.searchType.getWordNetQuery(this.person,wncOne.getURI());
        QueryResultTable results=null;
        try
        {
          results = DbFace.getModel().querySelect(query,"SPARQL");
        }
        catch (Exception e1)
        {
          //
        }
       
        if(results!=null&&!inJson)
        {
          for(QueryRow qr:results) {
           
            FilterResult fr = new FilterResult();
            fr.setResourceUri(qr.getValue(results.getVariables().get(0)).toString());
            fr.setResourceType(qr.getValue(results.getVariables().get(1)).toString());
            fr.setLabel(qr.getLiteralValue(results.getVariables().get(2)));
            try {
              fr.setContent(qr.getLiteralValue(results.getVariables().get(3)));
            } catch(Exception e) {
              fr.setContent(null);
            }
            try {
              fr.setCreator(qr.getValue(results.getVariables().get(4)).toString());
            }
            catch (Exception e) {
              fr.setCreator(null);
            }
            fr.setGroup(resOne.getURI().toString());
           
            result.add(fr);
          }
        }
        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

   */
  private JSONArray generateTreeNodes(String _user, String... uris) {
    String user = _user;
    user = SynchronizationAction.fixUserLogin(user);
    String sha1sum = Sha1sum.getInstance().calc(user);
    JSONArray jsonArray = new JSONArray();
    for(String uri : uris){
      String shaURI = (uri + "__"  + sha1sum);
      Set<List<String>> paths = PathFinder.getInstance(shaURI, false).getPathsForPerson(user);
      if(paths == null)
        return jsonArray;
      for(List<String> path : paths){
       
        //first element is the import directory for bookmarking source, second element is the first directory in the tree
        String dirUri = path.get(1);
        NodeContainer nc = new NodeContainer();


        WebBookmarkResource wbr = WebBookmarkResource.getWebBookmarkResource(dirUri);
        //set dynamic load
        nc.setDyn(true);

        //Web bookmark
        nc.setType("directory");
        DirectoryNode dn = new DirectoryNode();

        dn.setId(wbr.getResource().toString());

        dn.setLabel((wbr.getLabel()!=null&&!"".equals(wbr.getLabel())) ? escapeForJs(wbr.getLabel()) : wbr.getStringURI().toString() );

        int level = 3;
        dn.setLevel(level);
        dn.setOwn(true)
        dn.setStandalone(false);
        nc.setContent(dn);

        //add created nodes to the buffer
       
        jsonArray.add(nc.toJSONObject());
      }
    }
    return jsonArray;
  }
View Full Code Here

      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();
    }
     
View Full Code Here

TOP

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

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.