List of usage examples for org.json JSONObject getString
public String getString(String key) throws JSONException
From source file:com.daskiworks.ghwatch.backend.NotificationStreamParser.java
public static NotificationStream parseNotificationStream(JSONArray json) throws InvalidObjectException { NotificationStream ret = new NotificationStream(); try {/* w w w. j a v a 2 s. c om*/ for (int i = 0; i < json.length(); i++) { JSONObject notification = json.getJSONObject(i); JSONObject subject = notification.getJSONObject("subject"); JSONObject repository = notification.getJSONObject("repository"); String updatedAtStr = Utils.trimToNull(notification.getString("updated_at")); Date updatedAt = null; try { if (updatedAtStr != null) { if (updatedAtStr.endsWith("Z")) updatedAtStr = updatedAtStr.replace("Z", "GMT"); updatedAt = df.parse(updatedAtStr); } } catch (ParseException e) { Log.w(TAG, "Invalid date format for value: " + updatedAtStr); } ret.addNotification(new Notification(notification.getLong("id"), notification.getString("url"), subject.getString("title"), subject.getString("type"), subject.getString("url"), subject.getString("latest_comment_url"), repository.getString("full_name"), repository.getJSONObject("owner").getString("avatar_url"), updatedAt, notification.getString("reason"))); } } catch (Exception e) { throw new InvalidObjectException("JSON message is invalid: " + e.getMessage()); } return ret; }
From source file:net.mandaria.radioreddit.apis.RadioRedditAPI.java
public static RadioStreams GetStreams(Context context, RadioRedditApplication application) { RadioStreams radiostreams = new RadioStreams(); radiostreams.ErrorMessage = ""; radiostreams.RadioStreams = new ArrayList<RadioStream>(); try {/*from w w w. jav a 2s. c om*/ String url = context.getString(R.string.radio_reddit_streams); String outputStreams = ""; boolean errorGettingStreams = false; try { outputStreams = HTTPUtil.get(context, url); } catch (Exception ex) { errorGettingStreams = true; radiostreams.ErrorMessage = context.getString(R.string.error_RadioRedditServerIsDownNotification); application.radioRedditIsDownErrorMessage = radiostreams.ErrorMessage; application.isRadioRedditDown = true; } if (!errorGettingStreams && outputStreams.length() > 0) { JSONTokener tokener = new JSONTokener(outputStreams); JSONObject json = new JSONObject(tokener); JSONObject streams = json.getJSONObject("streams"); JSONArray streams_names = streams.names(); ArrayList<RadioStream> list_radiostreams = new ArrayList<RadioStream>(); // loop through each stream for (int i = 0; i < streams.length(); i++) { String name = streams_names.getString(i); JSONObject stream = streams.getJSONObject(name); RadioStream radiostream = new RadioStream(); radiostream.Name = name; // if(stream.has("type")) radiostream.Type = stream.getString("type"); radiostream.Description = stream.getString("description"); radiostream.Status = stream.getString("status"); // call status.json to get Relay // form url radioreddit.com + status + json String status_url = context.getString(R.string.radio_reddit_base_url) + radiostream.Status + context.getString(R.string.radio_reddit_status); String outputStatus = ""; boolean errorGettingStatus = false; try { outputStatus = HTTPUtil.get(context, status_url); } catch (Exception ex) { errorGettingStatus = true; radiostreams.ErrorMessage = context .getString(R.string.error_RadioRedditServerIsDownNotification); } //Log.e("RadioReddit", "Length of output: "+ outputStatus.length() + "; Content of output: " + outputStatus); // TODO: does outputStatus.length() > 0 need to be checked here and return a ErrorMessage back and set ErrorGettingStatus = true? if (!errorGettingStatus && outputStatus.length() > 0) { JSONTokener status_tokener = new JSONTokener(outputStatus); JSONObject status_json = new JSONObject(status_tokener); radiostream.Online = Boolean.parseBoolean(status_json.getString("online").toLowerCase()); if (radiostream.Online == true) // if offline, no other nodes are available { radiostream.Relay = status_json.getString("relay"); list_radiostreams.add(radiostream); } } } // JSON parsing reverses the list for some reason, fixing it... if (list_radiostreams.size() > 0) { // Sorting will happen later on select station activity //Collections.reverse(list_radiostreams); radiostreams.RadioStreams = list_radiostreams; application.isRadioRedditDown = false; } else { radiostreams.ErrorMessage = context.getString(R.string.error_NoStreams); application.radioRedditIsDownErrorMessage = radiostreams.ErrorMessage; application.isRadioRedditDown = true; } } } catch (Exception ex) { // We fail to get the streams... CustomExceptionHandler ceh = new CustomExceptionHandler(context); ceh.sendEmail(ex); radiostreams.ErrorMessage = ex.toString(); ex.printStackTrace(); } return radiostreams; }
From source file:net.mandaria.radioreddit.apis.RadioRedditAPI.java
public static RadioSong GetCurrentSongInformation(Context context, RadioRedditApplication application) { RadioSong radiosong = new RadioSong(); radiosong.ErrorMessage = ""; try {// ww w . j a va2 s . c om String status_url = context.getString(R.string.radio_reddit_base_url) + application.CurrentStream.Status + context.getString(R.string.radio_reddit_status); String outputStatus = ""; boolean errorGettingStatus = false; try { outputStatus = HTTPUtil.get(context, status_url); } catch (Exception ex) { ex.printStackTrace(); errorGettingStatus = true; // For now, not used. It is acceptable to error out and not alert the user // radiosong.ErrorMessage = context.getString(R.string.error_RadioRedditServerIsDownNotification); } if (!errorGettingStatus && outputStatus.length() > 0) { JSONTokener status_tokener = new JSONTokener(outputStatus); JSONObject status_json = new JSONObject(status_tokener); radiosong.Playlist = status_json.getString("playlist"); JSONObject songs = status_json.getJSONObject("songs"); JSONArray songs_array = songs.getJSONArray("song"); // get the first song in the array JSONObject song = songs_array.getJSONObject(0); radiosong.ID = song.getInt("id"); radiosong.Title = song.getString("title"); radiosong.Artist = song.getString("artist"); radiosong.Redditor = song.getString("redditor"); radiosong.Genre = song.getString("genre"); radiosong.CumulativeScore = song.getString("score"); if (radiosong.CumulativeScore.equals("{}")) radiosong.CumulativeScore = null; radiosong.Reddit_title = song.getString("reddit_title"); radiosong.Reddit_url = song.getString("reddit_url"); if (song.has("preview_url")) radiosong.Preview_url = song.getString("preview_url"); if (song.has("download_url")) radiosong.Download_url = song.getString("download_url"); if (song.has("bandcamp_link")) radiosong.Bandcamp_link = song.getString("bandcamp_link"); if (song.has("bandcamp_art")) radiosong.Bandcamp_art = song.getString("bandcamp_art"); if (song.has("itunes_link")) radiosong.Itunes_link = song.getString("itunes_link"); if (song.has("itunes_art")) radiosong.Itunes_art = song.getString("itunes_art"); if (song.has("itunes_price")) radiosong.Itunes_price = song.getString("itunes_price"); // get vote score String reddit_info_url = context.getString(R.string.reddit_link_by) + URLEncoder.encode(radiosong.Reddit_url); String outputRedditInfo = ""; boolean errorGettingRedditInfo = false; try { outputRedditInfo = HTTPUtil.get(context, reddit_info_url); } catch (Exception ex) { ex.printStackTrace(); errorGettingRedditInfo = true; // For now, not used. It is acceptable to error out and not alert the user // radiosong.ErrorMessage = "Unable to connect to reddit";//context.getString(R.string.error_RadioRedditServerIsDownNotification); } if (!errorGettingRedditInfo && outputRedditInfo.length() > 0) { // Log.e("radio_reddit_test", "Length: " + outputRedditInfo.length()); // Log.e("radio_reddit_test", "Value: " + outputRedditInfo); // TODO: sometimes the value contains "error: 404", need to check for that. (We can probably safely ignore this for now) JSONTokener reddit_info_tokener = new JSONTokener(outputRedditInfo); JSONObject reddit_info_json = new JSONObject(reddit_info_tokener); JSONObject data = reddit_info_json.getJSONObject("data"); // default value of score String score = context.getString(R.string.vote_to_submit_song); String likes = "null"; String name = ""; JSONArray children_array = data.getJSONArray("children"); // Song hasn't been submitted yet if (children_array.length() > 0) { JSONObject children = children_array.getJSONObject(0); JSONObject children_data = children.getJSONObject("data"); score = children_data.getString("score"); likes = children_data.getString("likes"); name = children_data.getString("name"); } radiosong.Score = score; radiosong.Likes = likes; radiosong.Name = name; } else { radiosong.Score = "?"; radiosong.Likes = "null"; radiosong.Name = ""; } return radiosong; } return null; } catch (Exception ex) { // We fail to get the current song information... CustomExceptionHandler ceh = new CustomExceptionHandler(context); ceh.sendEmail(ex); ex.printStackTrace(); radiosong.ErrorMessage = ex.toString(); return radiosong; } }
From source file:net.mandaria.radioreddit.apis.RadioRedditAPI.java
public static RadioEpisode GetCurrentEpisodeInformation(Context context, RadioRedditApplication application) { RadioEpisode radioepisode = new RadioEpisode(); radioepisode.ErrorMessage = ""; try {// w w w .j a va 2 s . c om String status_url = context.getString(R.string.radio_reddit_base_url) + application.CurrentStream.Status + context.getString(R.string.radio_reddit_status); String outputStatus = ""; boolean errorGettingStatus = false; try { outputStatus = HTTPUtil.get(context, status_url); } catch (Exception ex) { ex.printStackTrace(); errorGettingStatus = true; // For now, not used. It is acceptable to error out and not alert the user // radiosong.ErrorMessage = context.getString(R.string.error_RadioRedditServerIsDownNotification); } if (!errorGettingStatus && outputStatus.length() > 0) { JSONTokener status_tokener = new JSONTokener(outputStatus); JSONObject status_json = new JSONObject(status_tokener); radioepisode.Playlist = status_json.getString("playlist"); JSONObject episodes = status_json.getJSONObject("episodes"); JSONArray episodes_array = episodes.getJSONArray("episode"); // get the first episode in the array JSONObject song = episodes_array.getJSONObject(0); radioepisode.ID = song.getInt("id"); radioepisode.EpisodeTitle = song.getString("episode_title"); radioepisode.EpisodeDescription = song.getString("episode_description"); radioepisode.EpisodeKeywords = song.getString("episode_keywords"); radioepisode.ShowTitle = song.getString("show_title"); radioepisode.ShowHosts = song.getString("show_hosts").replaceAll(",", ", "); radioepisode.ShowRedditors = song.getString("show_redditors").replaceAll(",", ", "); radioepisode.ShowGenre = song.getString("show_genre"); radioepisode.ShowFeed = song.getString("show_feed"); radioepisode.Reddit_title = song.getString("reddit_title"); radioepisode.Reddit_url = song.getString("reddit_url"); if (song.has("preview_url")) radioepisode.Preview_url = song.getString("preview_url"); if (song.has("download_url")) radioepisode.Download_url = song.getString("download_url"); // get vote score String reddit_info_url = context.getString(R.string.reddit_link_by) + URLEncoder.encode(radioepisode.Reddit_url); String outputRedditInfo = ""; boolean errorGettingRedditInfo = false; try { outputRedditInfo = HTTPUtil.get(context, reddit_info_url); } catch (Exception ex) { ex.printStackTrace(); errorGettingRedditInfo = true; // For now, not used. It is acceptable to error out and not alert the user // radiosong.ErrorMessage = "Unable to connect to reddit";//context.getString(R.string.error_RadioRedditServerIsDownNotification); } if (!errorGettingRedditInfo && outputRedditInfo.length() > 0) { // Log.e("radio_reddit_test", "Length: " + outputRedditInfo.length()); // Log.e("radio_reddit_test", "Value: " + outputRedditInfo); // TODO: sometimes the value contains "error: 404", need to check for that (We can probably safely ignore this for now) JSONTokener reddit_info_tokener = new JSONTokener(outputRedditInfo); JSONObject reddit_info_json = new JSONObject(reddit_info_tokener); JSONObject data = reddit_info_json.getJSONObject("data"); // default value of score String score = context.getString(R.string.vote_to_submit_song); String likes = "null"; String name = ""; JSONArray children_array = data.getJSONArray("children"); // Episode hasn't been submitted yet if (children_array.length() > 0) { JSONObject children = children_array.getJSONObject(0); JSONObject children_data = children.getJSONObject("data"); score = children_data.getString("score"); likes = children_data.getString("likes"); name = children_data.getString("name"); } radioepisode.Score = score; radioepisode.Likes = likes; radioepisode.Name = name; } else { radioepisode.Score = "?"; radioepisode.Likes = "null"; radioepisode.Name = ""; } return radioepisode; } return null; } catch (Exception ex) { // We fail to get the current song information... CustomExceptionHandler ceh = new CustomExceptionHandler(context); ceh.sendEmail(ex); ex.printStackTrace(); radioepisode.ErrorMessage = ex.toString(); return radioepisode; } }
From source file:net.mandaria.radioreddit.apis.RadioRedditAPI.java
public static List<RadioSong> GetTopChartsByType(Context context, RadioRedditApplication application, String type) {//from w w w. ja v a 2 s .c o m List<RadioSong> radiosongs = new ArrayList<RadioSong>(); try { String chart_url = ""; if (type.equals("all")) chart_url = context.getString(R.string.radio_reddit_charts_all); else if (type.equals("month")) chart_url = context.getString(R.string.radio_reddit_charts_month); else if (type.equals("week")) chart_url = context.getString(R.string.radio_reddit_charts_week); else if (type.equals("day")) chart_url = context.getString(R.string.radio_reddit_charts_day); // TODO: might could merge this code with GetCurrentSongInformation String outputStatus = ""; boolean errorGettingStatus = false; try { outputStatus = HTTPUtil.get(context, chart_url); } catch (Exception ex) { ex.printStackTrace(); errorGettingStatus = true; // For now, not used. It is acceptable to error out and not alert the user // radiosong.ErrorMessage = context.getString(R.string.error_RadioRedditServerIsDownNotification); } if (!errorGettingStatus && outputStatus.length() > 0) { JSONTokener status_tokener = new JSONTokener(outputStatus); JSONObject status_json = new JSONObject(status_tokener); JSONObject songs = status_json.getJSONObject("songs"); JSONArray songs_array = songs.getJSONArray("song"); // get the first song in the array for (int i = 0; i < songs_array.length(); i++) { RadioSong radiosong = new RadioSong(); radiosong.ErrorMessage = ""; JSONObject song = songs_array.getJSONObject(i); //radiosong.ID = song.getInt("id"); radiosong.Title = song.getString("title"); radiosong.Artist = song.getString("artist"); radiosong.Redditor = song.getString("redditor"); radiosong.Genre = song.getString("genre"); //radiosong.CumulativeScore = song.getString("score"); //if(radiosong.CumulativeScore.equals("{}")) // radiosong.CumulativeScore = null; radiosong.Reddit_title = song.getString("reddit_title"); radiosong.Reddit_url = song.getString("reddit_url"); if (song.has("preview_url")) radiosong.Preview_url = song.getString("preview_url"); if (song.has("download_url")) radiosong.Download_url = song.getString("download_url"); if (song.has("bandcamp_link")) radiosong.Bandcamp_link = song.getString("bandcamp_link"); if (song.has("bandcamp_art")) radiosong.Bandcamp_art = song.getString("bandcamp_art"); if (song.has("itunes_link")) radiosong.Itunes_link = song.getString("itunes_link"); if (song.has("itunes_art")) radiosong.Itunes_art = song.getString("itunes_art"); if (song.has("itunes_price")) radiosong.Itunes_price = song.getString("itunes_price"); radiosongs.add(radiosong); } } } catch (Exception ex) { // We fail to get the current song information... CustomExceptionHandler ceh = new CustomExceptionHandler(context); ceh.sendEmail(ex); ex.printStackTrace(); // TODO: return error message?? Might need to wrap List<RadioSong> in an object that has an ErrorMessage data member //radiosong.ErrorMessage = ex.toString(); //return radiosong; } return radiosongs; }
From source file:net.mandaria.radioreddit.apis.RadioRedditAPI.java
public static RadioSong GetSongVoteScore(Context context, RadioRedditApplication application, RadioSong radiosong) {/*from w w w . ja v a2s . c om*/ try { // get vote score String reddit_info_url = context.getString(R.string.reddit_link_by) + URLEncoder.encode(radiosong.Reddit_url); String outputRedditInfo = ""; boolean errorGettingRedditInfo = false; try { outputRedditInfo = HTTPUtil.get(context, reddit_info_url); } catch (Exception ex) { ex.printStackTrace(); errorGettingRedditInfo = true; // For now, not used. It is acceptable to error out and not alert the user // radiosong.ErrorMessage = "Unable to connect to reddit";//context.getString(R.string.error_RadioRedditServerIsDownNotification); } if (!errorGettingRedditInfo && outputRedditInfo.length() > 0) { // Log.e("radio_reddit_test", "Length: " + outputRedditInfo.length()); // Log.e("radio_reddit_test", "Value: " + outputRedditInfo); // TODO: sometimes the value contains "error: 404", need to check for that. (We can probably safely ignore this for now) JSONTokener reddit_info_tokener = new JSONTokener(outputRedditInfo); JSONObject reddit_info_json = new JSONObject(reddit_info_tokener); JSONObject data = reddit_info_json.getJSONObject("data"); // default value of score String score = context.getString(R.string.vote_to_submit_song); String likes = "null"; String name = ""; JSONArray children_array = data.getJSONArray("children"); // Song hasn't been submitted yet if (children_array.length() > 0) { JSONObject children = children_array.getJSONObject(0); JSONObject children_data = children.getJSONObject("data"); score = children_data.getString("score"); likes = children_data.getString("likes"); name = children_data.getString("name"); } radiosong.Score = score; radiosong.Likes = likes; radiosong.Name = name; } else { radiosong.Score = "?"; radiosong.Likes = "null"; radiosong.Name = ""; } } catch (Exception ex) { // We fail to get the vote information... CustomExceptionHandler ceh = new CustomExceptionHandler(context); ceh.sendEmail(ex); ex.printStackTrace(); // return error message?? radiosong.ErrorMessage = context.getString(R.string.error_GettingVoteInformation); //return radiosong; } return radiosong; }
From source file:net.mandaria.radioreddit.apis.RadioRedditAPI.java
public static RadioEpisode GetEpisodeVoteScore(Context context, RadioRedditApplication application, RadioEpisode radioepisode) {/*from ww w .j a v a 2 s .co m*/ try { // get vote score String reddit_info_url = context.getString(R.string.reddit_link_by) + URLEncoder.encode(radioepisode.Reddit_url); String outputRedditInfo = ""; boolean errorGettingRedditInfo = false; try { outputRedditInfo = HTTPUtil.get(context, reddit_info_url); } catch (Exception ex) { ex.printStackTrace(); errorGettingRedditInfo = true; // For now, not used. It is acceptable to error out and not alert the user // radiosong.ErrorMessage = "Unable to connect to reddit";//context.getString(R.string.error_RadioRedditServerIsDownNotification); } if (!errorGettingRedditInfo && outputRedditInfo.length() > 0) { // Log.e("radio_reddit_test", "Length: " + outputRedditInfo.length()); // Log.e("radio_reddit_test", "Value: " + outputRedditInfo); // TODO: sometimes the value contains "error: 404", need to check for that. (We can probably safely ignore this for now) JSONTokener reddit_info_tokener = new JSONTokener(outputRedditInfo); JSONObject reddit_info_json = new JSONObject(reddit_info_tokener); JSONObject data = reddit_info_json.getJSONObject("data"); // default value of score String score = context.getString(R.string.vote_to_submit_song); String likes = "null"; String name = ""; JSONArray children_array = data.getJSONArray("children"); // Song hasn't been submitted yet if (children_array.length() > 0) { JSONObject children = children_array.getJSONObject(0); JSONObject children_data = children.getJSONObject("data"); score = children_data.getString("score"); likes = children_data.getString("likes"); name = children_data.getString("name"); } radioepisode.Score = score; radioepisode.Likes = likes; radioepisode.Name = name; } else { radioepisode.Score = "?"; radioepisode.Likes = "null"; radioepisode.Name = ""; } } catch (Exception ex) { // We fail to get the vote information... CustomExceptionHandler ceh = new CustomExceptionHandler(context); ceh.sendEmail(ex); ex.printStackTrace(); // return error message?? radioepisode.ErrorMessage = context.getString(R.string.error_GettingVoteInformation); //return radiosong; } return radioepisode; }
From source file:to.networld.fbtosemweb.FacebookToSIOC.java
/** * TODO: If a link was posted, add also the link to the SIOC block. * @throws IOException/*from w w w . j av a2s .c o m*/ * @throws JSONException */ public void createSIOC() throws IOException, JSONException { Element rootNode = this.rdfDocument.addElement(new QName("RDF", RDF_NS)); rootNode.add(SIOC_NS); rootNode.add(DCT_NS); JSONArray wallEntries = this.object.getJSONArray("data"); for (int count = 0; count < wallEntries.length(); count++) { JSONObject wallEntry = (JSONObject) wallEntries.get(count); Element siocPost = rootNode.addElement(new QName("Post", SIOC_NS)).addAttribute( new QName("about", RDF_NS), "http://graph.facebook.com/" + wallEntry.getString("id")); siocPost.addElement(new QName("content", SIOC_NS)).setText(wallEntry.getString("message")); String creatorID = wallEntry.getJSONObject("from").getString("id"); siocPost.addElement(new QName("hasCreator", SIOC_NS)).addAttribute(new QName("resource", RDF_NS), "http://graph.facebook.com/" + creatorID); try { siocPost.addElement(new QName("created", SIOC_NS)).setText(wallEntry.getString("created_time")); } catch (JSONException e) { } try { siocPost.addElement(new QName("modified", SIOC_NS)).setText(wallEntry.getString("updated_time")); } catch (JSONException e) { } try { JSONArray comments = wallEntry.getJSONObject("comments").getJSONArray("data"); for (int count1 = 0; count1 < comments.length(); count1++) { JSONObject comment = comments.getJSONObject(count1); Element replyNode = siocPost.addElement(new QName("has_reply", SIOC_NS)); Element replyPost = replyNode.addElement(new QName("Post", SIOC_NS)); replyPost.addAttribute(new QName("about", RDF_NS), "http://graph.facebook.com/" + comment.getString("id")); replyPost.addElement(new QName("content", SIOC_NS)).setText(comment.getString("message")); String replierID = comment.getJSONObject("from").getString("id"); replyPost.addElement(new QName("hasCreator", SIOC_NS)) .addAttribute(new QName("resource", RDF_NS), "http://graph.facebook.com/" + replierID); try { replyPost.addElement(new QName("created", SIOC_NS)) .setText(comment.getString("created_time")); } catch (JSONException e) { } try { replyPost.addElement(new QName("modified", SIOC_NS)) .setText(comment.getString("updated_time")); } catch (JSONException e) { } } } catch (JSONException e) { // TODO: Log here something, at least during development. } } }
From source file:com.fortydegree.ra.data.JsonUnmarshaller.java
public static Marker processGeoserviceJSONObject(JSONObject jo) throws JSONException { String type = jo.getString("type"); String metadata = jo.getString("metadata"); JSONObject jsonMetadata = new JSONObject(metadata); String title = jsonMetadata.optString("title"); Marker m = new Marker(jo.getDouble("latitude"), jo.getDouble("longitude"), jo.getDouble("altitude")); m.title = title;// w w w . j a v a 2 s . c o m m.distance = jo.getDouble("distance"); @SuppressWarnings("rawtypes") Iterator metadataIter = jsonMetadata.keys(); while (metadataIter.hasNext()) { String key = metadataIter.next().toString(); m.setData(key, jsonMetadata.getString(key)); } m.setData("title", title); m.setData("type", type); return m; }
From source file:de.kp.ames.web.function.domain.model.ImageObject.java
/** * Create RegistryObject representation of ImageObject * //from w w w.j a v a 2 s . c o m * @param data * @return * @throws Exception */ public RegistryObjectImpl create(JSONObject jForm) throws Exception { /* * Create extrinsic object that serves as a wrapper * for the respective image */ // ExtrinsicObjectImpl eo = jaxrLCM.createExtrinsicObject(); if (eo == null) throw new JAXRException("[ImageObject] Creation of ExtrinsicObject failed."); /* * Identifier */ String eid = JaxrIdentity.getInstance().getPrefixUID(FncConstants.IMAGE_PRE); eo.setLid(eid); eo.getKey().setId(eid); /* * Home url */ String home = jaxrHandle.getEndpoint().replace("/saml", ""); eo.setHome(home); /* * The document is actually transient and managed by the image cache */ ImageCacheManager cacheManager = ImageCacheManager.getInstance(); String key = jForm.getString(JsonConstants.J_KEY); DmsImage image = (DmsImage) cacheManager.getFromCache(key); if (image == null) throw new Exception("[ImageObject] Image with id <" + key + "> not found."); /* * Name & description */ String name = jForm.has(RIM_NAME) ? jForm.getString(RIM_NAME) : null; String desc = jForm.has(RIM_DESC) ? jForm.getString(RIM_DESC) : null; name = (name == null) ? image.getName() : name; int pos = name.lastIndexOf("."); if (pos != -1) name = name.substring(0, pos); eo.setName(jaxrLCM.createInternationalString(name)); desc = (desc == null) ? FncMessages.NO_DESCRIPTION_DESC : desc; eo.setDescription(jaxrLCM.createInternationalString(desc)); /* * Classifications */ JSONArray jClases = jForm.has(RIM_CLAS) ? new JSONArray(jForm.getString(RIM_CLAS)) : null; if (jClases != null) { List<ClassificationImpl> classifications = createClassifications(jClases); /* * Set composed object */ eo.addClassifications(classifications); } /* * Mimetype & repository item */ String mimetype = image.getMimetype(); DataHandler handler = new DataHandler(FileUtil.createByteArrayDataSource(image.getBytes(), mimetype)); eo.setMimeType(mimetype); eo.setRepositoryItem(handler); /* * Indicate as created */ this.created = true; return eo; }