Package org.codehaus.jettison.json

Examples of org.codehaus.jettison.json.JSONArray


            } else {
                id = "artist:" + urlEncode(json.getString("name"));
            }
            String name = json.getString("name");
            String image = null;
            JSONArray images = json.optJSONArray("image");
            if(images!=null && images.length()>0) {
                image = images.getJSONObject(images.length()-1).getString("#text");
                if(image.length()==0) {
                    image = null;
                }
            }
            LastFMArtist artist = new LastFMArtist(id, name, image);
View Full Code Here


        if (entity != null) {
            try {
                JSONObject object = Client.create().resource(getLastFmUrl("artist.getimages&artist=" + urlEncode(entity.getName()))).accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
                List<ResultItem<LastFMImage>> images = new ArrayList<ResultItem<LastFMImage>>();
                if (object.getJSONObject("images").has("image")) {
                    JSONArray array = object.getJSONObject("images").getJSONArray("image");
                    result.setCount(array.length());
                    for (int i = 0; i < array.length(); i++) {
                        if((firstItem==null || i>=firstItem) && (maxItems==null || maxItems>images.size())) {
                            images.add(createFromJSON("artist="+urlEncode(entity.getName()),array.getJSONObject(i)));
                        }
                    }
                }
                result.setItems(images);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } else if (currentId.startsWith(LastFMArtist.class.getSimpleName() + ":")) {
            try {
                String artistId = currentId.substring(13);
                JSONObject object = Client.create().resource(getLastFmUrl("artist.getimages" + createQueryFromId(artistId))).accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
                List<ResultItem<LastFMImage>> images = new ArrayList<ResultItem<LastFMImage>>();
                if (object.getJSONObject("images").has("image")) {
                    JSONArray array = object.getJSONObject("images").getJSONArray("image");
                    result.setCount(array.length());
                    for (int i = 0; i < array.length(); i++) {
                        if((firstItem==null || i>=firstItem) && (maxItems==null || maxItems>images.size())) {
                            images.add(createFromJSON(createQueryFromId(artistId).substring(1),array.getJSONObject(i)));
                        }
                    }
                }
                result.setItems(images);
            } catch (JSONException e) {
View Full Code Here

    public ResultItem<LastFMImage> findById(String id) {
        try {
            String artistId = id.substring(0,id.indexOf(":image"));
            JSONObject object = Client.create().resource(getLastFmUrl("artist.getimages" + createQueryFromId(artistId))).accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
            if (object.getJSONObject("images").has("image")) {
                JSONArray array = object.getJSONObject("images").getJSONArray("image");
                for (int i = 0; i < array.length(); i++) {
                    String imageId = id.substring(id.lastIndexOf(":")+1);
                    if(array.getJSONObject(i).getString("url").endsWith("/"+imageId)) {
                        return createFromJSON(id.substring(0,id.lastIndexOf(":image:")),array.getJSONObject(i));
                    }
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
View Full Code Here

        if(name.length()==0) {
            name = id;
        }
        id = artistId.replaceAll("mbid=","mbid:").replaceAll("artist=","artist:")+":image:"+id;
        String image = null;
        JSONArray images = json.getJSONObject("sizes").optJSONArray("size");
        if(images!=null && images.length()>0) {
            image = images.getJSONObject(images.length()-1).getString("#text");
            if(image.length()==0) {
                image = null;
            }
        }
        LastFMImage imageObject = new LastFMImage(id, name, image);
View Full Code Here

        if (entity != null) {
            try {
                JSONObject object = Client.create().resource(getLastFmUrl("track.search&track=" + urlEncode(entity.getRecording().getWorks().iterator().next().getName()))).accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
                List<ResultItem<LastFMTrack>> tracks = new ArrayList<ResultItem<LastFMTrack>>();
                JSONArray array = object.getJSONObject("results").getJSONObject("trackmatches").getJSONArray("track");
                result.setCount(array.length());
                for (int i = 0; i < array.length(); i++) {
                    if((firstItem==null || i>=firstItem) && (maxItems==null || maxItems>tracks.size())) {
                        tracks.add(createFromJSON(array.getJSONObject(i), null));
                    }
                }
                result.setItems(tracks);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } else if (currentId.startsWith(LastFMAlbum.class.getSimpleName() + ":")) {
            try {
                String artistId = currentId.substring(12);
                JSONObject object = Client.create().resource(getLastFmUrl("album.getinfo" + createQueryFromId(artistId))).accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
                List<ResultItem<LastFMTrack>> tracks = new ArrayList<ResultItem<LastFMTrack>>();
                if (object.getJSONObject("album").optJSONObject("tracks")!=null && object.getJSONObject("album").getJSONObject("tracks").has("track")) {
                    JSONArray array = object.getJSONObject("album").getJSONObject("tracks").getJSONArray("track");
                    result.setCount(array.length());
                    for (int i = 0; i < array.length(); i++) {
                        if((firstItem==null || i>=firstItem) && (maxItems==null || maxItems>tracks.size())) {
                            tracks.add(createFromJSON(array.getJSONObject(i),object.getJSONObject("album")));
                        }
                    }
                }
                result.setCount(tracks.size());
                result.setItems(tracks);
View Full Code Here

                }
                id = "artist:" + urlEncode(artist) + ":track:" + urlEncode(json.getString("name"));
            }
            String name = json.getString("name");
            String image = null;
            JSONArray images = json.optJSONArray("image");
            if(images!=null && images.length()>0) {
                image = images.getJSONObject(images.length()-1).getString("#text");
                if(image.length()==0) {
                    image = null;
                }
            }
            if(image==null && json.optJSONObject("album")!=null && json.getJSONObject("album").optJSONArray("image")!=null) {
                images = json.getJSONObject("album").getJSONArray("image");
                image = images.getJSONObject(images.length()-1).getString("#text");
                if(image.length()==0) {
                    image = null;
                }
            }
            if(image==null && jsonAlbum!=null && jsonAlbum.optJSONArray("image")!=null) {
                images = jsonAlbum.getJSONArray("image");
                image = images.getJSONObject(images.length()-1).getString("#text");
                if(image.length()==0) {
                    image = null;
                }
            }
            LastFMTrack track = new LastFMTrack(id, null, name, image);
View Full Code Here

        if (entity != null) {
            try {
                JSONObject object = Client.create().resource("http://ws.spotify.com/search/1/track.json?q=track:" + URLEncoder.encode(entity.getRecording().getWorks().iterator().next().getName(), "utf8")).accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
                result.setCount(object.getJSONObject("info").getInt("num_results"));
                List<ResultItem<SpotifyTrack>> tracks = new ArrayList<ResultItem<SpotifyTrack>>();
                JSONArray array = object.getJSONArray("tracks");
                result.setCount(array.length());
                for (int i = 0; i < array.length(); i++) {
                    if((firstItem==null || i>=firstItem) && (maxItems==null || maxItems>tracks.size())) {
                        tracks.add(createFromJSON(array.getJSONObject(i)));
                    }
                }
                result.setItems(tracks);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } else if (currentId.startsWith(SpotifyAlbum.class.getSimpleName() + ":")) {
            try {
                JSONObject object = Client.create().resource("http://ws.spotify.com/lookup/1/.json?uri=" + currentId.substring(13) + "&extras=track").accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
                List<ResultItem<SpotifyTrack>> tracks = new ArrayList<ResultItem<SpotifyTrack>>();
                JSONArray array = object.getJSONObject("album").getJSONArray("tracks");
                result.setCount(array.length());
                for (int i = 0; i < array.length(); i++) {
                    if((firstItem==null || i>=firstItem) && (maxItems==null || maxItems>tracks.size())) {
                        tracks.add(createFromJSON(array.getJSONObject(i)));
                    }
                }
                result.setItems(tracks);
            } catch (JSONException e) {
                e.printStackTrace();
View Full Code Here

                public TableViewItem getTableViewItem(Track track) {
                    return new TableViewItem(track.getId(), "(%object.medium.name|%object.medium.number)||[%object.medium,-]||%object.number||. ||%object.recording.works.parent.name||[%object.recording.works.parent,: ]||%object.recording.works.name", track);
                }
            });

            JSONArray array = Client.create().resource(HOSTURL + "/browse").accept(MediaType.APPLICATION_JSON).get(JSONArray.class);
            Set<ListItem> typeSet = new TreeSet<ListItem>(new Comparator<ListItem>() {
                @Override
                public int compare(ListItem item1, ListItem item2) {
                    return item1.getText().compareTo(item2.getText());
                }
            });
            for (int i = 0; i < array.length(); i++) {
                String type = array.getJSONObject(i).getString("id");
                if (type.contains(".")) {
                    String mainType = type.substring(0, type.indexOf("."));
                    String subType = type.substring(type.indexOf(".") + 1);
                    ListItem mainItem = new ListItem(mainType);
                    mainItem.setUserData(mainType);
View Full Code Here

                        if (previousCriterias.get(tableView) == null ||
                                !previousCriterias.get(tableView).equals(type + ":" + criteriaString)) {

                            // Execute query towards server
                            JSONObject object = Client.create().resource(HOSTURL + "/browse/" + type + "?" + criteriaString+"&itemInfo=true").accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
                            JSONArray objects = object.getJSONArray("items");
                            TableViewItem previousSelectedItem = null;

                            // Make sure we remember previous selection so we can re-select that item if it exists in the new search result
                            int previousSelectedIndex = -1;
                            if (tableView.getSelectedIndex() >= 0) {
                                previousSelectedItem = (TableViewItem) tableView.getTableData().get(tableView.getSelectedIndex());
                            }
                            tableView.getTableData().clear();
                            if (tableView != tracksTableView) {
                                // Add special "(All)" element at the top unless this is the tracks result list
                                ((List<TableViewItem>) tableView.getTableData()).add(new TableViewItem(null, "(All)", null));
                            }

                            // Convert each object from JSON to Java and add it to the table view
                            for (int i = 0; i < objects.length(); i++) {
                                T item = jsonProvider.fromJson(objects.getJSONObject(i).getJSONObject("item").toString(), itemClass);
                                TableViewItem tableViewItem = getTableViewItem(item);
                                int index = ((List<TableViewItem>) tableView.getTableData()).add(tableViewItem);

                                // If this is the previously selected object, make sure we remember its index
                                if (previousSelectedItem != null && tableViewItem.getId().equals(previousSelectedItem.getId())) {
View Full Code Here

    public void open(Display display, Window owner) {
        super.open(display, owner);

        try {

            JSONArray array = Client.create().resource(HOSTURL + "/configurations").accept(MediaType.APPLICATION_JSON).get(JSONArray.class);
            List<TableViewItem> configurations = new ArrayList();
            for (int i = 0; i < array.length(); i++) {
                String name = array.getJSONObject(i).getString("id");
                String type = array.getJSONObject(i).getString("type");
                String value = array.getJSONObject(i).getString("value");
                TableViewItem item = new TableViewItem(name, type, value);
                configurations.add(item);
            }
            preferencesTableView.setTableData(configurations);
            preferencesTableView.getTableViewRowListeners().add(new TableViewRowListener.Adapter() {
View Full Code Here

TOP

Related Classes of org.codehaus.jettison.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.