use of org.mozilla.jss.asn1.Tag in project omegat by omegat-org.
the class Handler method queueIgnoredTag.
/**
* Queue tag that should be ignored by editor, including content and all subtags.
*/
private void queueIgnoredTag(String tag, Attributes attributes) {
Tag xmltag = null;
setSpacePreservingTag(XMLUtils.convertAttributes(attributes));
if (xmltag == null) {
xmltag = new XMLTag(tag, getShortcut(tag), Tag.Type.BEGIN, attributes, this.translator);
xmlTagName.push(xmltag.getTag());
xmlTagAttributes.push(xmltag.getAttributes());
}
currEntry().add(xmltag);
}
use of org.mozilla.jss.asn1.Tag in project omegat by omegat-org.
the class XLIFFDialect method constructShortcuts.
@Override
public String constructShortcuts(List<Element> elements, List<ProtectedPart> protectedParts) {
protectedParts.clear();
// create shortcuts
InlineTagHandler tagHandler = new InlineTagHandler();
StringBuilder r = new StringBuilder();
for (Element el : elements) {
if (el instanceof XMLContentBasedTag) {
XMLContentBasedTag tag = (XMLContentBasedTag) el;
String shortcut = null;
int shortcutLetter;
int tagIndex;
boolean tagProtected;
if ("bpt".equals(tag.getTag())) {
// XLIFF specification requires 'rid' and 'id' attributes,
// but some tools uses 'i' attribute like for TMX
tagHandler.startBPT(tag.getAttribute("rid"), tag.getAttribute("id"), tag.getAttribute("i"));
shortcutLetter = calcTagShortcutLetter(tag, ignoreTypeForBptTags);
tagHandler.setTagShortcutLetter(shortcutLetter);
tagIndex = tagHandler.endBPT();
shortcut = "<" + (shortcutLetter != 0 ? String.valueOf(Character.toChars(shortcutLetter)) : 'f') + tagIndex + '>';
tagProtected = false;
} else if ("ept".equals(tag.getTag())) {
tagHandler.startEPT(tag.getAttribute("rid"), tag.getAttribute("id"), tag.getAttribute("i"));
tagIndex = tagHandler.endEPT();
shortcutLetter = tagHandler.getTagShortcutLetter();
shortcut = "</" + (shortcutLetter != 0 ? String.valueOf(Character.toChars(shortcutLetter)) : 'f') + tagIndex + '>';
tagProtected = false;
} else if ("it".equals(tag.getTag())) {
tagHandler.startOTHER();
tagHandler.setCurrentPos(tag.getAttribute("pos"));
tagIndex = tagHandler.endOTHER();
// XLIFF specification requires 'open/close' values,
// but some tools may use 'begin/end' values like for TMX
shortcutLetter = calcTagShortcutLetter(tag);
if ("close".equals(tagHandler.getCurrentPos()) || "end".equals(tagHandler.getCurrentPos())) {
// for better compatibility with corresponding TMX files
if (forceShortCutToF) {
shortcutLetter = 'f';
}
shortcut = "</" + (shortcutLetter != 0 ? String.valueOf(Character.toChars(shortcutLetter)) : 'f') + tagIndex + '>';
} else {
shortcut = "<" + (shortcutLetter != 0 ? String.valueOf(Character.toChars(shortcutLetter)) : 'f') + tagIndex + '>';
}
tagProtected = false;
} else if ("ph".equals(tag.getTag())) {
tagHandler.startOTHER();
tagIndex = tagHandler.endOTHER();
shortcutLetter = calcTagShortcutLetter(tag, ignoreTypeForPhTags);
shortcut = "<" + (shortcutLetter != 0 ? String.valueOf(Character.toChars(shortcutLetter)) : 'f') + tagIndex + "/>";
tagProtected = false;
} else if ("mrk".equals(tag.getTag())) {
tagHandler.startOTHER();
tagIndex = tagHandler.endOTHER();
shortcutLetter = 'm';
shortcut = "<m" + tagIndex + ">" + tag.getIntactContents().sourceToOriginal() + "</m" + tagIndex + ">";
tagProtected = true;
} else {
shortcutLetter = 'f';
tagIndex = -1;
tagProtected = false;
}
tag.setShortcutLetter(shortcutLetter);
tag.setShortcutIndex(tagIndex);
tag.setShortcut(shortcut);
r.append(shortcut);
ProtectedPart pp = new ProtectedPart();
pp.setTextInSourceSegment(shortcut);
pp.setDetailsFromSourceFile(tag.toOriginal());
if (tagProtected) {
// protected text with related tags, like <m0>Acme</m0>
if (StatisticsSettings.isCountingProtectedText()) {
// Protected texts are counted, but related tags are not counted in the word count
pp.setReplacementWordsCountCalculation(StaticUtils.TAG_REPLACEMENT + tag.getIntactContents().sourceToOriginal() + StaticUtils.TAG_REPLACEMENT);
} else {
// All protected parts are not counted in the word count(default)
pp.setReplacementWordsCountCalculation(StaticUtils.TAG_REPLACEMENT);
}
pp.setReplacementUniquenessCalculation(StaticUtils.TAG_REPLACEMENT);
pp.setReplacementMatchCalculation(tag.getIntactContents().sourceToOriginal());
} else {
// simple tag, like <i0>
if (StatisticsSettings.isCountingStandardTags()) {
pp.setReplacementWordsCountCalculation(tag.toSafeCalcShortcut());
} else {
pp.setReplacementWordsCountCalculation(StaticUtils.TAG_REPLACEMENT);
}
pp.setReplacementUniquenessCalculation(StaticUtils.TAG_REPLACEMENT);
pp.setReplacementMatchCalculation(StaticUtils.TAG_REPLACEMENT);
}
protectedParts.add(pp);
} else if (el instanceof Tag) {
Tag tag = (Tag) el;
int tagIndex = tagHandler.paired(tag.getTag(), tag.getType());
tag.setIndex(tagIndex);
String shortcut = tag.toShortcut();
r.append(shortcut);
ProtectedPart pp = new ProtectedPart();
pp.setTextInSourceSegment(shortcut);
pp.setDetailsFromSourceFile(tag.toOriginal());
if (StatisticsSettings.isCountingStandardTags()) {
pp.setReplacementWordsCountCalculation(tag.toSafeCalcShortcut());
} else {
pp.setReplacementWordsCountCalculation(StaticUtils.TAG_REPLACEMENT);
}
pp.setReplacementUniquenessCalculation(StaticUtils.TAG_REPLACEMENT);
pp.setReplacementMatchCalculation(StaticUtils.TAG_REPLACEMENT);
protectedParts.add(pp);
} else {
r.append(el.toShortcut());
}
}
return r.toString();
}
use of org.mozilla.jss.asn1.Tag in project omegat by omegat-org.
the class XLIFFFilterTest method testTags.
@Test
public void testTags() throws Exception {
String f = "test/data/filters/xliff/file-XLIFFFilter-tags.xlf";
IProject.FileInfo fi = loadSourceFiles(filter, f);
SourceTextEntry ste;
checkMultiStart(fi, f);
// #1988732
checkMultiNoPrevNext("Link to <m0>http://localhost</m0>.", null, null, null);
// #1988732
checkMultiNoPrevNext("About <b0>Gandalf</b0>", null, null, "7");
checkMultiNoPrevNext("<i0>Tags</i0> translation zz<i1>2</i1>z <b2>-NONTRANSLATED", null, null, null);
checkMultiNoPrevNext("one <a0> two </b1> three <c2> four </d3> five", null, null, null);
ste = checkMultiNoPrevNext("About <m0>Gandalf</m0> and <m1>other</m1>.", null, null, null);
assertEquals(3, ste.getProtectedParts().length);
assertEquals("<m0>Gandalf</m0>", ste.getProtectedParts()[0].getTextInSourceSegment());
assertEquals("<mrk mtype=\"protected\">Gandalf</mrk>", ste.getProtectedParts()[0].getDetailsFromSourceFile());
assertEquals("Gandalf", ste.getProtectedParts()[0].getReplacementMatchCalculation());
assertEquals("<m1>", ste.getProtectedParts()[1].getTextInSourceSegment());
assertEquals("<mrk mtype=\"other\">", ste.getProtectedParts()[1].getDetailsFromSourceFile());
assertEquals(StaticUtils.TAG_REPLACEMENT, ste.getProtectedParts()[1].getReplacementMatchCalculation());
assertEquals("</m1>", ste.getProtectedParts()[2].getTextInSourceSegment());
assertEquals("</mrk>", ste.getProtectedParts()[2].getDetailsFromSourceFile());
assertEquals(StaticUtils.TAG_REPLACEMENT, ste.getProtectedParts()[2].getReplacementMatchCalculation());
checkMultiNoPrevNext("one <o0>two</o0> three", null, null, null);
checkMultiNoPrevNext("one <t0/> three", null, null, null);
checkMultiNoPrevNext("one <w0/> three", null, null, null);
checkMultiNoPrevNext("Nested tags: before <g0><g1><x2/></g1></g0> after", null, null, null);
checkMultiNoPrevNext("<m0>Check protected-only tag reading</m0>", null, null, null);
checkMultiEnd();
File inFile = new File("test/data/filters/xliff/file-XLIFFFilter-tags.xlf");
filter.translateFile(inFile, outFile, new TreeMap<String, String>(), context, new ITranslateCallback() {
public String getTranslation(String id, String source, String path) {
return source.replace("NONTRANSLATED", "TRANSLATED");
}
public String getTranslation(String id, String source) {
return source.replace("NONTRANSLATED", "TRANSLATED");
}
public void linkPrevNextSegments() {
}
public void setPass(int pass) {
}
});
File trFile = new File(outFile.getPath() + "-translated");
List<String> lines = Files.lines(inFile.toPath()).map(line -> line.replace("NONTRANSLATED", "TRANSLATED")).collect(Collectors.toList());
Files.write(trFile.toPath(), lines);
compareXML(trFile, outFile);
}
use of org.mozilla.jss.asn1.Tag in project geowave by locationtech.
the class OsmXmlLoader method formatTags.
public static String formatTags(final Collection<Tag> tags) {
final StringBuilder sb = new StringBuilder(tags.size() * 20);
for (final Tag tag : tags) {
sb.append(", ");
sb.append(tag.getKey());
sb.append('=');
sb.append(tag.getValue());
}
if (sb.length() > 2) {
sb.delete(0, 2);
}
return sb.toString();
}
use of org.mozilla.jss.asn1.Tag in project opennms by OpenNMS.
the class MonitoringLocationsMigratorOffline method execute.
@Override
public void execute() throws OnmsUpgradeException {
if (monitoringLocationsConfig == null)
return;
log("Moving monitoring locations into the database...\n");
long count = 0;
try {
Connection connection = null;
final DBUtils dbUtils = new DBUtils(getClass());
try {
connection = DataSourceFactory.getInstance().getConnection();
dbUtils.watch(connection);
PreparedStatement insertLocation = connection.prepareStatement("INSERT INTO monitoringlocations (id, monitoringarea, geolocation, latitude, longitude, priority) VALUES (?,?,?,?,?,?)");
PreparedStatement insertPollingPackage = connection.prepareStatement("INSERT INTO monitoringlocationspollingpackages (monitoringlocationid, packagename) VALUES (?,?)");
PreparedStatement insertCollectionPackage = connection.prepareStatement("INSERT INTO monitoringlocationscollectionpackages (monitoringlocationid, packagename) VALUES (?,?)");
PreparedStatement insertTag = connection.prepareStatement("INSERT INTO monitoringlocationstags (monitoringlocationid, tag) VALUES (?,?)");
dbUtils.watch(insertLocation);
dbUtils.watch(insertPollingPackage);
dbUtils.watch(insertCollectionPackage);
dbUtils.watch(insertTag);
for (LocationDef location : monitoringLocationsConfig.getLocations()) {
// id
insertLocation.setString(1, location.getLocationName());
// monitoringarea
insertLocation.setString(2, location.getMonitoringArea());
if (location.getGeolocation() != null && !"".equals(location.getGeolocation().trim())) {
// geolocation
insertLocation.setString(3, location.getGeolocation());
} else {
insertLocation.setNull(3, Types.VARCHAR);
}
if (location.getCoordinates() != null && !"".equals(location.getCoordinates())) {
String[] latLong = location.getCoordinates().split(",");
if (latLong.length == 2) {
// latitude
insertLocation.setDouble(4, Double.valueOf(latLong[0]));
// longitude
insertLocation.setDouble(5, Double.valueOf(latLong[1]));
} else {
insertLocation.setNull(4, Types.DOUBLE);
insertLocation.setNull(5, Types.DOUBLE);
}
} else {
insertLocation.setNull(4, Types.DOUBLE);
insertLocation.setNull(5, Types.DOUBLE);
}
if (location.getPriority() == null) {
// priority
insertLocation.setNull(6, Types.INTEGER);
} else {
// priority
insertLocation.setLong(6, location.getPriority());
}
insertLocation.execute();
count++;
if (location.getPollingPackageName() != null && !"".equals(location.getPollingPackageName())) {
// monitoringlocationid
insertPollingPackage.setString(1, location.getLocationName());
// packagename
insertPollingPackage.setString(2, location.getPollingPackageName());
insertPollingPackage.execute();
}
if (location.getCollectionPackageName() != null && !"".equals(location.getCollectionPackageName())) {
// monitoringlocationid
insertCollectionPackage.setString(1, location.getLocationName());
// packagename
insertCollectionPackage.setString(2, location.getCollectionPackageName());
insertCollectionPackage.execute();
}
for (Tag tag : location.getTags()) {
if (tag.getName() != null && !"".equals(tag.getName().trim())) {
// monitoringlocationid
insertTag.setString(1, location.getLocationName());
// tag
insertTag.setString(2, tag.getName());
insertTag.execute();
}
}
}
} finally {
dbUtils.cleanUp();
}
} catch (Throwable e) {
throw new OnmsUpgradeException("Can't fix services configuration because " + e.getMessage(), e);
}
log("Moved %d monitoring locations into the database\n", count);
}
Aggregations