List of usage examples for org.apache.wicket.request.http WebRequest getQueryParameters
public IRequestParameters getQueryParameters()
From source file:com.googlecode.wicket.jquery.ui.plugins.whiteboard.WhiteboardBehavior.java
License:Apache License
protected void respond(final AjaxRequestTarget target) { RequestCycle cycle = RequestCycle.get(); WebRequest webRequest = (WebRequest) cycle.getRequest(); if (webRequest.getQueryParameters().getParameterValue("editedElement").toString() != null) { String editedElement = webRequest.getQueryParameters().getParameterValue("editedElement").toString(); try {/*from w w w . j a v a 2s . c o m*/ if (snapShot == null && snapShotCreation == null) { snapShot = new ArrayList<Element>(); snapShotCreation = new ArrayList<Boolean>(); } //Mapping JSON String to Objects and Adding to the Element List JSONObject jsonEditedElement = new JSONObject(editedElement); Element element = getElementObject(jsonEditedElement); if (elementMap.containsKey(element.getId()) && !elementMap.isEmpty()) { snapShot.add(elementMap.get(element.getId())); snapShotCreation.add(false); } else { snapShot.add(element); snapShotCreation.add(true); } if (!"PointFree".equals(element.getType())) { if (undoSnapshots.size() == 20) { undoSnapshots.pollFirst(); undoSnapshotCreationList.pollFirst(); } if ("PencilCurve".equals(element.getType())) { ArrayList<Element> lastElementSnapshot = undoSnapshots.getLast(); Element lastSnapshotElement = lastElementSnapshot.get(lastElementSnapshot.size() - 1); if ((lastSnapshotElement instanceof PencilCurve) && (lastSnapshotElement.getId() == element.getId())) { ArrayList<Boolean> lastCreationSnapshot = undoSnapshotCreationList.getLast(); for (int i = 0; i < snapShot.size(); i++) { lastElementSnapshot.add(snapShot.get(i)); lastCreationSnapshot.add(snapShotCreation.get(i)); } } else { undoSnapshots.addLast(snapShot); undoSnapshotCreationList.addLast(snapShotCreation); } } else { undoSnapshots.addLast(snapShot); undoSnapshotCreationList.addLast(snapShotCreation); } snapShot = null; snapShotCreation = null; } // Synchronizing newly added element between whiteboards if (element != null) { elementMap.put(element.getId(), element); IWebSocketConnectionRegistry reg = IWebSocketSettings.Holder.get(Application.get()) .getConnectionRegistry(); for (IWebSocketConnection c : reg.getConnections(Application.get())) { try { JSONObject jsonObject = new JSONObject(editedElement); c.sendMessage(getAddElementMessage(jsonObject).toString()); } catch (Exception e) { e.printStackTrace(); } } } } catch (JSONException e) { e.printStackTrace(); } } else if (webRequest.getQueryParameters().getParameterValue("undo").toString() != null) { if (!undoSnapshots.isEmpty()) { ArrayList<Boolean> undoCreationList = undoSnapshotCreationList.pollLast(); ArrayList<Element> undoElement = undoSnapshots.pollLast(); String deleteList = ""; JSONArray changeList = new JSONArray(); IWebSocketConnectionRegistry reg = IWebSocketSettings.Holder.get(Application.get()) .getConnectionRegistry(); for (int i = 0; i < undoElement.size(); i++) { if (undoCreationList.get(i)) { elementMap.remove(undoElement.get(i).getId()); if ("".equals(deleteList)) { deleteList = "" + undoElement.get(i).getId(); } else { deleteList += "," + undoElement.get(i).getId(); } } else { elementMap.put(undoElement.get(i).getId(), undoElement.get(i)); changeList.put(undoElement.get(i).getJSON()); } } for (IWebSocketConnection c : reg.getConnections(Application.get())) { try { c.sendMessage(getUndoMessage(changeList, deleteList).toString()); } catch (Exception e) { e.printStackTrace(); } } } } else if (webRequest.getQueryParameters().getParameterValue("eraseAll").toString() != null) { elementMap.clear(); IWebSocketConnectionRegistry reg = IWebSocketSettings.Holder.get(Application.get()) .getConnectionRegistry(); for (IWebSocketConnection c : reg.getConnections(Application.get())) { try { JSONArray jsonArray = new JSONArray(); c.sendMessage(getWhiteboardMessage(jsonArray).toString()); } catch (Exception e) { e.printStackTrace(); } } } else if (webRequest.getQueryParameters().getParameterValue("save").toString() != null) { JSONArray elementArray = new JSONArray(); for (int elementID : elementMap.keySet()) { elementArray.put(elementMap.get(elementID).getJSON()); } DateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss"); Date date = new Date(); File whiteboardFile = new File("Whiteboard_" + dateFormat.format(date) + ".json"); FileWriter writer = null; try { whiteboardFile.createNewFile(); System.out.println(whiteboardFile.getAbsolutePath()); writer = new FileWriter(whiteboardFile); writer.write(elementArray.toString()); writer.flush(); } catch (IOException e) { e.printStackTrace(); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { e.printStackTrace(); } } } } else if (webRequest.getQueryParameters().getParameterValue("clipArt").toString() != null) { IWebSocketConnectionRegistry reg = IWebSocketSettings.Holder.get(Application.get()) .getConnectionRegistry(); for (IWebSocketConnection c : reg.getConnections(Application.get())) { try { JSONArray jsonArray = new JSONArray(); jsonArray.put("http://icons.iconarchive.com/icons/femfoyou/angry-birds/64/angry-bird-icon.png"); jsonArray.put( "http://icons.iconarchive.com/icons/femfoyou/angry-birds/64/angry-bird-yellow-icon.png"); c.sendMessage(getClipArtListMessage(jsonArray).toString()); } catch (Exception e) { e.printStackTrace(); } } } }
From source file:org.wicketstuff.whiteboard.WhiteboardBehavior.java
License:Apache License
/** * This method handles all the Ajax calls coming from whiteboard * // w w w . ja va 2 s.c o m * @param target */ protected void respond(final AjaxRequestTarget target) { RequestCycle cycle = RequestCycle.get(); WebRequest webRequest = (WebRequest) cycle.getRequest(); // If geometric element is drawn of edited on whiteboard, message will be sent and this if clause handles that if (webRequest.getQueryParameters().getParameterNames().contains("editedElement")) { String editedElement = webRequest.getQueryParameters().getParameterValue("editedElement").toString(); handleEditedElement(editedElement); } // If undo button is clicked on whiteboard, message will be sent and this if clause handles that else if (webRequest.getQueryParameters().getParameterNames().contains("undo")) { handleUndo(); } // If eraseAll button is clicked on whiteboard, message will be sent and this if clause handles that else if (webRequest.getQueryParameters().getParameterNames().contains("eraseAll")) { handleEraseAll(); } // If save button is clicked on whiteboard, message will be sent and this if clause handles that else if (webRequest.getQueryParameters().getParameterNames().contains("save")) { handleSave(); } // If addClipArt button is clicked on whiteboard, message will be sent and this if clause handles that else if (webRequest.getQueryParameters().getParameterNames().contains("clipArt")) { handleClipArts(); } // If addDocument button is clicked on whiteboard, message will be sent and this if clause handles that else if (webRequest.getQueryParameters().getParameterNames().contains("docList")) { handleDocs(); ; } // If document page navigation buttons are clicked on whiteboard, message will be sent and this if clause // handles that else if (webRequest.getQueryParameters().getParameterNames().contains("docComponents")) { String docBaseName = webRequest.getQueryParameters().getParameterValue("docBaseName").toString(); handleDocComponents(docBaseName); } // If document is added to whiteboard, message will be sent and this if clause handles that else if (webRequest.getQueryParameters().getParameterNames().contains("background")) { String backgroundString = webRequest.getQueryParameters().getParameterValue("background").toString(); handleBackground(backgroundString); } }