/** * Get the text in the CDATA block. * @return The string up to the <code>]]></code>. * @throws JSONException If the <code>]]></code> is not found. */ public String nextCDATA() throws JSONException { char c; int i; StringBuffer sb = new StringBuffer(); for (;;) { c = next(); if (c == 0) { throw syntaxError("Unclosed CDATA."); } sb.append(c); i = sb.length() - 3; if (i >= 0 && sb.charAt(i) == ']' && sb.charAt(i + 1) == ']' && sb.charAt(i + 2) == '>') { sb.setLength(i); return sb.toString(); } } }
/** * Return the next entity. These entities are translated to Characters: * <code>& ' > < "</code>. * @param a An ampersand character. * @return A Character or an entity String if the entity is not recognized. * @throws JSONException If missing ';' in XML entity. */ public Object nextEntity(char a) throws JSONException { StringBuffer sb = new StringBuffer(); for (;;) { char c = next(); if (isLetterOrDigit(c) || c == '#') { sb.append(Character.toLowerCase(c)); } else if (c == ';') { break; } else { throw syntaxError("Missing ';' in XML entity: &" + sb); } } String s = sb.toString(); Object e = entity.get(s); return e != null ? e : a + s + ";"; }
private static String toJSON(String txt, boolean isGWTok, boolean isGWTerr) throws JSONException{ String res = null; if(txt.startsWith("[")){ JSONArray arr = new JSONArray(txt); res = arr.toString(4); } else { JSONObject obj = new JSONObject(txt); res = obj.toString(4); } if (isGWTok) { return "//OK" + res; } else if (isGWTerr) { return "//EX" + res; } else { return res; } }
/** * Parse a JSON data string into a Vector of CommentThing objects. * * @param commentsJson JSON reply to parse into Comments * @param startLevel Level of hierarchy to start at (most of the time 0) */ protected void parseComments(final String commentsJson, final int startLevel) { Vector comments = new Vector(); JSONObject listingJsonObject; try { // Recurse through any replies and their replies and ... listingJsonObject = new JSONArray(commentsJson).getJSONObject(1); recursivelyAddReplies(comments, listingJsonObject, startLevel); } catch (JSONException e) { System.out.println("Error parsing JSON response: " + e.getMessage()); } // Signal the listener when done finished = true; if (!aborted) { listener.commentsReceived(comments); } }
private void ShowScore(String Name) { SnapChatApiFx api = new SnapChatApiFx(); try { JSONObject Score = api.GetScore(Name,_Current.getString("username"),_Current.getString("auth_token")); JSONObject Friend = Score.getJSONObject(Name); JSONArray FriendsArray = Friend.getJSONArray("best_friends"); String BestString = new String(); int i = 0; for ( i = 0; i < FriendsArray.length();i++) { BestString = BestString + " " + FriendsArray.getString(i); } int score = Friend.getInt("score"); Dialog.inform(Name + "'s bests friends :" + BestString + ". Score : " + score); } catch (JSONException e) { Dialog.inform("Unable to get Score."); e.printStackTrace(); } }
protected void handleRequest(final HttpRequest request, final HttpResponse response) throws HttpException, IOException, JSONException, CalicoAPIErrorException { Properties params = this.getURLParams(request); try { GUITemplate gt = new GUITemplate("config/index.vm"); gt.setSection("config"); gt.put("get", params); //gt.put("config_client_threadopts_sleeptime", CalicoConfig.getConfigField("client.threadopts.sleeptime").get(null)); setupConfigClass(gt); gt.getOutput(response); } catch(Exception e) { e.printStackTrace(); } }
protected void handleRequest(final HttpRequest request, final HttpResponse response) throws HttpException, IOException, JSONException, CalicoAPIErrorException { try { GUITemplate gt = new GUITemplate("index.vm"); gt.setSection("home"); //gt.put("test.param.yar", "this is a big test"); gt.getOutput(response); } catch(Exception e) { e.printStackTrace(); } }
protected void handleRequest(final HttpRequest request, final HttpResponse response, byte[] data) throws HttpException, IOException, JSONException, CalicoAPIErrorException { try { CalicoUploadParser parser = new CalicoUploadParser(data, request); parser.parse(); Filedata ulfile = parser.getFile("Filedata"); if( !ulfile.getName().endsWith(".csb")) { throw new CalicoInvalidBackupException("You must upload a .csb file"); } FastByteArrayInputStream bais = new FastByteArrayInputStream(ulfile.getData() ); //ByteArrayInputStream bais = new ByteArrayInputStream(ulfile.getData() ); CalicoBackupHandler.restoreBackupStream(bais); throw new RedirectException("/gui/backup/?upload=1"); } catch(CalicoInvalidBackupException e) { throw new RedirectException("/gui/backup/?upload=2"); } }
protected void handleRequest(final HttpRequest request, final HttpResponse response) throws HttpException, IOException, JSONException, CalicoAPIErrorException { Properties params = this.getURLParams(request); try { GUITemplate gt = new GUITemplate("backup/index.vm"); gt.setSection("home"); gt.put("get", params); gt.getOutput(response); } catch(Exception e) { e.printStackTrace(); } }
protected void handleRequest(final HttpRequest request, final HttpResponse response) throws HttpException, IOException, JSONException, CalicoAPIErrorException { Properties params = this.getURLParams(request); try { GUITemplate gt = new GUITemplate("imagemgr/upload.vm"); gt.setSection("home"); gt.put("get", params); //gt.put("test.param.yar", "this is a big test"); gt.getOutput(response); } catch(Exception e) { e.printStackTrace(); } }
protected void handleRequest(final HttpRequest request, final HttpResponse response) throws HttpException, IOException, JSONException, CalicoAPIErrorException { try { GUITemplate gt = new GUITemplate("command_help.vm"); gt.setSection("console"); //gt.put("test.param.yar", "this is a big test"); gt.getOutput(response); } catch(Exception e) { e.printStackTrace(); } }
protected void handleRequest(final HttpRequest request, final HttpResponse response) throws HttpException, IOException, JSONException, CalicoAPIErrorException { try { String uri = request.getRequestLine().getUri().replaceFirst("/gui/images", ""); FileObject image = COptions.fs.resolveFile("jar:libs/admin_images.jar!"+uri); /*StringEntity body = new StringEntity( uri ); body.setContentType("text/html"); response.setEntity(body);*/ ByteArrayEntity bae = new ByteArrayEntity(FileUtil.getContent(image)); bae.setContentType("application/calico-backup-state"); response.setEntity(bae); image.close(); } catch(Exception e) { e.printStackTrace(); } }
/** * This function adds the layer details but also verifies that the min and max color * values don't be -1. If they are then it replaces them by the default color range of * the layer. * * @param {String} layerDetails */ public void setLayerDetails(String layerDetailsStr) { // In this case we have to update the min and max color with the // default color range of the layer. // We add the 'server' and the 'name' into the layer Details try { JSONObject layDet; if (layerDetailsStr.equals("")) { this.layerDetails = new JSONObject(); } else { this.layerDetails = new JSONObject(layerDetailsStr); if ((this.minColor == -1) && (this.maxColor == -1)) { this.minColor = Float.parseFloat((String) (((JSONArray) layerDetails.get("scaleRange")).get(0))); this.maxColor = Float.parseFloat((String) (((JSONArray) layerDetails.get("scaleRange")).get(1))); } } layerDetails.accumulate("server", server); layerDetails.accumulate("name", name); layerDetails.accumulate("srs", this.getProjection()); } catch (JSONException ex) { System.out.println("ERROR: The layerdetails JSON object can't be created on Layer class"); } }
/** * This method obtains the 'animation options' (the number of frames * available for the user selection). * @param {httpServlet} request * @param {HttpServletResponse}response * @param {PrintWriter} out * @throws ServletException * @throws IOException * @throws JSONException */ protected void getAnimationOptions(HttpServletRequest request, HttpServletResponse response, PrintWriter out) throws ServletException, IOException, JSONException, XMLFilesException { String layerName = request.getParameter("layerName"); String firstDay = request.getParameter("startDate"); String lastDay = request.getParameter("endDate"); LayerMenuManagerSingleton layers = LayerMenuManagerSingleton.getInstance(); Layer layer = layers.getLayerByName(layerName);//Search current layer //Retrieve all the times available on the first and last day of the //selected range JSONObject jsonStartDates = new JSONObject(NetCDFRequestManager.getLayerTimeStepsForAnimation(layer, firstDay, lastDay)); out.print(jsonStartDates.toString()); }
/** * Get the next XML outer token, trimming whitespace. There are two kinds * of tokens: the '<' character which begins a markup tag, and the content * text between markup tags. * * @return A string, or a '<' Character, or null if there is no more * source text. * @throws JSONException */ public Object nextContent() throws JSONException { char c; StringBuffer sb; do { c = next(); } while (isWhitespace(c)); if (c == 0) { return null; } if (c == '<') { return XML.LT; } sb = new StringBuffer(); for (;;) { if (c == '<' || c == 0) { back(); return sb.toString().trim(); } if (c == '&') { sb.append(nextEntity(c)); } else { sb.append(c); } c = next(); } }
private static JSONObject parseToJson(Note note) { JSONObject jsonNote = new JSONObject(); try { jsonNote.put(Note.TITLE, note.getTitle()); jsonNote.put(Note.CONTENT, note.getContent()); jsonNote.put(Note.TIMESTAMP, note.getTimestamp()); jsonNote.put(Note.PRIORITY, note.getPriority()); jsonNote.put(Note.CATEGORY, note.getCategory()); } catch (JSONException e1) { e1.printStackTrace(); } return jsonNote; }
/** * Recursively parse the given listingJsonObject for Comments, adding them * into the Vector specified. Will call itself until the comment tree is * whole (until there are no more child JSON objects to parse). * * @param comments Vector of comments * @param listingJsonObject JSON object (comment listing) to parse * @param level Depth level * @throws JSONException In case of a parsing error */ protected void recursivelyAddReplies(Vector comments, JSONObject listingJsonObject, int level) throws JSONException { JSONArray childrenJsonArray = listingJsonObject .getJSONObject("data") .getJSONArray("children"); // Reuse the same objects to avoid unnecessary overhead JSONObject thingDataObj; CommentThing comment; for (int i = 0, len = childrenJsonArray.length(); i < len && !aborted; i++) { thingDataObj = childrenJsonArray.getJSONObject(i).getJSONObject("data"); try { // Create a comment item and append it to the list comment = CommentThing.fromJson(thingDataObj); comment.setLevel(level); comments.addElement(comment); } catch (JSONException e) { System.out.println("Could not parse comment JSON: " + e.getMessage()); } // Process any further replies JSONObject repliesJsonObject = thingDataObj.optJSONObject("replies"); if (repliesJsonObject != null) { recursivelyAddReplies(comments, repliesJsonObject, level + 1); } } }
/** * Create a LinkThing from a JSON data String. * * @param obj JSONObject containing data for the Link * @return A LinkThing object * @throws JSONException If the given JSONObject can't be parsed */ public static LinkThing fromJson(JSONObject obj) throws JSONException { LinkThing thing = new LinkThing(); thing.setAuthor(obj.getString("author")); try { // "1329913184.0" -> "13299131840000" String dateStr = obj.getString("created_utc").substring(0, 9) + "0000"; thing.setCreated(new Date(Long.parseLong(dateStr))); } catch (Exception e) { System.out.println("Couldn't set date: " + e.getMessage()); } thing.setDomain(obj.getString("domain")); thing.setId(obj.getString("id")); thing.setName(obj.getString("name")); thing.setNumComments(obj.getInt("num_comments")); thing.setPermalink(obj.getString("permalink")); thing.setSubreddit(obj.getString("subreddit")); thing.setScore(obj.getInt("score")); thing.setThumbnail(obj.getString("thumbnail")); thing.setTitle(HtmlEntityDecoder.decode(obj.getString("title"))); thing.setUrl(obj.getString("url")); // 'Likes' can be true, false or null; map that to 1, -1, and 0 thing.setVote( obj.isNull("likes") ? 0 : obj.getBoolean("likes") ? 1: - 1 ); return thing; }
/** * Create a CommentThing from a JSON data String. * * @param obj JSONObject containing data for the Comment * @return A CommentThing object * @throws JSONException If the given JSONObject can't be parsed */ public static CommentThing fromJson(JSONObject obj) throws JSONException { CommentThing thing = new CommentThing(); thing.setAuthor(obj.optString("author")); thing.setBody(HtmlEntityDecoder.decode(obj.optString("body"))); // Comments have a created date, 'More' items don't if (obj.has("created_utc")) { try { // "1329913184.0" -> "13299131840000" String dateStr = obj.getString("created_utc").substring(0, 9) + "0000"; thing.setCreated(new Date(Long.parseLong(dateStr))); } catch (Exception e) { System.out.println("Couldn't set date: " + e.getMessage()); } } thing.setId(obj.optString("id")); thing.setName(obj.optString("name")); thing.setScore(obj.optInt("ups"), obj.optInt("downs")); // 'Likes' can be true, false or null; map that to 1, -1, and 0 thing.setVote( obj.isNull("likes") ? 0 : obj.getBoolean("likes") ? 1: - 1 ); // Set child IDs. These are used for dynamically fetching more replies // to a comment. JSONArray childrenArray = obj.optJSONArray("children"); if (childrenArray != null) { int len = childrenArray.length(); String[] childIds = new String[len]; for (int i = 0; i < len; i++) { childIds[i] = childrenArray.getString(i); } thing.setChildIds(childIds); } return thing; }
protected void handleRequest(final HttpRequest request, final HttpResponse response) throws HttpException, IOException, JSONException, CalicoAPIErrorException { try { GUITemplate gt = new GUITemplate("clients/index.vm"); gt.setSection("clients"); ArrayList<ClientInfo> clients = new ArrayList<ClientInfo>(); int[] clientids = ClientManager.get_clientids(); for(int i=0;i<clientids.length;i++) { ClientInfo temp = new ClientInfo(); Properties props = ClientManager.getClientProperties(clientids[i]); temp.clientid = ""+clientids[i]; temp.host = props.getProperty("tcp.host"); temp.port = props.getProperty("tcp.port"); temp.username = props.getProperty("username"); clients.add(temp); } gt.put("clients", clients); //gt.put("test.param.yar", "this is a big test"); gt.getOutput(response); } catch(Exception e) { e.printStackTrace(); } }
protected void handleRequest(final HttpRequest request, final HttpResponse response, byte[] data) throws HttpException, IOException, JSONException, CalicoAPIErrorException { String strData = new String(data); Properties params = parseURLParams(strData); handleRequestInternal(request, response, params); }
protected void handleRequestInternal(final HttpRequest request, final HttpResponse response, Properties params) throws HttpException, IOException, JSONException, CalicoAPIErrorException { try { GUITemplate gt = new GUITemplate("chat.vm"); gt.setSection("chat"); gt.getOutput(response); } catch(Exception e) { e.printStackTrace(); } }
protected void handleRequest(final HttpRequest request, final HttpResponse response, byte[] data) throws HttpException, IOException, JSONException, CalicoAPIErrorException { String strData = new String(data); Properties params = parseURLParams(strData); String chatService = params.getProperty("service","SERVER").toUpperCase(); String username = params.getProperty("user"); String message = params.getProperty("msg"); //System.out.println(username+" ("+chatService+") says \""+message+"\""); handleChatMessage(chatService, username, message, response); }
protected void handleRequest(final HttpRequest request, final HttpResponse response) throws HttpException, IOException, JSONException, CalicoAPIErrorException { Properties params = this.getURLParams(request); String chatService = params.getProperty("service","SERVER").toUpperCase(); String username = params.getProperty("user"); String message = params.getProperty("msg"); handleChatMessage(chatService, username, message, response); }
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * This servlet is used with the /ncAnimation request, and it * creates the final request send it to the ncWMS server to obtain * the netcdf animation. * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); try { response.setContentType("text/html;charset=UTF-8"); String req = request.getParameter("request"); switch(req.toLowerCase()){ case "dispanimation": dispAnimation(request, response, out, false); break; case "generatekmzlink": dispAnimation(request, response, out, true); break; case "getanimtimes": getAnimationOptions(request, response, out); break; } } catch (JSONException | XMLFilesException ex) { System.out.println("Exception reading NetCDF dates: " + ex.getMessage()); } finally { out.close(); } }
/** * Returns the next XML meta token. This is used for skipping over <!...> * and <?...?> structures. * @return Syntax characters (<code>< > / = ! ?</code>) are returned as * Character, and strings and names are returned as Boolean. We don't care * what the values actually are. * @throws JSONException If a string is not properly closed or if the XML * is badly structured. */ public Object nextMeta() throws JSONException { char c; char q; do { c = next(); } while (isWhitespace(c)); switch (c) { case 0: throw syntaxError("Misshaped meta tag."); case '<': return XML.LT; case '>': return XML.GT; case '/': return XML.SLASH; case '=': return XML.EQ; case '!': return XML.BANG; case '?': return XML.QUEST; case '"': case '\'': q = c; for (;;) { c = next(); if (c == 0) { throw syntaxError("Unterminated string."); } if (c == q) { return Boolean.TRUE; } } default: for (;;) { c = next(); if (isWhitespace(c)) { return Boolean.TRUE; } switch (c) { case 0: case '<': case '>': case '/': case '=': case '!': case '?': case '"': case '\'': back(); return Boolean.TRUE; } } } }
/** * Get the next XML Token. These tokens are found inside of angle * brackets. It may be one of these characters: <code>/ > = ! ?</code> or it * may be a string wrapped in single quotes or double quotes, or it may be a * name. * @return a String or a Character. * @throws JSONException If the XML is not well formed. */ public Object nextToken() throws JSONException { char c; char q; StringBuffer sb; do { c = next(); } while (isWhitespace(c)); switch (c) { case 0: throw syntaxError("Misshaped element."); case '<': throw syntaxError("Misplaced '<'."); case '>': return XML.GT; case '/': return XML.SLASH; case '=': return XML.EQ; case '!': return XML.BANG; case '?': return XML.QUEST; // Quoted string case '"': case '\'': q = c; sb = new StringBuffer(); for (;;) { c = next(); if (c == 0) { throw syntaxError("Unterminated string."); } if (c == q) { return sb.toString(); } if (c == '&') { sb.append(nextEntity(c)); } else { sb.append(c); } } default: // Name sb = new StringBuffer(); for (;;) { sb.append(c); c = next(); if (isWhitespace(c)) { return sb.toString(); } switch (c) { case 0: case '>': case '/': case '=': case '!': case '?': case '[': case ']': back(); return sb.toString(); case '<': case '"': case '\'': throw syntaxError("Bad character in a name."); } } } }
/** * Returns the next XML meta token. This is used for skipping over <!...> * and <?...?> structures. * @return Syntax characters (<code>< > / = ! ?</code>) are returned as * Character, and strings and names are returned as Boolean. We don't care * what the values actually are. * @throws JSONException If a string is not properly closed or if the XML * is badly structured. */ public Object nextMeta() throws JSONException { char c; char q; do { c = next(); } while (isWhitespace(c)); switch (c) { case 0: throw syntaxError("Misshaped meta tag."); case '<': return XML.LT; case '>': return XML.GT; case '/': return XML.SLASH; case '=': return XML.EQ; case '!': return XML.BANG; case '?': return XML.QUEST; case '"': case '\'': q = c; for (;;) { c = next(); if (c == 0) { throw syntaxError("Unterminated string."); } if (c == q) { //#if CLDC!="1.0" //# return Boolean.TRUE; //#else return JSONObject.TRUE; //#endif } } default: for (;;) { c = next(); if (isWhitespace(c)) { //#if CLDC!="1.0" //# return Boolean.TRUE; //#else return JSONObject.TRUE; //#endif } switch (c) { case 0: case '<': case '>': case '/': case '=': case '!': case '?': case '"': case '\'': back(); //#if CLDC!="1.0" //# return Boolean.TRUE; //#else return JSONObject.TRUE; //#endif } } } }
FriendSelector(JSONObject Current, UiApplication app) { int direction = Display.DIRECTION_NORTH; Ui.getUiEngineInstance().setAcceptableDirections(direction); this.setTitle(" CrapSnap - Select Receiver..."); Bitmap back = EncodedImage.getEncodedImageResource("Back.jpg") .getBitmap(); this.setBackground(BackgroundFactory.createBitmapBackground(back)); monApp = app; Send.setChangeListener(new FieldChangeListener() { public void fieldChanged(Field field, int context) { exitbol = false; if (CheckBox.getChecked() == true) { storybol = true; } quit(); } }); String[] names; try { JSONArray friends = Current.getJSONArray("friends"); names = new String[friends.length()]; for (int i = 0; i < friends.length(); i++) { JSONObject friend = friends.getJSONObject(i); names[i] = friend.getString("name"); } Comparator strComparator = new Comparator() { public int compare(Object o1, Object o2) { return o1.toString().compareTo(o2.toString()); } }; Arrays.sort(names, strComparator); for (int i = 0; i < names.length; i++) { ListManager.add(new FriendSelectorObject(names[i])); ListManager.add(new SeparatorField()); } } catch (JSONException e) { e.printStackTrace(); } this.addMenuItem(AddMenuItem); this.addMenuItem(CancelMenuItem); BtnManager.add(Send); MainManager.add(ListManager); HorizontalFieldManager StoryManager = new HorizontalFieldManager(); CheckBox.setFont(CheckBox.getFont().derive(Font.BOLD, 9, Ui.UNITS_pt)); StoryManager.add(new LabelField(" ")); StoryManager.add(CheckBox); MainManager.add(StoryManager); MainManager.add(BtnManager); this.add(MainManager); }
StoryViewers(JSONArray MyStory){ this.setTitle("Who has viewed my story ?"); Bitmap back = EncodedImage.getEncodedImageResource("Back.jpg").getBitmap(); this.setBackground(BackgroundFactory.createBitmapBackground(back)); for (int i = 0; i < MyStory.length(); i++){ JSONObject Storycore; try { Storycore = MyStory.getJSONObject(i).getJSONObject("story"); byte[] img = getImage( Storycore.getString("thumbnail_url"), Storycore.getString("thumbnail_iv"), Storycore.getString("media_key")); String Caption = Storycore.getString("caption_text_display"); if (Caption.equals("")){ Caption = "Not Named Story."; } JSONObject StoryExtra = MyStory.getJSONObject(i).getJSONObject("story_extras"); int viewcount = StoryExtra.getInt("view_count"); JSONArray StoryNotes = MyStory.getJSONObject(i).getJSONArray("story_notes"); String ViwerString = ""; for (int j = 0; j < StoryNotes.length(); j++ ){ if (ViwerString.equals("")){ ViwerString = StoryNotes.getJSONObject(j).getString("viewer"); } else { ViwerString = ViwerString + ", " + StoryNotes.getJSONObject(j).getString("viewer") ; } } Bitmap bmp = EncodedImage.createEncodedImage(img, 0, img.length).getBitmap(); list.add( new Object[] {bmp,Caption, "Viewed " + viewcount + " time(s)",ViwerString}); } catch (JSONException e) { e.printStackTrace(); } list.setCommand(new Command(new CommandHandler(){ public void execute(ReadOnlyCommandMetadata metadata, Object context) { String viewers = (String) list.get(list.getFocusRow())[3]; Dialog.inform("Viewed by : " + viewers); } })); } }
protected void handleRequest(final HttpRequest request, final HttpResponse response) throws HttpException, IOException, JSONException, CalicoAPIErrorException { handleRequestInternal(request, response, new Properties()); }
/** * This method makes the request of the animation. It builds * the url and makes the request. * @param request * @param response * @param out this parameter is used to send back a string * @param {boolean} kmlLink * @throws ServletException * @throws IOException * @throws JSONException */ protected void dispAnimation(HttpServletRequest request, HttpServletResponse response, PrintWriter out, Boolean kmlLink) throws ServletException, IOException, JSONException, XMLFilesException { String layerName = request.getParameter("layerName"); String datesStr = request.getParameter("dates"); String palette = request.getParameter("palette"); String colorscalerange = request.getParameter("colorscalerange"); String elevation = request.getParameter("elevation"); String videores = request.getParameter("videores"); int animRes = 0; LayerMenuManagerSingleton layers = LayerMenuManagerSingleton.getInstance(); Layer layer = layers.getLayerByName(layerName);//Search current layer String finalRequest = layer.getServer()+ "?"; finalRequest+= "REQUEST=GetMap&"; finalRequest+= "VERSION=1.3.0&"; finalRequest+= "SRS="+layer.getProjection()+"&"; finalRequest+= "CRS=CRS:84&";// WHAT IS THIS PARAMETER switch(videores){ case "high": animRes = 512; break; case "normal": animRes = 256; break; case "low": animRes = 128; break; default: animRes = 128; break; } if( (layer.getStyle().equals("vector")|| layer.getStyle().equals("contour") || layer.getStyle().equals("arrows") || layer.getStyle().equals("barb") ) && (animRes < 512) ){ //If we are animating vectors into lower resolutions we don't // display the vectors, they look bad. finalRequest+= "STYLES=boxfill/"+palette+"&"; }else{ finalRequest+= "STYLES="+layer.getStyle()+"/"+palette+"&"; } finalRequest+= "WIDTH="+animRes+"&";//width and height of the image finalRequest+= "HEIGHT="+animRes+"&"; finalRequest+= "ELEVATION="+elevation+"&"; if(kmlLink){ finalRequest+= "FORMAT=application/vnd.google-earth.kmz&"; }else{ finalRequest+= "FORMAT=image/gif&"; } finalRequest+= "TRANSPARENT=true&"; finalRequest+= "LAYERS="+layer.getName()+"&"; finalRequest+= "BBOX="+layer.getBbox()+"&"; finalRequest+= "TIME="+datesStr+"&"; finalRequest+= "COLORSCALERANGE="+colorscalerange; //Sends the final request back out.println(finalRequest); }
/** * Convert a well-formed (but not necessarily valid) XML string into a * JSONObject. Some information may be lost in this transformation * because JSON is a data format and XML is a document format. XML uses * elements, attributes, and content text, while JSON uses unordered * collections of name/value pairs and arrays of values. JSON does not * does not like to distinguish between elements and attributes. * Sequences of similar elements are represented as JSONArrays. Content * text may be placed in a "content" member. Comments, prologs, DTDs, and * <code><[ [ ]]></code> are ignored. * @param string The source string. * @return A JSONObject containing the structured data from the XML string. * @throws JSONException */ public static JSONObject toJSONObject(String string) throws JSONException { JSONObject o = new JSONObject(); XMLTokener x = new XMLTokener(string); while (x.more()) { x.skipPast("<"); parse(x, o, null); } return o; }