Search in sources :

Example 1 with XMLDialect

use of org.omegat.filters3.xml.XMLDialect in project omegat by omegat-org.

the class RelaxNGFilter method isFileSupported.

/**
 * Returns whether the file is supported by the filter by checking
 * RELAX NG element and namespace constraints.
 *
 * @return <code>true</code> or <code>false</code>
 */
public boolean isFileSupported(BufferedReader reader) {
    XMLDialect dialect = getDialect();
    if (dialect.getConstraints() == null || dialect.getConstraints().isEmpty()) {
        return true;
    }
    try {
        char[] cbuf = new char[OConsts.READ_AHEAD_LIMIT];
        int cbufLen = reader.read(cbuf);
        String buf = new String(cbuf, 0, cbufLen);
        return RelaxNGDialect.RELAXNG_ROOT_TAG.matcher(buf).find() && RelaxNGDialect.RELAXNG_XMLNS.matcher(buf).find();
    } catch (Exception e) {
        return false;
    }
}
Also used : XMLDialect(org.omegat.filters3.xml.XMLDialect)

Example 2 with XMLDialect

use of org.omegat.filters3.xml.XMLDialect in project omegat by omegat-org.

the class Typo3Filter method isFileSupported.

/**
 * Returns whether the file is supported by the filter, by checking root
 * tags constraints.
 *
 * @return <code>true</code> or <code>false</code>
 */
public boolean isFileSupported(BufferedReader reader) {
    XMLDialect dialect = getDialect();
    if (dialect.getConstraints() == null || dialect.getConstraints().isEmpty()) {
        return true;
    }
    try {
        char[] cbuf = new char[OConsts.READ_AHEAD_LIMIT];
        int cbufLen = reader.read(cbuf);
        String buf = new String(cbuf, 0, cbufLen);
        Matcher matcher = Typo3Dialect.TYPO3_ROOT_TAG.matcher(buf);
        if (matcher.find()) {
            // This a Typo3 main page...
            return true;
        } else {
            // Let's see if we have Typo3 secondary page...
            matcher = Typo3Dialect.TYPO3_ROOT_TAG2.matcher(buf);
            if (!matcher.find()) {
                return false;
            }
        }
    } catch (Exception e) {
        return false;
    }
    return true;
}
Also used : XMLDialect(org.omegat.filters3.xml.XMLDialect) Matcher(java.util.regex.Matcher)

Example 3 with XMLDialect

use of org.omegat.filters3.xml.XMLDialect in project omegat by omegat-org.

the class Entry method checkAndRecoverTags.

/**
 * Before setting translation checks whether the translation contains all
 * the same tags in weakly correct order. See
 * {@link #setTranslation(String, XMLDialect, List)} for details.
 */
private void checkAndRecoverTags(String translation, List<ProtectedPart> protectedParts) throws TranslationException {
    translatedEntry = new Entry(xmlDialect, handler);
    // /////////////////////////////////////////////////////////////////////
    // recovering tags
    List<TagUtil.Tag> shortTags = TagUtil.buildTagList(translation, protectedParts.toArray(new ProtectedPart[protectedParts.size()]));
    int pos = 0;
    for (TagUtil.Tag shortTag : shortTags) {
        if (pos < shortTag.pos) {
            translatedEntry.add(createTextInstance(translation.substring(pos, shortTag.pos)));
            pos = shortTag.pos;
        }
        for (int j = getFirstGood(); j <= getLastGood(); j++) {
            Element longElem = get(j);
            if (longElem instanceof Tag) {
                Tag longTag = (Tag) longElem;
                if (longTag.toShortcut().equals(shortTag.tag)) {
                    translatedEntry.add(longTag);
                    pos += shortTag.tag.length();
                    break;
                }
            }
        }
    // P.S. If shortcut tag isn't found, probably we should issue a
    // warning.
    }
    if (pos < translation.length()) {
        translatedEntry.add(createTextInstance(translation.substring(pos)));
    }
// /////////////////////////////////////////////////////////////////////
// checking tags
// TODO: implement checking
}
Also used : ProtectedPart(org.omegat.core.data.ProtectedPart) TagUtil(org.omegat.util.TagUtil) XMLContentBasedTag(org.omegat.filters3.xml.XMLContentBasedTag)

Example 4 with XMLDialect

use of org.omegat.filters3.xml.XMLDialect in project omegat by omegat-org.

the class DocBookFilter method isFileSupported.

/**
 * Returns whether the file is supported by the filter, by checking DB4
 * (DTD) or DB5 (Namespace) constraints.
 *
 * @return <code>true</code> or <code>false</code>
 */
public boolean isFileSupported(BufferedReader reader) {
    XMLDialect dialect = getDialect();
    if (dialect.getConstraints() == null || dialect.getConstraints().isEmpty()) {
        return true;
    }
    try {
        char[] cbuf = new char[OConsts.READ_AHEAD_LIMIT];
        int cbufLen = reader.read(cbuf);
        String buf = new String(cbuf, 0, cbufLen);
        return DocBookDialect.DOCBOOK_PUBLIC_DTD.matcher(buf).find() || DocBookDialect.DB5_XMLNS.matcher(buf).find();
    } catch (Exception e) {
        return false;
    }
}
Also used : XMLDialect(org.omegat.filters3.xml.XMLDialect)

Aggregations

XMLDialect (org.omegat.filters3.xml.XMLDialect)3 Matcher (java.util.regex.Matcher)1 ProtectedPart (org.omegat.core.data.ProtectedPart)1 XMLContentBasedTag (org.omegat.filters3.xml.XMLContentBasedTag)1 TagUtil (org.omegat.util.TagUtil)1