Search in sources :

Example 1 with TranslationException

use of org.eclipse.californium.proxy2.TranslationException in project omegat by omegat-org.

the class Searcher method searchFiles.

private void searchFiles() throws IOException {
    Path root = Paths.get(searchExpression.rootDir);
    FilterMaster fm = Core.getFilterMaster();
    final SearchCallback searchCallback = new SearchCallback(m_project.getProjectProperties());
    int depth = searchExpression.recursive ? Integer.MAX_VALUE : 0;
    Files.walk(root, depth, FileVisitOption.FOLLOW_LINKS).forEach(path -> {
        String filename = path.toString();
        FileInfo fi = new FileInfo();
        // determine actual file name w/ no root path info
        fi.filePath = root.relativize(path).toString();
        searchCallback.setCurrentFile(fi);
        try {
            fm.loadFile(filename, new FilterContext(m_project.getProjectProperties()), searchCallback);
        } catch (TranslationException | IOException ex) {
            Log.log(ex);
        }
        searchCallback.fileFinished();
        checkStop.checkInterrupted();
    });
}
Also used : Path(java.nio.file.Path) FileInfo(org.omegat.core.data.IProject.FileInfo) FilterMaster(org.omegat.filters2.master.FilterMaster) TranslationException(org.omegat.filters2.TranslationException) IOException(java.io.IOException) FilterContext(org.omegat.filters2.FilterContext)

Example 2 with TranslationException

use of org.eclipse.californium.proxy2.TranslationException in project omegat by omegat-org.

the class PdfFilterTest method testPasswordProtected.

@Test
public void testPasswordProtected() throws Exception {
    String f = "test/data/filters/pdf/file-PdfFilter-password.pdf";
    try {
        loadSourceFiles(new PdfFilter(), f);
        fail("Password-protected PDFs are not supported");
    } catch (TranslationException ex) {
    // OK
    }
}
Also used : TranslationException(org.omegat.filters2.TranslationException) PdfFilter(org.omegat.filters2.pdf.PdfFilter) Test(org.junit.Test)

Example 3 with TranslationException

use of org.eclipse.californium.proxy2.TranslationException in project omegat by omegat-org.

the class FilterMaster method translateFile.

/**
 * OmegaT core calls this method to translate a source file.
 * <ul>
 * <li>OmegaT first looks through registered filter instances to find filter(s) that can handle this file.
 * <li>Tests if filter(s) want to handle it.
 * <li>If the filter accepts the file,
 * <li>Filter is asked to process the file.
 * </ul>
 * If no filter is found, that processes this file, we simply copy it to target folder.
 *
 * @param sourcedir
 *            The folder of the source inFile.
 * @param filename
 *            The name of the source inFile to process (only the part, relative to source folder).
 * @param targetdir
 *            The folder to place the translated inFile to.
 * @param fc
 *            Filter context.
 */
public void translateFile(String sourcedir, String filename, String targetdir, FilterContext fc, ITranslateCallback translateCallback) throws IOException, TranslationException {
    LookupInformation lookup = lookupFilter(new File(sourcedir, filename), fc);
    if (lookup == null) {
        // The file is not supported by any of the filters.
        // Copying it
        FileUtils.copyFile(new File(sourcedir, filename), new File(targetdir, filename));
        return;
    }
    File inFile = new File(sourcedir, filename).getCanonicalFile();
    File outFile = new File(targetdir, getTargetForSource(filename, lookup, fc.getTargetLang())).getCanonicalFile();
    if (inFile.equals(outFile)) {
        throw new TranslationException(StringUtil.format(OStrings.getString("FILTERMASTER_ERROR_SRC_TRG_SAME_FILE"), inFile.getPath()));
    }
    fc.setInEncoding(lookup.outFilesInfo.getSourceEncoding());
    fc.setOutEncoding(lookup.outFilesInfo.getTargetEncoding());
    IFilter filterObject = lookup.filterObject;
    try {
        filterObject.translateFile(inFile, outFile, lookup.config, fc, translateCallback);
    } catch (Exception ex) {
        Log.log(ex);
    }
}
Also used : IFilter(org.omegat.filters2.IFilter) TranslationException(org.omegat.filters2.TranslationException) File(java.io.File) TranslationException(org.omegat.filters2.TranslationException) IOException(java.io.IOException)

Example 4 with TranslationException

use of org.eclipse.californium.proxy2.TranslationException in project omegat by omegat-org.

the class FilterMaster method loadFile.

/**
 * OmegaT core calls this method to load a source file.
 *
 * @param filename
 *            The name of the source file to load.
 * @return Whether the file was handled by one of OmegaT filters.
 * @see #translateFile(String, String, String, FilterContext,
 *      ITranslateCallback)
 */
