Skip to content

Commit

Permalink
okapi dependency update from V. 0.36 to 1.43.0 which is the latest ve…
Browse files Browse the repository at this point in the history
…rsion supporting java 8

extractNoteFromXMLComment fix - replaced textUnit.getProperty to textUnitUtils.getNote method

getNote fix - return textUnit.getProperty(NoteAnnotation.LOC_NOTE) if the property is not null

adding empty line at the end of the yaml files. The source file has the empty line at the end, so okapi version upgrade should have fixed it.

XLIFFNoteAnnotation was deprecated and removed. NoteAnnotation class came as a replacement for the old XLIFFNoteAnnotation class.

XLIFFNote was deprecated and removed. Note class came as a replacement for the old XLIFFNote class.

Property.NOTE string constant was deprecated and removed. It as replaced by NoteAnnotation.LOC_NOTE. The value of the string constant is no longer the same. Property.NOTE value was 'note' and NoteAnnotation.LOC_NOTE value is 'developer'
  • Loading branch information
hylstonnb committed Aug 29, 2023
1 parent 446350a commit d302d49
Show file tree
Hide file tree
Showing 17 changed files with 67 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ components:
schema:
type: string
pattern: ^\d+$
maxLength: 18
maxLength: 18
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ components:
schema:
type: string
pattern: ^\d+$
maxLength: 18
maxLength: 18
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ components:
schema:
type: string
pattern: ^\d+$
maxLength: 18
maxLength: 18
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.box.l10n.mojito.okapi;

