@Test public void testReadDictionary_dotConfig() throws Exception { final Map<String, Object> expectConfig = new HashMap<>(); expectConfig.put("foo", "bar"); expectConfig.put("foos", Stream.of("bar", "bar", "bar").toArray(String[]::new)); expectConfig.put("ones", Stream.of(1L, 1L, 1L).toArray(Long[]::new)); expectConfig.put("nothing", new String[0]); final String dotConfig = "foo=\"bar\"\n" + "foos=[\"bar\",\"bar\",\"bar\"]\n" + "ones=L[\"1\",\"1\",\"1\"]\n" + "nothing=[]"; final Map<String, Object> simpleConfig = DefaultSlingSimulator.readDictionary( new ByteArrayInputStream(dotConfig.getBytes(StandardCharsets.UTF_8)), "simple.config"); checkExpectedProperties(expectConfig, simpleConfig); }
static Map<String, Object> readDictionary( final InputStream is, final String id) throws IOException { final Map<String, Object> ht = new LinkedHashMap<>(); if (id.endsWith(".cfg.json")) { final String name = "jcrinstall:".concat(id); String configId; int pos = id.lastIndexOf('/'); if (pos == -1) { configId = id; } else { configId = id.substring(pos + 1); } pos = configId.indexOf('-'); if (pos != -1) { configId = configId.substring(0, pos).concat("~").concat(configId.substring(pos + 1)); } configId = removeConfigExtension(configId); try (final Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) { final Dictionary<String, Object> config = Configurations.buildReader() .withIdentifier(configId).build(reader).readConfiguration(); final Enumeration<String> i = config.keys(); while (i.hasMoreElements()) { final String key = i.nextElement(); ht.put(key, config.get(key)); } } } else { try (final BufferedInputStream in = new BufferedInputStream(is)) { if (id.endsWith(".config")) { in.mark(256); final int firstChar = in.read(); if (firstChar == '#') { int b; while ((b = in.read()) != '\n') { if (b == -1) { throw new IOException("Unable to read configuration."); } } } else { in.reset(); } @SuppressWarnings("unchecked") final Dictionary<String, Object> config = ConfigurationHandler.read(in); final Enumeration<String> i = config.keys(); while (i.hasMoreElements()) { final String key = i.nextElement(); ht.put(key, config.get(key)); } } else { final Properties p = new Properties(); in.mark(1); boolean isXml = in.read() == '<'; in.reset(); if (isXml) { p.loadFromXML(in); } else { p.load(in); } final Enumeration<Object> i = p.keys(); while (i.hasMoreElements()) { final Object key = i.nextElement(); ht.put(key.toString(), p.get(key)); } } } } return ht; }
DefaultSlingSimulator implements SlingSimulatorBackend, SlingSimulator { static Map<String, Object> readDictionary( final InputStream is, final String id) throws IOException { final Map<String, Object> ht = new LinkedHashMap<>(); if (id.endsWith(".cfg.json")) { final String name = "jcrinstall:".concat(id); String configId; int pos = id.lastIndexOf('/'); if (pos == -1) { configId = id; } else { configId = id.substring(pos + 1); } pos = configId.indexOf('-'); if (pos != -1) { configId = configId.substring(0, pos).concat("~").concat(configId.substring(pos + 1)); } configId = removeConfigExtension(configId); try (final Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) { final Dictionary<String, Object> config = Configurations.buildReader() .withIdentifier(configId).build(reader).readConfiguration(); final Enumeration<String> i = config.keys(); while (i.hasMoreElements()) { final String key = i.nextElement(); ht.put(key, config.get(key)); } } } else { try (final BufferedInputStream in = new BufferedInputStream(is)) { if (id.endsWith(".config")) { in.mark(256); final int firstChar = in.read(); if (firstChar == '#') { int b; while ((b = in.read()) != '\n') { if (b == -1) { throw new IOException("Unable to read configuration."); } } } else { in.reset(); } @SuppressWarnings("unchecked") final Dictionary<String, Object> config = ConfigurationHandler.read(in); final Enumeration<String> i = config.keys(); while (i.hasMoreElements()) { final String key = i.nextElement(); ht.put(key, config.get(key)); } } else { final Properties p = new Properties(); in.mark(1); boolean isXml = in.read() == '<'; in.reset(); if (isXml) { p.loadFromXML(in); } else { p.load(in); } final Enumeration<Object> i = p.keys(); while (i.hasMoreElements()) { final Object key = i.nextElement(); ht.put(key.toString(), p.get(key)); } } } } return ht; } }
DefaultSlingSimulator implements SlingSimulatorBackend, SlingSimulator { static Map<String, Object> readDictionary( final InputStream is, final String id) throws IOException { final Map<String, Object> ht = new LinkedHashMap<>(); if (id.endsWith(".cfg.json")) { final String name = "jcrinstall:".concat(id); String configId; int pos = id.lastIndexOf('/'); if (pos == -1) { configId = id; } else { configId = id.substring(pos + 1); } pos = configId.indexOf('-'); if (pos != -1) { configId = configId.substring(0, pos).concat("~").concat(configId.substring(pos + 1)); } configId = removeConfigExtension(configId); try (final Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) { final Dictionary<String, Object> config = Configurations.buildReader() .withIdentifier(configId).build(reader).readConfiguration(); final Enumeration<String> i = config.keys(); while (i.hasMoreElements()) { final String key = i.nextElement(); ht.put(key, config.get(key)); } } } else { try (final BufferedInputStream in = new BufferedInputStream(is)) { if (id.endsWith(".config")) { in.mark(256); final int firstChar = in.read(); if (firstChar == '#') { int b; while ((b = in.read()) != '\n') { if (b == -1) { throw new IOException("Unable to read configuration."); } } } else { in.reset(); } @SuppressWarnings("unchecked") final Dictionary<String, Object> config = ConfigurationHandler.read(in); final Enumeration<String> i = config.keys(); while (i.hasMoreElements()) { final String key = i.nextElement(); ht.put(key, config.get(key)); } } else { final Properties p = new Properties(); in.mark(1); boolean isXml = in.read() == '<'; in.reset(); if (isXml) { p.loadFromXML(in); } else { p.load(in); } final Enumeration<Object> i = p.keys(); while (i.hasMoreElements()) { final Object key = i.nextElement(); ht.put(key.toString(), p.get(key)); } } } } return ht; }  }
DefaultSlingSimulator implements SlingSimulatorBackend, SlingSimulator { static Map<String, Object> readDictionary( final InputStream is, final String id) throws IOException { final Map<String, Object> ht = new LinkedHashMap<>(); if (id.endsWith(".cfg.json")) { final String name = "jcrinstall:".concat(id); String configId; int pos = id.lastIndexOf('/'); if (pos == -1) { configId = id; } else { configId = id.substring(pos + 1); } pos = configId.indexOf('-'); if (pos != -1) { configId = configId.substring(0, pos).concat("~").concat(configId.substring(pos + 1)); } configId = removeConfigExtension(configId); try (final Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) { final Dictionary<String, Object> config = Configurations.buildReader() .withIdentifier(configId).build(reader).readConfiguration(); final Enumeration<String> i = config.keys(); while (i.hasMoreElements()) { final String key = i.nextElement(); ht.put(key, config.get(key)); } } } else { try (final BufferedInputStream in = new BufferedInputStream(is)) { if (id.endsWith(".config")) { in.mark(256); final int firstChar = in.read(); if (firstChar == '#') { int b; while ((b = in.read()) != '\n') { if (b == -1) { throw new IOException("Unable to read configuration."); } } } else { in.reset(); } @SuppressWarnings("unchecked") final Dictionary<String, Object> config = ConfigurationHandler.read(in); final Enumeration<String> i = config.keys(); while (i.hasMoreElements()) { final String key = i.nextElement(); ht.put(key, config.get(key)); } } else { final Properties p = new Properties(); in.mark(1); boolean isXml = in.read() == '<'; in.reset(); if (isXml) { p.loadFromXML(in); } else { p.load(in); } final Enumeration<Object> i = p.keys(); while (i.hasMoreElements()) { final Object key = i.nextElement(); ht.put(key.toString(), p.get(key)); } } } } return ht; }  static SlingSimulatorBackend instance(); @Override void startedScan(); @Override void setSession(final Session session); @Override void setPackageManager(final JcrPackageManager packageManager); @Override void setErrorListener(final ErrorListener errorListener); @Override @Nullable SlingInstallable dequeueInstallable(); @SuppressWarnings("unchecked") @Override @NotNull Fun.ThrowingSupplier<ResourceType> open(@NotNull final SlingOpenable<ResourceType> installable); @NotNull JcrPackage openEmbeddedPackage(@NotNull final EmbeddedPackageInstallable installable); @Override @Nullable SlingInstallable addInstallableNode(final @NotNull PackageId parentPackageId,
                                                         final @NotNull Node node); }
