use of gen.core.filters.Filter in project omegat by omegat-org.
the class FilterMaster method cloneFilter.
/**
* Clone one filter's config for editing.
*
* @param f
* one filter's config
* @return new config instance
*/
public static Filter cloneFilter(Filter filter) {
Filter f = new Filter();
f.setClassName(filter.getClassName());
f.setEnabled(filter.isEnabled());
for (Files ff : filter.getFiles()) {
f.getFiles().add(cloneFiles(ff));
}
for (Option o : filter.getOption()) {
Option fo = new Option();
fo.setName(o.getName());
fo.setValue(o.getValue());
f.getOption().add(fo);
}
return f;
}
use of gen.core.filters.Filter in project omegat by omegat-org.
the class FilterMaster method lookupFilter.
/**
* Gets the filter according to the source filename provided. In case of failing to find a filter to
* handle the file returns <code>null</code>.
*
* In case of finding an appropriate filter it
* <ul>
* <li>Creates the filter (use <code>OneFilter.getFilter()</code> to get it)
* <li>Creates a reader (use <code>OneFilter.getReader()</code> to get it)
* <li>Checks whether the filter supports the file.
* </ul>
*
* @param inFile The full path to the source file
* @return The corresponding LookupInformation
*/
private LookupInformation lookupFilter(File inFile, FilterContext fc) throws TranslationException, IOException {
for (Filter f : config.getFilters()) {
if (!f.isEnabled()) {
continue;
}
for (Files ff : f.getFiles()) {
if (!matchesMask(inFile.getName(), ff.getSourceFilenameMask())) {
continue;
}
IFilter filterObject = getFilterInstance(f.getClassName());
if (filterObject == null) {
continue;
}
fc.setInEncoding(ff.getSourceEncoding());
fc.setOutEncoding(ff.getTargetEncoding());
// only for exist filters
Map<String, String> config = forFilter(f.getOption());
if (!filterObject.isFileSupported(inFile, config, fc)) {
break;
}
return new LookupInformation(filterObject, ff, config);
}
}
return null;
}
use of gen.core.filters.Filter in project omegat by omegat-org.
the class FilterMaster method isFileSupported.
/**
* Check to see if a file is supported by any filter. When
* <code>quick</code> is true, only the filename will be checked to see if
* it matches known supported patterns. When false, the filter may have to
* actually load some or all of the file in order to determine whether or
* not it is supported.
*
* @param file
* The file to check
* @param quick
* When true, check only the file name
* @return Whether or not the file is supported
*/
public boolean isFileSupported(File file, boolean quick) {
FilterContext fc = new FilterContext(null, null, true);
for (Filter f : config.getFilters()) {
if (!f.isEnabled()) {
continue;
}
for (Files ff : f.getFiles()) {
boolean matchesMask = matchesMask(file.getName(), ff.getSourceFilenameMask());
if (!matchesMask) {
continue;
}
if (quick && matchesMask) {
return true;
}
IFilter filterObject = getFilterInstance(f.getClassName());
if (filterObject == null) {
continue;
}
fc.setInEncoding(ff.getSourceEncoding());
fc.setOutEncoding(ff.getTargetEncoding());
// only for exist filters
Map<String, String> config = forFilter(f.getOption());
if (!filterObject.isFileSupported(file, config, fc)) {
break;
}
return true;
}
}
return false;
}
use of gen.core.filters.Filter in project omegat by omegat-org.
the class FilterMaster method addNewFiltersToConfig.
/**
* Adds new filters(which was not exist in config yet) into config.
*/
private static boolean addNewFiltersToConfig(final Filters conf) {
boolean result = false;
for (Class<?> fclass : filtersClasses) {
boolean found = false;
for (Filter fc : conf.getFilters()) {
if (fclass.getName().equals(fc.getClassName())) {
// filter already exist in config
found = true;
break;
}
}
if (!found) {
// filter not found in config
Filter f = getDefaultSettingsFromFilter(fclass.getName());
if (f != null) {
conf.getFilters().add(f);
result = true;
}
}
}
return result;
}
use of gen.core.filters.Filter in project omegat by omegat-org.
the class FiltersCustomizerController method doEdit.
private void doEdit(int row) {
if (!isEditable()) {
return;
}
Filter filter = getFilterAtRow(row);
FilterEditor editor = new FilterEditor(SwingUtilities.windowForComponent(panel), filter);
editor.setVisible(true);
if (editor.result != null) {
List<Filter> filters = editableFilters.getFilters();
filters.set(filters.indexOf(filter), editor.result);
}
}
Aggregations