public IFilter loadFile(String filename, FilterContext fc, IParseCallback parseCallback) throws IOException, TranslationException {
    IFilter filterObject = null;
    try {
        LookupInformation lookup = lookupFilter(new File(filename), fc);
        if (lookup == null) {
            return null;
        }
        File inFile = new File(filename);
        fc.setInEncoding(lookup.outFilesInfo.getSourceEncoding());
        fc.setOutEncoding(lookup.outFilesInfo.getTargetEncoding());
        filterObject = lookup.filterObject;
        filterObject.parseFile(inFile, lookup.config, fc, parseCallback);
    } catch (Exception ioe) {
        throw new IOException(filename + "\n" + ioe, ioe);
    }
    return filterObject;
}
Also used : IFilter(org.omegat.filters2.IFilter) IOException(java.io.IOException) File(java.io.File) TranslationException(org.omegat.filters2.TranslationException) IOException(java.io.IOException)

Example 5 with TranslationException

use of org.eclipse.californium.proxy2.TranslationException in project omegat by omegat-org.

the class ResourceBundleFilter method normalizeInputLine.

/**
 * Processes an input line for use in OmegaT by doing the following:
 * <ul>
 * <li>Converts ASCII-encoded \\uxxxx chars to normal characters.
 * <li>Converts \r, \n and \t to CR, line feed and tab.
 * <li>But! Keeps a backspace in '\ ', '\=', '\:', etc. (non-trimmable space
 * or non-key-value-breaking equals).
 * <ul>
 */
protected String normalizeInputLine(String line) throws IOException, TranslationException {
    // Whitespace at the beginning of lines is ignored
    boolean strippingWhitespace = true;
    StringBuilder result = new StringBuilder(line.length());
    for (int cp, len = line.length(), i = 0; i < len; i += Character.charCount(cp)) {
        cp = line.codePointAt(i);
        if (strippingWhitespace && (strippingWhitespace = Character.isWhitespace(cp))) {
            continue;
        }
        if (cp == '\\' && line.codePointCount(i, len) > 1) {
            i += Character.charCount(cp);
            cp = line.codePointAt(i);
            if (cp != 'u') {
                if (cp == 'n') {
                    cp = '\n';
                } else if (cp == 'r') {
                    cp = '\r';
                } else if (cp == 't') {
                    cp = '\t';
                } else {
                    result.append('\\');
                }
            } else if (dontUnescapeULiterals) {
                // Put back the \ we swallowed
                result.append('\\');
            } else {
                // checking if the string is long enough
                if (line.codePointCount(i, len) < 1 + 4) {
                    throw new TranslationException(OStrings.getString("RBFH_ERROR_ILLEGAL_U_SEQUENCE"));
                }
                int uStart = line.offsetByCodePoints(i, 1);
                int uEnd = line.offsetByCodePoints(uStart, 4);
                String uStr = line.substring(uStart, uEnd);
                try {
                    cp = Integer.parseInt(uStr, 16);
                    if (!Character.isValidCodePoint(cp)) {
                        throw new TranslationException(OStrings.getString("RBFH_ERROR_ILLEGAL_U_SEQUENCE"));
                    }
                    i = uEnd - Character.charCount(cp);
                } catch (NumberFormatException ex) {
                    throw new TranslationException(OStrings.getString("RBFH_ERROR_ILLEGAL_U_SEQUENCE"), ex);
                }
            }
        }
        result.appendCodePoint(cp);
    }
    return result.toString();
}
Also used : TranslationException(org.omegat.filters2.TranslationException)

Aggregations

TranslationException (org.omegat.filters2.TranslationException)16 TranslationException (org.eclipse.californium.proxy2.TranslationException)8 IOException (java.io.IOException)7 File (java.io.File)6 Request (org.eclipse.californium.core.coap.Request)5 URI (java.net.URI)4 InetSocketAddress (java.net.InetSocketAddress)3 Response (org.eclipse.californium.core.coap.Response)3 Test (org.junit.Test)3 BufferedReader (java.io.BufferedReader)2 FileOutputStream (java.io.FileOutputStream)2 InputStream (java.io.InputStream)2 ZipEntry (java.util.zip.ZipEntry)2 ZipFile (java.util.zip.ZipFile)2 ZipOutputStream (java.util.zip.ZipOutputStream)2 Option (org.eclipse.californium.core.coap.Option)2 IFilter (org.omegat.filters2.IFilter)2 XMLStreamReader (org.omegat.util.xml.XMLStreamReader)2 StringReader (java.io.StringReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1