DefaultSlingSimulator implements SlingSimulatorBackend, SlingSimulator { static Map<String, Object> readDictionary( final InputStream is, final String id) throws IOException { final Map<String, Object> ht = new LinkedHashMap<>(); if (id.endsWith(".cfg.json")) { final String name = "jcrinstall:".concat(id); String configId; int pos = id.lastIndexOf('/'); if (pos == -1) { configId = id; } else { configId = id.substring(pos + 1); } pos = configId.indexOf('-'); if (pos != -1) { configId = configId.substring(0, pos).concat("~").concat(configId.substring(pos + 1)); } configId = removeConfigExtension(configId); try (final Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) { final Dictionary<String, Object> config = Configurations.buildReader() .withIdentifier(configId).build(reader).readConfiguration(); final Enumeration<String> i = config.keys(); while (i.hasMoreElements()) { final String key = i.nextElement(); ht.put(key, config.get(key)); } } } else { try (final BufferedInputStream in = new BufferedInputStream(is)) { if (id.endsWith(".config")) { in.mark(256); final int firstChar = in.read(); if (firstChar == '#') { int b; while ((b = in.read()) != '\n') { if (b == -1) { throw new IOException("Unable to read configuration."); } } } else { in.reset(); } @SuppressWarnings("unchecked") final Dictionary<String, Object> config = ConfigurationHandler.read(in); final Enumeration<String> i = config.keys(); while (i.hasMoreElements()) { final String key = i.nextElement(); ht.put(key, config.get(key)); } } else { final Properties p = new Properties(); in.mark(1); boolean isXml = in.read() == '<'; in.reset(); if (isXml) { p.loadFromXML(in); } else { p.load(in); } final Enumeration<Object> i = p.keys(); while (i.hasMoreElements()) { final Object key = i.nextElement(); ht.put(key.toString(), p.get(key)); } } } } return ht; }  static SlingSimulatorBackend instance(); @Override void startedScan(); @Override void setSession(final Session session); @Override void setPackageManager(final JcrPackageManager packageManager); @Override void setErrorListener(final ErrorListener errorListener); @Override @Nullable SlingInstallable dequeueInstallable(); @SuppressWarnings("unchecked") @Override @NotNull Fun.ThrowingSupplier<ResourceType> open(@NotNull final SlingOpenable<ResourceType> installable); @NotNull JcrPackage openEmbeddedPackage(@NotNull final EmbeddedPackageInstallable installable); @Override @Nullable SlingInstallable addInstallableNode(final @NotNull PackageId parentPackageId,
                                                         final @NotNull Node node);  }