diff --git a/core/src/main/java/lucee/runtime/config/ConfigAdmin.java b/core/src/main/java/lucee/runtime/config/ConfigAdmin.java index ea7856db22..596c34540a 100755 --- a/core/src/main/java/lucee/runtime/config/ConfigAdmin.java +++ b/core/src/main/java/lucee/runtime/config/ConfigAdmin.java @@ -942,7 +942,7 @@ public void removeRestMapping(String virtual) throws ExpressionException, Securi public void removeCustomTag(String virtual) throws SecurityException { checkWriteAccess(); - Array mappings = ConfigWebUtil.getAsArray("customTagMappings", root); + Array mappings = ConfigWebUtil.getAsArray(root, true, KeyConstants._virtual, KeyConstants._physical, false, "customTagMappings", "customTagPaths"); Key[] keys = mappings.keys(); Struct data; String v; @@ -981,7 +981,7 @@ private void _removeScheduledTask(String name) throws ExpressionException { public void removeComponentMapping(String virtual) throws SecurityException { checkWriteAccess(); - Array mappings = ConfigWebUtil.getAsArray("componentMappings", root); + Array mappings = ConfigWebUtil.getAsArray(root, true, KeyConstants._virtual, KeyConstants._physical, false, "componentMappings", "componentPaths"); Key[] keys = mappings.keys(); Struct data; String v; @@ -1032,7 +1032,7 @@ private void _updateCustomTag(String virtual, String physical, String archive, S throw new ExpressionException("physical must have a value when primary has value physical"); } - Array mappings = ConfigWebUtil.getAsArray("customTagMappings", root); + Array mappings = ConfigWebUtil.getAsArray(root, true, KeyConstants._virtual, KeyConstants._physical, false, "customTagMappings", "customTagPaths"); Key[] keys = mappings.keys(); // Update String v; @@ -1131,7 +1131,7 @@ private void _updateComponentMapping(String virtual, String physical, String arc throw new ExpressionException("physical must have a value when primary has value physical"); } - Array componentMappings = ConfigWebUtil.getAsArray("componentMappings", root); + Array componentMappings = ConfigWebUtil.getAsArray(root, true, KeyConstants._virtual, KeyConstants._physical, false, "componentMappings", "componentPaths"); Key[] keys = componentMappings.keys(); Struct el; diff --git a/core/src/main/java/lucee/runtime/config/ConfigWebFactory.java b/core/src/main/java/lucee/runtime/config/ConfigWebFactory.java index 6dac42c43d..e0a106a41d 100644 --- a/core/src/main/java/lucee/runtime/config/ConfigWebFactory.java +++ b/core/src/main/java/lucee/runtime/config/ConfigWebFactory.java @@ -2924,8 +2924,7 @@ else if (hasCS) { } } - // Struct customTag = ConfigWebUtil.getAsStruct("customTag", root); - Array ctMappings = ConfigWebUtil.getAsArray("customTagMappings", root); + Array ctMappings = ConfigWebUtil.getAsArray(root, true, KeyConstants._virtual, KeyConstants._physical, true, "customTagMappings", "customTagPaths"); // Web Mapping boolean hasSet = false; @@ -5267,7 +5266,8 @@ else if (configServer != null) { // sct.setEL("physical", "{lucee-config}/components/"); // Web Mapping - Array compMappings = ConfigWebUtil.getAsArray("componentMappings", root); + + Array compMappings = ConfigWebUtil.getAsArray(root, true, KeyConstants._virtual, KeyConstants._physical, false, "componentMappings", "componentPaths"); hasSet = false; Mapping[] mappings = null; if (hasAccess) { diff --git a/core/src/main/java/lucee/runtime/config/ConfigWebUtil.java b/core/src/main/java/lucee/runtime/config/ConfigWebUtil.java index e33487a290..b242a4c75c 100755 --- a/core/src/main/java/lucee/runtime/config/ConfigWebUtil.java +++ b/core/src/main/java/lucee/runtime/config/ConfigWebUtil.java @@ -1002,6 +1002,82 @@ public static Array getAsArray(String name, Struct sct) { return tmp; } + /** + * get an array that matches oe of the given key or creates the array in place + * + * @param input struct to look for the names + * @param convertStructToArray if true and the value is a struct, convert it to an array + * @param convertKey if the value is a struct the key of that strcut will be copied to the array + * with that name + * @param stringKey in case the array contains string values and this key is set, create a struct + * containing a key with the string as value + * @param names + * @return + * @throws PageException + */ + public static Array getAsArray(Struct input, boolean convertStructToArray, Key convertKey, Key stringKey, boolean replacePlaceHolder, String... names) { + Array arr = null; + if (input == null) return arr; + + Object obj; + for (String name: names) { + obj = input.get(KeyImpl.init(name), null); + if (obj instanceof Array && (arr = (Array) obj).size() > 0) { + if (name != names[0]) { + input.setEL(KeyImpl.init(names[0]), arr); + input.removeEL(KeyImpl.init(name)); + } + break; + } + if (arr == null && convertStructToArray && obj instanceof Struct) { + Struct sct = (Struct) obj; + arr = new ArrayImpl(); + input.setEL(KeyImpl.init(name), arr); + if (name != names[0]) { + input.setEL(KeyImpl.init(names[0]), arr); + input.removeEL(KeyImpl.init(name)); + } + Iterator> it = sct.entryIterator(); + Entry e; + Struct s; + Object v; + while (it.hasNext()) { + e = it.next(); + v = e.getValue(); + if (convertKey != null && v instanceof Struct) { + s = (Struct) v; + if (!s.containsKey(convertKey)) s.setEL(convertKey, e.getKey().getString()); + } + arr.appendEL(v); + } + break; + } + } + + // validate the array values + if (arr != null && stringKey != null) { + Key[] keys = arr.keys(); + Object val; + for (Key k: keys) { + val = arr.get(k, null); + if (val instanceof CharSequence) { + Struct sct = new StructImpl(); + sct.setEL(stringKey, val); + arr.setEL(k, sct); + } + } + } + else if (arr == null) { + arr = new ArrayImpl(); + input.setEL(KeyImpl.init(names[0]), arr); + return arr; + } + + if (replacePlaceHolder) return (Array) replaceConfigPlaceHolders(arr); + + return arr; + } + public static String getAsString(String name, Struct sct, String defaultValue) { if (sct == null) return defaultValue; Object obj = sct.get(KeyImpl.init(name), null); diff --git a/core/src/main/java/lucee/runtime/type/util/KeyConstants.java b/core/src/main/java/lucee/runtime/type/util/KeyConstants.java index 95b3066470..85f773aad1 100644 --- a/core/src/main/java/lucee/runtime/type/util/KeyConstants.java +++ b/core/src/main/java/lucee/runtime/type/util/KeyConstants.java @@ -2993,6 +2993,7 @@ public class KeyConstants { public static final Key _metric = KeyImpl._const("metric"); public static final Key _monitoring = KeyImpl._const("monitoring"); public static final Key _expression = KeyImpl._const("expression"); + public static final Key _physical = KeyImpl._const("physical"); private static Map _____keys; static {