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

The following examples show how to use org.apache.wicket.util.resource.FileResourceStream. 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: ExportDocumentDialogContent.java    From webanno with Apache License 2.0 5 votes vote down vote up
private FileResourceStream export()
{
    File downloadFile = null;
    
    String username;
    
    if (state.getObject().getMode()
            .equals(Mode.AUTOMATION)
            && preferences.getObject().documentType
                    .equals(SELECTEXPORT.AUTOMATED.toString())) {
        username = WebAnnoConst.CORRECTION_USER;
    }
    else {
        username = state.getObject().getUser().getUsername();
    }
    
    try {
        downloadFile = importExportService.exportAnnotationDocument(
                state.getObject().getDocument(), username,
                importExportService.getFormatByName(preferences.getObject().format)
                        .get(),
                state.getObject().getDocument().getName(), state.getObject().getMode());
    }
    catch (Exception e) {
        LOG.error("Export failed", e);
        error("Export failed:" + ExceptionUtils.getRootCauseMessage(e));
        // This will cause the open dialog to pop up again, but at least
        // the error feedback message will be visible. With the 
        // RestartResponseException the feedback message only flashes.
        throw new NonResettingRestartException(getPage().getPageClass());
    }
        
    return new FileResourceStream(downloadFile);
}
 
Example #2
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 #3
Source File: FileSystemResource.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Override
public void respond(Attributes attributes)
{
    FileResourceStream fileResourceStream = new FileResourceStream(file);
    ResourceStreamResource resource = new ResourceStreamResource(fileResourceStream);
    resource.respond(attributes);
}
 
Example #4
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 #5
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);
}