private void updateFilterConfigurationMapper() { if (fcMapper == null) { fcMapper = new FilterConfigurationMapper(); DefaultFilters.setMappings(fcMapper, true, true); } }
@Override public void addConfigurations (String filterClass) { addConfigurations(filterClass, null); }
public void addCustomConfiguration (String configId, IParameters parameters) { FilterConfiguration fc; fc = new FilterConfiguration(); fc.custom = true; fc.configId = configId; // Get the filter String[] res = splitFilterFromConfiguration(fc.configId); if ( res == null ) { // Cannot found the filter in the ID LOGGER.error("Cannot find filter ID in: {}. Cannot add configuration", configId); return; } // Create the filter (this assumes the base-name is the default config ID) tmpFilter = createFilter(res[0], tmpFilter); if ( tmpFilter == null ) { LOGGER.error("Cannot find filter with ID: {}. Cannot add configuration", res[0]); return; } // Set the data //fc.classLoader = (URLClassLoader) tmpFilter.getClass().getClassLoader(); fc.parametersLocation = fc.configId + CONFIGFILE_EXT; fc.filterClass = tmpFilter.getClass().getName(); fc.mimeType = tmpFilter.getMimeType(); fc.description = "Configuration "+fc.configId; // Temporary fc.name = fc.configId; // Temporary fc.parameters = parameters; addConfiguration(fc); }
/** * Updates the custom configurations for this mapper. This should * be called if the custom configurations directory has changed. */ public void updateCustomConfigurations () { File dir = new File(customParmsDir); String res[] = dir.list(new DefaultFilenameFilter(CONFIGFILE_EXT)); clearConfigurations(true); // Only custom configurations if ( res == null ) return; for ( int i=0; i<res.length; i++ ) { addCustomConfiguration(Util.getFilename(res[i], false)); } }
/** * Creates an instance of the filter for a given URL of a fprm file defining a * custom configuration. * @param customConfig the URL of a fprm file defining the custom configuration * the filter should be loaded from. The file extension should be .fprm. * The file name should follow the pattern of custom filter configurations, * i.e. contain a filter name like "okf_xmlstream@custom_config.fprm". * @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(URL customConfig) { FilterConfigurationMapper fcMapper = new FilterConfigurationMapper(); DefaultFilters.setMappings(fcMapper, true, true); return fcMapper.createFilter(addCustomConfig(fcMapper, customConfig)); }
public SdlPackageFilter () { super(); Parameters params = (Parameters)getParameters(); params.setMimeType(MIME_TYPE); params.setSimplifierRules(null); FilterConfigurationMapper fcMapper = new FilterConfigurationMapper(); fcMapper.addConfigurations("net.sf.okapi.filters.xliff.XLIFFFilter"); setFilterConfigurationMapper(fcMapper); configs = new ArrayList<>(); FilterConfiguration fc = new FilterConfiguration(getName(), MIME_TYPE, this.getClass().getName(), "SDL Trados Package Files", "SDL Trados 2017 SDLPPX and SDLRPX files", null, ".sdlppx;.sdlrpx;"); configs.add(fc); }
private void makeTempTM () { FilterConfigurationMapper fcMapper = new FilterConfigurationMapper(); FilterConfiguration fc = fcMapper.getDefaultConfigurationFromExtension( Util.getExtension(file.getName()));
/** * Adds to a given {@link FilterConfigurationMapper} object the custom configuration * defined in the fprm file denoted by a given URL. * @param fcMapper the given {@link FilterConfigurationMapper}. * @param customConfig the URL of a fprm file defining the custom configuration * the filter should be loaded from. The file extension should be .fprm. * The file name should follow the pattern of custom filter configurations, * i.e. contain a filter name like "okf_xmlstream@custom_config.fprm". * @return the configuration identifier or null if the configuration was not added. */ public static String addCustomConfig(FilterConfigurationMapper fcMapper, URL customConfig) { String configId = null; try { String path = customConfig.toURI().getPath(); String root = Util.getDirectoryName(path) + File.separator; configId = Util.getFilename(path, false); fcMapper.setCustomConfigurationsDirectory(root); fcMapper.addCustomConfiguration(configId); fcMapper.updateCustomConfigurations(); } catch (URISyntaxException e) { throw new OkapiIOException(e); } return configId; }
String[] res = splitFilterFromConfiguration(baseConfig.configId); if ( res == null ) { // Cannot create the configuration because of ID return null; IFilter filter = instantiateFilter(baseConfig, null); IParameters baseParams = getParameters(baseConfig, filter); if ( baseParams == null ) { // Filter without parameters return null;
public void addFromPlugins (PluginsManager pm) { java.util.List<PluginItem> list = pm.getList(); for ( PluginItem item : list ) { if ( item.getType() == PluginItem.TYPE_IFILTER ) { String paramsClassName = addConfigurations(item.getClassName(), pm.getClassLoader()); if ( item.getEditorDescriptionProvider() != null ) { addDescriptionProvider(item.getEditorDescriptionProvider(), paramsClassName); } if ( item.getParamsEditor() != null ) { addEditor(item.getParamsEditor(), paramsClassName); } } } }
String[] res = splitFilterFromConfiguration(config.configId); config.classLoader = configMap.containsKey(res[0]) ? configMap.get(res[0]).classLoader : null;
((FilterConfigurationMapper)fcMapper).updateCustomConfigurations();
public void addCustomConfiguration (String configId) { addCustomConfiguration(configId, null); }
/** * Creates an instance of the filter for a given configuration identifier * and loads its corresponding parameters. This method accepts a list of the * URLs of fprm files defining custom configurations, and can be used to create * a filter and configure its sub-filters in one call. * @param configId the filter configuration identifier. Can be either one of Okapi * default filter configurations or one of the custom configurations defined in * the fprm files. * @param customConfigs a list of the URLs of fprm files defining custom configurations. * Every file name should follow the pattern of custom filter configurations, * i.e. contain a filter name like "okf_xmlstream@custom_config.fprm". The file extension * should be .fprm. * @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, URL... customConfigs) { FilterConfigurationMapper fcMapper = new FilterConfigurationMapper(); DefaultFilters.setMappings(fcMapper, true, true); for (URL customConfig : customConfigs) { addCustomConfig(fcMapper, customConfig); } IFilter filter = fcMapper.createFilter(configId); filter.setFilterConfigurationMapper(fcMapper); return filter; }
@Override public void setDocumentInformation (String relativeInputPath, String filterConfigId, String filterParameters, String inputEncoding, String relativeTargetPath, String targetEncoding, ISkeletonWriter skelWriter) { if ( Util.isEmpty(filterConfigId) ) { manifest.addDocument(++docId, Manifest.EXTRACTIONTYPE_NONE, relativeInputPath, "", filterParameters, inputEncoding, relativeTargetPath, targetEncoding); } else { this.skelWriter = skelWriter; String res[] = FilterConfigurationMapper.splitFilterFromConfiguration(filterConfigId); manifest.addDocument(++docId, extractionType, relativeInputPath, res[0], filterParameters, inputEncoding, relativeTargetPath, targetEncoding); } }
/** * 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); }
/** * 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); }
/** * Default constructor */ public AbstractFilter() { // defaults setNewlineType("\n"); //$NON-NLS-1$ setMultilingual(false); setFilterConfigurationMapper(new FilterConfigurationMapper()); documentId = new IdGenerator(null, IdGenerator.START_DOCUMENT); }
fcMapper = new FilterConfigurationMapper(); DefaultFilters.setMappings(fcMapper, true, true);
public BasePlainTextFilter() { setFilterConfigurationMapper(new FilterConfigurationMapper()); codeFinder = new InlineCodeFinder();