import java.util.Objects;
import net.sf.okapi.common.annotation.XLIFFNoteAnnotation;
import net.sf.okapi.common.annotation.NoteAnnotation;
import net.sf.okapi.common.resource.ITextUnit;
import net.sf.okapi.common.resource.Property;
import net.sf.okapi.common.resource.TextContainer;
Expand Down Expand Up @@ -30,12 +30,12 @@ public String getNote(ITextUnit textUnit) {

if (textUnit != null) {

XLIFFNoteAnnotation xliffNoteAnnotation = textUnit.getAnnotation(XLIFFNoteAnnotation.class);

if (xliffNoteAnnotation == null) {
note = Objects.toString(textUnit.getProperty(Property.NOTE), null);
NoteAnnotation noteAnnotation = textUnit.getAnnotation(NoteAnnotation.class);
Property noteProp = textUnit.getProperty(NoteAnnotation.LOC_NOTE);
if (noteAnnotation == null || noteProp != null) {
note = Objects.toString(noteProp, null);
} else {
note = xliffNoteAnnotation.getNote(0).getNoteText();
note = noteAnnotation.getNote(0).getNoteText();
}
}

Expand All @@ -51,7 +51,7 @@ public String getNote(ITextUnit textUnit) {
public void setNote(ITextUnit textUnit, String note) {

if (textUnit != null) {
textUnit.setProperty(new Property(Property.NOTE, note));
textUnit.setProperty(new Property(NoteAnnotation.LOC_NOTE, note));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import net.sf.okapi.common.LocaleId;
import net.sf.okapi.common.filters.FilterConfiguration;
import net.sf.okapi.common.resource.ITextUnit;
import net.sf.okapi.common.resource.Property;
import net.sf.okapi.common.resource.RawDocument;
import net.sf.okapi.common.resource.TextUnit;
import net.sf.okapi.common.skeleton.GenericSkeleton;
Expand Down Expand Up @@ -198,7 +197,7 @@ protected void extractNoteFromXMLCommentInSkeletonIfNone(TextUnit textUnit) {

String skeleton = textUnit.getSkeleton().toString();

if (textUnit.getProperty(Property.NOTE) == null) {
if (textUnitUtils.getNote(textUnit) == null) {
String note = getNoteFromXMLCommentsInSkeleton(skeleton);
if (note != null) {
textUnitUtils.setNote(textUnit, note);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.box.l10n.mojito.okapi.filters;

import net.sf.okapi.common.annotation.NoteAnnotation;
import net.sf.okapi.common.resource.ITextUnit;
import net.sf.okapi.common.resource.Property;
import net.sf.okapi.filters.table.csv.CommaSeparatedValuesFilter;
Expand Down Expand Up @@ -45,7 +46,7 @@ public CSVFilter() {
@Override
protected boolean processTU(ITextUnit textUnit) {

Property note = textUnit.getProperty(Property.NOTE);
Property note = textUnit.getProperty(NoteAnnotation.LOC_NOTE);
if (note != null) {
String comments = note.toString();
char quote = "\"".charAt(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.sf.okapi.common.IParameters;
import net.sf.okapi.common.MimeTypeMapper;
import net.sf.okapi.common.Util;
import net.sf.okapi.common.annotation.NoteAnnotation;
import net.sf.okapi.common.encoder.EncoderManager;
import net.sf.okapi.common.exceptions.OkapiIOException;
import net.sf.okapi.common.exceptions.OkapiUnsupportedEncodingException;
Expand Down Expand Up @@ -268,7 +269,7 @@ private TextUnit readTextUnit() {
skel.append(data.toString());
textUnit = processKeyValueLine();
if (textUnit != null && comment != null) {
textUnit.setProperty(new Property(Property.NOTE, comment, true));
textUnit.setProperty(new Property(NoteAnnotation.LOC_NOTE, comment, true));
}
break;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sf.okapi.common.Event;
import net.sf.okapi.common.annotation.XLIFFNote;
import net.sf.okapi.common.annotation.XLIFFNoteAnnotation;
import net.sf.okapi.common.annotation.Note;
import net.sf.okapi.common.annotation.NoteAnnotation;
import net.sf.okapi.common.filters.FilterConfiguration;
import net.sf.okapi.common.resource.ITextUnit;
import net.sf.okapi.common.resource.RawDocument;
Expand Down Expand Up @@ -44,7 +44,7 @@ public class JSONFilter extends net.sf.okapi.filters.json.JSONFilter {
*/
boolean noteKeepOrReplace = false;

XLIFFNoteAnnotation xliffNoteAnnotation;
NoteAnnotation noteAnnotation;
UsagesAnnotation usagesAnnotation;
String currentKeyName;
String comment = null;
Expand Down Expand Up @@ -144,17 +144,17 @@ void extractUsageIfMatch(String value) {
}
}

void addXliffNote(String value) {
XLIFFNote xliffNote = new XLIFFNote(value);
xliffNote.setFrom(currentKeyName);
xliffNote.setAnnotates(XLIFFNote.Annotates.SOURCE);
void addNote(String value) {
Note note = new Note(value);
note.setFrom(currentKeyName);
note.setAnnotates(Note.Annotates.SOURCE);

if (xliffNoteAnnotation == null || noteKeepOrReplace) {
logger.debug("create the xliff note annotation");
xliffNoteAnnotation = new XLIFFNoteAnnotation();
if (noteAnnotation == null || noteKeepOrReplace) {
logger.debug("create the note annotation");
noteAnnotation = new NoteAnnotation();
}

xliffNoteAnnotation.add(xliffNote);
noteAnnotation.add(note);
}

void extractNoteIfMatch(String value) {
Expand All @@ -163,7 +163,7 @@ void extractNoteIfMatch(String value) {

if (m.matches()) {
logger.debug("key matches noteKeyPattern, add the value as note");
addXliffNote(value);
addNote(value);
}
}
}
Expand All @@ -172,10 +172,10 @@ void processComment() {
if (comment != null) {
ITextUnit textUnit = getEventTextUnit();
if (textUnit != null) {
String xliffNote = comment.replace("//", "").trim();
addXliffNote(xliffNote);
textUnit.setAnnotation(xliffNoteAnnotation);
xliffNoteAnnotation = null;
String note = comment.replace("//", "").trim();
addNote(note);
textUnit.setAnnotation(noteAnnotation);
noteAnnotation = null;
}
comment = null;
}
Expand All @@ -184,14 +184,14 @@ void processComment() {
@Override
public void handleObjectEnd() {

if (xliffNoteAnnotation != null || usagesAnnotation != null) {
if (noteAnnotation != null || usagesAnnotation != null) {

ITextUnit textUnit = getEventTextUnit();

if (textUnit != null) {
if (xliffNoteAnnotation != null) {
if (noteAnnotation != null) {
logger.debug("Set note on text unit with name: {}", textUnit.getName());
textUnit.setAnnotation(xliffNoteAnnotation);
textUnit.setAnnotation(noteAnnotation);
}

if (usagesAnnotation != null) {
Expand All @@ -203,10 +203,9 @@ public void handleObjectEnd() {
}
}

logger.debug(
"Reset the xliffNoteAnnotation and Usage Annotation if not using keepOrReplace option");
logger.debug("Reset the noteAnnotation and Usage Annotation if not using keepOrReplace option");
if (!noteKeepOrReplace) {
xliffNoteAnnotation = null;
noteAnnotation = null;
}

if (!usagesKeepOrReplace) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sf.okapi.common.*;
import net.sf.okapi.common.annotation.NoteAnnotation;
import net.sf.okapi.common.filters.FilterConfiguration;
import net.sf.okapi.common.resource.*;
import net.sf.okapi.common.skeleton.GenericSkeleton;
Expand Down Expand Up @@ -121,7 +122,7 @@ protected void extractNoteFromXMLCommentInSkeletonIfNone(TextUnit textUnit) {

String skeleton = textUnit.getSkeleton().toString();

if (textUnit.getProperty(Property.NOTE) == null) {
if (textUnit.getProperty(NoteAnnotation.LOC_NOTE) == null) {
String note = getNoteFromXMLCommentsInSkeleton(skeleton);
if (note != null) {
comment = note;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public Event handleEvent(Event event) {
switch (event.getEventType()) {
case START_DOCUMENT:
handleStartDocument(event);
return Event.NOOP_EVENT;
return Event.createNoopEvent();

case END_DOCUMENT:
return processEndDocument(event);
Expand All @@ -95,7 +95,7 @@ public Event handleEvent(Event event) {
case TEXT_UNIT:
// handle all the events between START_DOCUMENT and END_DOCUMENT
filterWriter.handleEvent(event);
return Event.NOOP_EVENT;
return Event.createNoopEvent();
}

// Else, just return the event
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<maven.compiler.version>3.5.1</maven.compiler.version>
<maven.deploy.version>2.8.2</maven.deploy.version>
<maven.release.version>2.5.3</maven.release.version>
<okapi.version>0.36</okapi.version>
<okapi.version>1.43.0</okapi.version>
<guava.version>29.0-jre</guava.version>
<hibernate.joda-time.version>1.4</hibernate.joda-time.version>
<usertype.core.version>6.0.1.GA</usertype.core.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.box.l10n.mojito.json.ObjectMapper;
import com.box.l10n.mojito.service.tm.ImportExportNote;
import java.io.IOException;
import net.sf.okapi.common.annotation.XLIFFNote;
import net.sf.okapi.common.annotation.XLIFFNoteAnnotation;
import net.sf.okapi.common.annotation.Note;
import net.sf.okapi.common.annotation.NoteAnnotation;
import net.sf.okapi.common.resource.ITextUnit;
import net.sf.okapi.common.resource.Property;
import net.sf.okapi.common.resource.TextUnit;
Expand Down Expand Up @@ -33,7 +33,7 @@ public class ImportExportTextUnitUtils {
public void setNote(ITextUnit textUnit, String note) {

if (textUnit != null) {
textUnit.setProperty(new Property(Property.NOTE, note));
textUnit.setProperty(new Property(NoteAnnotation.LOC_NOTE, note));
}
}

Expand Down Expand Up @@ -76,15 +76,15 @@ public void setImportExportNote(ITextUnit textUnit, ImportExportNote importExpor

String importExportNoteStr = objectMapper.writeValueAsStringUnchecked(importExportNote);

XLIFFNoteAnnotation xliffNoteAnnotation = textUnit.getAnnotation(XLIFFNoteAnnotation.class);
NoteAnnotation noteAnnotation = textUnit.getAnnotation(NoteAnnotation.class);

if (xliffNoteAnnotation == null) {
xliffNoteAnnotation = new XLIFFNoteAnnotation();
textUnit.setAnnotation(xliffNoteAnnotation);
if (noteAnnotation == null) {
noteAnnotation = new NoteAnnotation();
textUnit.setAnnotation(noteAnnotation);
} else {
setNote(textUnit, importExportNoteStr);
}

xliffNoteAnnotation.add(new XLIFFNote(importExportNoteStr));
noteAnnotation.add(new Note(importExportNoteStr));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected Event handleTextUnit(Event event) {
if (androidEvent == null) {
switch (getRemoveUntranslatedStrategyFromAnnotation()) {
case NOOP_EVENT:
event = Event.NOOP_EVENT;
event = Event.createNoopEvent();
break;
case PLACEHOLDER_AND_POST_PROCESSING:
logger.debug("Set untranslated placeholder for text unit with name: {}", name);
Expand Down
16 changes: 8 additions & 8 deletions webapp/src/main/java/com/box/l10n/mojito/okapi/XLIFFWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import net.sf.okapi.common.annotation.GenericAnnotations;
import net.sf.okapi.common.annotation.ITSLQIAnnotations;
import net.sf.okapi.common.annotation.ITSProvenanceAnnotations;
import net.sf.okapi.common.annotation.Note;
import net.sf.okapi.common.annotation.NoteAnnotation;
import net.sf.okapi.common.annotation.TermsAnnotation;
import net.sf.okapi.common.annotation.XLIFFNote;
import net.sf.okapi.common.annotation.XLIFFNoteAnnotation;
import net.sf.okapi.common.encoder.EncoderManager;
import net.sf.okapi.common.filterwriter.IFilterWriter;
import net.sf.okapi.common.filterwriter.ITSContent;
Expand Down Expand Up @@ -602,23 +602,23 @@ public void writeTextUnit(ITextUnit tu, String phaseName) {
}

// Notes
if (tu.hasProperty(Property.NOTE)) {
if (tu.hasProperty(NoteAnnotation.LOC_NOTE)) {
writer.writeStartElement("note");
writer.writeString(tu.getProperty(Property.NOTE).getValue());
writer.writeString(tu.getProperty(NoteAnnotation.LOC_NOTE).getValue());
writer.writeEndElementLineBreak(); // note
}
if (tu.hasProperty(Property.TRANSNOTE)) {
if (tu.hasProperty(NoteAnnotation.TRANS_NOTE)) {
writer.writeStartElement("note");
writer.writeAttributeString("from", "translator");
writer.writeString(tu.getProperty(Property.TRANSNOTE).getValue());
writer.writeString(tu.getProperty(NoteAnnotation.TRANS_NOTE).getValue());
writer.writeEndElementLineBreak(); // note
}

// CHANGES FOR MOJITO
XLIFFNoteAnnotation annotation = tu.getAnnotation(XLIFFNoteAnnotation.class);
NoteAnnotation annotation = tu.getAnnotation(NoteAnnotation.class);

if (annotation != null) {
XLIFFNote note = annotation.getNote(0);
Note note = annotation.getNote(0);
writer.writeStartElement("note");
writer.writeString(note.getNoteText());
writer.writeEndElementLineBreak();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public void disableAllChecks() {
setCheckXliffSchema(false);
setCheckPatterns(false);
setCheckWithLT(false);
setTranslateLTMsg(false);
setLtBilingualMode(false);
setDoubledWord(false);
setCorruptedCharacters(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import net.sf.okapi.common.EventType;
import net.sf.okapi.common.IParameters;
import net.sf.okapi.common.LocaleId;
import net.sf.okapi.common.annotation.XLIFFNote;
import net.sf.okapi.common.annotation.XLIFFNoteAnnotation;
import net.sf.okapi.common.annotation.Note;
import net.sf.okapi.common.annotation.NoteAnnotation;
import net.sf.okapi.common.encoder.EncoderManager;
import net.sf.okapi.common.filters.FilterConfiguration;
import net.sf.okapi.common.filters.IFilter;
Expand Down Expand Up @@ -235,10 +235,10 @@ private TextUnit getNextTextUnit() throws NoSuchElementException {
if (textUnitDTO.getComment() != null) {
importExportTextUnitUtils.setNote(textUnit, textUnitDTO.getComment());

XLIFFNoteAnnotation xliffNoteAnnotation = new XLIFFNoteAnnotation();
XLIFFNote xliffNote = new XLIFFNote(textUnitDTO.getComment());
xliffNoteAnnotation.add(xliffNote);
textUnit.getSource().setAnnotation(xliffNoteAnnotation);
NoteAnnotation noteAnnotation = new NoteAnnotation();
Note xliffNote = new Note(textUnitDTO.getComment());
noteAnnotation.add(xliffNote);
textUnit.getSource().setAnnotation(noteAnnotation);
}

return textUnit;
Expand Down
Loading

0 comments on commit d302d49

Please sign in to comment.