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 EnableChat
Browse files Browse the repository at this point in the history
Conflicts:
	zanata-war/src/main/java/org/zanata/webtrans/client/resources/WebTransMessages.java
  • Loading branch information
Alex Eng committed Jun 6, 2012
2 parents f71262f + 21c9f2e commit 67ca476
Show file tree
Hide file tree
Showing 8 changed files with 359 additions and 34 deletions.
Expand Up @@ -23,6 +23,7 @@
import java.io.InputStream;
import java.util.List;

import org.hibernate.validator.InvalidStateException;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
Expand Down Expand Up @@ -51,6 +52,8 @@
import org.zanata.service.TranslationFileService;
import org.zanata.service.TranslationService;

import javax.faces.context.FacesContext;

@Name("projectIterationFilesAction")
@Scope(ScopeType.PAGE)
public class ProjectIterationFilesAction
Expand Down Expand Up @@ -125,7 +128,7 @@ public TransUnitWords getTransUnitWordsForDocument(HDocument doc)
}

@Restrict("#{projectIterationFilesAction.fileUploadAllowed}")
public void uploadTranslationFile()
public String uploadTranslationFile()
{
TranslationsResource transRes = null;
try
Expand Down Expand Up @@ -156,10 +159,14 @@ public void uploadTranslationFile()
{
FacesMessages.instance().add(Severity.ERROR, zex.getMessage(), this.translationFileUpload.getFileName());
}

// NB This needs to be done as for some reason seam is losing the parameters when redirecting
// This is efectively the same as returning void
return FacesContext.getCurrentInstance().getViewRoot().getViewId();
}

