List of usage examples for org.apache.wicket.util.resource IResourceStream length
Bytes length();
From source file:org.hippoecm.frontend.plugins.console.editor.BinaryEditor.java
License:Apache License
public BinaryEditor(String id, JcrPropertyModel model, final IPluginContext pluginContext) { super(id, model); final IResourceStream stream = new BinaryResourceStream(model); // download//from w w w . j av a2 s . com final ResourceStreamResource resource = new ResourceStreamResource(stream); resource.setCacheDuration(Duration.NONE); try { final Node node = model.getProperty().getParent().getParent(); final StringBuilder fileName = new StringBuilder(node.getName()); if (isExtractedTextProperty(model.getProperty())) { fileName.append(".txt"); } resource.setFileName(fileName.toString()); } catch (RepositoryException e) { log.error("Unexpected exception while determining download filename", e); } final Link downloadLink = new ResourceLink("binary-download-lnk", resource); downloadLink.add(new Label("binary-download-text", "download (" + getSizeString(stream.length()) + ")")); add(downloadLink); // upload IDialogFactory factory = new IDialogFactory() { private static final long serialVersionUID = 1L; public IDialogService.Dialog createDialog() { return new BinaryUploadDialog(model); } }; final IDialogService service = pluginContext.getService(IDialogService.class.getName(), IDialogService.class); final DialogLink uploadLink = new DialogLink("binary-upload-link", new Model<>("Upload binary"), factory, service); add(uploadLink); // Jackrabbit Binary Content Identifier if this Binary is in BinaryStore. final Label contentIdentityValueLabel = new Label("content-identity-value", new PropertyModel<String>(this, "contentIdentity")); contentIdentityValueLabel.setOutputMarkupPlaceholderTag(true); contentIdentityValueLabel.setVisible(false); add(contentIdentityValueLabel); final AjaxLink contentIdentityShowLink = new AjaxLink("content-identity-show-link") { @Override public void onClick(AjaxRequestTarget target) { setContentIdentity(retrieveJackrabbitContentIdentity()); target.add(contentIdentityValueLabel.setVisible(true)); target.add(this.setVisible(false)); } }; add(contentIdentityShowLink); }
From source file:org.wicketstuff.html5.image.CanvasImage.java
License:Apache License
/** * Renders the complete image tag with the base64 encoded content. */// ww w . j a v a 2 s . com @Override protected void onComponentTag(ComponentTag tag) { checkComponentTag(tag, "img"); super.onComponentTag(tag); IResourceStream packageResourceStream = packageResourceReference.getResource().getResourceStream(); if (packageResourceStream != null) { try { StringBuilder builder = new StringBuilder(); builder.append("data:"); builder.append(packageResourceStream.getContentType()); builder.append(";base64,"); byte[] bytes = new byte[(int) packageResourceStream.length().bytes()]; DataInputStream dataInputStream = new DataInputStream(packageResourceStream.getInputStream()); dataInputStream.readFully(bytes); builder.append(Base64.encodeBase64String(bytes)); tag.put("src", builder.toString()); } catch (Exception e) { throw new WicketRuntimeException("An error occured while reading the package resource stream", e); } } else { // If the package resource stream is not set create an empty image tag.put("src", "#"); tag.put("style", "display:none;"); } }