Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#4550 - Clean up code #4633

Merged
merged 1 commit into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.Serializable;
import java.lang.invoke.MethodHandles;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
Expand Down Expand Up @@ -55,7 +56,7 @@ public class ExportDocumentDialogContent
{
private static final long serialVersionUID = -2102136855109258306L;

private static final Logger LOG = LoggerFactory.getLogger(ExportDocumentDialogContent.class);
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

private @SpringBean DocumentImportExportService importExportService;
private @SpringBean DocumentService documentService;
Expand Down Expand Up @@ -100,9 +101,8 @@ private IResourceStream export()
{
File exportedFile = null;
try {
AnnotatorState s = state.getObject();
FormatSupport format = importExportService
.getFormatByName(preferences.getObject().format).get();
var s = state.getObject();
var format = importExportService.getFormatByName(preferences.getObject().format).get();
exportedFile = importExportService.exportAnnotationDocument(s.getDocument(),
s.getUser().getUsername(), format, s.getMode());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ default AnalysisEngineDescription getWriterDescription(Project aProject,
default void read(Project aProject, CAS cas, File aFile)
throws ResourceInitializationException, IOException, CollectionException
{
CollectionReaderDescription readerDescription = getReaderDescription(aProject, null);
var readerDescription = getReaderDescription(aProject, null);
addConfigurationParameters(readerDescription,
ResourceCollectionReaderBase.PARAM_SOURCE_LOCATION,
aFile.getParentFile().getAbsolutePath(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ void commonInit()
@Override
public void onRequest()
{
IResourceStream is = AjaxDownloadLink.this.getModelObject();
var 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;
var name = filename != null ? filename.getObject() : null;
if (name == null) {
if (is instanceof FileResourceStream) {
name = ((FileResourceStream) is).getFile().getName();
Expand All @@ -101,7 +101,7 @@ else if (is instanceof InputStreamResourceStream) {
}
}

ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(
var handler = new ResourceStreamRequestHandler(
AjaxDownloadLink.this.getModelObject(), name);
handler.setContentDisposition(ContentDisposition.ATTACHMENT);
getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(handler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class InputStreamResourceStream

private final InputStream inputStream;
private final String name;
private String contentType;

public InputStreamResourceStream(InputStream aInputStream)
{
Expand All @@ -43,6 +44,13 @@ public InputStreamResourceStream(InputStream aInputStream, String aName)
name = aName;
}

public InputStreamResourceStream(InputStream aInputStream, String aName, String aContentType)
{
inputStream = aInputStream;
name = aName;
contentType = aContentType;
}

@Override
public InputStream getInputStream() throws ResourceStreamNotFoundException
{
Expand All @@ -59,4 +67,20 @@ public void close() throws IOException
{
inputStream.close();
}

public InputStreamResourceStream setContentType(String aContentType)
{
contentType = aContentType;
return this;
}

@Override
public String getContentType()
{
if (contentType != null) {
return contentType;
}

return super.getContentType();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ private void actionCancel(AjaxRequestTarget aTarget)

private IResourceStream exportFullTypeSystemAsUimaXml()
{
try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
try (var bos = new ByteArrayOutputStream()) {
var tsd = annotationService.getFullProjectTypeSystem(getModelObject().getProject(),
false);
tsd.toXML(bos);
Expand Down