Example usage for org.apache.wicket.request.resource ByteArrayResource ByteArrayResource

List of usage examples for org.apache.wicket.request.resource ByteArrayResource ByteArrayResource

Introduction

In this page you can find the example usage for org.apache.wicket.request.resource ByteArrayResource ByteArrayResource.

Prototype

public ByteArrayResource(final String contentType) 

Source Link

Document

Creates a ByteArrayResource which will provide its data dynamically with #getData(org.apache.wicket.request.resource.IResource.Attributes)

Usage

From source file:de.inren.frontend.health.backup.BackupRestorePanel.java

License:Apache License

private Component getMyBackupLink(String id) {
    Calendar cal = Calendar.getInstance();

    final String key = "HealthBackup_" + getUser().getUsername() + "_" + cal.getTime().toString() + ".xml";

    ResourceReference rr = new ResourceReference(key) {

        @Override// ww  w. j av a2  s .  co m
        public IResource getResource() {
            return new ByteArrayResource("text/xml") {

                @Override
                protected byte[] getData(Attributes attributes) {
                    try {
                        String xml = healthXmlBackupRestoreService.dumpDbToXml(getUser().getUsername());
                        return xml.getBytes("UTF-8");
                    } catch (Exception e) {
                        log.error(e.getMessage(), e);
                        throw new RuntimeException(e.getMessage());
                    }
                }
            };
        }
    };
    return new ResourceLink(id, rr);
}

From source file:de.inren.frontend.health.backup.BackupRestorePanel.java

License:Apache License

private Component getAllBackupLink(String id) {
    Calendar cal = Calendar.getInstance();

    final String key = "HealthBackup_AllUser" + "_" + cal.getTime().toString() + ".xml";

    ResourceReference rr = new ResourceReference(key) {

        @Override/*from  w  ww  .j  av a2  s  .  c om*/
        public IResource getResource() {
            return new ByteArrayResource("text/xml") {

                @Override
                protected byte[] getData(Attributes attributes) {
                    try {
                        String xml = healthXmlBackupRestoreService.dumpDbToXml();
                        return xml.getBytes("UTF-8");
                    } catch (Exception e) {
                        log.error(e.getMessage(), e);
                        throw new RuntimeException(e.getMessage());
                    }
                }
            };
        }
    };
    return new ResourceLink(id, rr);
}

From source file:org.apache.openmeetings.web.user.rooms.RoomsPanel.java

License:Apache License

public RoomsPanel(String id, List<Room> rooms) {
    super(id);//from www.  j av  a  2 s.c o m
    add(new RoomListPanel("list", rooms, Application.getString(131)) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onContainerClick(AjaxRequestTarget target, Room r) {
            roomId = r.getId();
            updateRoomDetails(target);
        }

        @Override
        public void onRefreshClick(AjaxRequestTarget target, Room r) {
            super.onRefreshClick(target, r);
            roomId = r.getId();
            updateRoomDetails(target);
        }
    });

    // Users in this Room
    add(details.setOutputMarkupId(true).setVisible(rooms.size() > 0));
    details.add(new Label("roomId", roomID));
    details.add(new Label("roomName", roomName));
    details.add(new Label("roomComment", roomComment));
    clients = new ListView<Client>("clients", clientsInRoom) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem<Client> item) {
            Client client = item.getModelObject();
            final Long userId = client.getUserId();
            item.add(new Image("clientImage", new ByteArrayResource("image/jpeg") {
                private static final long serialVersionUID = 1L;

                @Override
                protected ResourceResponse newResourceResponse(Attributes attributes) {
                    ResourceResponse rr = super.newResourceResponse(attributes);
                    rr.disableCaching();
                    return rr;
                }

                @Override
                protected byte[] getData(Attributes attributes) {
                    String uri = null;
                    if (userId != null) {
                        uri = Application.getBean(UserDao.class).get(userId > 0 ? userId : -userId)
                                .getPictureuri();
                    }
                    File img = OmFileHelper.getUserProfilePicture(userId, uri);
                    try (InputStream is = new FileInputStream(img)) {
                        return IOUtils.toByteArray(is);
                    } catch (Exception e) {
                        //no-op
                    }
                    return null;
                }
            }));
            item.add(new Label("clientLogin", client.getUsername()));
            item.add(new Label("from", client.getConnectedSince()));
        }
    };
    details.add(clientsContainer.add(clients.setOutputMarkupId(true)).setOutputMarkupId(true));
}

From source file:org.apache.openmeetings.web.util.ProfileImageResourceReference.java

License:Apache License

@Override
public IResource getResource() {
    return new ByteArrayResource("image/jpeg") {
        private static final long serialVersionUID = 1L;
        private Long userId = null;
        private String uri = null;

        @Override/* w w  w  .j  a  va 2s  .c o m*/
        protected ResourceResponse newResourceResponse(Attributes attributes) {
            PageParameters params = attributes.getParameters();
            userId = params.get("id").toOptionalLong();
            uri = getBean(UserDao.class).get(userId).getPictureuri();
            ResourceResponse rr = super.newResourceResponse(attributes);
            rr.disableCaching();
            return rr;
        }

        @Override
        protected byte[] getData(Attributes attributes) {
            if (!isAbsolute(uri)) {
                File img = OmFileHelper.getUserProfilePicture(userId, uri);
                try (InputStream is = new FileInputStream(img)) {
                    return IOUtils.toByteArray(is);
                } catch (Exception e) {
                    log.error("failed to get bytes from image", e);
                }
            }
            return null;
        }
    };
}