Package net.sf.json

Examples of net.sf.json.JSONArray


            temp += (char)current;
        }
        reader.close();
       
        String json = new String(temp);
        JSONArray array = (JSONArray) JSONSerializer.toJSON(json);
        int size = array.size();
       
        for(int i = 0; i < size; i++){
          JSONObject object = array.getJSONObject(i);
          String name = object.names().getString(0);
          JSONArray array_object = object.getJSONArray(name);
          int arraySize = array_object.size();
          Entity entity = new Entity(name);
         
        for(int j = 0; j < arraySize; j++){
              String user = array_object.getJSONObject(j).names().getString(0);

          if(user.equalsIgnoreCase("not_exist")) {
            notExistantUser.add(name);
            continue;
          }
          try{
            Double value = Double.parseDouble(user);
            userPredefined.add(new Ent_Eva(new Entity(name),value));
            continue;
           
          }catch (Exception e) {}
         
          JSONArray userArray = array_object.getJSONObject(j).getJSONArray(user);
          String domain = findDomain(userArray.getString(0));
        if(domain == null) {
          System.out.println("Error: domain is not known from user "+
          entity.getUniqueIdentificator()+" and it is discarted:"+ userArray.getString(0));
          continue;
        }
        if(!name.equals("")){
          entity.addIdentificatorInCommunities(GlobalModel.getCommunities().get(domain),
            new EntityIdentifier(user,null));
        }
        else{
          entity.addIdentificatorInCommunities(GlobalModel.getCommunities().get(domain),
            new EntityIdentifier(entity.getUniqueIdentificator(),userArray.getString(0)));
        }
         
        if(!entity.getIdentificatorInCommunities().isEmpty()) {
          GlobalModel.addEntity(entity);
        }
View Full Code Here


      ce.printStackTrace();
      ModelException.throwException(ModelException.SCRAPPY_CONNECTION_ERROR,
          "Connection exception to execute Scrappy");
    }
    try {
      JSONArray array = (JSONArray) JSONSerializer.toJSON(scrappy_dump);
      for(int j=0; j < array.size(); j++){
              JSONObject dumpObject = array.getJSONObject(j);
              if(system.getUriFormat().toString().contains("/$User_Profile_History_Posts")) {
                if(dumpObject.has("http://purl.org/dc/elements/1.1/Usuario")){
              JSONArray array_usuarios = dumpObject.getJSONArray(
                  "http://purl.org/dc/elements/1.1/Usuario");
              JSONObject objeto_usuarios = array_usuarios.getJSONObject(0);
                  //System.out.println("Informacion de usuario:");
                  if(objeto_usuarios.has("http://purl.org/dc/elements/1.1/Nombre")){
                    JSONArray array_user = objeto_usuarios.getJSONArray(
                        "http://purl.org/dc/elements/1.1/Nombre");
                    userName = array_user.getString(0);
                    ModelException.sendMessage(ModelException.INFO,"  Nombre: "+userName);
                  }
                  if(objeto_usuarios.has("http://purl.org/dc/elements/1.1/Posts")){
                    JSONArray array_user = objeto_usuarios.getJSONArray(
                        "http://purl.org/dc/elements/1.1/Posts");
                    String posts = array_user.getString(0);
                    ModelException.sendMessage(ModelException.INFO, "  Posts: " + posts);
                  }
                  if(objeto_usuarios.has("http://purl.org/dc/elements/1.1/URLPosts")){
                    JSONArray array_user = objeto_usuarios.getJSONArray(
                        "http://purl.org/dc/elements/1.1/URLPosts");
                    urlPosts = array_user.getString(0);
                    ModelException.sendMessage(ModelException.INFO,"  URLPosts: "+urlPosts);           
                  }
            }
              } else {
                ModelException.throwException(ModelException.NOT_URI_KNOWN,
View Full Code Here

    if(urlPosts == null) {
      ModelException.throwException(ModelException.SCRAPPY_ERROR,"scrappyImportation " +
          "method must be called before this method or it had an incorrect execution");
    }
    String scrappy_dump = Ejecutor.executeScrappy(urlPosts, "0");
    JSONArray array = (JSONArray) JSONSerializer.toJSON(scrappy_dump);
        JSONObject objeto_dump = array.getJSONObject(0);
        int totalPages = 1;
        if(objeto_dump.has("http://purl.org/dc/elements/1.1/TotalPages")){
          JSONArray number = objeto_dump.getJSONArray("http://purl.org/dc/elements/1.1/TotalPages");
          totalPages = Integer.parseInt(number.getString(0));
        } else {
          ModelException.sendMessage(ModelException.INFO,
              "Slackers scrappy template could be out of date or incorrect. " +
          "There is not http://purl.org/dc/elements/1.1/TotalPages found. Default to 1");
        }
        int postsCount = 0;
        ModelException.sendMessage(ModelException.INFO,"  Maximum posts: " + Property.getPOSTS_NUMBER());       
        for (int j = 1; j <= totalPages; j++){         
      if (postsCount >= Property.getPOSTS_NUMBER()) {
        break;
      }                 
          if (j > 1){
            String newUrlPosts = urlPosts + ",page=" + j;
            scrappy_dump = Ejecutor.executeScrappy(newUrlPosts, "0");
            array = (JSONArray) JSONSerializer.toJSON(scrappy_dump);
            objeto_dump = array.getJSONObject(0);
          }
          if (objeto_dump.has("http://purl.org/dc/elements/1.1/Posts")){
            JSONArray array_objeto_post = objeto_dump.getJSONArray("http://purl.org/dc/elements/1.1/Posts");
            ModelException.sendMessage(ModelException.INFO,
                "  Calculate reputation over "+array_objeto_post.size()+" posts");
            for(int i=0;i<array_objeto_post.size();i++){ 
              if (postsCount == Property.getPOSTS_NUMBER())
                break;
                JSONObject objeto_array_post = array_objeto_post.getJSONObject(i);
              //System.out.println("Informacion de post:");
              if(objeto_array_post.has("http://purl.org/dc/elements/1.1/PostURL")){
                if(system.getUriFormat().toString().contains("/$User_Thread")) {
                  JSONArray array_postURL = objeto_array_post.getJSONArray(
                      "http://purl.org/dc/elements/1.1/PostURL");
                  String postURL = array_postURL.getString(0);
                  ModelException.sendMessage(ModelException.INFO,"    PostURL: " + postURL);
                  if(userThreads == null) {
                    userThreads = new ArrayList<String>();
                  }
                  userThreads.add(Ejecutor.executeScrappy(postURL, "0"));
View Full Code Here

        Locale locale = request.getLocale();
        if(!uiLabelObject.isEmpty()) {
            Set<String> resourceSet = UtilGenerics.checkSet(uiLabelObject.keySet());
            // Iterate over the resouce set
            for (String resource : resourceSet) {
                JSONArray labels = uiLabelObject.getJSONArray(resource);
                if (labels.isEmpty() || labels == null) {
                    continue;
                }

                // Iterate over the uiLabel List
                Iterator<String> jsonLabelIterator = UtilGenerics.cast(labels.iterator());
                JSONArray resourceLabelList = new JSONArray();
                while(jsonLabelIterator.hasNext()) {
                    String label = jsonLabelIterator.next();
                    String receivedLabel = UtilProperties.getMessage(resource, label, locale);
                    if (UtilValidate.isNotEmpty(receivedLabel)) {
                        resourceLabelList.add(receivedLabel);
                    }
                }
                jsonUiLabel.element(resource, resourceLabelList);
            }
        }
View Full Code Here

            uiLabelObject = new JSONObject();
            // Transform JSON String to Object
            uiLabelObject = (JSONObject) JSONSerializer.toJSON(requiredLabels);
        }

        JSONArray jsonUiLabel = new JSONArray();
        Locale locale = request.getLocale();
        if(!uiLabelObject.isEmpty()) {
            Set<String> resourceSet = UtilGenerics.checkSet(uiLabelObject.keySet());
            // Iterate over the resource set
            // here we need a keySet because we don't now which label resource to load
            // the key set should have the size one, if greater or empty error should returned
            if (UtilValidate.isEmpty(resourceSet)) {
                Debug.logError("No resource and labels found", module);
                return "error";
            } else if (resourceSet.size() > 1) {
                Debug.logError("More than one resource found, please use the method: getJSONuiLabelArray", module);
                return "error";
            }

            for (String resource : resourceSet) {
                String label = uiLabelObject.getString(resource);
                if (UtilValidate.isEmail(label)) {
                    continue;
                }

                String receivedLabel = UtilProperties.getMessage(resource, label, locale);
                jsonUiLabel.add(receivedLabel);
            }
        }

        writeJSONtoResponse(jsonUiLabel, response);
        return "success";
View Full Code Here

    getJspContext().setAttribute(getVar(), result);
  }

  private Object parseJsonArray(String jsonString) {
    JSONArray jsonArray = JSONArray.fromObject(jsonString);
    return JSONArray.toCollection(jsonArray, ArrayList.class);
  }
View Full Code Here

    }catch(Exception e){
     
    }
    String outs = "";
    int size = nodes.size();
    JSONArray ja = JSONArray.fromObject(nodes);
    out.print(ja.toString());
  }
View Full Code Here

    /**!
     * 获取参数
     */
    String templateName = json.getString(TEMPLATE_PARAM_NAME);
    String targetFileName = json.getString(TARGET_FILE_NAME);
    JSONArray rowHeaders = json.getJSONArray(ROW_HEADERS);
    List<List<String>> myRowHeaders = new ArrayList<List<String>>();
    convertRowHeaders(rowHeaders,myRowHeaders);
    JSONArray columnHeaders = json.getJSONArray(COLUMN_HEADERS);
    List<List<String>> myColumnHeaders = new ArrayList<List<String>>();
    convertColumnHeaders(columnHeaders,myColumnHeaders);
    JSONArray data = json.getJSONArray(DATA);
    int leftCount = 0;
    int topCount = 0;
    if(rowHeaders!=null){
      leftCount = rowHeaders.size();
    }
    if(columnHeaders!=null){
      topCount = columnHeaders.size();
    }
    int maxColumns = -1;
    if(leftCount>0){
      if(columnHeaders!=null){
        for(int i=0;i<myColumnHeaders.size();i++){
          List<String> columnRow = myColumnHeaders.get(i);
          if(columnRow!=null){
            for(int j=0;j<leftCount;j++){
              columnRow.add(0, "");
            }
          }
          if(columnRow.size()>maxColumns){
            maxColumns = columnRow.size();
          }
        }
      }
      if(data!=null&&rowHeaders!=null){
        for(int i=0;i<rowHeaders.size();i++){
          List<String> rowHeaderRow = myRowHeaders.get(i);
          for(int j=0;j<rowHeaderRow.size();j++){
            if(j<data.size()){
              JSONArray dataRow = data.getJSONArray(j);
              dataRow.add(i,rowHeaderRow.get(j));
            }
          }
        }
      }
    }
View Full Code Here

    if(columnHeaders!=null&&myColumnHeaders!=null){
      for(int i=0;i<columnHeaders.size();i++){
        JSONObject columnHeader = columnHeaders.getJSONObject(i);
        if(columnHeader!=null){
          List<String> myColumnHeader = new ArrayList<String>();
          JSONArray items = columnHeader.getJSONArray("items");
          if(items!=null){
            for(int j=0;j<items.size();j++){
              JSONObject item = items.getJSONObject(j);
              String header = item.getString("header");
              if(header==null){
                header = "";
              }
              int span = item.getInt("span");
View Full Code Here

      for(int i=0;i<rowHeaders.size();i++){
        JSONObject rowHeader = rowHeaders.getJSONObject(i);
        if(rowHeader!=null){
          List<String> myRowHeader = new ArrayList<String>();
          int width = rowHeader.getInt("width");
          JSONArray items = rowHeader.getJSONArray("items");
          if(items!=null){
            for(int j=0;j<items.size();j++){
              JSONObject item = items.getJSONObject(j);
              String header = item.getString("header");
              if(header==null){
                header = "";
              }
              int span = item.getInt("span");
View Full Code Here

TOP

Related Classes of net.sf.json.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.