List of usage examples for org.apache.wicket Application get
public static Application get()
From source file:org.wicketstuff.security.StringAction.java
License:Apache License
public ActionFactory getActionFactory() { // not a very good implementation since it binds this action type to // wicket//from w w w . j a va2s .com return ((WaspApplication) Application.get()).getActionFactory(); // real world implementations should use the Actions class or some other // non wicket specific way }
From source file:org.wicketstuff.servlet3.secure.example.ui.BasePage.java
License:Apache License
public BasePage(PageParameters parameters) { super(parameters); add(new UserInfoPanel("userInfo")); add(new StatelessLink("home") { @Override//from ww w . jav a 2 s . c om public void onClick() { setResponsePage(Application.get().getHomePage()); } }.setVisible(this.getClass() != Application.get().getHomePage())); add(new AdminLink("admin") { @Override public void onClick() { setResponsePage(AdminPage.class); } }.setVisible(this.getClass() != AdminPage.class)); add(new SecureLink("invalidate") { @Override public void onClick() { Session.get().invalidate(); //This logs out user and removes the rememberMe cookie setResponsePage(Application.get().getHomePage()); } }); add(new SecureLink("logout") { @Override public void onClick() { AuthenticatedWebSession.get().signOut(); //log out and do not delete cookie setResponsePage(Application.get().getHomePage()); } }); }
From source file:org.wicketstuff.shiro.wicket.page.store.SessionPageStore.java
License:Apache License
protected IManageablePage deserializePage(final byte data[]) { // TODO: test this, Serializer replacing old // WicketObjects.byteArrayToObject(data); // call/*from w w w . j av a 2 s . co m*/ return (IManageablePage) Application.get().getFrameworkSettings().getSerializer().deserialize(data); }
From source file:org.wicketstuff.shiro.wicket.page.store.SessionPageStore.java
License:Apache License
protected byte[] serializePage(final String sessionId, final IManageablePage page) { Args.notNull(sessionId, "sessionId"); Args.notNull(page, "page"); // TODO: test this, Serializer replacing old // WicketObjects.objectToByteArray(page, applicationName); // call//from ww w . j a v a2 s .c om final byte data[] = Application.get().getFrameworkSettings().getSerializer().serialize(page); return data; }
From source file:org.wicketstuff.springreference.SpringReferenceSupporter.java
License:Apache License
/** * @return instance registered with the current threads wicket application *///from ww w.j a va 2 s . c om protected static SpringReferenceSupporter get() { return Application.get().getMetaData(LOCATOR_KEY); }
From source file:org.wicketstuff.validation.client.AbstractClientAndServerValidatingBehavior.java
License:Apache License
@Override public final void renderHead(Component c, IHeaderResponse response) { super.renderHead(c, response); // add our validation javascript file response.render(/*from www . j ava2s.c o m*/ JavaScriptHeaderItem.forReference(new PackageResourceReference(getClass(), "validation.js"))); // add a trigger that will add our validation to the forms' onSubmit methods response.render(OnLoadHeaderItem.forScript("ClientAndServerValidator.addFormOnloadEvents();")); CharSequence formID = jsEscape(mForm.getMarkupId()); CharSequence compID = jsEscape(mComponent.getMarkupId()); String message = Application.get().getResourceSettings().getLocalizer().getString(getResourceKey(), mComponent); Map<String, Object> vars = variablesMap(mForm, mComponent); boolean thrExc = Application.get().getResourceSettings().getThrowExceptionOnMissingResource(); MapVariableInterpolator mvi = new MapVariableInterpolator(message, vars, thrExc); CharSequence escapedMessage = jsEscape(mvi.toString()); String validator = createValidatorConstructorJavaScript(formID, compID, escapedMessage); String js = "ClientAndServerValidator.registerValidator(" + validator + ");"; response.render(OnDomReadyHeaderItem.forScript(js)); }
From source file:org.wicketstuff.whiteboard.WhiteboardBehavior.java
License:Apache License
/** * Mapping JSON String to Objects and Adding to the Element List * // ww w . j a va 2 s. com * @param editedElement * @return */ private boolean handleEditedElement(String editedElement) { try { JSONObject jsonEditedElement = new JSONObject(editedElement); Element element = getElementObject(jsonEditedElement); boolean isLoaded = false; if (!elementMap.isEmpty() && loadedElementMap.get(element.getId()) != null && !loadedElementMap.isEmpty()) { isLoaded = isEqual(element.getJSON(), loadedElementMap.get(element.getId()).getJSON()); } // If the edited element is not from file loaded content this clause executes if (!isLoaded) { // Adding the element creation/editing is add to the undo snapshots if (snapShot == null && snapShotCreation == null) { snapShot = new ArrayList<Element>(); snapShotCreation = new ArrayList<Boolean>(); } if (elementMap.containsKey(element.getId()) && !elementMap.isEmpty()) { snapShot.add(elementMap.get(element.getId())); snapShotCreation.add(false); } else { snapShot.add(element); snapShotCreation.add(true); } if (Type.PointFree != element.getType()) { if (undoSnapshots.size() == 20) { undoSnapshots.pollFirst(); undoSnapshotCreationList.pollFirst(); } if (Type.PencilCurve == element.getType()) { List<Element> lastElementSnapshot = undoSnapshots.peekLast(); if (lastElementSnapshot != null) { Element lastSnapshotElement = lastElementSnapshot.get(lastElementSnapshot.size() - 1); if ((lastSnapshotElement instanceof PencilCurve) && (lastSnapshotElement.getId() == element.getId())) { List<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); isElementSnapshotList.addLast(true); } } } else if (Type.ClipArt == element.getType()) { List<Element> snapShotTemp = undoSnapshots.pollLast(); List<Boolean> snapShotCreationTemp = undoSnapshotCreationList.pollLast(); for (int i = 0; i < snapShotTemp.size(); i++) { snapShot.add(snapShotTemp.get(i)); snapShotCreation.add(snapShotCreationTemp.get(i)); } undoSnapshots.addLast(snapShot); undoSnapshotCreationList.addLast(snapShotCreation); isElementSnapshotList.addLast(true); } else { undoSnapshots.addLast(snapShot); undoSnapshotCreationList.addLast(snapShotCreation); isElementSnapshotList.addLast(true); } snapShot = null; snapShotCreation = null; } // Synchronizing newly added/edited element between whiteboard clients if (element != null) { elementMap.put(element.getId(), element); IWebSocketConnectionRegistry reg = WebSocketSettings.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) { log.error("Unexpected error while sending message through the web socket", e); } } } } return true; } catch (JSONException e) { log.error("Unexpected error while editing element", e); } return false; }
From source file:org.wicketstuff.whiteboard.WhiteboardBehavior.java
License:Apache License
/** * Synchronizing newly added/edited background between whiteboard clients * //from w ww . j a v a2 s. c om * @param backgroundString * @return */ private boolean handleBackground(String backgroundString) { try { JSONObject backgroundJSON = new JSONObject(backgroundString); Background backgroundObject = new Background(backgroundJSON); background = backgroundObject; Background previousBackground = new Background("Background", "", 0.0, 0.0, 0.0, 0.0); if (whiteboardMap.get(whiteboardObjectId).getBackground() != null) { previousBackground = whiteboardMap.get(whiteboardObjectId).getBackground(); } whiteboardMap.get(whiteboardObjectId).setBackground(background); undoSnapshotCreationList_Background.addLast(previousBackground == null); undoSnapshots_Background.addLast(previousBackground); isElementSnapshotList.addLast(false); IWebSocketConnectionRegistry reg = WebSocketSettings.Holder.get(Application.get()) .getConnectionRegistry(); for (IWebSocketConnection c : reg.getConnections(Application.get())) { try { JSONObject jsonObject = new JSONObject(backgroundString); c.sendMessage(getAddBackgroundMessage(jsonObject).toString()); } catch (Exception e) { log.error("Unexpected error while sending message through the web socket", e); } } return true; } catch (JSONException e) { e.printStackTrace(); } return false; }
From source file:org.wicketstuff.whiteboard.WhiteboardBehavior.java
License:Apache License
/** * Undo one step and synchronizing undo between whiteboard clients * /*from w w w .ja v a2 s . c o m*/ * @return */ private boolean handleUndo() { if (!isElementSnapshotList.isEmpty()) { if (isElementSnapshotList.pollLast()) { List<Boolean> undoCreationList = undoSnapshotCreationList.pollLast(); List<Element> undoElement = undoSnapshots.pollLast(); String deleteList = ""; JSONArray changeList = new JSONArray(); IWebSocketConnectionRegistry reg = WebSocketSettings.Holder.get(Application.get()) .getConnectionRegistry(); for (int i = 0; i < undoElement.size(); i++) { if (undoCreationList.get(i)) { elementMap.remove(undoElement.get(i).getId()); if (loadedElementMap.containsKey(undoElement.get(i).getId())) { loadedContent = ""; whiteboardMap.get(whiteboardObjectId).setLoadedContent(""); loadedElementMap.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)); try { changeList.put(undoElement.get(i).getJSON()); } catch (JSONException e) { log.error("Unexpected error while getting JSON", e); } } } for (IWebSocketConnection c : reg.getConnections(Application.get())) { try { c.sendMessage(getUndoMessage(changeList, deleteList).toString()); } catch (Exception e) { log.error("Unexpected error while sending message through the web socket", e); } } } else { Background previousBackground = undoSnapshots_Background.pollLast(); background = previousBackground; whiteboardMap.get(whiteboardObjectId).setBackground(previousBackground); IWebSocketConnectionRegistry reg = WebSocketSettings.Holder.get(Application.get()) .getConnectionRegistry(); for (IWebSocketConnection c : reg.getConnections(Application.get())) { try { if (previousBackground != null) { c.sendMessage(getAddBackgroundMessage(previousBackground.getJSON()).toString()); } else { c.sendMessage(getAddBackgroundMessage(new JSONObject()).toString()); } } catch (Exception e) { log.error("Unexpected error while sending message through the web socket", e); } } } return true; } return false; }
From source file:org.wicketstuff.whiteboard.WhiteboardBehavior.java
License:Apache License
/** * Synchronizing eraseAll request between whiteboard clients * // w w w . ja v a 2s . com * @return */ private boolean handleEraseAll() { elementMap.clear(); IWebSocketConnectionRegistry reg = WebSocketSettings.Holder.get(Application.get()).getConnectionRegistry(); for (IWebSocketConnection c : reg.getConnections(Application.get())) { try { JSONArray jsonArray = new JSONArray(); c.sendMessage(getEraseAllMessage(jsonArray).toString()); return true; } catch (Exception e) { log.error("Unexpected error while sending message through the web socket", e); } } return false; }