RequestedModuleNames implements IRequestedModuleNames { protected void unfoldModules(JSONObject modules, Map<Integer, String> sparseArray) throws IOException, JSONException { final String sourceMethod = "unfoldModules"; if (isTraceLogging) { log.entering(RequestedModuleNames.class.getName(), sourceMethod, new Object[]{modules, sparseArray}); } Iterator<?> it = modules.keys(); String[] prefixes = null; if (modules.containsKey(PLUGIN_PREFIXES_PROP_NAME)) { @SuppressWarnings("unchecked") Map<String, String> oPrefixes = (Map<String, String>) modules.get(PLUGIN_PREFIXES_PROP_NAME); prefixes = new String[oPrefixes.size()]; for (String key : oPrefixes.keySet()) { prefixes[Integer.parseInt(oPrefixes.get(key))] = key; } } while (it.hasNext()) { String key = (String) it.next(); if (!NON_PATH_PROP_PATTERN.matcher(key).find()) { unfoldModulesHelper(modules.get(key), key, prefixes, sparseArray); } } if (isTraceLogging) { log.exiting(RequestedModuleNames.class.getName(), sourceMethod, sparseArray); } } RequestedModuleNames(HttpServletRequest request, List<String> idList, byte[] idListHash); @Override List<String> getDeps(); @Override List<String> getModules(); @Override List<String> getPreloads(); @Override List<String> getScripts(); @Override List<String> getExcludes(); @Override String toString(); boolean isVersionError(); String toString(boolean decode); static public Pattern NON_PATH_PROP_PATTERN; static public String PLUGIN_PREFIXES_PROP_NAME; }
@Test public void testUnfoldModules() throws Exception { IAggregator mockAggregator = TestUtils.createMockAggregator(); HttpServletRequest request = TestUtils.createMockRequest(mockAggregator); EasyMock.replay(request, mockAggregator); RequestedModuleNames requestedNames = new RequestedModuleNames(request, null, null); JSONObject obj = new JSONObject("{foo:{bar:'0', baz:{xxx:'2', yyy:'1'}}, dir:'3'}"); Map<Integer, String> paths = new TreeMap<Integer, String>(); requestedNames.unfoldModules(obj, paths); Assert.assertArrayEquals(new String[] {"foo/bar", "foo/baz/yyy", "foo/baz/xxx", "dir" }, paths.values().toArray()); obj = new JSONObject("{'"+RequestedModuleNames.PLUGIN_PREFIXES_PROP_NAME+"':{'combo/text':'0', abc:'1'},foo:{bar:'0', baz:{xxx.txt:'1-0', yyy.txt:'2-1'}}}"); paths = new TreeMap<Integer, String>(); requestedNames.unfoldModules(obj, paths); Assert.assertArrayEquals(new String[] {"foo/bar", "combo/text!foo/baz/xxx.txt", "abc!foo/baz/yyy.txt"}, paths.values().toArray()); obj = new JSONObject("{foo:{bar:'0', baz:{xxx.txt:'1-combo/text', yyy.txt:'2-abc'}}}"); paths = new TreeMap<Integer, String>(); requestedNames.unfoldModules(obj, paths); Assert.assertArrayEquals(new String[] {"foo/bar", "combo/text!foo/baz/xxx.txt", "abc!foo/baz/yyy.txt"}, paths.values().toArray()); }