org.apache.wicket.util.resource.IResourceStream Java Examples

The following examples show how to use org.apache.wicket.util.resource.IResourceStream. 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: ExportJson.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
public IResourceStream createResourceStreamWriter()
{
  final IResourceStream iResourceStream = new AbstractResourceStreamWriter() {
    private static final long serialVersionUID = 7780552906708508709L;

    @Override
    public String getContentType()
    {
      return "application/json";
    }

    @Override
    public void write(final OutputStream output)
    {
      try {
        IOUtils.write(new Gson().toJson(result), output);
      } catch (IOException ex) {
        log.error("Exception encountered " + ex, ex);
      }
    }
  };
  return iResourceStream;
}
 
Example #2
Source File: ExportZipArchive.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
public IResourceStream createResourceStreamWriter()
{
  final IResourceStream iResourceStream = new AbstractResourceStreamWriter() {
    private static final long serialVersionUID = 7780552906708508709L;

    @Override
    public String getContentType()
    {
      return "application/zip";
    }

    @Override
    public void write(final OutputStream output)
    {
      ExportZipArchive.this.write(output);
    }
  };
  return iResourceStream;
}
 
Example #3
Source File: SassResourceStream.java    From webanno with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor.
 *
 * @param sassStream
 *            The resource stream that loads the Sass content. Only UrlResourceStream is
 *            supported at the moment!
 * @param scopeClass
 *            The name of the class used as a scope to resolve "package!" dependencies/imports
 */
public SassResourceStream(IResourceStream sassStream, String scopeClass)
{
    Args.notNull(sassStream, "sassStream");

    while (sassStream instanceof ResourceStreamWrapper) {
        ResourceStreamWrapper wrapper = (ResourceStreamWrapper) sassStream;
        try {
            sassStream = wrapper.getDelegate();
        }
        catch (Exception x) {
            throw new WicketRuntimeException(x);
        }
    }

    if (!(sassStream instanceof UrlResourceStream)) {
        throw new IllegalArgumentException(String.format("%s can work only with %s",
                SassResourceStream.class.getSimpleName(), UrlResourceStream.class.getName()));
    }

    URL sassUrl = ((UrlResourceStream) sassStream).getURL();

    SassCacheManager cacheManager = SassCacheManager.get();

    this.sassSource = cacheManager.getSassContext(sassUrl, scopeClass);
}
 
Example #4
Source File: LayerDetailForm.java    From webanno with Apache License 2.0 6 votes vote down vote up
private IResourceStream exportUimaTypeSystem()
{
    try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
        TypeSystemDescription tsd = annotationService
                .getAllProjectTypes(getModelObject().getProject());
        tsd.toXML(bos);
        return new InputStreamResourceStream(new ByteArrayInputStream(bos.toByteArray()));
    }
    catch (Exception e) {
        error("Unable to generate the UIMA type system file: "
                + ExceptionUtils.getRootCauseMessage(e));
        ProjectLayersPanel.LOG.error("Unable to generate the UIMA type system file", e);
        RequestCycle.get().find(IPartialPageRequestHandler.class)
                .ifPresent(handler -> handler.addChildren(getPage(), IFeedback.class));
        return null;
    }
}
 
Example #5
Source File: LayerDetailForm.java    From webanno with Apache License 2.0 5 votes vote down vote up
private IResourceStream exportLayerJson()
{
    try {
        AnnotationLayer layer = getModelObject();

        List<ExportedAnnotationLayer> exLayers = new ArrayList<>();

        ExportedAnnotationLayer exMainLayer = ImportUtil.exportLayerDetails(null, null,
                layer, annotationService);
        exLayers.add(exMainLayer);

        // If the layer is attached to another layer, then we also have to export
        // that, otherwise we would be missing it during re-import.
        if (layer.getAttachType() != null) {
            AnnotationLayer attachLayer = layer.getAttachType();
            ExportedAnnotationLayer exAttachLayer = ImportUtil.exportLayerDetails(null,
                    null, attachLayer, annotationService);
            exMainLayer.setAttachType(
                    new ExportedAnnotationLayerReference(exAttachLayer.getName()));
            exLayers.add(exAttachLayer);
        }

        return new InputStreamResourceStream(new ByteArrayInputStream(
                JSONUtil.toPrettyJsonString(exLayers).getBytes("UTF-8")));
    }
    catch (Exception e) {
        error("Unable to generate the JSON file: " + ExceptionUtils.getRootCauseMessage(e));
        ProjectLayersPanel.LOG.error("Unable to generate the JSON file", e);
        RequestCycle.get().find(IPartialPageRequestHandler.class)
                .ifPresent(handler -> handler.addChildren(getPage(), IFeedback.class));
        return null;
    }
}
 
