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());
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) {