use of org.apache.wicket.util.resource.FileResourceStream in project inception by inception-project.
the class FileSystemResource method respond.
@Override
public void respond(Attributes attributes) {
FileResourceStream fileResourceStream = new FileResourceStream(file);
ResourceStreamResource resource = new ResourceStreamResource(fileResourceStream);
resource.respond(attributes);
}
use of org.apache.wicket.util.resource.FileResourceStream in project inception by inception-project.
the class TagSetEditorPanel method export.
private FileResourceStream export() {
File exportFile = null;
if (exportFormat.getObject().equals(JSON_FORMAT)) {
try {
exportFile = File.createTempFile("exportedtagsets", ".json");
} catch (IOException e1) {
error("Unable to create temporary File!!");
return null;
}
if (isNull(selectedTagSet.getObject().getId())) {
error("Project not yet created. Please save project details first!");
} else {
TagSet tagSet = selectedTagSet.getObject();
ExportedTagSet exTagSet = new ExportedTagSet();
exTagSet.setDescription(tagSet.getDescription());
exTagSet.setLanguage(tagSet.getLanguage());
exTagSet.setName(tagSet.getName());
List<ExportedTag> exportedTags = new ArrayList<>();
for (Tag tag : annotationSchemaService.listTags(tagSet)) {
ExportedTag exportedTag = new ExportedTag();
exportedTag.setDescription(tag.getDescription());
exportedTag.setName(tag.getName());
exportedTags.add(exportedTag);
}
exTagSet.setTags(exportedTags);
try {
JSONUtil.generatePrettyJson(exTagSet, exportFile);
} catch (IOException e) {
error("File Path not found or No permision to save the file!");
}
info("TagSets successfully exported to :" + exportFile.getAbsolutePath());
}
} else if (exportFormat.getObject().equals(TAB_FORMAT)) {
TagSet tagSet = selectedTagSet.getObject();
try {
exportFile = File.createTempFile("exportedtagsets", ".txt");
} catch (IOException e1) {
error("Unable to create temporary File!!");
}
OutputStream os;
OutputStreamWriter osw;
BufferedWriter bw;
try {
String tagSetDescription = tagSet.getDescription() == null ? "" : tagSet.getDescription();
os = new FileOutputStream(exportFile);
osw = new OutputStreamWriter(os, "UTF-8");
bw = new BufferedWriter(osw);
bw.write(tagSet.getName() + "\t" + tagSetDescription.replace("\n", "\\n") + "\n");
bw.write(tagSet.getLanguage() + "\t" + " \n");
for (Tag tag : annotationSchemaService.listTags(tagSet)) {
String tagDescription = tag.getDescription() == null ? "" : tag.getDescription();
bw.write(tag.getName() + "\t" + tagDescription.replace("\n", "\\n") + "\n");
}
bw.flush();
bw.close();
} catch (FileNotFoundException e) {
error("The file for export not found " + ExceptionUtils.getRootCauseMessage(e));
} catch (UnsupportedEncodingException e) {
error("Unsupported encoding " + ExceptionUtils.getRootCauseMessage(e));
} catch (IOException e) {
error(ExceptionUtils.getRootCause(e));
}
}
return new FileResourceStream(exportFile);
}
use of org.apache.wicket.util.resource.FileResourceStream in project oc-explorer by devgateway.
the class FolderContentResource method respond.
public void respond(final Attributes attributes) {
PageParameters parameters = attributes.getParameters();
String fileName = parameters.get(PARAM_FILE_NAME).toString();
// we use FilenameUtils to prevent "security tricks", only a file name
// without path is allowed
File file = new File(rootFolder, FilenameUtils.getName(fileName));
FileResourceStream fileResourceStream = new FileResourceStream(file);
ResourceStreamResource resource = new ResourceStreamResource(fileResourceStream);
resource.respond(attributes);
}
use of org.apache.wicket.util.resource.FileResourceStream in project midpoint by Evolveum.
the class AjaxDownloadBehaviorFromFile method onRequest.
public void onRequest() {
final File file = initFile();
IResourceStream resourceStream = new FileResourceStream(new File(file));
getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(new ResourceStreamRequestHandler(resourceStream) {
@Override
public void respond(IRequestCycle requestCycle) {
try {
super.respond(requestCycle);
} finally {
if (removeFile) {
LOGGER.debug("Removing file '{}'.", file.getAbsolutePath());
Files.remove(file);
}
}
}
}.setFileName(file.getName()).setContentDisposition(ContentDisposition.ATTACHMENT).setCacheDuration(Duration.ofSeconds(1)));
}
use of org.apache.wicket.util.resource.FileResourceStream in project webanno by webanno.
the class TagSetEditorPanel method export.
private FileResourceStream export() {
File exportFile = null;
if (exportFormat.getObject().equals(ExportedTagSetConstant.JSON_FORMAT)) {
try {
exportFile = File.createTempFile("exportedtagsets", ".json");
} catch (IOException e1) {
error("Unable to create temporary File!!");
return null;
}
if (isNull(selectedTagSet.getObject().getId())) {
error("Project not yet created. Please save project details first!");
} else {
TagSet tagSet = selectedTagSet.getObject();
ExportedTagSet exTagSet = new ExportedTagSet();
exTagSet.setDescription(tagSet.getDescription());
exTagSet.setLanguage(tagSet.getLanguage());
exTagSet.setName(tagSet.getName());
List<ExportedTag> exportedTags = new ArrayList<>();
for (Tag tag : annotationSchemaService.listTags(tagSet)) {
ExportedTag exportedTag = new ExportedTag();
exportedTag.setDescription(tag.getDescription());
exportedTag.setName(tag.getName());
exportedTags.add(exportedTag);
}
exTagSet.setTags(exportedTags);
try {
JSONUtil.generatePrettyJson(exTagSet, exportFile);
} catch (IOException e) {
error("File Path not found or No permision to save the file!");
}
info("TagSets successfully exported to :" + exportFile.getAbsolutePath());
}
} else if (exportFormat.getObject().equals(ExportedTagSetConstant.TAB_FORMAT)) {
TagSet tagSet = selectedTagSet.getObject();
try {
exportFile = File.createTempFile("exportedtagsets", ".txt");
} catch (IOException e1) {
error("Unable to create temporary File!!");
}
OutputStream os;
OutputStreamWriter osw;
BufferedWriter bw;
try {
String tagSetDescription = tagSet.getDescription() == null ? "" : tagSet.getDescription();
os = new FileOutputStream(exportFile);
osw = new OutputStreamWriter(os, "UTF-8");
bw = new BufferedWriter(osw);
bw.write(tagSet.getName() + "\t" + tagSetDescription.replace("\n", "\\n") + "\n");
bw.write(tagSet.getLanguage() + "\t" + " \n");
for (Tag tag : annotationSchemaService.listTags(tagSet)) {
String tagDescription = tag.getDescription() == null ? "" : tag.getDescription();
bw.write(tag.getName() + "\t" + tagDescription.replace("\n", "\\n") + "\n");
}
bw.flush();
bw.close();
} catch (FileNotFoundException e) {
error("The file for export not found " + ExceptionUtils.getRootCauseMessage(e));
} catch (UnsupportedEncodingException e) {
error("Unsupported encoding " + ExceptionUtils.getRootCauseMessage(e));
} catch (IOException e) {
error(ExceptionUtils.getRootCause(e));
}
}
return new FileResourceStream(exportFile);
}
Aggregations