List of usage examples for org.apache.wicket.request.handler.resource ResourceStreamRequestHandler setContentDisposition
public final ResourceStreamRequestHandler setContentDisposition(ContentDisposition contentDisposition)
From source file:com.chitek.ignition.drivers.generictcp.meta.config.ui.MessageConfigUI.java
License:Apache License
private void addComponents() { // Select the first message for initial display if (getConfig().messages.isEmpty()) { // No messages configured. Create a new message with id=1. getConfig().addMessageConfig(new MessageConfig(1)); }/*from www . j a v a 2 s .c o m*/ currentMessage = getConfig().getMessageList().get(0); currentMessage.calcOffsets(getConfig().getMessageIdType().getByteSize()); currentMessageId = currentMessage.getMessageId(); // ******************************************************************************************* // *** Form for XML import final FileUploadField uploadField = new FileUploadField("upload-field", new ListModel<FileUpload>()); Form<?> uploadForm = new Form<Object>("upload-form") { @Override protected void onSubmit() { try { FileUpload upload = uploadField.getFileUpload(); if (upload != null) { handleOnUpload(upload.getInputStream()); } else { warn(new StringResourceModel("warn.noFileToUpload", this, null).getString()); } } catch (Exception e) { this.error(new StringResourceModel("import.error", this, null).getString() + " Exception: " + e.toString()); } } }; uploadForm.add(uploadField); SubmitLink importLink = new SubmitLink("import-link"); uploadForm.add(importLink); add(uploadForm); // ******************************************************************************************* // *** The message configuration currentMessageModel = new PropertyModel<MessageConfig>(this, "currentMessage"); editForm = new Form<MessageConfig>("edit-form", new CompoundPropertyModel<MessageConfig>(currentMessageModel)) { @Override protected void onError() { // Validation error - reset the message dropdown to the original value // Clear input causes the component to reload the model currentMessageIdDropdown.clearInput(); super.onError(); } }; editForm.add(new MessageFormValidator()); WebMarkupContainer tableContainer = new WebMarkupContainer("table-container"); messageIdTypeDropDown = getMessageIdTypeDropdown(); tableContainer.add(messageIdTypeDropDown); currentMessageIdDropdown = getCurrentMessageIdDropdown(); tableContainer.add(currentMessageIdDropdown); Button buttonNew = new Button("new"); buttonNew.add(new AjaxFormSubmitBehavior("onclick") { @Override protected void onSubmit(AjaxRequestTarget target) { handleNew(target); } @Override protected void onError(AjaxRequestTarget target) { handleError(target); } }); tableContainer.add(buttonNew); Button buttonCopy = new Button("copy"); buttonCopy.add(new AjaxFormSubmitBehavior("onclick") { @Override protected void onSubmit(AjaxRequestTarget target) { handleCopy(target); } @Override protected void onError(AjaxRequestTarget target) { handleError(target); } }); tableContainer.add(buttonCopy); Button deleteButton = new Button("delete"); deleteButton.add(new AjaxEventBehavior("onclick") { @Override protected void onEvent(AjaxRequestTarget target) { handleDelete(target); } }); tableContainer.add(deleteButton); messageTypeDropdown = getMessageTypeDropdown(); tableContainer.add(messageTypeDropdown); tableContainer.add(getQueueModeDropdown()); tableContainer.add(new CheckBox("usePersistance").setOutputMarkupId(true)); WebMarkupContainer listEditorContainer = new WebMarkupContainer("list-editor"); messageIdTextField = getMessageIdTextField(); listEditorContainer.add(messageIdTextField); messageAliasTextField = getMessageAliasTextField(); listEditorContainer.add(messageAliasTextField); // Create the list editor editor = new ListEditor<TagConfig>("tags", new PropertyModel<List<TagConfig>>(currentMessageModel, "tags")) { @Override protected void onPopulateItem(EditorListItem<TagConfig> item) { item.setModel(new CompoundPropertyModel<TagConfig>(item.getModelObject())); BinaryDataType dataType = item.getModelObject().getDataType(); boolean enable = dataType.isSpecial() ? false : true; // Offset is displayed only for information item.add(new Label("offset").setOutputMarkupId(true)); if (enable) { item.add(getIdTextField()); } else { // The static TextField has no validation. Validation would fail for special tags. item.add(getSpecialIdTextField().setEnabled(false)); } item.add(getAliasTextField().setVisible(enable)); item.add(getSizeTextField().setEnabled(dataType.isArrayAllowed())); item.add(getTagLengthTypeDropDown().setEnabled(dataType.supportsVariableLength())); item.add(getDataTypeDropdown()); // Create the edit links to be used in the list editor item.add(getInsertLink()); item.add(getDeleteLink()); item.add(getMoveUpLink().setVisible(item.getIndex() > 0)); item.add(getMoveDownLink().setVisible(item.getIndex() < getList().size() - 1)); } }; listEditorContainer.add(editor); Label noItemsLabel = new Label("no-items-label", new StringResourceModel("noitems", this, null)) { @Override public boolean isVisible() { return editor.getList().size() == 0; } }; listEditorContainer.add(noItemsLabel); listEditorContainer.add(new EditorSubmitLink("add-row-link") { @Override public void onSubmit() { editor.addItem(new TagConfig()); // Adjust the visibility of the edit links updateListEditor(editor); } }); listEditorContainer.setOutputMarkupId(true); tableContainer.add(listEditorContainer); editForm.add(tableContainer); // XML export SubmitLink exportLink = new SubmitLink("export-link", editForm) { @Override public void onSubmit() { ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(getResourceStream(), getFileName()); handler.setContentDisposition(ContentDisposition.ATTACHMENT); handler.setCacheDuration(Duration.NONE); getRequestCycle().scheduleRequestHandlerAfterCurrent(handler); } private String getFileName() { return String.format("MsgConfig_%s.xml", currentMessageModel.getObject().getMessageId()); } private IResourceStream getResourceStream() { String config = currentMessageModel.getObject().toXMLString(); return new StringResourceStream(config, "text/xml"); } }; editForm.add(exportLink); uploadForm.add(editForm); }
From source file:de.alpharogroup.wicket.behaviors.AjaxDownloadBehavior.java
License:Apache License
/** * {@inheritDoc}//from www . j a v a 2 s . c om */ @Override public void onRequest() { final ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(getResourceStream(), getFileName()); handler.setContentDisposition(ContentDisposition.ATTACHMENT); getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(handler); }
From source file:de.tudarmstadt.ukp.clarin.webanno.support.AJAXDownload.java
License:Apache License
@Override public void onRequest() { ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(getResourceStream(), getFileName()); handler.setContentDisposition(ContentDisposition.ATTACHMENT); getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(handler); }
From source file:org.apache.isis.viewer.wicket.model.models.ActionModel.java
License:Apache License
private static IRequestHandler handlerFor(final IResourceStream resourceStream, final NamedWithMimeType namedWithMimeType) { final ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(resourceStream, namedWithMimeType.getName()); handler.setContentDisposition(ContentDisposition.ATTACHMENT); return handler; }
From source file:org.apache.isis.viewer.wicket.ui.components.widgets.cssmenu.AjaxDownload.java
License:Apache License
@Override protected IRequestHandler getRequestHandler() { ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(getResourceStream(), getFileName()); handler.setContentDisposition(ContentDisposition.ATTACHMENT); return handler; }
From source file:org.apache.openmeetings.web.util.AjaxDownload.java
License:Apache License
@Override public void onRequest() { ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(getResourceStream(), getFileName()); handler.setContentDisposition(getContentDisposition()); getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(handler); }
From source file:org.apache.solomax.AjaxDownload.java
License:Apache License
@Override public void onResourceRequested() { ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(getResourceStream(), getFileName()); handler.setContentDisposition(getContentDisposition()); component.getRequestCycle().scheduleRequestHandlerAfterCurrent(handler); }
From source file:org.apache.syncope.client.console.pages.BasePage.java
License:Apache License
public BasePage(final PageParameters parameters) { super(parameters); // Native WebSocket add(new WebSocketBehavior() { private static final long serialVersionUID = 3109256773218160485L; @Override/* w ww . j a va 2s. co m*/ protected void onConnect(final ConnectedMessage message) { super.onConnect(message); SyncopeConsoleSession.get().scheduleAtFixedRate(new ApprovalsWidget.ApprovalInfoUpdater(message), 0, 30, TimeUnit.SECONDS); if (BasePage.this instanceof Dashboard) { SyncopeConsoleSession.get().scheduleAtFixedRate(new JobWidget.JobInfoUpdater(message), 0, 10, TimeUnit.SECONDS); SyncopeConsoleSession.get().scheduleAtFixedRate( new ReconciliationWidget.ReconciliationJobInfoUpdater(message), 0, 10, TimeUnit.SECONDS); } } }); body = new WebMarkupContainer("body"); Serializable leftMenuCollapse = SyncopeConsoleSession.get() .getAttribute(SyncopeConsoleSession.MENU_COLLAPSE); if ((leftMenuCollapse instanceof Boolean) && ((Boolean) leftMenuCollapse)) { body.add(new AttributeAppender("class", " sidebar-collapse")); } add(body); notificationPanel = new NotificationPanel(Constants.FEEDBACK); body.addOrReplace(notificationPanel.setOutputMarkupId(true)); // header, footer body.add(new Label("version", SyncopeConsoleApplication.get().getVersion())); body.add(new Label("username", SyncopeConsoleSession.get().getSelfTO().getUsername())); body.add(new ApprovalsWidget("approvalsWidget", getPageReference()).setRenderBodyOnly(true)); // right sidebar SystemInfo systemInfo = SyncopeConsoleSession.get().getSystemInfo(); body.add(new Label("hostname", systemInfo.getHostname())); body.add(new Label("processors", systemInfo.getAvailableProcessors())); body.add(new Label("os", systemInfo.getOs())); body.add(new Label("jvm", systemInfo.getJvm())); Link<Void> dbExportLink = new Link<Void>("dbExportLink") { private static final long serialVersionUID = -4331619903296515985L; @Override public void onClick() { try { HttpResourceStream stream = new HttpResourceStream(new ConfigurationRestClient().dbExport()); ResourceStreamRequestHandler rsrh = new ResourceStreamRequestHandler(stream); rsrh.setFileName( stream.getFilename() == null ? SyncopeConsoleSession.get().getDomain() + "Content.xml" : stream.getFilename()); rsrh.setContentDisposition(ContentDisposition.ATTACHMENT); getRequestCycle().scheduleRequestHandlerAfterCurrent(rsrh); } catch (Exception e) { SyncopeConsoleSession.get().error(getString(Constants.ERROR) + ": " + e.getMessage()); } } }; MetaDataRoleAuthorizationStrategy.authorize(dbExportLink, WebPage.ENABLE, StandardEntitlement.CONFIGURATION_EXPORT); body.add(dbExportLink); // menu WebMarkupContainer liContainer = new WebMarkupContainer(getLIContainerId("dashboard")); body.add(liContainer); liContainer.add(BookmarkablePageLinkBuilder.build("dashboard", Dashboard.class)); liContainer = new WebMarkupContainer(getLIContainerId("realms")); body.add(liContainer); BookmarkablePageLink<? extends BasePage> link = BookmarkablePageLinkBuilder.build("realms", Realms.class); MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.REALM_LIST); liContainer.add(link); liContainer = new WebMarkupContainer(getLIContainerId("topology")); body.add(liContainer); link = BookmarkablePageLinkBuilder.build("topology", Topology.class); StringBuilder bld = new StringBuilder(); bld.append(StandardEntitlement.CONNECTOR_LIST).append(",").append(StandardEntitlement.RESOURCE_LIST) .append(","); MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, bld.toString()); liContainer.add(link); liContainer = new WebMarkupContainer(getLIContainerId("reports")); body.add(liContainer); link = BookmarkablePageLinkBuilder.build("reports", Reports.class); MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.REPORT_LIST); liContainer.add(link); WebMarkupContainer confLIContainer = new WebMarkupContainer(getLIContainerId("configuration")); body.add(confLIContainer); WebMarkupContainer confULContainer = new WebMarkupContainer(getULContainerId("configuration")); confLIContainer.add(confULContainer); liContainer = new WebMarkupContainer(getLIContainerId("workflow")); confULContainer.add(liContainer); link = BookmarkablePageLinkBuilder.build("workflow", Workflow.class); MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.WORKFLOW_DEF_READ); liContainer.add(link); liContainer = new WebMarkupContainer(getLIContainerId("audit")); confULContainer.add(liContainer); link = BookmarkablePageLinkBuilder.build("audit", Audit.class); MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.AUDIT_LIST); liContainer.add(link); liContainer = new WebMarkupContainer(getLIContainerId("logs")); confULContainer.add(liContainer); link = BookmarkablePageLinkBuilder.build("logs", Logs.class); MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.LOG_LIST); liContainer.add(link); liContainer = new WebMarkupContainer(getLIContainerId("securityquestions")); confULContainer.add(liContainer); bld = new StringBuilder(); bld.append(StandardEntitlement.SECURITY_QUESTION_CREATE).append(",") .append(StandardEntitlement.SECURITY_QUESTION_DELETE).append(",") .append(StandardEntitlement.SECURITY_QUESTION_UPDATE); link = BookmarkablePageLinkBuilder.build("securityquestions", SecurityQuestions.class); MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, bld.toString()); liContainer.add(link); liContainer = new WebMarkupContainer(getLIContainerId("types")); confULContainer.add(liContainer); link = BookmarkablePageLinkBuilder.build("types", Types.class); MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.SCHEMA_LIST); liContainer.add(link); liContainer = new WebMarkupContainer(getLIContainerId("roles")); confULContainer.add(liContainer); link = BookmarkablePageLinkBuilder.build("roles", Roles.class); MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.ROLE_LIST); liContainer.add(link); liContainer = new WebMarkupContainer(getLIContainerId("policies")); confULContainer.add(liContainer); link = BookmarkablePageLinkBuilder.build("policies", Policies.class); MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.POLICY_LIST); liContainer.add(link); liContainer = new WebMarkupContainer(getLIContainerId("notifications")); confULContainer.add(liContainer); link = BookmarkablePageLinkBuilder.build("notifications", Notifications.class); MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.NOTIFICATION_LIST); liContainer.add(link); liContainer = new WebMarkupContainer(getLIContainerId("parameters")); confULContainer.add(liContainer); link = BookmarkablePageLinkBuilder.build("parameters", Parameters.class); MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.CONFIGURATION_LIST); liContainer.add(link); body.add(new AjaxLink<Void>("collapse") { private static final long serialVersionUID = -7978723352517770644L; @Override public void onClick(final AjaxRequestTarget target) { SyncopeConsoleSession.get().setAttribute(SyncopeConsoleSession.MENU_COLLAPSE, SyncopeConsoleSession.get().getAttribute(SyncopeConsoleSession.MENU_COLLAPSE) == null ? true : !(Boolean) SyncopeConsoleSession.get() .getAttribute(SyncopeConsoleSession.MENU_COLLAPSE)); } }); body.add(new Label("domain", SyncopeConsoleSession.get().getDomain())); body.add(new BookmarkablePageLink<Page>("logout", Logout.class)); // set 'active' menu item for everything but extensions // 1. check if current class is set to top-level menu Component containingLI = body.get(getLIContainerId(getClass().getSimpleName().toLowerCase())); // 2. if not, check if it is under 'Configuration' if (containingLI == null) { containingLI = confULContainer.get(getLIContainerId(getClass().getSimpleName().toLowerCase())); } // 3. when found, set CSS coordinates for menu if (containingLI != null) { containingLI.add(new Behavior() { private static final long serialVersionUID = 1469628524240283489L; @Override public void onComponentTag(final Component component, final ComponentTag tag) { tag.put("class", "active"); } }); if (confULContainer.getId().equals(containingLI.getParent().getId())) { confULContainer.add(new Behavior() { private static final long serialVersionUID = 3109256773218160485L; @Override public void onComponentTag(final Component component, final ComponentTag tag) { tag.put("class", "treeview-menu menu-open"); tag.put("style", "display: block;"); } }); confLIContainer.add(new Behavior() { private static final long serialVersionUID = 3109256773218160485L; @Override public void onComponentTag(final Component component, final ComponentTag tag) { tag.put("class", "treeview active"); } }); } } // Extensions ClassPathScanImplementationLookup classPathScanImplementationLookup = (ClassPathScanImplementationLookup) SyncopeConsoleApplication .get().getServletContext().getAttribute(ConsoleInitializer.CLASSPATH_LOOKUP); List<Class<? extends BaseExtPage>> extPageClasses = classPathScanImplementationLookup.getExtPageClasses(); WebMarkupContainer extensionsLI = new WebMarkupContainer(getLIContainerId("extensions")); extensionsLI.setOutputMarkupPlaceholderTag(true); extensionsLI.setVisible(!extPageClasses.isEmpty()); body.add(extensionsLI); ListView<Class<? extends BaseExtPage>> extPages = new ListView<Class<? extends BaseExtPage>>("extPages", extPageClasses) { private static final long serialVersionUID = 4949588177564901031L; @Override protected void populateItem(final ListItem<Class<? extends BaseExtPage>> item) { WebMarkupContainer containingLI = new WebMarkupContainer("extPageLI"); item.add(containingLI); if (item.getModelObject().equals(BasePage.this.getClass())) { containingLI.add(new Behavior() { private static final long serialVersionUID = 1469628524240283489L; @Override public void onComponentTag(final Component component, final ComponentTag tag) { tag.put("class", "active"); } }); } ExtPage ann = item.getModelObject().getAnnotation(ExtPage.class); BookmarkablePageLink<Page> link = new BookmarkablePageLink<>("extPage", item.getModelObject()); link.add(new Label("extPageLabel", ann.label())); MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, ann.listEntitlement()); containingLI.add(link); Label extPageIcon = new Label("extPageIcon"); extPageIcon.add(new AttributeModifier("class", "fa " + ann.icon())); link.add(extPageIcon); } }; extPages.setOutputMarkupId(true); extensionsLI.add(extPages); if (getPage() instanceof BaseExtPage) { extPages.add(new Behavior() { private static final long serialVersionUID = 1469628524240283489L; @Override public void onComponentTag(final Component component, final ComponentTag tag) { tag.put("class", "treeview-menu menu-open"); tag.put("style", "display: block;"); } }); extensionsLI.add(new Behavior() { private static final long serialVersionUID = 1469628524240283489L; @Override public void onComponentTag(final Component component, final ComponentTag tag) { tag.put("class", "treeview active"); } }); } }
From source file:org.apache.syncope.client.console.pages.Configuration.java
License:Apache License
@SuppressWarnings({ "unchecked", "rawtypes" }) private void setupSyncopeConf() { final WebMarkupContainer parameters = new WebMarkupContainer("parameters"); parameters.setOutputMarkupId(true);/*from w w w . j a v a2 s .co m*/ add(parameters); setWindowClosedCallback(syncopeConfWin, parameters); AjaxLink<Void> confLink = new IndicatingAjaxLink<Void>("confLink") { private static final long serialVersionUID = -7978723352517770644L; @Override public void onClick(final AjaxRequestTarget target) { syncopeConfWin.setPageCreator(new ModalWindow.PageCreator() { private static final long serialVersionUID = -7834632442532690940L; @Override public Page createPage() { return new ConfModalPage(getPageReference(), editNotificationWin, parameters); } }); syncopeConfWin.show(target); } }; parameters.add(confLink); Link<Void> dbExportLink = new Link<Void>("dbExportLink") { private static final long serialVersionUID = -4331619903296515985L; @Override public void onClick() { try { HttpResourceStream stream = new HttpResourceStream(confRestClient.dbExport()); ResourceStreamRequestHandler rsrh = new ResourceStreamRequestHandler(stream); rsrh.setFileName(stream.getFilename() == null ? "content.xml" : stream.getFilename()); rsrh.setContentDisposition(ContentDisposition.ATTACHMENT); getRequestCycle().scheduleRequestHandlerAfterCurrent(rsrh); } catch (Exception e) { error(getString(Constants.ERROR) + ": " + e.getMessage()); } } }; MetaDataRoleAuthorizationStrategy.authorize(dbExportLink, ENABLE, xmlRolesReader.getEntitlement("Configuration", "export")); add(dbExportLink); }
From source file:org.apache.syncope.client.console.panels.SAML2SPPanel.java
License:Apache License
public SAML2SPPanel(final String id) { super(id);//from www . j a v a2s.com add(new Link<Void>("downloadMetadata") { private static final long serialVersionUID = -4331619903296515985L; @Override public void onClick() { try { HttpResourceStream stream = new HttpResourceStream(ClientBuilder.newClient() .target(RequestCycle.get().getUrlRenderer().renderFullUrl(Url.parse( UrlUtils.rewriteToContextRelative("saml2sp/metadata", RequestCycle.get())))) .request().get()); ResourceStreamRequestHandler rsrh = new ResourceStreamRequestHandler(stream); rsrh.setFileName(stream.getFilename() == null ? SyncopeConsoleSession.get().getDomain() + "-SAML-SP-Metadata.xml" : stream.getFilename()); rsrh.setContentDisposition(ContentDisposition.ATTACHMENT); getRequestCycle().scheduleRequestHandlerAfterCurrent(rsrh); } catch (Exception e) { LOG.error("While exporting SAML 2.0 SP metadata", e); SyncopeConsoleSession.get().error(getString(Constants.ERROR) + ": " + e.getMessage()); } } }); }