Example #6
Source File: SiteStatsApplication.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public IResourceStream locate(final Class clazz, final String path) {
	IResourceStream located = super.locate(clazz, trimFolders(path));
	if(located != null){
		return located;
	}
	return super.locate(clazz, path);
}
 
Example #7
Source File: SiteStatsApplication.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public IResourceStream locate(final Class clazz, final String path) {
	IResourceStream located = super.locate(clazz, trimFolders(path));
	if(located != null){
		return located;
	}
	return super.locate(clazz, path);
}
 
Example #8
Source File: PageDelegate.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
public IResourceStream getMarkupResourceStream(MarkupContainer container,
		Class<?> containerClass, String wrapTag) {
	if(container.getClass().equals(containerClass)) {
		return new OPageResourceStream(pageDocumentModel.getObject(), wrapTag);
	} else {
		return DEFAULT_MARKUP_PROVIDER.getMarkupResourceStream(container, containerClass);
	}
}
 
Example #9
Source File: AjaxDownloadLink.java    From webanno with Apache License 2.0 5 votes vote down vote up
void commonInit()
{
    downloadBehavior = new AbstractAjaxBehavior()
    {
        private static final long serialVersionUID = 3472918725573624819L;

        @Override
        public void onRequest()
        {
            IResourceStream is = AjaxDownloadLink.this.getModelObject();
            
            if (is != null) {
                // If no filename has been set explicitly, try to get it from the resource
                String name = filename != null ? filename.getObject() : null;
                if (name == null) {
                    if (is instanceof FileResourceStream) {
                        name = ((FileResourceStream) is).getFile().getName();
                    }
                    else if (is instanceof FileSystemResourceStream) {
                        name = ((FileSystemResourceStream) is).getPath().getFileName()
                                .toString();
                    }
                }
                
                ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(
                        AjaxDownloadLink.this.getModelObject(), name);
                handler.setContentDisposition(ContentDisposition.ATTACHMENT);
                getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(handler);
            }
        }
    };
    add(downloadBehavior);
}
 
Example #10
Source File: ExportCommand.java    From Orienteer with 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 #11
Source File: LayerDetailForm.java    From webanno with Apache License 2.0 5 votes vote down vote up
private IResourceStream exportLayer()
{
    switch (exportMode) {
    case JSON:
        return exportLayerJson();
    case UIMA:
        return exportUimaTypeSystem();
    default:
        throw new IllegalStateException("Unknown mode: [" + exportMode + "]");
    }
}
 
Example #12
Source File: GuidelinesDialogContent.java    From webanno with Apache License 2.0 5 votes vote down vote up
public GuidelinesDialogContent(String aId, final ModalWindow modalWindow,
        final IModel<AnnotatorState> aModel)
{
    super(aId);

    // Overall progress by Projects
    RepeatingView guidelineRepeater = new RepeatingView("guidelineRepeater");
    add(guidelineRepeater);
    
    for (String guidelineFileName : projectService
            .listGuidelines(aModel.getObject().getProject())) {
        AbstractItem item = new AbstractItem(guidelineRepeater.newChildId());

        guidelineRepeater.add(item);

        // Add a popup window link to display annotation guidelines
        PopupSettings popupSettings = new PopupSettings(RESIZABLE | SCROLLBARS)
                        .setHeight(500)
                        .setWidth(700);

        IResourceStream stream = new FileResourceStream(projectService
                .getGuideline(aModel.getObject().getProject(), guidelineFileName));
        ResourceStreamResource resource = new ResourceStreamResource(stream);
        ResourceLink<Void> rlink = new ResourceLink<>("guideine", resource);
        rlink.setPopupSettings(popupSettings);
        item.add(new Label("guidelineName", guidelineFileName));
        item.add(rlink);
    }
    
    add(new LambdaAjaxLink("cancel", (target) -> modalWindow.close(target)));
}
 
