org.apache.wicket.request.resource.IResource Java Examples
The following examples show how to use
org.apache.wicket.request.resource.IResource.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImageModalPanel.java From syncope with Apache License 2.0 | 6 votes |
public ImageModalPanel(final BaseModal<T> modal, final byte[] content, final PageReference pageRef) { super(modal, pageRef); Image image = new Image("image", new Model<IResource>()) { private static final long serialVersionUID = -8457850449086490660L; @Override protected IResource getImageResource() { return new DynamicImageResource() { private static final long serialVersionUID = 923201517955737928L; @Override protected byte[] getImageData(final IResource.Attributes attributes) { return content; } }; } }; image.setOutputMarkupId(true); add(image); }
Example #2
Source File: OrientResourceAuthorizationStrategy.java From wicket-orientdb with Apache License 2.0 | 6 votes |
@Override public boolean isResourceAuthorized(IResource resource, PageParameters parameters) { RequiredOrientResource[] resources = getRequiredOrientResources(resource.getClass()); if(resources!=null) { if(!checkResources(resources, Component.RENDER)) return false; } if(resource instanceof ISecuredComponent) { resources = ((ISecuredComponent)resource).getRequiredResources(); if(resources!=null) { if(!checkResources(resources, Component.RENDER)) return false; } } return true; }
Example #3
Source File: WicketResourceMounterImpl.java From yes-cart with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public void mountResources(final WebApplication webApplication) { if (resources != null) { for (final Map.Entry<String, IResource> resource : resources.entrySet()) { final String key = resource.getKey(); final IResource source = resource.getValue(); LOG.info("Mounting url '/{}' to resource '{}'", key, source.getClass().getCanonicalName()); webApplication.mountResource("/" + key, new ResourceReference(key){ @Override public IResource getResource() { return source; } }); } } }
Example #4
Source File: BirtImage.java From Orienteer with Apache License 2.0 | 5 votes |
public IResource toResource() { try { if(source == IImage.URL_IMAGE) { return new ResourceStreamResource(new UrlResourceStream(new URL(getID()))); } else if (source == IImage.FILE_IMAGE) { return new FileSystemResource( Paths.get(FileUtil.getURI(getID()))); } else { return new ByteArrayResource(getMIMEType(), data); } } catch (MalformedURLException e) { throw new WicketRuntimeException("Can't transform to resource", e); } }
Example #5
Source File: AbstractBirtReportPanel.java From Orienteer with Apache License 2.0 | 5 votes |
@Override public void onRequest() { RequestCycle requestCycle = RequestCycle.get(); IRequestParameters params = requestCycle.getRequest().getRequestParameters(); String imageId = params.getParameterValue(RESOURCE_IMAGE_ID).toOptionalString(); if(imageId!=null) { IResource resource = imageHandler.getBirtImageAsResource(imageId); if(resource!=null) { resource.respond(new Attributes(requestCycle.getRequest(), requestCycle.getResponse(), null)); } } }
Example #6
Source File: OMetricsResource.java From Orienteer with Apache License 2.0 | 5 votes |
private WriteCallback createWriteCallback(CollectorRegistry registry, Set<String> metrics) { return new WriteCallback() { @Override public void writeData(IResource.Attributes attributes) throws IOException { try(OutputStreamWriter writer = new OutputStreamWriter(attributes.getResponse().getOutputStream(), "UTF8")) { TextFormat.write004(writer, registry.filteredMetricFamilySamples(metrics)); writer.flush(); } } }; }
Example #7
Source File: GalleryImageRenderer.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Creates a new instance of <code>GalleryImageRenderer</code>. */ public GalleryImageRenderer(String id, String imageResourceId) { super(id); if (imageResourceId == null) { add(new ContextImage("img",new Model(ProfileConstants.UNAVAILABLE_IMAGE))); return; } else if (sakaiProxy.getResource(imageResourceId) == null) { // may have been deleted in CHS add(new ContextImage("img",new Model(ProfileConstants.UNAVAILABLE_IMAGE))); return; } final byte[] imageBytes = sakaiProxy.getResource(imageResourceId).getBytes(); if (imageBytes != null && imageBytes.length > 0) { BufferedDynamicImageResource imageResource = new BufferedDynamicImageResource() { private static final long serialVersionUID = 1L; @Override protected byte[] getImageData(IResource.Attributes ignored) { return imageBytes; } }; Image myPic = new Image("img", new Model(imageResource)); myPic.add(new AttributeModifier("alt", new StringResourceModel("profile.gallery.image.alt",this,null).getString())); add(myPic); } else { add(new ContextImage("img",new Model(ProfileConstants.UNAVAILABLE_IMAGE))); } }
Example #8
Source File: BinaryImagePreviewer.java From syncope with Apache License 2.0 | 5 votes |
@Override public Component preview(final byte[] uploadedBytes) { return this.addOrReplace( new NonCachingImage("previewImage", new ThumbnailImageResource(new DynamicImageResource() { private static final long serialVersionUID = 923201517955737928L; @Override protected byte[] getImageData(final IResource.Attributes attributes) { return uploadedBytes; } }, IMG_SIZE))); }
Example #9
Source File: BinaryPDFPreviewer.java From syncope with Apache License 2.0 | 5 votes |
@Override protected byte[] getImageData(final IResource.Attributes attributes) { if (thumbnail == null) { thumbnail = toImageData(getScaledImageInstance()); setLastModifiedTime(Instant.now()); } return thumbnail; }
Example #10
Source File: GalleryImageRenderer.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Creates a new instance of <code>GalleryImageRenderer</code>. */ public GalleryImageRenderer(String id, String imageResourceId) { super(id); if (imageResourceId == null) { add(new ContextImage("img",new Model(ProfileConstants.UNAVAILABLE_IMAGE))); return; } else if (sakaiProxy.getResource(imageResourceId) == null) { // may have been deleted in CHS add(new ContextImage("img",new Model(ProfileConstants.UNAVAILABLE_IMAGE))); return; } final byte[] imageBytes = sakaiProxy.getResource(imageResourceId).getBytes(); if (imageBytes != null && imageBytes.length > 0) { BufferedDynamicImageResource imageResource = new BufferedDynamicImageResource() { private static final long serialVersionUID = 1L; @Override protected byte[] getImageData(IResource.Attributes ignored) { return imageBytes; } }; Image myPic = new Image("img", new Model(imageResource)); myPic.add(new AttributeModifier("alt", new StringResourceModel("profile.gallery.image.alt",this,null).getString())); add(myPic); } else { add(new ContextImage("img",new Model(ProfileConstants.UNAVAILABLE_IMAGE))); } }
Example #11
Source File: EmbeddableImage.java From webanno with Apache License 2.0 | 5 votes |
public EmbeddableImage(String aComponentId, IResource aResource) { super(aComponentId); add(new Image("image", aResource) { private static final long serialVersionUID = 1L; @Override protected boolean shouldAddAntiCacheParameter() { return false; } }); }
Example #12
Source File: GroupCustomCssResourceReference.java From openmeetings with Apache License 2.0 | 5 votes |
@Override public IResource getResource() { return new FileSystemResource() { private static final long serialVersionUID = 1L; @Override protected String getMimeType() throws IOException { return "text/css"; } @Override protected ResourceResponse newResourceResponse(Attributes attr) { PageParameters params = attr.getParameters(); StringValue idStr = params.get("id"); Long id = null; try { id = idStr.toOptionalLong(); } catch (NumberFormatException e) { //no-op expected } File file = getGroupCss(id, true); if (file != null) { ResourceResponse rr = createResourceResponse(attr, file.toPath()); rr.setFileName(file.getName()); return rr; } else { log.debug("Custom CSS was not found"); return null; } } }; }
Example #13
Source File: OContentShareResource.java From Orienteer with Apache License 2.0 | 5 votes |
private WriteCallback createWriteCallback(byte [] data) { return new WriteCallback() { @Override public void writeData(IResource.Attributes attributes) throws IOException { attributes.getResponse().write(data); } }; }
Example #14
Source File: OrienteerWebApplication.java From Orienteer with Apache License 2.0 | 5 votes |
private void mountOrUnmountPackage(String packageName, ClassLoader classLoader, boolean mount) { ClassPath classPath; try { classPath = ClassPath.from(classLoader); } catch (IOException e) { throw new WicketRuntimeException("Can't scan classpath", e); } for(ClassInfo classInfo : classPath.getTopLevelClassesRecursive(packageName)) { Class<?> clazz = classInfo.load(); MountPath mountPath = clazz.getAnnotation(MountPath.class); if(mountPath!=null) { if(IRequestablePage.class.isAssignableFrom(clazz)) { Class<? extends IRequestablePage> pageClass = (Class<? extends IRequestablePage>) clazz; forEachOnMountPath(mountPath, path -> { if(mount) { if ("/".equals(path)) { mount(new HomePageMapper(pageClass)); } mount(new MountedMapper(path, pageClass)); } else { unmount(path); } }); } else if(IResource.class.isAssignableFrom(clazz)) { if(mount) { String resourceKey = clazz.getName(); getSharedResources().add(resourceKey, (IResource) getServiceInstance(clazz)); SharedResourceReference reference = new SharedResourceReference(resourceKey); forEachOnMountPath(mountPath, path -> mountResource(path, reference)); } else { forEachOnMountPath(mountPath, this::unmount); } } else { throw new WicketRuntimeException("@"+MountPath.class.getSimpleName()+" should be only on pages or resources"); } } } }
Example #15
Source File: ExportCommand.java From Orienteer with Apache License 2.0 | 5 votes |
@Override protected AbstractLink newLink(String id) { IResource resource = new ResourceStreamResource() { @Override protected IResourceStream getResourceStream(Attributes attrs) { return new DataExportResourceStreamWriter(dataExporter, table); } }.setFileName(fileNameModel.getObject() + "." + dataExporter.getFileNameExtension()); return new ResourceLink<Void>(id, resource); }
Example #16
Source File: JavaScriptConcatResourceBundleReference.java From onedev with MIT License | 5 votes |
@Override public IResource getResource() { ConcatBundleResource bundleResource = new ConcatBundleResource(getProvidedResources()) { @Override protected byte[] readAllResources(List<IResourceStream> resources) throws IOException, ResourceStreamNotFoundException { ByteArrayOutputStream output = new ByteArrayOutputStream(); for (IResourceStream curStream : resources) { IOUtils.copy(curStream.getInputStream(), output); output.write(";\n".getBytes()); } byte[] bytes = output.toByteArray(); if (getCompressor() != null) { String nonCompressed = new String(bytes, "UTF-8"); bytes = getCompressor().compress(nonCompressed).getBytes("UTF-8"); } return bytes; } }; ITextResourceCompressor compressor = getCompressor(); if (compressor != null) { bundleResource.setCompressor(compressor); } return bundleResource; }
Example #17
Source File: CssConcatResourceBundleReference.java From onedev with MIT License | 5 votes |
@Override public IResource getResource() { ConcatBundleResource bundleResource = new ConcatBundleResource(getProvidedResources()) { @Override protected byte[] readAllResources(List<IResourceStream> resources) throws IOException, ResourceStreamNotFoundException { ByteArrayOutputStream output = new ByteArrayOutputStream(); for (IResourceStream curStream : resources) { IOUtils.copy(curStream.getInputStream(), output); output.write("\n".getBytes()); } byte[] bytes = output.toByteArray(); if (getCompressor() != null) { String nonCompressed = new String(bytes, "UTF-8"); bytes = getCompressor().compress(nonCompressed).getBytes("UTF-8"); } return bytes; } }; ITextResourceCompressor compressor = getCompressor(); if (compressor != null) { bundleResource.setCompressor(compressor); } return bundleResource; }
Example #18
Source File: OpenFlashChart.java From nextreports-server with Apache License 2.0 | 5 votes |
@Override public void onResourceRequested() { //System.out.println("OpenFlashChart.onResourceRequested()"); //System.out.println("requestUrl = " + RequestCycle.get().getRequest().getUrl()); //System.out.println("... " + this); IResource jsonResource = createJsonResource(); // IResource.Attributes attrs = new IResource.Attributes(RequestCycle.get().getRequest(), RequestCycle.get().getResponse(), null); // jsonResource.respond(attrs); IRequestHandler requestHandler = new ResourceRequestHandler(jsonResource, null); requestHandler.respond(getRequestCycle()); }
Example #19
Source File: HelloTextReference.java From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public IResource getResource() { return resource; }
Example #20
Source File: OContentShareResource.java From Orienteer with Apache License 2.0 | 4 votes |
@Override protected ResourceResponse newResourceResponse(IResource.Attributes attributes) { final ResourceResponse response = new ResourceResponse(); response.setLastModified(Time.now()); if (response.dataNeedsToBeWritten(attributes)) { PageParameters params = attributes.getParameters(); String ridStr = "#"+params.get("rid").toOptionalString(); ORID orid = ORecordId.isA(ridStr) ? new ORecordId(ridStr) : null; if (orid != null) { String field = params.get("field").toString(); byte [] data = getContent(orid, field); if (data != null && data.length > 0) { String contentType = params.get("type").toOptionalString(); if (Strings.isEmpty(contentType)) { contentType = new Tika().detect(data); } if(isCacheAllowed()) { if(params.get("v").isEmpty()) response.disableCaching(); else response.setCacheDurationToMaximum(); } response.setContentType(contentType); Integer maxSize = params.get("s").toOptionalInteger(); if(maxSize!=null && maxSize>0 && contentType.startsWith("image/")) { double quality = params.get("q").toDouble(0.8); ByteArrayOutputStream thumbnailOS = new ByteArrayOutputStream(); try { Thumbnails.of(new ByteArrayInputStream(data)) .size(maxSize, maxSize) .keepAspectRatio(true) .outputQuality(quality) .toOutputStream(thumbnailOS); data = thumbnailOS.toByteArray(); } catch (IOException e) { LOG.error("Can't create thumbnail. Using original image. ", e); } } response.setWriteCallback(createWriteCallback(data)); } } if (response.getWriteCallback() == null) { response.setError(HttpServletResponse.SC_NOT_FOUND); } } return response; }
Example #21
Source File: HelloDbUpdatesReference.java From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public IResource getResource() { return resource; }
Example #22
Source File: TestModule.java From Orienteer with Apache License 2.0 | 4 votes |
@Test public void testModuleLoaded() throws EngineException, IOException { OrienteerWebApplication app = tester.getApplication(); assertNotNull(app); IOrienteerModule module = app.getModuleByName(Module.MODULE_NAME); assertNotNull(module); assertTrue(module instanceof Module); ClassLoader loader = getClass().getClassLoader(); URL innerResource = loader.getResource("test.rptdesign"); HtmlBirtResource resource = new HtmlBirtResource( new BirtHtmlReportPanel("rp", new BirtReportFileConfig(innerResource.getFile()) ) ); MockWebRequest request = new MockWebRequest(new Url()); ByteArrayResponse response = new ByteArrayResponse(); Attributes attributes = new IResource.Attributes(request, response); resource.respond(attributes); String newResult = new String(response.getBytes()); FileInputStream savedStream = new FileInputStream(loader.getResource("test.rptdesign.result.html").getFile()); String oldResult; try { oldResult = IOUtils.toString(savedStream); } finally { savedStream.close(); } assertEquals(oldResult.replace("\r\n", "\n"),newResult.replace("\r\n", "\n")); //ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); //OutputStream stream = response.getOutputStream(); //FileOutputStream out = new FileOutputStream("test.rptdesign.result.html"); //out.write(response.getBytes()); //out.close(); //System.out.println(new String(response.getBytes())); //BirtHtmlReportPanel testedPanel = new BirtHtmlReportPanel("panel", null); }
Example #23
Source File: HelloDbReference.java From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public IResource getResource() { return resource; }
Example #24
Source File: HelloJsonReference.java From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public IResource getResource() { return resource; }
Example #25
Source File: LessResourceReference.java From projectforge-webapp with GNU General Public License v3.0 | 4 votes |
@Override public IResource getResource() { return new LessPackageResource(getName(), file); }
Example #26
Source File: XlsxResourceReference.java From nextreports-server with Apache License 2.0 | 4 votes |
@Override public IResource getResource() { return resource; }
Example #27
Source File: MarkdownReportDownloadResourceReference.java From onedev with MIT License | 4 votes |
@Override public IResource getResource() { return new MarkdownReportDownloadResource(); }
Example #28
Source File: LogoResourceReference.java From nextreports-server with Apache License 2.0 | 4 votes |
@Override public IResource getResource() { return new LogoResource(); }
Example #29
Source File: AbstractBirtHTMLImageHandler.java From Orienteer with Apache License 2.0 | 4 votes |
public IResource getBirtImageAsResource(String id) { BirtImage image = imageMap.get(id); return image!=null?image.toResource():null; }
Example #30
Source File: SpringSecurityAuthorizationStrategy.java From AppStash with Apache License 2.0 | 4 votes |
@Override public boolean isResourceAuthorized(IResource resource, PageParameters parameters) { return true; }