Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge branch 'master' into review-2-rhbz953734
Browse files Browse the repository at this point in the history
Conflicts:
	zanata-war/src/main/java/org/zanata/action/ProjectIterationFilesAction.java
  • Loading branch information
Patrick Huang committed May 29, 2013
2 parents 466eab7 + 68606d7 commit be192c6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 36 deletions.
Expand Up @@ -266,13 +266,17 @@ public String uploadDocumentFile()
{
uploadPotFile();
}
else if (translationFileServiceImpl.hasAdapterFor(documentFileUpload.getFileName()))
{
uploadAdapterFile();
}
else
{
FacesMessages.instance().add(Severity.ERROR, "Unrecognized file extension for {0}.", documentFileUpload.getFileName());
DocumentType type = translationFileServiceImpl.getDocumentType(documentFileUpload.getFileName());
if (translationFileServiceImpl.hasAdapterFor(type))
{
uploadAdapterFile();
}
else
{
FacesMessages.instance().add(Severity.ERROR, "Unrecognized file extension for {0}.", documentFileUpload.getFileName());
}
}

// NB This needs to be done as for some reason seam is losing the
Expand Down Expand Up @@ -677,7 +681,7 @@ public String apply(@Nullable

private Optional<String> getOptionalParams()
{
return Optional.of(Strings.emptyToNull(documentFileUpload.getAdapterParams()));
return Optional.fromNullable(Strings.emptyToNull(documentFileUpload.getAdapterParams()));
}

/**
Expand Down
Expand Up @@ -235,7 +235,7 @@ private Optional<Response> checkUploadAllowed(String projectSlug, String iterati

private Optional<Response> checkValidUploadType(DocumentFileUploadForm uploadForm)
{
if (!uploadForm.getFileType().equals(".pot") && !translationFileServiceImpl.hasAdapterFor(uploadForm.getFileType()))
if (!uploadForm.getFileType().equals(".pot") && !translationFileServiceImpl.hasAdapterFor(DocumentType.typeFor(uploadForm.getFileType())))
{
return Optional.of(
Response.status(Status.BAD_REQUEST)
Expand Down Expand Up @@ -769,7 +769,7 @@ public Response uploadTranslationFile( @PathParam("projectSlug") String projectS

String fileType = uploadForm.getFileType();
boolean isPoFile = fileType.equals(".po");
if (!isPoFile && !translationFileServiceImpl.hasAdapterFor(fileType))
if (!isPoFile && !translationFileServiceImpl.hasAdapterFor(DocumentType.typeFor(fileType)))
{
return Response.status(Status.BAD_REQUEST)
.entity(new ChunkUploadResponse("The type \"" + fileType + "\" specified in form parameter 'type' is not valid for a translation file on this server."))
Expand Down
Expand Up @@ -103,26 +103,12 @@ Resource parseUpdatedAdapterDocumentFile(URI documentFile, String docId, String
*/
boolean hasAdapterFor(DocumentType type);

/**
* Check whether a handler for the given file type is available.
*
* @param fileNameOrExtension full filename with extension, or just extension
* @return
* @deprecated use {@link #hasAdapterFor(DocumentType)}s
*/
@Deprecated
boolean hasAdapterFor(String fileNameOrExtension);

Set<String> getSupportedExtensions();

/**
* @deprecated use {@link #getAdapterFor(DocumentType)}
*/
@Deprecated
FileFormatAdapter getAdapterFor(String fileNameOrExtension);

FileFormatAdapter getAdapterFor(DocumentType type);

DocumentType getDocumentType(String fileNameOrExtension);

/**
* Persist an input stream to a temporary file.
*
Expand Down
Expand Up @@ -265,12 +265,7 @@ public boolean hasAdapterFor(DocumentType type)
return DOCTYPEMAP.containsKey(type);
}

/**
* @deprecated use {@link #hasAdapterFor(DocumentType)}s
*/
@Deprecated
@Override
public boolean hasAdapterFor(String fileNameOrExtension)
private boolean hasAdapterFor(String fileNameOrExtension)
{
String extension = extractExtension(fileNameOrExtension);
if (extension == null)
Expand All @@ -285,12 +280,7 @@ public boolean hasAdapterFor(String fileNameOrExtension)
return hasAdapterFor(documentType);
}

/**
* @deprecated use {@link #getAdapterFor(DocumentType)}
*/
@Deprecated
@Override
public FileFormatAdapter getAdapterFor(String fileNameOrExtension)
private FileFormatAdapter getAdapterFor(String fileNameOrExtension)
{
// FIXME throw exception when not found

Expand All @@ -307,6 +297,12 @@ public FileFormatAdapter getAdapterFor(String fileNameOrExtension)
return getAdapterFor(documentType);
}

@Override
public DocumentType getDocumentType(String fileNameOrExtension)
{
return DocumentType.typeFor(extractExtension(fileNameOrExtension));
}

@Override
public FileFormatAdapter getAdapterFor(DocumentType type)
{
Expand Down

0 comments on commit be192c6

Please sign in to comment.