Example #13
Source File: ChatToolbar.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
@Override
protected IResourceStream getResourceStream(Attributes attributes) {
	final boolean admin = hasAdminLevel(getRights());
	final StringBuilder sb = new StringBuilder();
	chatForm.process(
			() -> {
				if (admin) {
					setFileName(String.format(CHAT_FNAME_TMPL, "global"));
					export(chatDao.getGlobal(0, Integer.MAX_VALUE), sb);
				}
				return true;
			}
			, r -> {
				if (admin || isModerator(cm, getUserId(), r.getId())) {
					setFileName(String.format(CHAT_FNAME_TMPL, "room_" + r.getId()));
					export(chatDao.getRoom(r.getId(), 0, Integer.MAX_VALUE, true), sb);
				}
				return true;
			}, u -> {
				setFileName(String.format(CHAT_FNAME_TMPL, "user_" + u.getId()));
				export(chatDao.getUser(u.getId(), 0, Integer.MAX_VALUE), sb);
				return true;
			});
	StringResourceStream srs = new StringResourceStream(sb, "text/csv");
	srs.setCharset(UTF_8);
	return srs;
}
 
Example #14
Source File: JavaScriptConcatResourceBundleReference.java    From onedev with 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 #15
Source File: CssConcatResourceBundleReference.java    From onedev with 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 #16
Source File: DownloadUtils.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
public static void setDownloadTarget(final String filename, final IResourceStream resourceStream)
{
  final ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(resourceStream);
  handler.setFileName(filename).setContentDisposition(ContentDisposition.ATTACHMENT);
  RequestCycle.get().scheduleRequestHandlerAfterCurrent(handler);
  log.info("Starting download for file. filename:" + filename + ", content-type:" + resourceStream.getContentType());
}
 
Example #17
Source File: PairwiseCodingAgreementTable.java    From webanno with Apache License 2.0 4 votes vote down vote up
private Behavior makeDownloadBehavior(final String aKey1, final String aKey2)
{
    return new AjaxEventBehavior("click")
    {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onEvent(AjaxRequestTarget aTarget)
        {
            AJAXDownload download = new AJAXDownload() {
                private static final long serialVersionUID = 1L;
                
                @Override
                protected IResourceStream getResourceStream()
                {
                    return new AbstractResourceStream() {
                        private static final long serialVersionUID = 1L;

                        @Override
                        public InputStream getInputStream()
                            throws ResourceStreamNotFoundException
                        {
                            try {
                                CodingAgreementResult result = PairwiseCodingAgreementTable.this
                                        .getModelObject().getStudy(aKey1, aKey2);
                                
                                switch (formatField.getModelObject()) {
                                case CSV:
                                    return AgreementUtils.generateCsvReport(result);
                                case DEBUG:
                                    return generateDebugReport(result);
                                default:
                                    throw new IllegalStateException("Unknown export format ["
                                            + formatField.getModelObject() + "]");
                                }
                            }
                            catch (Exception e) {
                                // FIXME Is there some better error handling here?
                                LOG.error("Unable to generate agreement report", e);
                                throw new ResourceStreamNotFoundException(e);
                            }
                        }

                        @Override
                        public void close()
                            throws IOException
                        {
                            // Nothing to do
                        }
                    };
                }
            };
            getComponent().add(download);
            download.initiate(aTarget,
                    "agreement" + formatField.getModelObject().getExtension());
        }
    };      
}
 
Example #18
Source File: EmbeddedWebPage.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@Override
public IResourceStream getMarkupResourceStream(MarkupContainer container,
		Class<?> containerClass) {
	return delegate.getMarkupResourceStream(container, containerClass, "wicket:extend");
}
 
Example #19
Source File: FullWebPage.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@Override
public IResourceStream getMarkupResourceStream(MarkupContainer container,
		Class<?> containerClass) {
	return delegate.getMarkupResourceStream(container, containerClass);
}
 
Example #20
Source File: LessResourceReference.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
@Override
public IResourceStream getResourceStream()
{
  return new FileResourceStream(file);
}
 
