List of usage examples for org.apache.wicket.request.http WebResponse getContainerResponse
public abstract Object getContainerResponse();
From source file:de.alpharogroup.wicket.base.util.WicketComponentExtensions.java
License:Apache License
/** * Gets the http servlet response.//w w w .j a va2s .c om * * @param response * the response * @return the http servlet response */ public static HttpServletResponse getHttpServletResponse(final Response response) { final WebResponse webResponse = (WebResponse) response; final HttpServletResponse httpServletResponse = (HttpServletResponse) webResponse.getContainerResponse(); return httpServletResponse; }
From source file:name.martingeisse.wicket.util.json.AbstractJsonRequestHandler.java
License:Open Source License
@Override public void respond(IRequestCycle requestCycle) { WebRequest request = (WebRequest) requestCycle.getRequest(); WebResponse response = (WebResponse) requestCycle.getResponse(); JavascriptAssembler assembler = new JavascriptAssembler(); generateJson(assembler, request);// ww w.j a v a2 s . c o m response.setHeader("Cache-Control", "no-cache, must-revalidate"); response.setHeader("Pragma", "no-cache"); response.setContentType(getContentType()); ((HttpServletResponse) response.getContainerResponse()).setCharacterEncoding("utf-8"); response.write(assembler.getAssembledCode()); }
From source file:org.brixcms.plugin.site.resource.ResourceNodeHandler.java
License:Apache License
@Override public void respond(IRequestCycle requestCycle) { boolean save = (this.save != null) ? this.save : Strings.isTrue(RequestCycle.get().getRequest().getRequestParameters() .getParameterValue(SAVE_PARAMETER).toString()); BrixFileNode node = (BrixFileNode) this.node.getObject(); if (!SitePlugin.get().canViewNode(node, Action.Context.PRESENTATION)) { throw Brix.get().getForbiddenException(); }/*from ww w . j a v a 2s . c o m*/ WebResponse response = (WebResponse) RequestCycle.get().getResponse(); response.setContentType(node.getMimeType()); Date lastModified = node.getLastModified(); response.setLastModifiedTime(Time.valueOf(lastModified)); try { final HttpServletRequest r = (HttpServletRequest) requestCycle.getRequest().getContainerRequest(); String since = r.getHeader("If-Modified-Since"); if (!save && since != null) { Date d = new Date(r.getDateHeader("If-Modified-Since")); // the weird toString comparison is to prevent comparing // milliseconds if (d.after(lastModified) || d.toString().equals(lastModified.toString())) { response.setContentLength(node.getContentLength()); response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return; } } String fileName = node.getName(); long length = node.getContentLength(); HttpServletResponse httpServletResponse = (HttpServletResponse) response.getContainerResponse(); InputStream stream = node.getDataAsStream(); new Streamer(length, stream, fileName, save, r, httpServletResponse).stream(); } catch (Exception e) { log.error("Error writing resource data to content", e); } }
From source file:org.brixcms.plugin.snapshot.ManageSnapshotsPanel.java
License:Apache License
public ManageSnapshotsPanel(String id, final IModel<Workspace> model) { super(id, model); add(new FeedbackPanel("feedback")); IModel<List<Workspace>> snapshotsModel = new LoadableDetachableModel<List<Workspace>>() { @Override/*from w w w . j av a 2 s . co m*/ protected List<Workspace> load() { List<Workspace> list = SnapshotPlugin.get().getSnapshotsForWorkspace(getModelObject()); return getBrix().filterVisibleWorkspaces(list, Context.ADMINISTRATION); } }; add(new ListView<Workspace>("snapshots", snapshotsModel) { @Override protected IModel<Workspace> getListItemModel(IModel<? extends List<Workspace>> listViewModel, int index) { return new WorkspaceModel(listViewModel.getObject().get(index)); } @Override protected void populateItem(final ListItem<Workspace> item) { Workspace workspace = item.getModelObject(); final String name = SnapshotPlugin.get().getUserVisibleName(workspace, true); final String comment = SnapshotPlugin.get().getComment(workspace); Link<Object> link = new Link<Object>("browse") { @Override public void onClick() { Workspace workspace = item.getModelObject(); model.setObject(workspace); } }; item.add(link); Link restoreLink = new Link<Void>("restore") { @Override public void onClick() { Workspace target = ManageSnapshotsPanel.this.getModelObject(); SnapshotPlugin.get().restoreSnapshot(item.getModelObject(), target); getSession().info(ManageSnapshotsPanel.this.getString("restoreSuccessful")); } /** * Take care that restoring is only allowed in case the workspaces aren't the same */ @Override public boolean isEnabled() { if (item.getModelObject().getId() .equals(ManageSnapshotsPanel.this.getModelObject().getId())) { return false; } return true; } @Override public boolean isVisible() { Workspace target = ManageSnapshotsPanel.this.getModelObject(); Action action = new RestoreSnapshotAction(Context.ADMINISTRATION, item.getModelObject(), target); return getBrix().getAuthorizationStrategy().isActionAuthorized(action); } }; /* * in case the link is enabled, make sure it is intended... */ if (restoreLink.isEnabled()) { restoreLink.add(new SimpleAttributeModifier("onClick", "return confirm('" + getLocalizer().getString("restoreOnClick", this) + "')")); } item.add(restoreLink); item.add(new Link<Void>("delete") { @Override public void onClick() { Workspace snapshot = item.getModelObject(); snapshot.delete(); } @Override public boolean isVisible() { Action action = new DeleteSnapshotAction(Context.ADMINISTRATION, item.getModelObject()); return getBrix().getAuthorizationStrategy().isActionAuthorized(action); } }); item.add(new Label("label", name)); item.add(new Label("commentlabel", comment)); } }); add(new Link<Object>("downloadWorkspace") { @Override public void onClick() { getRequestCycle().scheduleRequestHandlerAfterCurrent(new IRequestHandler() { public void detach(IRequestCycle requestCycle) { } public void respond(IRequestCycle requestCycle) { WebResponse resp = (WebResponse) requestCycle.getResponse(); resp.setAttachmentHeader("workspace.xml"); String id = ManageSnapshotsPanel.this.getModelObject().getId(); Brix brix = getBrix(); JcrSession session = brix.getCurrentSession(id); HttpServletResponse containerResponse = (HttpServletResponse) resp.getContainerResponse(); ServletOutputStream containerResponseOutputStream = null; try { containerResponseOutputStream = containerResponse.getOutputStream(); } catch (IOException e) { throw new RuntimeException(e); } session.exportSystemView(brix.getRootPath(), containerResponseOutputStream, false, false); } }); } }); /** * Form to create a new Snapshot and put any comment to it */ Form<Object> commentForm = new Form<Object>("commentForm") { @Override public boolean isVisible() { Workspace target = ManageSnapshotsPanel.this.getModelObject(); Action action = new CreateSnapshotAction(Context.ADMINISTRATION, target); return getBrix().getAuthorizationStrategy().isActionAuthorized(action); } }; final TextArea<String> area = new TextArea<String>("area", new Model<String>()); commentForm.add(area); commentForm.add(new SubmitLink("createSnapshot") { /** * @see org.apache.wicket.markup.html.form.IFormSubmittingComponent#onSubmit() */ @Override public void onSubmit() { String comment = area.getModelObject(); SnapshotPlugin.get().createSnapshot(ManageSnapshotsPanel.this.getModelObject(), comment); area.setModelObject(""); } }); add(commentForm); Form<Object> uploadForm = new Form<Object>("uploadForm") { @Override public boolean isVisible() { Workspace target = ManageSnapshotsPanel.this.getModelObject(); Action action = new RestoreSnapshotAction(Context.ADMINISTRATION, target); return getBrix().getAuthorizationStrategy().isActionAuthorized(action); } }; final FileUploadField upload = new FileUploadField("upload", new Model<FileUpload>()); uploadForm.add(upload); uploadForm.add(new SubmitLink("submit") { @Override public void onSubmit() { List<FileUpload> uploadList = upload.getModelObject(); if (uploadList != null) { for (FileUpload u : uploadList) { try { InputStream s = u.getInputStream(); String id = ManageSnapshotsPanel.this.getModelObject().getId(); Brix brix = getBrix(); JcrSession session = brix.getCurrentSession(id); if (session.itemExists(brix.getRootPath())) { session.getItem(brix.getRootPath()).remove(); } session.importXML("/", s, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING); session.save(); brix.initWorkspace(ManageSnapshotsPanel.this.getModelObject(), session); getSession().info(ManageSnapshotsPanel.this.getString("restoreSuccessful")); } catch (IOException e) { throw new BrixException(e); } } } } }); add(uploadForm); }
From source file:org.icepush.integration.wicket.core.WicketPushRequestContext.java
License:Mozilla Public License
public WicketPushRequestContext(WebRequest webRequest, WebResponse webResponse) { intializePushContext((HttpServletRequest) webRequest.getContainerRequest(), (HttpServletResponse) webResponse.getContainerResponse()); }
From source file:org.jaulp.wicket.base.util.WicketComponentUtils.java
License:Apache License
/** * Gets the http servlet response./*from w ww .j a v a 2s.com*/ * * @param response * the response * @return the http servlet response */ public static HttpServletResponse getHttpServletResponse(Response response) { WebResponse webResponse = (WebResponse) response; HttpServletResponse httpServletResponse = (HttpServletResponse) webResponse.getContainerResponse(); return httpServletResponse; }
From source file:org.wicketstuff.rest.contenthandling.serialdeserial.TextualObjectSerialDeserial.java
License:Apache License
/** * Sets the charset response.//from w w w .j a va 2s . c o m * * @param response * the new charset response */ private void setCharsetResponse(WebResponse response) { if (response.getContainerResponse() instanceof ServletResponse) { ServletResponse sResponse = (ServletResponse) response.getContainerResponse(); sResponse.setCharacterEncoding(charset); } }