Search in sources :

Example 46 with Tag

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);
}
Also used : Tag(org.omegat.filters3.Tag)

Example 47 with Tag

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();
}
Also used : ProtectedPart(org.omegat.core.data.ProtectedPart) XMLContentBasedTag(org.omegat.filters3.xml.XMLContentBasedTag) Element(org.omegat.filters3.Element) InlineTagHandler(org.omegat.util.InlineTagHandler) XMLTag(org.omegat.filters3.xml.XMLTag) Tag(org.omegat.filters3.Tag) XMLContentBasedTag(org.omegat.filters3.xml.XMLContentBasedTag)

Example 48 with Tag

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);
}
Also used : SourceTextEntry(org.omegat.core.data.SourceTextEntry) URISyntaxException(java.net.URISyntaxException) StatCount(org.omegat.core.statistics.StatCount) PatternConsts(org.omegat.util.PatternConsts) StaticUtils(org.omegat.util.StaticUtils) TranslationException(org.omegat.filters2.TranslationException) XMLTag(org.omegat.filters3.xml.XMLTag) Tag(org.omegat.filters3.Tag) Core(org.omegat.core.Core) Assert.fail(org.junit.Assert.fail) XLIFFFilter(org.omegat.filters3.xml.xliff.XLIFFFilter) Before(org.junit.Before) IProject(org.omegat.core.data.IProject) ITranslateCallback(org.omegat.filters2.ITranslateCallback) Files(java.nio.file.Files) Assert.assertTrue(org.junit.Assert.assertTrue) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) XLIFFOptions(org.omegat.filters3.xml.xliff.XLIFFOptions) Collectors(java.util.stream.Collectors) File(java.io.File) StatisticsSettings(org.omegat.core.statistics.StatisticsSettings) List(java.util.List) XLIFFDialect(org.omegat.filters3.xml.xliff.XLIFFDialect) TreeMap(java.util.TreeMap) Assert.assertFalse(org.junit.Assert.assertFalse) SAXException(org.xml.sax.SAXException) Preferences(org.omegat.util.Preferences) Assert.assertEquals(org.junit.Assert.assertEquals) ITranslateCallback(org.omegat.filters2.ITranslateCallback) SourceTextEntry(org.omegat.core.data.SourceTextEntry) File(java.io.File) IProject(org.omegat.core.data.IProject) Test(org.junit.Test)

Example 49 with Tag

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();
}
Also used : Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag)

Example 50 with Tag

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);
}
Also used : LocationDef(org.opennms.upgrade.implementations.monitoringLocations16.LocationDef) Connection(java.sql.Connection) DBUtils(org.opennms.core.utils.DBUtils) PreparedStatement(java.sql.PreparedStatement) Tag(org.opennms.upgrade.implementations.monitoringLocations16.Tag) OnmsUpgradeException(org.opennms.upgrade.api.OnmsUpgradeException)

Aggregations

Tag (org.openstreetmap.osmosis.core.domain.v0_6.Tag)66 SEQUENCE (org.mozilla.jss.asn1.SEQUENCE)23 CommonEntityData (org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData)23 WayNode (org.openstreetmap.osmosis.core.domain.v0_6.WayNode)17 IOException (java.io.IOException)16 Test (org.junit.Test)16 Node (org.openstreetmap.osmosis.core.domain.v0_6.Node)16 OsmUser (org.openstreetmap.osmosis.core.domain.v0_6.OsmUser)16 Way (org.openstreetmap.osmosis.core.domain.v0_6.Way)12 Date (java.util.Date)10 RelationMember (org.openstreetmap.osmosis.core.domain.v0_6.RelationMember)10 OsmosisRuntimeException (org.openstreetmap.osmosis.core.OsmosisRuntimeException)9 Relation (org.openstreetmap.osmosis.core.domain.v0_6.Relation)9 Tag (org.mozilla.jss.asn1.Tag)7 SQLException (java.sql.SQLException)6 ArrayList (java.util.ArrayList)6 EXPLICIT (org.mozilla.jss.asn1.EXPLICIT)6 Osmformat (crosby.binary.Osmformat)5 NodeContainer (org.openstreetmap.osmosis.core.container.v0_6.NodeContainer)5 Point (com.vividsolutions.jts.geom.Point)4