Example #21
Source File: PageDelegate.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@Override
public IResourceStream getMarkupResourceStream(MarkupContainer container,
		Class<?> containerClass) {
	return getMarkupResourceStream(container, containerClass, null);
}
 
Example #22
Source File: TestPage.java    From syncope with Apache License 2.0 4 votes vote down vote up
@Override
public IResourceStream getMarkupResourceStream(final MarkupContainer container,
        final Class<?> containerClass) {
    return new StringResourceStream("<html><body>"
            + "<form wicket:id=\"form\"><span wicket:id=\"field\"></span></form></body></html>");
}
 
Example #23
Source File: OccurrenceWebResource.java    From ontopia with Apache License 2.0 4 votes vote down vote up
public static final IResourceStream getResourceStream(OccurrenceIF occ)  {
  if (occ == null) return null;
  Reader reader = occ.getReader();
  return (reader == null ? null : new Base64EncodedResourceStream(reader));
}
 
Example #24
Source File: OccurrenceWebResource.java    From ontopia with Apache License 2.0 4 votes vote down vote up
@Override
public IResourceStream getResourceStream() {
  Reader reader = getReader();
  return (reader == null ? null : new Base64EncodedResourceStream(reader));
}
 
Example #25
Source File: OccurrenceImageRequestTargetUrlCodingStrategy.java    From ontopia with Apache License 2.0 4 votes vote down vote up
public OccurrenceResourceStreamRequestTarget(IResourceStream resourceStream, String topicMapId, String occurrenceId) {
  super(resourceStream);
  this.topicMapId = topicMapId;
  this.occurrenceId = occurrenceId;
}
 
Example #26
Source File: PairwiseCodingAgreementTable.java    From webanno with Apache License 2.0 4 votes vote down vote up
private IResourceStream exportAllAgreements()
    {
        return new AbstractResourceStream()
        {
            private static final long serialVersionUID = 1L;

            @Override
            public InputStream getInputStream()
                throws ResourceStreamNotFoundException
            {
                AnnotationFeature feature = getModelObject().getFeature();
                DefaultAgreementTraits traits = getModelObject().getTraits();
                
                Map<String, List<CAS>> casMap = casMapSupplier.get();

                List<DiffAdapter> adapters = CasDiff.getDiffAdapters(annotationService,
                        asList(feature.getLayer()));

                CasDiff diff = doDiff(adapters, traits.getLinkCompareBehavior(), casMap);

//                AgreementResult agreementResult = AgreementUtils.makeStudy(diff,
//                        feature.getLayer().getName(), feature.getName(),
//                        pref.excludeIncomplete, casMap);
                // TODO: for the moment, we always include incomplete annotations during this
                // export.
                CodingAgreementResult agreementResult = makeCodingStudy(diff,
                        feature.getLayer().getName(), feature.getName(), false, casMap);
                
                try {
                    return AgreementUtils.generateCsvReport(agreementResult);
                }
                catch (Exception e) {
                    // FIXME Is there some better error handling here?
                    LOG.error("Unable to generate report", e);
                    throw new ResourceStreamNotFoundException(e);
                }
            }

            @Override
            public void close()
                throws IOException
            {
                // Nothing to do
            }
        };
    }
 
Example #27
Source File: AjaxDownloadLink.java    From webanno with Apache License 2.0 4 votes vote down vote up
public AjaxDownloadLink(String aId, IModel<String> aFilename, IModel<IResourceStream> aData)
{
    super(aId, aData);
    filename = aFilename;
    commonInit();
}
 
Example #28
Source File: AjaxDownloadLink.java    From webanno with Apache License 2.0 4 votes vote down vote up
public AjaxDownloadLink(String aId, IModel<IResourceStream> aData)
{
    super(aId, aData);
    filename = null;
    commonInit();
}
 
Example #29
Source File: SassPackageResource.java    From webanno with Apache License 2.0 4 votes vote down vote up
@Override
public IResourceStream getResourceStream()
{
    IResourceStream resourceStream = super.getResourceStream();
    return new SassResourceStream(resourceStream, getScope().getName());
}
 
Example #30
Source File: StorefrontApplication.java    From yes-cart with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public IResourceStream find(final Class<?> aClass, final String s) {
    return configureMultiWebApplicationPath().find(aClass, s);
}