List of usage examples for org.apache.wicket.util.resource ResourceStreamNotFoundException ResourceStreamNotFoundException
public ResourceStreamNotFoundException(final Throwable cause)
From source file:com.googlesource.gerrit.plugins.gitblit.app.GerritGitBlit.java
License:Apache License
@Override public InputStream getResourceAsStream(String file) throws ResourceStreamNotFoundException { String resourceName = "/static/" + file; InputStream is = getClass().getResourceAsStream(resourceName); if (is == null) { throw new ResourceStreamNotFoundException("Cannot access resource " + resourceName + " using class-loader " + getClass().getClassLoader()); }/*from w ww . ja va 2s . co m*/ return is; }
From source file:com.userweave.application.images.ImageResourceStream.java
License:Open Source License
@Override public InputStream getInputStream() throws ResourceStreamNotFoundException { if (inputStream == null) { if (image == null || image.getImageData() == null) { throw new ResourceStreamNotFoundException("Image not found"); }/*from w w w. ja v a 2s . c om*/ inputStream = new ByteArrayInputStream(image.getImageData()); } return inputStream; }
From source file:de.tudarmstadt.ukp.clarin.webanno.monitoring.page.AgreementTable.java
License:Apache License
private Behavior makeDownloadBehavior(final String aKey1, final String aKey2) { return new AjaxEventBehavior("onclick") { private static final long serialVersionUID = 1L; @Override/*from w w w .j a v a 2s .com*/ 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 { AgreementResult result = AgreementTable.this.getModelObject().getStudy(aKey1, aKey2); switch (settings.getObject().exportFormat) { case CSV: return generateCsvReport(result); case DEBUG: return generateDebugReport(result); default: throw new IllegalStateException("Unknown export format [" + settings.getObject().exportFormat + "]"); } } 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" + settings.getObject().exportFormat.getExtension()); } }; }
From source file:org.apache.openmeetings.web.admin.labels.LangPanel.java
License:Apache License
public LangPanel(String id) { super(id);//from w w w . j a v a 2s. c om // Create feedback panels add(feedback.setOutputMarkupId(true)); language = new AbstractMap.SimpleEntry<Long, Locale>(1L, Locale.ENGLISH); final LabelsForm form = new LabelsForm("form", this, new StringLabel(null, null)); form.showNewRecord(); add(form); final SearchableDataView<StringLabel> dataView = new SearchableDataView<StringLabel>("langList", new SearchableDataProvider<StringLabel>(LabelDao.class) { private static final long serialVersionUID = 1L; @Override protected LabelDao getDao() { return (LabelDao) super.getDao(); } @Override public long size() { return getDao().count(language.getValue(), search); } @Override public Iterator<? extends StringLabel> iterator(long first, long count) { return getDao().get(language.getValue(), search, (int) first, (int) count, getSort()) .iterator(); } }) { private static final long serialVersionUID = 1L; @Override protected void populateItem(final Item<StringLabel> item) { final StringLabel fv = item.getModelObject(); item.add(new Label("key")); item.add(new Label("value")); item.add(new AjaxEventBehavior("click") { private static final long serialVersionUID = 1L; @Override protected void onEvent(AjaxRequestTarget target) { form.setModelObject(fv); form.hideNewRecord(); target.add(form, listContainer); target.appendJavaScript("labelsInit();"); } }); item.add(AttributeModifier.append("class", getRowClass(fv.getId(), form.getModelObject().getId()))); } }; add(listContainer.add(dataView).setOutputMarkupId(true)); PagedEntityListPanel navigator = new PagedEntityListPanel("navigator", dataView) { private static final long serialVersionUID = 1L; @Override protected void onEvent(AjaxRequestTarget target) { dataView.modelChanging(); target.add(listContainer); } }; DataViewContainer<StringLabel> container = new DataViewContainer<StringLabel>(listContainer, dataView, navigator); container.addLink(new OmOrderByBorder<StringLabel>("orderByName", "key", container)) .addLink(new OmOrderByBorder<StringLabel>("orderByValue", "value", container)); add(container.getLinks()); add(navigator); langForm = new LangForm("langForm", listContainer, this); fileUploadField = new FileUploadField("fileInput"); langForm.add(fileUploadField); langForm.add(new UploadProgressBar("progress", langForm, fileUploadField)); fileUploadField.add(new AjaxFormSubmitBehavior(langForm, "change") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target) { FileUpload download = fileUploadField.getFileUpload(); try { if (download == null || download.getInputStream() == null) { feedback.error("File is empty"); return; } LabelDao.upload(language.getValue(), download.getInputStream()); } catch (Exception e) { log.error("Exception on panel language editor import ", e); feedback.error(e); } // repaint the feedback panel so that it is hidden target.add(listContainer, feedback); } }); // Add a component to download a file without page refresh final AjaxDownload download = new AjaxDownload(); langForm.add(download); langForm.add(new AjaxButton("export") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { final String name = LabelDao.getLabelFileName(language.getValue()); download.setFileName(name); download.setResourceStream(new AbstractResourceStream() { private static final long serialVersionUID = 1L; private transient InputStream is; @Override public InputStream getInputStream() throws ResourceStreamNotFoundException { try { is = Application.class.getResourceAsStream(name); return is; } catch (Exception e) { throw new ResourceStreamNotFoundException(e); } } @Override public void close() throws IOException { if (is != null) { is.close(); is = null; } } }); download.initiate(target); // repaint the feedback panel so that it is hidden target.add(feedback); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { // repaint the feedback panel so errors are shown target.add(feedback); } }); add(langForm); final AddLanguageDialog addLang = new AddLanguageDialog("addLang", this); add(addLang, new AjaxLink<Void>("addLangBtn") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { addLang.open(target); } }); add(BootstrapFileUploadBehavior.INSTANCE); }
From source file:org.apache.openmeetings.web.util.RecordingResourceReference.java
License:Apache License
@Override public IResource getResource() { return new AbstractResource() { private static final long serialVersionUID = 1L; private final static String ACCEPT_RANGES_HEADER = "Accept-Ranges"; private final static String RANGE_HEADER = "Range"; private final static String CONTENT_RANGE_HEADER = "Content-Range"; private final static String RANGES_BYTES = "bytes"; private File file; private boolean isRange = false; private long start = 0; private long end = 0; private long getChunkLength() { return isRange ? end - start + 1 : (file == null ? -1 : file.length()); }//from ww w. j a v a2s .co m private IResourceStream getResourceStream() { return file == null ? null : new FileResourceStream(file) { private static final long serialVersionUID = 2546785247219805747L; private transient BoundedInputStream bi; @Override public InputStream getInputStream() throws ResourceStreamNotFoundException { if (bi == null) { //bi = new BoundedInputStream(super.getInputStream(), end + 1); bi = new BoundedInputStream(super.getInputStream(), isRange ? end + 1 : (file == null ? -1 : file.length())); try { bi.skip(start); } catch (IOException e) { throw new ResourceStreamNotFoundException(e); } } return bi; } @Override public Bytes length() { return Bytes.bytes(getChunkLength()); } @Override public void close() throws IOException { if (bi != null) { bi.close(); //also will close original stream bi = null; } } @Override public String getContentType() { return RecordingResourceReference.this.getContentType(); } }; } @Override protected void setResponseHeaders(ResourceResponse data, Attributes attributes) { Response response = attributes.getResponse(); if (response instanceof WebResponse) { WebResponse webResponse = (WebResponse) response; webResponse.setStatus( isRange ? HttpServletResponse.SC_PARTIAL_CONTENT : HttpServletResponse.SC_OK); } super.setResponseHeaders(data, attributes); } @Override protected ResourceResponse newResourceResponse(Attributes attributes) { ResourceResponse rr = new ResourceResponse(); FlvRecording r = getRecording(attributes); if (r != null) { isRange = false; file = getFile(r); rr.setFileName(getFileName(r)); rr.setContentType(RecordingResourceReference.this.getContentType()); rr.setContentDisposition(ContentDisposition.INLINE); rr.setLastModified(Time.millis(file.lastModified())); rr.getHeaders().addHeader(ACCEPT_RANGES_HEADER, RANGES_BYTES); String range = ((HttpServletRequest) attributes.getRequest().getContainerRequest()) .getHeader(RANGE_HEADER); if (range != null && range.startsWith(RANGES_BYTES)) { String[] bounds = range.substring(RANGES_BYTES.length() + 1).split("-"); if (bounds != null && bounds.length > 0) { long length = file.length(); isRange = true; start = Long.parseLong(bounds[0]); end = bounds.length > 1 ? Long.parseLong(bounds[1]) : length - 1; //Content-Range: bytes 229376-232468/232469 rr.getHeaders().addHeader(CONTENT_RANGE_HEADER, String.format("%s %d-%d/%d", RANGES_BYTES, start, end, length)); } } rr.setContentLength(getChunkLength()); rr.setWriteCallback(new WriteCallback() { @Override public void writeData(Attributes attributes) throws IOException { IResourceStream rStream = getResourceStream(); try { writeStream(attributes, rStream.getInputStream()); } catch (ResourceStreamNotFoundException e1) { } catch (ResponseIOException e) { // in case of range operations we expecting such exceptions if (!isRange) { log.error("Error while playing the stream", e); } } finally { rStream.close(); } } }); } else { rr.setError(HttpServletResponse.SC_NOT_FOUND); } return rr; } }; }
From source file:org.hippoecm.frontend.resource.JcrResourceStream.java
License:Apache License
@Override public InputStream getInputStream() throws ResourceStreamNotFoundException { try {// w ww. jav a 2 s .c o m if (stream != null) { stream.close(); } Node node = getNode(); if (node != null) { stream = node.getProperty("jcr:data").getStream(); } else { stream = new ByteArrayInputStream(new byte[0]); } } catch (RepositoryException ex) { throw new ResourceStreamNotFoundException(ex); } catch (IOException ex) { throw new ResourceStreamNotFoundException(ex); } return stream; }
From source file:org.hippoecm.frontend.skin.IconUtil.java
License:Apache License
public static String svgAsString(PackageResourceReference reference, String... cssClasses) throws ResourceStreamNotFoundException, IOException { final PackageResource resource = reference.getResource(); final IResourceStream resourceStream = resource.getResourceStream(); if (resourceStream == null) { throw new ResourceStreamNotFoundException("Cannot find SVG icon " + resource); }//w w w . j a v a2s. c om String svgAsString = IOUtils.toString(resourceStream.getInputStream()); int rootIndex = svgAsString.indexOf("<svg"); if (rootIndex == -1) { throw new IllegalArgumentException("Cannot find SVG root element in " + resource); } //skip everything (comments, xml declaration and dtd definition) before <svg element svgAsString = svgAsString.substring(rootIndex); //append css classes if present final String cssClassesAsString = cssClassesAsString(cssClasses); if (StringUtils.isNotEmpty(cssClassesAsString)) { //check if class attribute is present and part of <svg element final int classAttributeIndex = svgAsString.indexOf("class=\""); if (classAttributeIndex > -1 && classAttributeIndex < svgAsString.indexOf(">")) { int insertCssClassesAt = classAttributeIndex + 7; svgAsString = svgAsString.substring(0, insertCssClassesAt) + cssClassesAsString + " " + svgAsString.substring(insertCssClassesAt); } else { svgAsString = "<svg class=\"" + cssClassesAsString + "\"" + svgAsString.substring(4); } } return svgAsString; }
From source file:org.sakaiproject.scorm.ui.player.util.ContentPackageResourceStream.java
License:Educational Community License
public InputStream getInputStream() throws ResourceStreamNotFoundException { try {/*from w w w. j a v a2s . c o m*/ in = resource.getInputStream(); if (in == null) throw new ResourceNotFoundException(resource.getPath()); } catch (ResourceNotFoundException rnfe) { log.error("Could not return input stream for resource: " + resource.getPath()); throw new ResourceStreamNotFoundException( "The requested resource was not found: " + resource.getPath()); } return in; }
From source file:org.syncope.console.commons.HttpResourceStream.java
License:Apache License
@Override public InputStream getInputStream() throws ResourceStreamNotFoundException { try {// w ww.j av a 2 s . c o m execute(); return responseEntity.getContent(); } catch (Exception e) { throw new ResourceStreamNotFoundException(e); } }