Z3950Catalog implements BibliographicCatalog { public static Z3950Catalog get(CatalogConfiguration c) { if (c == null || !TYPE.equals(c.getType())) { return null; } String host = null; int port = -1; String url = c.getUrl(); if (url != null) { try { URI uri = new URI(url); host = uri.getHost(); if (host == null || host.isEmpty()) { LOG.log(Level.SEVERE, "Missing host in URL.\n{0}", c); return null; } port = uri.getPort(); if (port == -1) { LOG.log(Level.SEVERE, "Missing port in URL.\n{0}", c); return null; } } catch (URISyntaxException ex) { LOG.log(Level.SEVERE, c.toString(), ex); return null; } } String base = c.getProperty(PROPERTY_BASE); String recordCharset = c.getProperty(PROPERTY_RECORD_CHARSET); Charset charset = null; if (recordCharset != null) { try { charset = Charset.forName(recordCharset); } catch (Exception ex) { LOG.log(Level.SEVERE, c.toString(), ex); } } Map<String, Z3950Field> fields = readFields(c); return new Z3950Catalog(host, port, base, charset, fields); } Z3950Catalog(String host, int port, String base, Charset recordCharset, Map<String, Z3950Field> fields); static Z3950Catalog get(CatalogConfiguration c); @Override List<MetadataItem> find(String fieldId, String value, Locale locale); static final String TYPE; }
@Test public void testGet() { final String host = "localhost"; final int port = 9991; final String base = "testbase"; final String recordCharset = "UTF-8"; final String id = "z3950"; CatalogConfiguration c = new CatalogConfiguration(id, "", new BaseConfiguration() {{ addProperty(CatalogConfiguration.PROPERTY_URL, "tcp: addProperty(CatalogConfiguration.PROPERTY_NAME, "test"); addProperty(CatalogConfiguration.PROPERTY_TYPE, Z3950Catalog.TYPE); addProperty(Z3950Catalog.PROPERTY_BASE, "testbase"); addProperty(Z3950Catalog.PROPERTY_RECORD_CHARSET, "UTF-8"); }}); Z3950Catalog result = Z3950Catalog.get(c); assertNotNull(result); assertEquals(host, result.getHost()); assertEquals(port, result.getPort()); assertEquals(base, result.getBase()); assertEquals(Charset.forName(recordCharset), result.getRecordCharset()); }