Java Code Examples for org.apache.wicket.request.resource.IResource

The following examples show how to use org.apache.wicket.request.resource.IResource. These examples are extracted from open source projects. 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 Project: yes-cart   Source File: WicketResourceMounterImpl.java    License: Apache License 2.0 6 votes vote down vote up
/** {@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 2
@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 Project: syncope   Source File: ImageModalPanel.java    License: Apache License 2.0 6 votes vote down vote up
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 4
Source Project: onedev   Source File: CssConcatResourceBundleReference.java    License: MIT License 5 votes vote down vote up
@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 5
Source Project: onedev   Source File: JavaScriptConcatResourceBundleReference.java    License: MIT License 5 votes vote down vote up
@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 6
@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 7
Source Project: webanno   Source File: EmbeddableImage.java    License: Apache License 2.0 5 votes vote down vote up
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 8
/**
 * 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 9
Source Project: syncope   Source File: BinaryPDFPreviewer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected byte[] getImageData(final IResource.Attributes attributes) {
    if (thumbnail == null) {
        thumbnail = toImageData(getScaledImageInstance());
        setLastModifiedTime(Instant.now());
    }
    return thumbnail;
}
 
Example 10
Source Project: syncope   Source File: BinaryImagePreviewer.java    License: Apache License 2.0 5 votes vote down vote up
@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 11
/**
 * 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 12
Source Project: Orienteer   Source File: OMetricsResource.java    License: Apache License 2.0 5 votes vote down vote up
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 13
Source Project: Orienteer   Source File: BirtImage.java    License: Apache License 2.0 5 votes vote down vote up
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 14
Source Project: Orienteer   Source File: AbstractBirtReportPanel.java    License: Apache License 2.0 5 votes vote down vote up
@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 15
Source Project: Orienteer   Source File: OContentShareResource.java    License: Apache License 2.0 5 votes vote down vote up
private WriteCallback createWriteCallback(byte [] data) {
    return new WriteCallback() {
        @Override
        public void writeData(IResource.Attributes attributes) throws IOException {
            attributes.getResponse().write(data);
        }
    };
}
 
Example 16
Source Project: Orienteer   Source File: OrienteerWebApplication.java    License: Apache License 2.0 5 votes vote down vote up
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 17
Source Project: Orienteer   Source File: ExportCommand.java    License: Apache License 2.0 5 votes vote down vote up
@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 18
Source Project: nextreports-server   Source File: OpenFlashChart.java    License: Apache License 2.0 5 votes vote down vote up
@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 Project: onedev   Source File: MarkdownReportDownloadResourceReference.java    License: MIT License 4 votes vote down vote up
@Override
public IResource getResource() {
	return new MarkdownReportDownloadResource();
}
 
Example 20
Source Project: onedev   Source File: HtmlReportDownloadResourceReference.java    License: MIT License 4 votes vote down vote up
@Override
public IResource getResource() {
	return new HtmlReportDownloadResource();
}
 
Example 21
Source Project: onedev   Source File: ArchiveDownloadResourceReference.java    License: MIT License 4 votes vote down vote up
@Override
public IResource getResource() {
	return new ArchiveDownloadResource();
}
 
Example 22
Source Project: onedev   Source File: ServerLogDownloadResourceReference.java    License: MIT License 4 votes vote down vote up
@Override
public IResource getResource() {
	return new ServerLogDownloadResource();
}
 
Example 23
Source Project: onedev   Source File: ArtifactDownloadResourceReference.java    License: MIT License 4 votes vote down vote up
@Override
public IResource getResource() {
	return new ArtifactDownloadResource();
}
 
Example 24
Source Project: onedev   Source File: BuildLogDownloadResourceReference.java    License: MIT License 4 votes vote down vote up
@Override
public IResource getResource() {
	return new BuildLogDownloadResource();
}
 
Example 25
Source Project: onedev   Source File: RawBlobDownloadResourceReference.java    License: MIT License 4 votes vote down vote up
@Override
public IResource getResource() {
	return new RawBlobDownloadResource();
}
 
Example 26
Source Project: onedev   Source File: AttachmentDownloadResourceReference.java    License: MIT License 4 votes vote down vote up
@Override
public IResource getResource() {
	return new AttachmentDownloadResource();
}
 
Example 27
Source Project: onedev   Source File: TopContributorsResourceReference.java    License: MIT License 4 votes vote down vote up
@Override
public IResource getResource() {
	return new TopContributorsResource();
}
 
Example 28
Source Project: onedev   Source File: LastCommitsResourceReference.java    License: MIT License 4 votes vote down vote up
@Override
public IResource getResource() {
	return new LastCommitsResource();
}
 
Example 29
@Override
public boolean isResourceAuthorized(IResource resource, PageParameters parameters) {
    return true;
}
 
Example 30
Source Project: openmeetings   Source File: GroupLogoResourceReference.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public IResource getResource() {
	return new FileSystemResource() {
		private static final long serialVersionUID = 1L;

		@Override
		protected String getMimeType() throws IOException {
			return PNG_MIME_TYPE;
		}

		@Override
		protected ResourceResponse newResourceResponse(Attributes attrs) {
			Long id = null;
			boolean allowed = false;
			WebSession ws = WebSession.get();
			if (ws.isSignedIn()) {
				PageParameters params = attrs.getParameters();
				StringValue _id = params.get("id");
				try {
					id = _id.toOptionalLong();
				} catch (Exception e) {
					//no-op expected
				}
				allowed = id == null || hasAdminLevel(getRights()) || null != groupUserDao.getByGroupAndUser(id, getUserId());
				if (!allowed && ws.getInvitation() != null) {
					Room r = ws.getInvitation().getRoom() == null ? null : roomDao.get(ws.getInvitation().getRoom().getId());
					if (r != null && r.getGroups() != null) {
						for (RoomGroup rg : r.getGroups()) {
							if (id.equals(rg.getGroup().getId())) {
								allowed = true;
								break;
							}
						}
					}
				}
			}
			if (allowed) {
				return createResourceResponse(attrs, getGroupLogo(id, true).toPath());
			} else {
				log.debug("Not authorized");
				ResourceResponse rr = new ResourceResponse();
				rr.setError(HttpServletResponse.SC_FORBIDDEN);
				return rr;
			}
		}
	};
}