@Restrict("#{projectIterationFilesAction.documentUploadAllowed}")
public void uploadDocumentFile()
public String uploadDocumentFile()
{
try
{
Expand All @@ -169,7 +176,7 @@ public void uploadDocumentFile()
// TODO Copy Trans values
// Extensions are hard-coded to GetText, since it is the only supported format at the time
this.documentServiceImpl.saveDocument(this.projectSlug, this.iterationSlug,
this.documentFileUpload.getDocumentPath() + doc.getName(), doc, new StringSet(ExtensionType.GetText.toString()),
doc, new StringSet(ExtensionType.GetText.toString()),
false);

FacesMessages.instance().add(Severity.INFO, "Document file {0} uploaded.", this.documentFileUpload.getFileName());
Expand All @@ -178,6 +185,14 @@ public void uploadDocumentFile()
{
FacesMessages.instance().add(Severity.ERROR, zex.getMessage(), this.documentFileUpload.getFileName());
}
catch (InvalidStateException isex)
{
FacesMessages.instance().add(Severity.ERROR, "Invalid arguments");
}

// NB This needs to be done as for some reason seam is losing the parameters when redirecting
// This is efectively the same as returning void
return FacesContext.getCurrentInstance().getViewRoot().getViewId();
}

public boolean isFileUploadAllowed()
Expand Down
Expand Up @@ -239,7 +239,7 @@ public Response post(Resource resource, @QueryParam("ext") Set<String> extension
// TODO No need for docId param since it's resource.getName()
document =
this.documentServiceImpl.saveDocument(
this.projectSlug, this.iterationSlug, resource.getName(), resource, extensions, copytrans);
this.projectSlug, this.iterationSlug, resource, extensions, copytrans);

EntityTag etag = eTagUtils.generateETagForDocument(hProjectIteration, document.getDocId(), extensions);

Expand Down Expand Up @@ -350,7 +350,8 @@ public Response putResource(@PathParam("id") String idNoSlash, Resource resource
response = Response.ok();
}

document = this.documentServiceImpl.saveDocument(projectSlug, iterationSlug, id, resource, extensions, copytrans);
resource.setName( id );
document = this.documentServiceImpl.saveDocument(projectSlug, iterationSlug, resource, extensions, copytrans);

EntityTag etag = eTagUtils.generateETagForDocument(hProjectIteration, document.getDocId(), extensions);

Expand Down
Expand Up @@ -35,13 +35,12 @@ public interface DocumentService
*
* @param projectSlug The document's project id.
* @param iterationSlug The document's project iteration id.
* @param docId The document id.
* @param sourceDoc The document contents.
* @param sourceDoc The document to save. (If the document's name matches a docId already stored, it will be overwritten)
* @param extensions Document extensions to save.
* @param copyTrans Whether to copy translations from other projects or not. A true value does not guarantee that
* this will happen, it is only a suggestion.
* @return The created / updated document
*/
public HDocument saveDocument( String projectSlug, String iterationSlug, String docId, Resource sourceDoc,
public HDocument saveDocument( String projectSlug, String iterationSlug, Resource sourceDoc,
Set<String> extensions, boolean copyTrans );
}
Expand Up @@ -68,31 +68,14 @@ public class DocumentServiceImpl implements DocumentService
private ApplicationConfiguration applicationConfiguration;


public DocumentServiceImpl()
{
}

public DocumentServiceImpl(ProjectIterationDAO projectIterationDAO,
DocumentDAO documentDAO,
LocaleService localeService,
CopyTransService copyTransService,
ResourceUtils resourceUtils,
ApplicationConfiguration applicationConfiguration)
{
this.projectIterationDAO = projectIterationDAO;
this.documentDAO = documentDAO;
this.localeServiceImpl = localeService;
this.copyTransServiceImpl = copyTransService;
this.resourceUtils = resourceUtils;
this.applicationConfiguration = applicationConfiguration;
}

public HDocument saveDocument( String projectSlug, String iterationSlug, String docId, Resource sourceDoc,
public HDocument saveDocument( String projectSlug, String iterationSlug, Resource sourceDoc,
Set<String> extensions, boolean copyTrans )
{
// Only active iterations allow the addition of a document
HProjectIteration hProjectIteration = projectIterationDAO.getBySlug(projectSlug, iterationSlug);

String docId = sourceDoc.getName();

HDocument document = documentDAO.getByDocIdAndIteration(hProjectIteration, docId);
HLocale hLocale = this.localeServiceImpl.validateSourceLocale( sourceDoc.getLang() );

Expand Down
Expand Up @@ -100,13 +100,15 @@ private Resource parsePotFile( InputStream fileContents, String docPath, String
PoReader2 poReader = new PoReader2();
// assume english as source locale
Resource res = poReader.extractTemplate(new InputSource(fileContents), new LocaleId("en"), fileName);
// trim extra spaces
docPath = docPath.trim();
// get rid of leading slashes ("/")
if( docPath.startsWith("/") )
while( docPath.startsWith("/") )
{
docPath = docPath.substring(1);
}
// Add a trailing slash ("/") if there isn't one
if( !docPath.endsWith("/") )
// Add a trailing slash ("/") if there isn't one, and there is a need for one
if( docPath.length() > 0 && !docPath.endsWith("/") )
{
docPath = docPath.concat("/");
}
Expand Down
Expand Up @@ -325,4 +325,14 @@ public interface WebTransMessages extends Messages

@DefaultMessage("Warning! This is a public channel")
String thisIsAPublicChannel();

@DefaultMessage("Only show documents that contain the search text with matching case")
String docListFilterCaseSensitiveDescription();

@DefaultMessage("Only show documents with full path and name in the search text")
String docListFilterExactMatchDescription();

@DefaultMessage("Enter text to filter the document list. Use commas (,) to separate multiple searches")
String docListFilterDescription();

}
Expand Up @@ -79,14 +79,18 @@ interface DocumentListViewUiBinder extends UiBinder<LayoutPanel, DocumentListVie
@Inject
public DocumentListView(Resources resources, WebTransMessages messages, UiMessages uiMessages, final CachingDispatchAsync dispatcher, EventBus eventBus)
{

this.resources = resources;
this.messages = messages;


dataProvider = new ListDataProvider<DocumentNode>();
filterTextBox = new ClearableTextBox(resources, uiMessages);
initWidget(uiBinder.createAndBindUi(this));
filterTextBox.setTitle(messages.docListFilterDescription());
// TODO set this from the presenter if possible
dataProvider = new ListDataProvider<DocumentNode>();
caseSensitiveCheckBox.setTitle(messages.docListFilterCaseSensitiveDescription());
exactSearchCheckBox.setTitle(messages.docListFilterExactMatchDescription());

initWidget(uiBinder.createAndBindUi(this));
}

@Override
Expand Down

0 comments on commit 67ca476

Please sign in to comment.