public void initializeSubFilters () { // Now create the map of filter instances // (Based on the map of format to use) subFilterCols = new HashMap<>(); // Skip the loop if needed if ( formatCols == null ) return; // Else: do it for ( String configId : formatCols.values() ) { if ( fcMapper == null ) { throw new RuntimeException("You must specify a filter configuration mapper for this filter."); } if ( !subFilterCols.containsKey(configId) ) { IFilter sf = fcMapper.createFilter(configId); subFilterCols.put(configId, sf); } } }
/** * Creates an instance of the filter for a given configuration identifier * and loads its corresponding parameters. * @param filterClass class of the filter. * @param configId the filter configuration identifier. Can be either one of Okapi * default filter configurations or one of the built-in configurations defined in * the filter class. * @return a new {@link IFilter} object (with its parameters loaded) for the given * configuration identifier, or null if the object could not be created. */ public static IFilter createFilter(Class<? extends IFilter> filterClass, String configId) { IFilterConfigurationMapper fcMapper = new FilterConfigurationMapper(); DefaultFilters.setMappings(fcMapper, true, true); fcMapper.addConfigurations(filterClass.getName()); return fcMapper.createFilter(configId); }
fcMapper.clearConfigurations(false); fcMapper.clearDescriptionProviders(); fcMapper.clearEditors(); fcMapper.addConfigurations(value); if ( list.contains(key3) ) { value = res.getString(key3); fcMapper.addEditor(value, paramsClass); if ( list.contains(key3) ) { value = res.getString(key3); fcMapper.addDescriptionProvider(value, paramsClass);
public AutoXLIFFFilter() { fcMapper.addConfigurations("net.sf.okapi.filters.xliff.XLIFFFilter"); fcMapper.addConfigurations("net.sf.okapi.filters.xliff2.XLIFF2Filter"); }
/** * Creates an instance of the filter for a given configuration identifier * and loads its corresponding parameters. Only Okapi default filter configurations * are accepted. * @param configId the filter configuration identifier. Can only be one of default filter * configurations. * @return a new {@link IFilter} object (with its parameters loaded) for the given * configuration identifier, or null if the object could not be created. */ public static IFilter createFilter(String configId) { IFilterConfigurationMapper fcMapper = new FilterConfigurationMapper(); DefaultFilters.setMappings(fcMapper, true, true); return fcMapper.createFilter(configId); }
/** * Gets the sub-filter or null for a given file in the archive. * @param name the name of the file entry to check. * @return the instance of the {@link IFilter} to use for the given file, * or null if this file is not associated to a filter configuration and should * not be extracted. */ private IFilter getSubFilter (String name) { for (int i = 0; i < fileNames.length; i++) { String fname = fileNames[i]; if ( StringUtil.matchesWildcard(name, fname, true) ) { // Create sub-filter // If there is no instance possible we will get an error // but the process will not be stopped, the file will just be // treated as non-extractable return getFilterConfigurationMapper().createFilter(configIds[i]); } } return null; // File is not to be extracted }
private void readEntriesToCopy () { toCopy = new HashMap<String, ITextUnit>(); try (IFilter filter = fcMapper.createFilter(toCopyInput.getFilterConfigId(), null)) { // Open the second input for this batch item filter.open(toCopyInput); while ( filter.hasNext() ) { final Event event = filter.next(); if ( event.getEventType() == EventType.TEXT_UNIT ) { ITextUnit tu = event.getTextUnit(); String id = tu.getName(); if ( Util.isEmpty(id) ) { logger.warn("Entry without id detected in second file."); continue; } // Else: put in the hash table if ( toCopy.get(id) != null ) { logger.warn("Duplicate id detected: {}", id); continue; } toCopy.put(id, tu); } } } } }
public void processDocument (RawDocument rd) { rawDoc = rd; srcLoc = rawDoc.getSourceLocale(); trgLoc = rawDoc.getTargetLocale(); if ( !initDone ) { initialize(); } filter = fcMapper.createFilter(rd.getFilterConfigId(), filter); if ( filter == null ) { throw new OkapiException(String.format( "No filter available for the configuration '%s'.", rd.getFilterConfigId())); } processInput(); }
delegate = isXLIFF2 ? fcMapper.createFilter(params.getXLIFF20Config()) : fcMapper.createFilter(params.getXLIFF12Config()); delegate.setFilterConfigurationMapper(fcMapper); delegate.open(input, generateSkeleton);
filter = fcMapper.createFilter(rawDoc.getFilterConfigId());
private void initializeDocumentData () { filter2 = fcMapper.createFilter(rawDoc2.getFilterConfigId(), filter2); filter3 = fcMapper.createFilter( rawDoc3.getFilterConfigId(), filter3);
@Override protected void component_init() { // Commons, should be included in all descendants introducing own params params = getParameters(Parameters.class); // Throws OkapiBadFilterParametersException super.component_init(); // Initialization if ( params.useCodeFinder && ( codeFinder != null )) { codeFinder.fromString(params.codeFinderRules); codeFinder.compile(); } idGenerator = new IdGenerator(null, IdGenerator.TEXT_UNIT); idGenerator.createId(IdGenerator.TEXT_UNIT); subfilterIndex = 0; if ( params.subfilter != null ) { subFilter = getFilterConfigurationMapper().createFilter(params.subfilter, subFilter); } }
filter = fcMapper.createFilter(partConfiguration, filter);
private void getTargetTextUnits() { try (IFilter filter = fcMapper.createFilter(targetInput.getFilterConfigId(), null)) {
logger.info("Merging: {}", info.getRelativeInputPath()); filter = fcMapper.createFilter(info.getFilterId(), filter); if ( filter == null ) { throw new OkapiBadFilterInputException(String.format("Filter cannot be created (%s).", info.getFilterId()));
@SuppressWarnings("resource") @Override protected Event handleRawDocument(final Event event) { filter = fcMapper.createFilter(originalDocument.getFilterConfigId(), filter); if (filter == null) { throw new OkapiFilterCreationException(String.format(
IFilter newFilter = fcMapper.createFilter(params.getFilterConfigId()); if (newFilter == null) { throw new OkapiBadFilterParametersException("Cannot create a filter for the filter config ID specified in filter parameters");
IFilter sf = fcMapper.createFilter(configId, null); if ( sf == null ) { throw new OkapiBadFilterInputException(String.format("Could not instantiate subfilter '%s'.", configId));
filter1 = fcMapper.createFilter(filterConfigId); filter2 = fcMapper.createFilter(filterConfigId); if (filter1 == null) { throw new OkapiException("Unsupported filter type."); filter1 = fcMapper.createFilter(filterConfigId); filter1.open(initialDoc); filter2.open(tmpDoc);
IFilterWriter writer = null; try { filter = fcMapper.createFilter(rawDoc.getFilterConfigId()); filter.open(rawDoc); int tuIndex = 0;