/** * Creates a new FilterConfigurationMapper object with no mappings and the * custom configuration directory set to the current directory. */ public FilterConfigurationMapper () { super(); configMap = new LinkedHashMap<String, FilterConfiguration>(); filters = new ArrayList<FilterInfo>(); String customDir; try { customDir = Util.getDirectoryName((new File(".")).getAbsolutePath()); } catch (SecurityException ex) { // Resolving "." will try to read the user.dir system property, // which is restricted in some scenarios so we fall back to // something safe in that case. See "Forbidden System Properties": // https://docs.oracle.com/javase/tutorial/deployment/doingMoreWithRIA/properties.html customDir = "/"; } setCustomConfigurationsDirectory(customDir); }
/** * 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; }